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

feat: 13526 support component specific overrides in summary2 #13734

Merged
merged 29 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
9f7f253
added custom type for checkbox and Multipleselect
JamalAlabdullah Oct 3, 2024
65727ac
add function to isCompact checkbox
JamalAlabdullah Oct 7, 2024
8e5c3c0
Merge branch 'main' into feat13526-support-component-specific-overrid…
JamalAlabdullah Oct 7, 2024
492450e
fixed intial value for displaytype
JamalAlabdullah Oct 7, 2024
ce4284f
Merge branch 'feat13526-support-component-specific-overrides-in-summa…
JamalAlabdullah Oct 7, 2024
f67c9a5
updated test
JamalAlabdullah Oct 8, 2024
3012238
updated test
JamalAlabdullah Oct 8, 2024
ab240f7
fixed comments
JamalAlabdullah Oct 10, 2024
d3c8dc1
update Summary2OverrideDisplaytype
JamalAlabdullah Oct 10, 2024
a73b46c
fixed comments --WIP
JamalAlabdullah Oct 11, 2024
5ad6a9a
added index file
JamalAlabdullah Oct 11, 2024
2af1751
fix comment
JamalAlabdullah Oct 11, 2024
a55a8e7
test
JamalAlabdullah Oct 11, 2024
4f0c666
test
JamalAlabdullah Oct 11, 2024
5741683
Merge branch 'main' into feat13526-support-component-specific-overrid…
JamalAlabdullah Oct 11, 2024
2eb9fd7
test
JamalAlabdullah Oct 11, 2024
de879a1
Merge branch 'feat13526-support-component-specific-overrides-in-summa…
JamalAlabdullah Oct 11, 2024
83323e2
test
JamalAlabdullah Oct 11, 2024
db68cff
added test
JamalAlabdullah Oct 15, 2024
bceaa31
update
JamalAlabdullah Oct 15, 2024
c4cb5c5
changed logiv for isCompact
JamalAlabdullah Oct 16, 2024
1c208ff
Merge branch 'main' into feat13526-support-component-specific-overrid…
JamalAlabdullah Oct 16, 2024
12078e6
updated test
JamalAlabdullah Oct 16, 2024
a1533b6
Merge branch 'feat13526-support-component-specific-overrides-in-summa…
JamalAlabdullah Oct 16, 2024
2343b25
Merge branch 'main' into feat13526-support-component-specific-overrid…
JamalAlabdullah Oct 16, 2024
7ad6e9c
Merge branch 'main' into feat13526-support-component-specific-overrid…
JamalAlabdullah Oct 16, 2024
f654e4c
Merge branch 'main' into feat13526-support-component-specific-overrid…
JamalAlabdullah Oct 16, 2024
f0420b2
update test
JamalAlabdullah Oct 17, 2024
150ca0d
Merge branch 'feat13526-support-component-specific-overrides-in-summa…
JamalAlabdullah Oct 17, 2024
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
5 changes: 5 additions & 0 deletions frontend/language/src/nb.json
Original file line number Diff line number Diff line change
Expand Up @@ -1244,6 +1244,11 @@
"ux_editor.component_properties.optionsId": "Kodeliste",
"ux_editor.component_properties.overrides": "Overstyringer",
"ux_editor.component_properties.overrides_description": "Overstyringer per komponent for oppsummeringen",
"ux_editor.component_properties.overrides_is_compact": "Kompakt visning",
"ux_editor.component_properties.overrides_list": "Liste",
"ux_editor.component_properties.overrides_not_set": "Ikke satt",
"ux_editor.component_properties.overrides_string": "Tekst",
"ux_editor.component_properties.overrides_type": "Vis type",
"ux_editor.component_properties.pageBreak": "PDF-innstillinger (pageBreak)",
"ux_editor.component_properties.pageRef": "Navnet til siden det gjelder (pageRef)",
"ux_editor.component_properties.pagination": "Paginering",
Expand Down
4 changes: 4 additions & 0 deletions frontend/packages/shared/src/types/ComponentSpecificConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ type SummarizableComponentProps = {

export type SummaryTargetType = 'page' | 'layoutSet' | 'component';

export type SummaryCustomTargetType = 'list' | 'string' | 'notSet';

type LabeledComponentProps = {
labelSettings?: LabelSettings;
};
Expand Down Expand Up @@ -139,6 +141,8 @@ export type Summary2OverrideConfig = {
forceShow?: boolean;
emptyFieldText?: string;
hideEmptyFields?: boolean;
isCompact?: boolean;
displayType?: SummaryCustomTargetType;
};

export type Summary2TargetConfig = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ import { Summary2Override, type Summary2OverrideProps } from './Summary2Override
import { QueryKey } from 'app-shared/types/QueryKey';
import { app, org } from '@studio/testing/testids';
import userEvent from '@testing-library/user-event';
import { component1IdMock, layout1NameMock, layoutMock } from '../../../../../testing/layoutMock';
import {
component1IdMock,
container1IdMock,
layout1NameMock,
layoutMock,
} from '../../../../../testing/layoutMock';
import { textMock } from '@studio/testing/mocks/i18nMock';
import { layoutSet1NameMock } from '../../../../../testing/layoutSetsMock';
import { renderWithProviders } from '../../../../../testing/mocks';
Expand All @@ -32,11 +37,41 @@ describe('Summary2Override', () => {
expect(defaultProps.onChange).toHaveBeenCalledWith([]);
});

it('should be able to show "vis type" comobox when componenetId is checkbox', async () => {
const user = userEvent.setup();
render({ overrides: [{ componentId: 'Checkboxes' }] });
await user.click(addNewOverrideButton());
expect(
screen.getByRole('combobox', {
name: textMock('ux_editor.component_properties.overrides_type'),
}),
).toBeInTheDocument();
});

it('should be able to show "vis type" comobox when componenetId is multipleSelect', async () => {
const user = userEvent.setup();
render({ overrides: [{ componentId: 'MultipleSelect' }] });
await user.click(addNewOverrideButton());
expect(
screen.getByRole('combobox', {
name: textMock('ux_editor.component_properties.overrides_type'),
}),
).toBeInTheDocument();
});

it('should not show "vis type" comobox when componenetId is not checkbox or multipleSelect', async () => {
render({ overrides: [{ componentId: '1' }] });
await userEvent.click(addNewOverrideButton());
expect(
screen.queryByRole('combobox', {
name: textMock('ux_editor.component_properties.overrides_type'),
}),
).not.toBeInTheDocument();
});

it('should be able to change override componentId', async () => {
const user = userEvent.setup();
render({
overrides: [{ componentId: '1' }],
});
render({ overrides: [{ componentId: '1' }] });
const componentId = component1IdMock;
await user.click(overrideComponentSelect());
await user.click(
Expand All @@ -51,9 +86,7 @@ describe('Summary2Override', () => {

it('should be able to change override hidden', async () => {
const user = userEvent.setup();
render({
overrides: [{ componentId: '1' }],
});
render({ overrides: [{ componentId: '1' }] });
await user.click(
screen.getByRole('checkbox', {
name: textMock('ux_editor.component_properties.summary.override.hidden'),
Expand All @@ -68,9 +101,7 @@ describe('Summary2Override', () => {

it('should be able to change override forceShow', async () => {
const user = userEvent.setup();
render({
overrides: [{ componentId: '1' }],
});
render({ overrides: [{ componentId: '1' }] });
await user.click(
screen.getByRole('checkbox', {
name: textMock('ux_editor.component_properties.summary.override.force_show'),
Expand All @@ -85,9 +116,7 @@ describe('Summary2Override', () => {

it('should be able to change override hideEmptyFields', async () => {
const user = userEvent.setup();
render({
overrides: [{ componentId: '1' }],
});
render({ overrides: [{ componentId: '1' }] });
await user.click(
screen.getByRole('checkbox', {
name: textMock('ux_editor.component_properties.summary.override.hide_empty_fields'),
Expand All @@ -100,6 +129,186 @@ describe('Summary2Override', () => {
);
});

it('"isCompact" checkbox should not be checked when isCompact is false', async () => {
const user = userEvent.setup();
render({ overrides: [{ componentId: container1IdMock, isCompact: false }] });
const compactCheckbox = screen.getByRole('checkbox', {
name: textMock('ux_editor.component_properties.overrides_is_compact'),
});
expect(compactCheckbox).toBeInTheDocument();
expect(compactCheckbox).not.toBeChecked();
await user.click(compactCheckbox);
await waitFor(() =>
expect(defaultProps.onChange).toHaveBeenCalledWith(
expect.arrayContaining([{ componentId: container1IdMock, isCompact: true }]),
),
);
});

it('"isCompact" checkbox Should be checked when isCompact is true', async () => {
const user = userEvent.setup();
render({ overrides: [{ componentId: container1IdMock, isCompact: true }] });
const compactCheckbox = screen.getByRole('checkbox', {
name: textMock('ux_editor.component_properties.overrides_is_compact'),
});
expect(compactCheckbox).toBeInTheDocument();
expect(compactCheckbox).toBeChecked();
await user.click(compactCheckbox);
await waitFor(() =>
expect(defaultProps.onChange).toHaveBeenCalledWith(
expect.arrayContaining([{ componentId: container1IdMock, isCompact: false }]),
),
);
});

it('should render the list of custom types', async () => {
render({ overrides: [{ componentId: 'MultipleSelect' }] });
await userEvent.click(addNewOverrideButton());
expect(
screen.getByRole('option', {
name: textMock('ux_editor.component_properties.overrides_list'),
}),
).toBeInTheDocument();
expect(
screen.getByRole('option', {
name: textMock('ux_editor.component_properties.overrides_string'),
}),
).toBeInTheDocument();
expect(
screen.getByRole('option', {
name: textMock('ux_editor.component_properties.overrides_not_set'),
}),
).toBeInTheDocument();
});

it('should be able to change override displayType when choosing list and componentId is MultipleSelect', async () => {
const user = userEvent.setup();
render({ overrides: [{ componentId: 'MultipleSelect', displayType: 'list' }] });
await user.click(addNewOverrideButton());
await user.click(
screen.getByRole('option', {
name: textMock('ux_editor.component_properties.overrides_list'),
}),
);
await waitFor(() =>
expect(defaultProps.onChange).toHaveBeenCalledWith(
expect.arrayContaining([{ componentId: 'MultipleSelect', displayType: 'list' }]),
),
);
});

it('should be able to change override displayType when choosing string and componentId is MultipleSelect', async () => {
const user = userEvent.setup();
render({ overrides: [{ componentId: 'MultipleSelect', displayType: 'string' }] });
await user.click(addNewOverrideButton());
await user.click(
screen.getByRole('option', {
name: textMock('ux_editor.component_properties.overrides_string'),
}),
);
await waitFor(() =>
expect(defaultProps.onChange).toHaveBeenCalledWith(
expect.arrayContaining([{ componentId: 'MultipleSelect', displayType: 'string' }]),
),
);
});

it('should be able to change override displayType when choosing notSet and componentId is MultipleSelect', async () => {
const user = userEvent.setup();
render({ overrides: [{ componentId: 'MultipleSelect', displayType: 'notSet' }] });
await user.click(addNewOverrideButton());
await user.click(
screen.getByRole('option', {
name: textMock('ux_editor.component_properties.overrides_not_set'),
}),
);
await waitFor(() =>
expect(defaultProps.onChange).toHaveBeenCalledWith(
expect.arrayContaining([{ componentId: 'MultipleSelect', displayType: 'notSet' }]),
),
);
});

it('should be able to change override displayType when choosing list and componentId is Checkboxes', async () => {
const user = userEvent.setup();
render({ overrides: [{ componentId: 'Checkboxes', displayType: 'list' }] });
await user.click(addNewOverrideButton());
await user.click(
screen.getByRole('option', {
name: textMock('ux_editor.component_properties.overrides_list'),
}),
);
await waitFor(() =>
expect(defaultProps.onChange).toHaveBeenCalledWith(
expect.arrayContaining([{ componentId: 'Checkboxes', displayType: 'list' }]),
),
);
});

it('should be able to change override displayType when choosing string and componentId is Checkboxes', async () => {
const user = userEvent.setup();
render({ overrides: [{ componentId: 'Checkboxes', displayType: 'string' }] });
await user.click(addNewOverrideButton());
await user.click(
screen.getByRole('option', {
name: textMock('ux_editor.component_properties.overrides_string'),
}),
);
await waitFor(() =>
expect(defaultProps.onChange).toHaveBeenCalledWith(
expect.arrayContaining([{ componentId: 'Checkboxes', displayType: 'string' }]),
),
);
});

it('should be able to change override displayType when choosing notSet and componentId is Checkboxes', async () => {
const user = userEvent.setup();
render({ overrides: [{ componentId: 'Checkboxes', displayType: 'notSet' }] });
await user.click(addNewOverrideButton());
await user.click(
screen.getByRole('option', {
name: textMock('ux_editor.component_properties.overrides_not_set'),
}),
);
await waitFor(() =>
expect(defaultProps.onChange).toHaveBeenCalledWith(
expect.arrayContaining([{ componentId: 'Checkboxes', displayType: 'notSet' }]),
),
);
});

it('should displayType have a new option value when user select a new option.', async () => {
const user = userEvent.setup();
render({ overrides: [{ componentId: 'Checkboxes', displayType: 'string' }] });
await user.click(addNewOverrideButton());
await user.click(
screen.getByRole('option', {
name: textMock('ux_editor.component_properties.overrides_string'),
}),
);
await waitFor(() =>
expect(defaultProps.onChange).toHaveBeenCalledWith(
expect.arrayContaining([{ componentId: 'Checkboxes', displayType: 'string' }]),
),
);
});

it('should handle custom type change', async () => {
const user = userEvent.setup();
render({ overrides: [{ componentId: 'Checkboxes' }] });
await user.click(addNewOverrideButton());

const select = screen.getByRole('combobox', {
name: textMock('ux_editor.component_properties.overrides_type'),
});
await user.selectOptions(select, 'list');
await waitFor(() =>
expect(defaultProps.onChange).toHaveBeenCalledWith(
expect.arrayContaining([{ componentId: 'Checkboxes', displayType: 'list' }]),
),
);
});

it('should be able to change override emptyFieldText', async () => {
const user = userEvent.setup();
render({
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import React, { type ReactElement } from 'react';
import { StudioCard, StudioNativeSelect } from '@studio/components';
import type {
Summary2OverrideConfig,
SummaryCustomTargetType,
} from 'app-shared/types/ComponentSpecificConfig';
import { type CustomConfigType, useCustomConfigType } from './hook/useCustomConfigType';
import { useTranslation } from 'react-i18next';
import { mapSelectedTypeToConfig } from './utils';

export type Summary2OverrideDisplayTypeProps = {
override: Summary2OverrideConfig;
onChange: (override: Summary2OverrideConfig) => void;
};

export const Summary2OverrideDisplayType = ({
override,
onChange,
}: Summary2OverrideDisplayTypeProps) => {
const { t } = useTranslation();

const handleCustomTypeChange = (event: React.ChangeEvent<HTMLSelectElement>): void => {
const newSelectedType = event.target.value as SummaryCustomTargetType;
const summary2OverrideConfig = mapSelectedTypeToConfig(newSelectedType, override.componentId);
onChange(summary2OverrideConfig);
};

return (
<StudioCard.Content>
<StudioNativeSelect
size='sm'
label={t('ux_editor.component_properties.overrides_type')}
onChange={handleCustomTypeChange}
value={override.displayType || 'string'}
>
<CustomConfigTypeOptions />
</StudioNativeSelect>
</StudioCard.Content>
);
};

const CustomConfigTypeOptions = (): ReactElement[] => {
const customConfigTypes: CustomConfigType[] = useCustomConfigType();
return customConfigTypes.map((type: CustomConfigType) => (
<option key={type.value} value={type.value}>
{type.label}
</option>
));
};
Loading