From ff2234967676b449989b78f464bfb22f6299109a Mon Sep 17 00:00:00 2001 From: Jonas Dyrlie Date: Wed, 12 Feb 2025 12:31:28 +0100 Subject: [PATCH 1/3] feat(summary2): add new props to overrides Adds a new property to overrides for RepeatingGroup and Subform `display`. This property has a default value dependent on which component is targeted. RepeatingGroup is `full` and Subform is `table` (see layout.schema.v1.json) commit-id:a7e89d34 --- frontend/language/src/nb.json | 3 + .../src/types/ComponentSpecificConfig.ts | 11 +-- .../OverrideFields/CompactViewSwitch.tsx | 19 +---- .../Summary2OverrideDisplaySelect.tsx | 41 ++++++++++ .../Summary2OverrideDisplayType.tsx | 19 +---- .../Override/Summary2Override.test.tsx | 78 ++++++++++++++++--- .../Override/Summary2OverrideEntry.tsx | 71 ++++++++++++++--- .../Summary2/Override/utils.test.tsx | 6 +- .../Summary2/Override/utils.ts | 4 +- .../ux-editor/src/testing/layoutMock.ts | 9 +++ 10 files changed, 198 insertions(+), 63 deletions(-) create mode 100644 frontend/packages/ux-editor/src/components/config/componentSpecificContent/Summary2/Override/OverrideFields/Summary2OverrideDisplaySelect.tsx diff --git a/frontend/language/src/nb.json b/frontend/language/src/nb.json index d8049c8a7c7..b817258ef7d 100644 --- a/frontend/language/src/nb.json +++ b/frontend/language/src/nb.json @@ -1489,6 +1489,9 @@ "ux_editor.component_properties.summary.add_override": "Lag en ny overstyring", "ux_editor.component_properties.summary.override.choose_component": "Velg komponent", "ux_editor.component_properties.summary.override.description": "Overstyringer per komponent for oppsummeringen", + "ux_editor.component_properties.summary.override.display": "Visningstype", + "ux_editor.component_properties.summary.override.display.full": "Fullstendig", + "ux_editor.component_properties.summary.override.display.table": "Tabell", "ux_editor.component_properties.summary.override.display_type": "Visningstype", "ux_editor.component_properties.summary.override.display_type.list": "Liste", "ux_editor.component_properties.summary.override.display_type.string": "Tekst", diff --git a/frontend/packages/shared/src/types/ComponentSpecificConfig.ts b/frontend/packages/shared/src/types/ComponentSpecificConfig.ts index 4070d791908..3a1f1b898c4 100644 --- a/frontend/packages/shared/src/types/ComponentSpecificConfig.ts +++ b/frontend/packages/shared/src/types/ComponentSpecificConfig.ts @@ -105,10 +105,6 @@ type SummarizableComponentProps = { renderAsSummary?: BooleanExpression; }; -export type SummaryTargetType = 'page' | 'layoutSet' | 'component'; - -export type SummaryCustomTargetType = 'list' | 'string'; - type LabeledComponentProps = { labelSettings?: LabelSettings; }; @@ -136,14 +132,19 @@ type PageValidation = { show: AllowedValidationMasks; }; +export type OverrideDisplayType = 'list' | 'string'; +export type OverrideDisplay = 'table' | 'full'; export type Summary2OverrideConfig = { componentId: string; hidden?: boolean; emptyFieldText?: string; isCompact?: boolean; - displayType?: SummaryCustomTargetType; + displayType?: OverrideDisplayType; + display?: OverrideDisplay; }; +export type SummaryTargetType = 'page' | 'layoutSet' | 'component'; + export type Summary2TargetConfig = { type?: SummaryTargetType; id?: string; diff --git a/frontend/packages/ux-editor/src/components/config/componentSpecificContent/Summary2/Override/OverrideFields/CompactViewSwitch.tsx b/frontend/packages/ux-editor/src/components/config/componentSpecificContent/Summary2/Override/OverrideFields/CompactViewSwitch.tsx index 2fd55c70706..b2a113d28a8 100644 --- a/frontend/packages/ux-editor/src/components/config/componentSpecificContent/Summary2/Override/OverrideFields/CompactViewSwitch.tsx +++ b/frontend/packages/ux-editor/src/components/config/componentSpecificContent/Summary2/Override/OverrideFields/CompactViewSwitch.tsx @@ -2,32 +2,15 @@ import React, { type ChangeEvent } from 'react'; import type { Summary2OverrideConfig } from 'app-shared/types/ComponentSpecificConfig'; import { StudioSwitch } from '@studio/components'; import { useTranslation } from 'react-i18next'; -import { useStudioEnvironmentParams } from 'app-shared/hooks/useStudioEnvironmentParams'; -import { useAppContext } from '../../../../../../hooks'; -import { useFormLayoutsQuery } from '../../../../../../hooks/queries/useFormLayoutsQuery'; -import { getAllLayoutComponents } from '../../../../../../utils/formLayoutUtils'; -import { ComponentType } from 'app-shared/types/ComponentType'; type CompactViewSwitchProps = { onChange: (updatedOverride: Summary2OverrideConfig) => void; override: Summary2OverrideConfig; }; -export const CompactViewSwitch = ({ onChange, override }: CompactViewSwitchProps) => { +export const Summary2OverrideCompactSwitch = ({ onChange, override }: CompactViewSwitchProps) => { const { t } = useTranslation(); - const { org, app } = useStudioEnvironmentParams(); - const { selectedFormLayoutSetName } = useAppContext(); - const { data: formLayoutsData } = useFormLayoutsQuery(org, app, selectedFormLayoutSetName); - const components = Object.values(formLayoutsData).flatMap((layout) => - getAllLayoutComponents(layout), - ); - const component = components.find((comp) => comp.id === override.componentId); - const isGroupComponent = component?.type === (ComponentType.Group as ComponentType); - - if (!isGroupComponent) { - return null; - } return ( void; + override: Summary2OverrideConfig; +}; + +export const Summary2OverrideDisplaySelect = ({ + onChange, + override, +}: Summary2OverrideDisplaySelectProps) => { + const { t } = useTranslation(); + + const options = [ + { value: 'table', text: t('ux_editor.component_properties.summary.override.display.table') }, + { value: 'full', text: t('ux_editor.component_properties.summary.override.display.full') }, + ]; + + return ( + { + onChange({ ...override, display: event.target.value as OverrideDisplay }); + }} + > + {options.map((option) => ( + + ))} + + ); +}; diff --git a/frontend/packages/ux-editor/src/components/config/componentSpecificContent/Summary2/Override/OverrideFields/Summary2OverrideDisplayType.tsx b/frontend/packages/ux-editor/src/components/config/componentSpecificContent/Summary2/Override/OverrideFields/Summary2OverrideDisplayType.tsx index 734167bd50a..d59c738911e 100644 --- a/frontend/packages/ux-editor/src/components/config/componentSpecificContent/Summary2/Override/OverrideFields/Summary2OverrideDisplayType.tsx +++ b/frontend/packages/ux-editor/src/components/config/componentSpecificContent/Summary2/Override/OverrideFields/Summary2OverrideDisplayType.tsx @@ -2,39 +2,26 @@ import React from 'react'; import { StudioCard, StudioNativeSelect } from '@studio/components'; import type { Summary2OverrideConfig, - SummaryCustomTargetType, + OverrideDisplayType, } from 'app-shared/types/ComponentSpecificConfig'; import { type CustomConfigType, useCustomConfigType } from '../hook/useCustomConfigType'; import { useTranslation } from 'react-i18next'; import { mapSelectedTypeToConfig } from '../utils'; -import { ComponentType } from 'app-shared/types/ComponentType'; -import type { TargetComponentProps } from '../../Summary2Target/targetUtils'; export type Summary2OverrideDisplayTypeProps = { override: Summary2OverrideConfig; - componentOptions: TargetComponentProps[]; onChange: (override: Summary2OverrideConfig) => void; }; export const Summary2OverrideDisplayType = ({ override, - componentOptions, onChange, }: Summary2OverrideDisplayTypeProps) => { const { t } = useTranslation(); const { displayType, componentId } = override; - const selectedComponentType = componentOptions?.find((comp) => comp.id === componentId)?.type; const customConfigTypes: CustomConfigType[] = useCustomConfigType(); - const checkboxOrMultipleselect = - selectedComponentType?.includes(ComponentType.MultipleSelect) || - selectedComponentType?.includes(ComponentType.Checkboxes); - - if (!checkboxOrMultipleselect) { - return null; - } - - const handleCustomTypeChange = (newDisplayType: SummaryCustomTargetType): void => { + const handleCustomTypeChange = (newDisplayType: OverrideDisplayType): void => { const summary2OverrideConfig = mapSelectedTypeToConfig({ componentId, displayType: newDisplayType, @@ -48,7 +35,7 @@ export const Summary2OverrideDisplayType = ({ size='sm' label={t('ux_editor.component_properties.summary.override.display_type')} value={displayType || 'list'} - onChange={(e) => handleCustomTypeChange(e.target.value as SummaryCustomTargetType)} + onChange={(e) => handleCustomTypeChange(e.target.value as OverrideDisplayType)} > {customConfigTypes.map((type: CustomConfigType) => (