Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/ some bugs in attachmentList #12680

Merged
merged 3 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion frontend/language/src/nb.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ const defaultLayoutSets: LayoutSets = {
dataTypes: 'layoutSetId3',
tasks: ['Task_3'],
},
{
id: 'layoutSetId4',
dataTypes: 'layoutSetId4',
tasks: ['CustomReceipt'],
},
],
};

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -54,6 +58,7 @@ export const AttachmentListComponent = ({
onChange={handleChange}
availableAttachments={availableAttachments}
internalDataFormat={internalDataFormat}
isTaskCustomReceipt={isTaskCustomReceipt}
/>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<InternalDataTypesFormat>(internalDataFormat);
const [isValid, setIsValid] = useState<boolean>(true);
Expand Down Expand Up @@ -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 (
<Fieldset
legend={t('ux_editor.component_title.AttachmentList_legend')}
error={!isValid && t('ux_editor.component_title.AttachmentList_error')}
error={!isValid && errorMessage}
>
<Switch
onChange={(e) => handleCurrentTaskChange(e.target.checked)}
Expand All @@ -81,13 +88,15 @@ export const AttachmentListInternalFormat = ({
>
{t('ux_editor.component_properties.current_task')}
</Switch>
<Switch
onChange={(e) => handleIncludePdfChange(e.target.checked)}
size='small'
checked={includePdf}
>
{t('ux_editor.component_properties.select_pdf')}
</Switch>
{isTaskCustomReceipt && (
<Switch
onChange={(e) => handleIncludePdfChange(e.target.checked)}
size='small'
checked={includePdf}
>
{t('ux_editor.component_properties.select_pdf')}
</Switch>
)}
<AttachmentListContent
currentAvailableAttachments={currentAvailableAttachments}
selectedDataTypes={ArrayUtils.intersection(selectedDataTypes, currentAvailableAttachments)}
Expand Down
Loading