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: 14164 implement the legg til ny component for the last four standard choices #14392

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
1a87bcc
render komponentbredde through a button --WIP
JamalAlabdullah Jan 3, 2025
7f1f2ea
Merge remote-tracking branch 'origin/main' into 14164-implement-the-l…
JamalAlabdullah Jan 7, 2025
17897d2
render sortOrder inside a button
JamalAlabdullah Jan 7, 2025
2aa8afe
render validation and preselected props through buttons
JamalAlabdullah Jan 8, 2025
b510fde
move CollapsiblePropertyEditor files to an own folder
JamalAlabdullah Jan 8, 2025
90b6cf6
added test fro CollapsiblePropertyEditor
JamalAlabdullah Jan 8, 2025
ec78568
added test
JamalAlabdullah Jan 9, 2025
61f9d12
fixed plass for grid button
JamalAlabdullah Jan 9, 2025
8f8be43
Merge remote-tracking branch 'origin/main' into 14164-implement-the-l…
JamalAlabdullah Jan 16, 2025
90aefab
reorder
JamalAlabdullah Jan 17, 2025
4aaeba1
unused textResouce for grid
JamalAlabdullah Jan 17, 2025
7eec7f6
render all strig properites through CollapsiblePropertyEditor
JamalAlabdullah Jan 19, 2025
660230b
render grid inside card
JamalAlabdullah Jan 20, 2025
d9cf36b
update test
JamalAlabdullah Jan 20, 2025
4e745a0
test
JamalAlabdullah Jan 20, 2025
06a64ba
Merge branch 'main' into 14164-implement-the-legg-til-ny-component-fo…
JamalAlabdullah Jan 20, 2025
14749f7
Merge remote-tracking branch 'origin/main' into 14164-implement-the-l…
JamalAlabdullah Jan 20, 2025
bb758a5
update
JamalAlabdullah Jan 20, 2025
b9258b8
add test
JamalAlabdullah Jan 20, 2025
442fc6a
refacture
JamalAlabdullah Jan 20, 2025
fe43f1c
Merge branch 'main' into 14164-implement-the-legg-til-ny-component-fo…
JamalAlabdullah Jan 21, 2025
b7caecd
fixed css of grid
JamalAlabdullah Jan 21, 2025
18c1102
Merge branch '14164-implement-the-legg-til-ny-component-for-the-last-…
JamalAlabdullah Jan 21, 2025
51e4a2b
fixed comments
JamalAlabdullah Jan 23, 2025
86637a4
Fix Form component config
mlqn Jan 28, 2025
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
4 changes: 3 additions & 1 deletion frontend/language/src/nb.json
Original file line number Diff line number Diff line change
Expand Up @@ -1386,11 +1386,13 @@
"ux_editor.component_properties.optionalIndicator": "Vis valgfri-indikator på ledetekst",
"ux_editor.component_properties.options": "Alternativer",
"ux_editor.component_properties.optionsId": "Kodeliste",
"ux_editor.component_properties.page": "Side",
"ux_editor.component_properties.pageBreak": "PDF-innstillinger (pageBreak)",
"ux_editor.component_properties.pageRef": "Navnet til siden det gjelder (pageRef)",
"ux_editor.component_properties.pagination": "Sidenummerering",
"ux_editor.component_properties.position": "Plassering av valuta",
"ux_editor.component_properties.preselectedOptionIndex": "Angi det valget som skal være forhåndsvalgt.",
"ux_editor.component_properties.preselectedOptionIndex_button": "Plassering av forhåndsvalgt verdi (indeks)",
"ux_editor.component_properties.preselected_help_text": "Eksempel: Hvis du har 5 valg, kan du bruke tall fra 0-4.",
"ux_editor.component_properties.queryParameters": "Parametere i spørringen",
"ux_editor.component_properties.readOnly": "Feltet kan kun leses",
Expand Down Expand Up @@ -1419,7 +1421,7 @@
"ux_editor.component_properties.showIcon": "Vis ikon",
"ux_editor.component_properties.showLabelsInTable": "Alternativene skal alltid vises i tabeller",
"ux_editor.component_properties.showPageInAccordion": "Vis side i trekkspilliste",
"ux_editor.component_properties.showValidations": "Vis valideringer",
"ux_editor.component_properties.showValidations": "Vis valideringstyper",
"ux_editor.component_properties.simplified": "Forenklet visning",
"ux_editor.component_properties.size": "Størrelse",
"ux_editor.component_properties.sortOrder": "Sorteringsrekkefølge",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,13 @@
await user.click(saveButton);

expect(onEditMock).toHaveBeenCalledTimes(1);
expect(onEditMock).toHaveBeenCalledWith({

Check failure on line 80 in frontend/packages/ux-editor/src/components/Properties/EditSubformTableColumns/ColumnElement/ColumnElement.test.tsx

View workflow job for this annotation

GitHub Actions / Testing

ColumnElement › should call onEdit with updated header content when click on save button

expect(jest.fn()).toHaveBeenCalledWith(...expected) - Expected + Received Object { "cellContent": Object { - "default": "Default", - "query": "Query", + "query": "some-path", }, "headerContent": "subform_table_column_title_test-layout-set-3", }, Number of calls: 1 at Object.toHaveBeenCalledWith (packages/ux-editor/src/components/Properties/EditSubformTableColumns/ColumnElement/ColumnElement.test.tsx:80:24)
...mockTableColumn,
headerContent: expect.stringContaining('subform_table_column_title_'),
cellContent: { query: subformLayoutMock.component1.dataModelBindings.simpleBinding },
headerContent: 'subform_table_column_title_test-layout-set-3',
cellContent: {
query: cellContentQueryMock,
default: cellContentDefaultMock,
},
});
});

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
.collapsibleContainer {
display: flex;
flex-direction: row;
align-items: flex-end;
gap: var(--fds-spacing-4);
padding-bottom: var(--fds-spacing-4);
padding-top: var(--fds-spacing-1);
}

.collapsibleContainerClosed {
margin-top: var(--fds-spacing-1);
margin-bottom: var(--fds-spacing-1);
}

.editorContent {
flex: 1;
}

.button {
display: flex;
gap: var(--fds-spacing-3);
padding-left: 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import React from 'react';
import {
CollapsiblePropertyEditor,
type CollapsiblePropertyEditorProps,
} from './CollapsiblePropertyEditor';
import userEvent from '@testing-library/user-event';
import { screen } from '@testing-library/react';
import { renderWithProviders } from 'app-development/test/mocks';
import { textMock } from '@studio/testing/mocks/i18nMock';

// Test data
const label = 'Test label';
const children = <div>Test children</div>;
const icon = <div>Test icon</div>;

describe('CollapsiblePropertyEditor', () => {
it('should render the label', () => {
renderCollapsiblePropertyEditor({ label: label });
expect(screen.getByText('Test label')).toBeInTheDocument();
});

it('should render the icon', () => {
renderCollapsiblePropertyEditor({ icon: <div>Test icon</div> });
expect(screen.getByText('Test icon')).toBeInTheDocument();
});

it('should render the children', () => {
renderCollapsiblePropertyEditor();
expect(screen.queryByText('Test children')).not.toBeInTheDocument();
});

it('should render the children when the button is clicked', async () => {
const user = userEvent.setup();
renderCollapsiblePropertyEditor();
await user.click(screen.getByText('Test label'));
expect(screen.getByText('Test children')).toBeInTheDocument();
});

it('should hide the children when the close button is clicked', async () => {
const user = userEvent.setup();
renderCollapsiblePropertyEditor();
await user.click(screen.getByText('Test label'));
expect(screen.getByText('Test children')).toBeInTheDocument();
await user.click(screen.getByRole('button', { name: textMock('general.close') }));
expect(screen.queryByText('Test children')).not.toBeInTheDocument();
});
});

const defaultProps: CollapsiblePropertyEditorProps = {
label,
children,
icon,
};

const renderCollapsiblePropertyEditor = (props: Partial<CollapsiblePropertyEditorProps> = {}) => {
renderWithProviders()(<CollapsiblePropertyEditor {...defaultProps} {...props} />);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import React, { useState } from 'react';
import { PlusCircleIcon, XMarkIcon } from '@studio/icons';
import { StudioButton, StudioProperty } from '@studio/components';
import classes from './CollapsiblePropertyEditor.module.css';
import { useTranslation } from 'react-i18next';
import cn from 'classnames';

export type CollapsiblePropertyEditorProps = {
label?: string;
children?: React.ReactNode;
icon?: React.ReactNode;
disabledCloseButton?: boolean;
};

export const CollapsiblePropertyEditor = ({
label,
children,
disabledCloseButton = false,
icon = <PlusCircleIcon />,
}: CollapsiblePropertyEditorProps) => {
const { t } = useTranslation();
const [isVisible, setIsVisible] = useState(false);

return (
<div
className={cn(isVisible ? classes.collapsibleContainer : classes.collapsibleContainerClosed)}
>
{!isVisible ? (
<StudioProperty.Button
className={classes.button}
icon={icon}
onClick={() => setIsVisible(true)}
property={label}
/>
JamalAlabdullah marked this conversation as resolved.
Show resolved Hide resolved
) : (
<>
<div className={classes.editorContent}>{children}</div>
{!disabledCloseButton && (
<StudioButton
icon={<XMarkIcon />}
onClick={() => setIsVisible(false)}
title={t('general.close')}
variant='secondary'
/>
JamalAlabdullah marked this conversation as resolved.
Show resolved Hide resolved
)}
</>
)}
</div>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { CollapsiblePropertyEditor } from './CollapsiblePropertyEditor';
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,25 @@
.downIcon {
font-size: var(--fds-sizing-6);
}

.gridButton {
padding: 0;
}

.gridHeader {
padding: 0; /* Optional: Adjust padding as needed */
}

.flexContainer {
display: flex;
align-items: center;
justify-content: space-between;
}

.heading {
margin-left: var(--fds-spacing-5);
}

.button {
margin: var(--fds-spacing-2);
}
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,88 @@ describe('FormComponentConfig', () => {
expect(screen.queryByText('unsupportedProperty')).not.toBeInTheDocument();
});

it('should render CollapsiblePropertyEditor for the "sortOrder" property', () => {
render({
props: {
schema: {
...InputSchema,
properties: {
...InputSchema.properties,
sortOrder: {
type: 'array',
items: {
type: 'string',
enum: ['option1', 'option2'],
},
},
},
},
},
});
expect(
screen.getByText(textMock('ux_editor.component_properties.sortOrder')),
).toBeInTheDocument();
expect(
screen.getByRole('combobox', {
name: textMock('ux_editor.component_properties.sortOrder'),
}),
).toBeInTheDocument();
});

it('should render CollapsiblePropertyEditor for the "showValidations" property and EditStringValue for other properties', () => {
render({
props: {
schema: {
...InputSchema,
properties: {
...InputSchema.properties,
showValidations: {
type: 'array',
items: {
type: 'string',
enum: ['true', 'false'],
},
},
anotherProperty: {
type: 'array',
items: {
type: 'string',
enum: ['option1', 'option2'],
},
},
},
},
},
});
expect(
screen.getByText(textMock('ux_editor.component_properties.showValidations')),
).toBeInTheDocument();
});

it('should render CollapsiblePropertyEditor for "preselectedOptionIndex" and EditNumberValue for other properties', () => {
render({
props: {
schema: {
...InputSchema,
properties: {
...InputSchema.properties,
preselectedOptionIndex: {
type: 'number',
enum: [0, 1, 2],
},
anotherNumberProperty: {
type: 'number',
description: 'A sample number property',
},
},
},
},
});
expect(
screen.getByText(textMock('ux_editor.component_properties.preselectedOptionIndex_button')),
).toBeInTheDocument();
});

it('should not render property if it is null', () => {
render({
props: {
Expand Down
Loading
Loading