diff --git a/src/codegen/Common.ts b/src/codegen/Common.ts index 9cb57cba51..55841b7d73 100644 --- a/src/codegen/Common.ts +++ b/src/codegen/Common.ts @@ -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()), diff --git a/src/features/datamodel/useBindingSchema.tsx b/src/features/datamodel/useBindingSchema.tsx index 7d6f0b588b..8ad4c6be18 100644 --- a/src/features/datamodel/useBindingSchema.tsx +++ b/src/features/datamodel/useBindingSchema.tsx @@ -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({ diff --git a/src/features/expressions/shared-tests/functions/displayValue/summary2.json b/src/features/expressions/shared-tests/functions/displayValue/summary2.json index 35f1d9586f..ce220888dd 100644 --- a/src/features/expressions/shared-tests/functions/displayValue/summary2.json +++ b/src/features/expressions/shared-tests/functions/displayValue/summary2.json @@ -24,7 +24,7 @@ { "id": "summary2", "type": "Summary2", - "whatToRender": { + "target": { "type": "component", "id": "penger" } diff --git a/src/layout/Checkboxes/config.ts b/src/layout/Checkboxes/config.ts index 0a5ffe26c5..e5ad9abc40 100644 --- a/src/layout/Checkboxes/config.ts +++ b/src/layout/Checkboxes/config.ts @@ -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') diff --git a/src/layout/Dropdown/DropdownSummary.tsx b/src/layout/Dropdown/DropdownSummary.tsx index afcf4c5ae5..a7528bbb2f 100644 --- a/src/layout/Dropdown/DropdownSummary.tsx +++ b/src/layout/Dropdown/DropdownSummary.tsx @@ -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; diff --git a/src/layout/Dropdown/config.ts b/src/layout/Dropdown/config.ts index 93486c0a21..19227b7b4c 100644 --- a/src/layout/Dropdown/config.ts +++ b/src/layout/Dropdown/config.ts @@ -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') diff --git a/src/layout/Input/InputSummary.tsx b/src/layout/Input/InputSummary.tsx index 91929d0c9e..37d4663a24 100644 --- a/src/layout/Input/InputSummary.tsx +++ b/src/layout/Input/InputSummary.tsx @@ -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 ( } diff --git a/src/layout/Input/config.ts b/src/layout/Input/config.ts index b74f48cdb9..65b23b692a 100644 --- a/src/layout/Input/config.ts +++ b/src/layout/Input/config.ts @@ -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') diff --git a/src/layout/MultipleSelect/config.ts b/src/layout/MultipleSelect/config.ts index 732b51b02a..86cabe469b 100644 --- a/src/layout/MultipleSelect/config.ts +++ b/src/layout/MultipleSelect/config.ts @@ -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') diff --git a/src/layout/RadioButtons/config.ts b/src/layout/RadioButtons/config.ts index 54bdb3aa0c..82a5803bad 100644 --- a/src/layout/RadioButtons/config.ts +++ b/src/layout/RadioButtons/config.ts @@ -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') diff --git a/src/layout/Summary2/CommonSummaryComponents/MultipleValueSummary.tsx b/src/layout/Summary2/CommonSummaryComponents/MultipleValueSummary.tsx index c211631aa7..6067b7eb79 100644 --- a/src/layout/Summary2/CommonSummaryComponents/MultipleValueSummary.tsx +++ b/src/layout/Summary2/CommonSummaryComponents/MultipleValueSummary.tsx @@ -25,6 +25,8 @@ export const MultipleValueSummary = ({ showAsList, }: MultipleValueSummaryProps) => (
+
{JSON.stringify(displayData, null, 2)}
+
0 })}> {displayData && showAsList && ( diff --git a/src/layout/Summary2/CommonSummaryComponents/SingleValueSummary.tsx b/src/layout/Summary2/CommonSummaryComponents/SingleValueSummary.tsx index 29d472b6d5..72f9c7af0d 100644 --- a/src/layout/Summary2/CommonSummaryComponents/SingleValueSummary.tsx +++ b/src/layout/Summary2/CommonSummaryComponents/SingleValueSummary.tsx @@ -36,7 +36,7 @@ export const SingleValueSummary = ({ })} > - {!displayData && } + {!displayData && } {displayData} diff --git a/src/layout/Summary2/SummaryComponent2/ComponentSummary.tsx b/src/layout/Summary2/SummaryComponent2/ComponentSummary.tsx index b6c865308e..5a7a25431b 100644 --- a/src/layout/Summary2/SummaryComponent2/ComponentSummary.tsx +++ b/src/layout/Summary2/SummaryComponent2/ComponentSummary.tsx @@ -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) => ( @@ -36,13 +32,17 @@ export function ComponentSummary({ componentNode, summaryOverrides }: ComponentS )); const renderedComponent = componentNode.def.renderSummary2 - ? componentNode.def.renderSummary2(componentNode as LayoutNode, overrides) + ? componentNode.def.renderSummary2(componentNode as LayoutNode, override) : null; if (!renderedComponent) { return null; } + if (override?.hidden) { + return null; + } + return ( ); } - if (summaryNode.item.whatToRender.type === 'page') { + if (summaryNode.item.target.type === 'page') { return ( ); } - if (summaryNode.item.whatToRender.type === 'component') { + if (summaryNode.item.target.type === 'component') { return ( ); } - 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; @@ -53,7 +53,7 @@ export function _SummaryComponent2({ summaryNode }: ISummaryComponent2) { taskId={taskId} pageId={pageId} componentId={componentId} - summaryOverrides={summaryNode.item.overWriteProperties} + summaryOverrides={summaryNode.item.overrides} /> ); diff --git a/src/layout/Summary2/config.tsx b/src/layout/Summary2/config.tsx index 0ef57e351f..b052c3ef22 100644 --- a/src/layout/Summary2/config.tsx +++ b/src/layout/Summary2/config.tsx @@ -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'; @@ -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', @@ -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, diff --git a/src/layout/Summary2/taskIdStore.tsx b/src/layout/Summary2/taskIdStore.tsx index 0f0e535ce8..5a651c735e 100644 --- a/src/layout/Summary2/taskIdStore.tsx +++ b/src/layout/Summary2/taskIdStore.tsx @@ -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; @@ -17,12 +17,12 @@ interface TaskState { export const createTaskIdStore = () => create((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 }), })); diff --git a/src/utils/layout/NodesContext.tsx b/src/utils/layout/NodesContext.tsx index 52d0f39644..2dbd8f0156 100644 --- a/src/utils/layout/NodesContext.tsx +++ b/src/utils/layout/NodesContext.tsx @@ -27,7 +27,7 @@ interface NodesContext { setHiddenComponents: (mutator: (hidden: Set) => Set) => void; } -export function initialCreateStore() { +function initialCreateStore() { return createStore((set) => ({ nodes: undefined, setNodes: (nodes: LayoutPages) => set({ nodes }),