Skip to content

Commit

Permalink
several changes after code reivew
Browse files Browse the repository at this point in the history
  • Loading branch information
adamhaeger committed Jun 20, 2024
1 parent 5eaeebe commit 0b5c9b2
Show file tree
Hide file tree
Showing 17 changed files with 57 additions and 97 deletions.
6 changes: 5 additions & 1 deletion src/codegen/Common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import { DEFAULT_DEBOUNCE_TIMEOUT } from 'src/features/formData/types';
import type { MaybeSymbolizedCodeGenerator } from 'src/codegen/CodeGenerator';

const common = {
ISummaryOverridesCommon: () => new CG.obj(new CG.prop('componentId', new CG.str())),
ISummaryOverridesCommon: () =>
new CG.obj(
new CG.prop('componentId', new CG.str()),
new CG.prop('hidden', new CG.expr(ExprVal.Boolean).optional()),
),
ILayoutFile: () =>
new CG.obj(
new CG.prop('$schema', new CG.str().optional()),
Expand Down
6 changes: 3 additions & 3 deletions src/features/datamodel/useBindingSchema.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@ export function useDataModelUrl(includeRowIds: boolean, dataType: string | undef
}

export function useCurrentDataModelName() {
const { overriddenDataModelId } = useTaskStore(({ overriddenDataModelId }) => ({ overriddenDataModelId }));
const { overriddenDataModelType } = useTaskStore(({ overriddenDataModelType }) => ({ overriddenDataModelType }));

const application = useApplicationMetadata();
const layoutSets = useLayoutSets();
const taskId = useProcessTaskId();

if (overriddenDataModelId) {
return overriddenDataModelId;
if (overriddenDataModelType) {
return overriddenDataModelType;
}

return getCurrentDataTypeForApplication({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
{
"id": "summary2",
"type": "Summary2",
"whatToRender": {
"target": {
"type": "component",
"id": "penger"
}
Expand Down
7 changes: 0 additions & 7 deletions src/layout/Checkboxes/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,6 @@ import { ExprVal } from 'src/features/expressions/types';
import { CompCategory } from 'src/layout/common';

export const CHECKBOX_SUMMARY_PROPS = new CG.obj(
new CG.prop(
'hidden',
new CG.bool()
.optional()
.setTitle('Hidden')
.setDescription('Boolean value indicating if the component should be hidden in the summary'),
),
new CG.prop(
'displayType',
new CG.enum('list', 'string')
Expand Down
2 changes: 1 addition & 1 deletion src/layout/Dropdown/DropdownSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type DropdownComponentSummaryProps = {
summaryOverrides?: CompDropdownInternal['summaryProps'];
};

export const DropdownSummary = ({ componentNode, displayData, summaryOverrides }: DropdownComponentSummaryProps) => {
export const DropdownSummary = ({ componentNode, displayData }: DropdownComponentSummaryProps) => {
const validations = useUnifiedValidationsForNode(componentNode);
const errors = validationsOfSeverity(validations, 'error');
const title = componentNode.item.textResourceBindings?.title;
Expand Down
10 changes: 1 addition & 9 deletions src/layout/Dropdown/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,7 @@ import { CG, Variant } from 'src/codegen/CG';
import { ExprVal } from 'src/features/expressions/types';
import { CompCategory } from 'src/layout/common';

export const DROPDOWN_SUMMARY_PROPS = new CG.obj(
new CG.prop(
'hidden',
new CG.bool()
.optional()
.setTitle('Hidden')
.setDescription('Boolean value indicating if the component should be hidden in the summary'),
),
)
export const DROPDOWN_SUMMARY_PROPS = new CG.obj()
.extends(CG.common('ISummaryOverridesCommon'))
.optional()
.setTitle('Summary properties')
Expand Down
13 changes: 12 additions & 1 deletion src/layout/Input/InputSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,21 @@ type InputComponentSummaryProps = {
summaryOverrides?: CompInputInternal['summaryProps'];
};

export const InputSummary = ({ componentNode, displayData, summaryOverrides }: InputComponentSummaryProps) => {
/*
* Hidden: Dersom hidden = true fjernes hele node fra hierarkiet.
* hvis vi da rendrer summary, vil fjernes også være fjernet fra summary
* Hvis vi da vil vise komponent kun på summary, er det vanskelig å få til.
*
*
* hideInSummary
*
* */

export const InputSummary = ({ componentNode, displayData }: InputComponentSummaryProps) => {
const validations = useUnifiedValidationsForNode(componentNode);
const errors = validationsOfSeverity(validations, 'error');
const title = componentNode.item.textResourceBindings?.title;

return (
<SingleValueSummary
title={title && <Lang id={title} />}
Expand Down
10 changes: 1 addition & 9 deletions src/layout/Input/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,7 @@ import { CG, Variant } from 'src/codegen/CG';
import { ExprVal } from 'src/features/expressions/types';
import { CompCategory } from 'src/layout/common';

export const INPUT_SUMMARY_PROPS = new CG.obj(
new CG.prop(
'hidden',
new CG.bool()
.optional()
.setTitle('Hidden')
.setDescription('Boolean value indicating if the component should be hidden in the summary'),
),
)
export const INPUT_SUMMARY_PROPS = new CG.obj()
.extends(CG.common('ISummaryOverridesCommon'))
.optional()
.setTitle('Summary properties')
Expand Down
7 changes: 0 additions & 7 deletions src/layout/MultipleSelect/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,6 @@ import { ExprVal } from 'src/features/expressions/types';
import { CompCategory } from 'src/layout/common';

export const MULTIPLE_SELECT_SUMMARY_PROPS = new CG.obj(
new CG.prop(
'hidden',
new CG.bool()
.optional()
.setTitle('Hidden')
.setDescription('Boolean value indicating if the component should be hidden in the summary'),
),
new CG.prop(
'displayType',
new CG.enum('list', 'string')
Expand Down
10 changes: 1 addition & 9 deletions src/layout/RadioButtons/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,7 @@ import { CG, Variant } from 'src/codegen/CG';
import { ExprVal } from 'src/features/expressions/types';
import { CompCategory } from 'src/layout/common';

export const RADIO_SUMMARY_PROPS = new CG.obj(
new CG.prop(
'hidden',
new CG.bool()
.optional()
.setTitle('Hidden')
.setDescription('Boolean value indicating if the component should be hidden in the summary'),
),
)
export const RADIO_SUMMARY_PROPS = new CG.obj()
.extends(CG.common('ISummaryOverridesCommon'))
.optional()
.setTitle('Summary properties')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export const MultipleValueSummary = ({
showAsList,
}: MultipleValueSummaryProps) => (
<div className={classes.checkboxSummaryItem}>
<pre>{JSON.stringify(displayData, null, 2)}</pre>

<div className={cn(classes.labelValueWrapper, { [classes.error]: errors.length > 0 })}>
<Label weight={'regular'}>{title}</Label>
{displayData && showAsList && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const SingleValueSummary = ({
})}
>
<span>
{!displayData && <Lang id={'general.empty_summary'}></Lang>}
{!displayData && <Lang id={'general.empty_summary'} />}
{displayData}
</span>
</Paragraph>
Expand Down
18 changes: 9 additions & 9 deletions src/layout/Summary2/SummaryComponent2/ComponentSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,16 @@ import type { LayoutNode } from 'src/utils/layout/LayoutNode';

interface ComponentSummaryProps {
componentNode: LayoutNode;
summaryOverrides?: CompSummary2Internal['overWriteProperties'];
summaryOverrides?: CompSummary2Internal['overrides'];
}

interface ResolveComponentProps {
summaryProps: CompSummary2External;
summaryOverrides?: any;
summaryOverrides?: CompSummary2Internal['overrides'];
}

export function ComponentSummary({ componentNode, summaryOverrides }: ComponentSummaryProps) {
if (componentNode.isHidden()) {
return null;
}
const override = summaryOverrides?.find((override) => override.componentId === componentNode.item.id);

const overrides = summaryOverrides?.find((override) => override.componentId === componentNode.item.id);
const childComponents =
componentNode.item.type === 'Group' &&
componentNode.item.childComponents.map((child) => (
Expand All @@ -36,13 +32,17 @@ export function ComponentSummary({ componentNode, summaryOverrides }: ComponentS
));

const renderedComponent = componentNode.def.renderSummary2
? componentNode.def.renderSummary2(componentNode as LayoutNode<any>, overrides)
? componentNode.def.renderSummary2(componentNode as LayoutNode<any>, override)
: null;

if (!renderedComponent) {
return null;
}

if (override?.hidden) {
return null;
}

return (
<Grid
item={true}
Expand All @@ -56,7 +56,7 @@ export function ComponentSummary({ componentNode, summaryOverrides }: ComponentS
}

export function ResolveComponent({ summaryProps, summaryOverrides }: ResolveComponentProps) {
const resolvedComponent = useNode(summaryProps.whatToRender.id);
const resolvedComponent = useNode(summaryProps.target.id);

if (!resolvedComponent) {
return null;
Expand Down
26 changes: 13 additions & 13 deletions src/layout/Summary2/SummaryComponent2/SummaryComponent2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,37 @@ export interface ISummaryComponent2 {
}

export function _SummaryComponent2({ summaryNode }: ISummaryComponent2) {
if (summaryNode.item.whatToRender.type === 'layoutSet') {
if (summaryNode.item.target.type === 'layoutSet') {
return (
<LayoutSetSummary
layoutSetId={summaryNode.item.whatToRender.id}
summaryOverrides={summaryNode.item.overWriteProperties}
layoutSetId={summaryNode.item.target.id}
summaryOverrides={summaryNode.item.overrides}
/>
);
}

if (summaryNode.item.whatToRender.type === 'page') {
if (summaryNode.item.target.type === 'page') {
return (
<PageSummary
pageId={summaryNode.item.whatToRender.id}
summaryOverrides={summaryNode.item.overWriteProperties}
pageId={summaryNode.item.target.id}
summaryOverrides={summaryNode.item.overrides}
/>
);
}

if (summaryNode.item.whatToRender.type === 'component') {
if (summaryNode.item.target.type === 'component') {
return (
<ResolveComponent
componentId={summaryNode.item.id}
summaryOverrides={summaryNode.item.overWriteProperties}
summaryProps={summaryNode.item}
summaryOverrides={summaryNode.item.overrides}
/>
);
}

if (summaryNode.item.whatToRender.type === 'task') {
const IDSplitted = summaryNode.item.whatToRender.id.split('>');
if (summaryNode.item.target.type === 'task') {
const IDSplitted = summaryNode.item.target.id.split('>');

const taskId = IDSplitted.length > 1 ? IDSplitted[0] : summaryNode.item.whatToRender.id;
const taskId = IDSplitted.length > 1 ? IDSplitted[0] : summaryNode.item.target.id;
const pageId = IDSplitted.length > 1 ? IDSplitted[1] : undefined;

const componentId = IDSplitted.length > 2 ? IDSplitted[2] : undefined;
Expand All @@ -53,7 +53,7 @@ export function _SummaryComponent2({ summaryNode }: ISummaryComponent2) {
taskId={taskId}
pageId={pageId}
componentId={componentId}
summaryOverrides={summaryNode.item.overWriteProperties}
summaryOverrides={summaryNode.item.overrides}
/>
</TaskIdStoreProvider>
);
Expand Down
25 changes: 3 additions & 22 deletions src/layout/Summary2/config.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CG, Variant } from 'src/codegen/CG';
import { CG } from 'src/codegen/CG';
import { CHECKBOX_SUMMARY_PROPS } from 'src/layout/Checkboxes/config';
import { CompCategory } from 'src/layout/common';
import { DROPDOWN_SUMMARY_PROPS } from 'src/layout/Dropdown/config';
Expand All @@ -19,26 +19,7 @@ export const Config = new CG.component({
})
.addProperty(
new CG.prop(
'children',
new CG.arr(new CG.str())
.optional()
.setTitle('Children')
.setDescription('Array of component IDs that should be displayed in the summary'),
).onlyIn(Variant.External),
)
.addProperty(new CG.prop('childComponents', new CG.arr(CG.layoutNode)).onlyIn(Variant.Internal))
.addProperty(
new CG.prop(
'children',
new CG.arr(new CG.str())
.optional()
.setTitle('Children')
.setDescription('Array of component IDs that should be displayed in the summary'),
).onlyIn(Variant.External),
)
.addProperty(
new CG.prop(
'whatToRender',
'target',
new CG.obj(
new CG.prop(
'type',
Expand All @@ -53,7 +34,7 @@ export const Config = new CG.component({
)
.addProperty(
new CG.prop(
'overWriteProperties',
'overrides',
new CG.arr(
new CG.union(
INPUT_SUMMARY_PROPS,
Expand Down
6 changes: 3 additions & 3 deletions src/layout/Summary2/taskIdStore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { create } from 'zustand';

interface TaskState {
overriddenTaskId?: string;
overriddenDataModelId?: string;
overriddenDataModelType?: string;
overriddenLayoutSetId?: string;
setOverriddenLayoutSetId?: (layoutSetId: string) => void;
setOverriddenDataModelId?: (taskId: string) => void;
Expand All @@ -17,12 +17,12 @@ interface TaskState {
export const createTaskIdStore = () =>
create<TaskState>((set) => ({
overriddenTaskId: '',
overriddenDataModelId: '',
overriddenDataModelType: '',
overriddenLayoutSetId: '',
depth: 1,
setTaskId: (overriddenTaskId: string) => set({ overriddenTaskId }),
setOverriddenLayoutSetId: (overriddenLayoutSetId: string) => set({ overriddenLayoutSetId }),
setOverriddenDataModelId: (overriddenDataModelId: string) => set({ overriddenDataModelId }),
setOverriddenDataModelId: (overriddenDataModelType: string) => set({ overriddenDataModelType }),
clearTaskId: () => set({ overriddenTaskId: '' }),
setDepth: (depth: number) => set({ depth }),
}));
Expand Down
2 changes: 1 addition & 1 deletion src/utils/layout/NodesContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ interface NodesContext {
setHiddenComponents: (mutator: (hidden: Set<string>) => Set<string>) => void;
}

export function initialCreateStore() {
function initialCreateStore() {
return createStore<NodesContext>((set) => ({
nodes: undefined,
setNodes: (nodes: LayoutPages) => set({ nodes }),
Expand Down

0 comments on commit 0b5c9b2

Please sign in to comment.