diff --git a/frontend/language/src/nb.json b/frontend/language/src/nb.json index c3efac252ff..ee66ceadf06 100644 --- a/frontend/language/src/nb.json +++ b/frontend/language/src/nb.json @@ -1646,7 +1646,8 @@ "ux_editor.component_title.AddressComponent": "Adresse", "ux_editor.component_title.Alert": "Varsel", "ux_editor.component_title.AttachmentList": "Liste over vedlegg", - "ux_editor.component_title.AttachmentList_error": "Du må velge minst ett vedlegg eller PDF", + "ux_editor.component_title.AttachmentListOrPdf_error": "Du må velge minst ett vedlegg eller PDF", + "ux_editor.component_title.AttachmentList_error": "Du må velge minst ett vedlegg", "ux_editor.component_title.AttachmentList_legend": "Vedleggsliste", "ux_editor.component_title.Button": "Knapp", "ux_editor.component_title.ButtonGroup": "Knappegruppe", diff --git a/frontend/packages/ux-editor/src/components/config/FormComponentConfig.tsx b/frontend/packages/ux-editor/src/components/config/FormComponentConfig.tsx index dee2fe7d7e2..92b0e874f18 100644 --- a/frontend/packages/ux-editor/src/components/config/FormComponentConfig.tsx +++ b/frontend/packages/ux-editor/src/components/config/FormComponentConfig.tsx @@ -40,7 +40,13 @@ export const FormComponentConfig = ({ const { hasCustomFileEndings, validFileEndings, grid } = properties; // Add any properties that have a custom implementation to this list so they are not duplicated in the generic view - const customProperties = ['hasCustomFileEndings', 'validFileEndings', 'grid', 'children']; + const customProperties = [ + 'hasCustomFileEndings', + 'validFileEndings', + 'grid', + 'children', + 'dataTypeIds', + ]; const booleanPropertyKeys: string[] = getSupportedPropertyKeysForPropertyType( schema.properties, diff --git a/frontend/packages/ux-editor/src/components/config/componentSpecificContent/AttachmentList/AttachmentListComponent.test.tsx b/frontend/packages/ux-editor/src/components/config/componentSpecificContent/AttachmentList/AttachmentListComponent.test.tsx index 01fbde064e3..e501466195f 100644 --- a/frontend/packages/ux-editor/src/components/config/componentSpecificContent/AttachmentList/AttachmentListComponent.test.tsx +++ b/frontend/packages/ux-editor/src/components/config/componentSpecificContent/AttachmentList/AttachmentListComponent.test.tsx @@ -34,6 +34,11 @@ const defaultLayoutSets: LayoutSets = { dataTypes: 'layoutSetId3', tasks: ['Task_3'], }, + { + id: 'layoutSetId4', + dataTypes: 'layoutSetId4', + tasks: ['CustomReceipt'], + }, ], }; @@ -117,7 +122,7 @@ describe('AttachmentListComponent', () => { dataTypeIds: ['test3', 'test4'], }, }, - 'layoutSetId3', + 'layoutSetId4', ); // Todo: Combobox onChangeValue trigger on initial render, this can be fixed when we start to use >v0.55.0 of designsystem. Replace value prop with initialValue prop in combobox @@ -145,6 +150,23 @@ describe('AttachmentListComponent', () => { expect(handleComponentChange).toHaveBeenCalledTimes(2); }); + it('should not display pdf checkbox when current task is not CustomReceipt', async () => { + await render( + { + component: { + ...defaultComponent, + }, + }, + 'layoutSetId3', + ); + + expect( + screen.queryByRole('checkbox', { + name: textMock('ux_editor.component_properties.select_pdf'), + }), + ).not.toBeInTheDocument(); + }); + it('should save to backend when toggle of current task and output is valid', async () => { await render( { diff --git a/frontend/packages/ux-editor/src/components/config/componentSpecificContent/AttachmentList/AttachmentListComponent.tsx b/frontend/packages/ux-editor/src/components/config/componentSpecificContent/AttachmentList/AttachmentListComponent.tsx index 1ad639edc46..b4bef12a4c1 100644 --- a/frontend/packages/ux-editor/src/components/config/componentSpecificContent/AttachmentList/AttachmentListComponent.tsx +++ b/frontend/packages/ux-editor/src/components/config/componentSpecificContent/AttachmentList/AttachmentListComponent.tsx @@ -46,6 +46,10 @@ export const AttachmentListComponent = ({ }); }; + const isTaskCustomReceipt = layoutSets?.sets + .find((layoutSet) => layoutSet.id === selectedFormLayoutSetName) + ?.tasks.includes('CustomReceipt'); + const { dataTypeIds = [] } = component || {}; const internalDataFormat = convertExternalToInternalFormat(availableAttachments, dataTypeIds); @@ -54,6 +58,7 @@ export const AttachmentListComponent = ({ onChange={handleChange} availableAttachments={availableAttachments} internalDataFormat={internalDataFormat} + isTaskCustomReceipt={isTaskCustomReceipt} /> ); }; diff --git a/frontend/packages/ux-editor/src/components/config/componentSpecificContent/AttachmentList/AttachmentListInternalFormat.tsx b/frontend/packages/ux-editor/src/components/config/componentSpecificContent/AttachmentList/AttachmentListInternalFormat.tsx index 7c173acf59d..808de95fe80 100644 --- a/frontend/packages/ux-editor/src/components/config/componentSpecificContent/AttachmentList/AttachmentListInternalFormat.tsx +++ b/frontend/packages/ux-editor/src/components/config/componentSpecificContent/AttachmentList/AttachmentListInternalFormat.tsx @@ -10,12 +10,14 @@ type AttachmentListInternalFormatProps = { onChange: (selectedDataTypes: InternalDataTypesFormat) => void; availableAttachments: AvailableAttachementLists; internalDataFormat: InternalDataTypesFormat; + isTaskCustomReceipt: boolean; }; export const AttachmentListInternalFormat = ({ onChange, availableAttachments, internalDataFormat, + isTaskCustomReceipt, }: AttachmentListInternalFormatProps) => { const [dataTypesState, setDataTypesState] = useState(internalDataFormat); const [isValid, setIsValid] = useState(true); @@ -69,10 +71,15 @@ export const AttachmentListInternalFormat = ({ availableAttachments, ); const { includePdf, currentTask, selectedDataTypes } = dataTypesState; + + const errorMessage = isTaskCustomReceipt + ? t('ux_editor.component_title.AttachmentListOrPdf_error') + : t('ux_editor.component_title.AttachmentList_error'); + return (
handleCurrentTaskChange(e.target.checked)} @@ -81,13 +88,15 @@ export const AttachmentListInternalFormat = ({ > {t('ux_editor.component_properties.current_task')} - handleIncludePdfChange(e.target.checked)} - size='small' - checked={includePdf} - > - {t('ux_editor.component_properties.select_pdf')} - + {isTaskCustomReceipt && ( + handleIncludePdfChange(e.target.checked)} + size='small' + checked={includePdf} + > + {t('ux_editor.component_properties.select_pdf')} + + )}