-
Notifications
You must be signed in to change notification settings - Fork 70
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: add codeListEditor in config options #13953
Open
Konrad-Simso
wants to merge
9
commits into
main
Choose a base branch
from
feat/update-code-list-config-add-editor
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+422
−153
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a789754
Added manual edit functionality for codelists. But it's not done.
Konrad-Simso 6db7a5e
Update tests and move handleClose from onClose to onBeforeClose
Konrad-Simso 063c1f5
Remove unused imports and update typing. Type changes for StudioCodeL…
Konrad-Simso c950bab
Update types, linting
Konrad-Simso da9ef74
Update tests and remove unused export.
Konrad-Simso b0b3c3e
Add featureFlag for CodeListTableEditor.
Konrad-Simso c185b83
Updated CodeListTableEditor.tsx
Konrad-Simso 7092614
Added functionality to call handleClose when clicking outside Modal t…
Konrad-Simso 9e70770
Updates from review
Konrad-Simso File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
frontend/libs/studio-components/src/components/StudioCodelistEditor/types/CodeListItem.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
export type CodeListItem = { | ||
export type CodeListItem<T extends string | boolean | number = string | boolean | number> = { | ||
description?: string; | ||
helpText?: string; | ||
label: string; | ||
value: string; | ||
value: T; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,4 @@ | ||
export type Option<T extends string | boolean | number = string | boolean | number> = { | ||
label: string; | ||
value: T; | ||
description?: string; | ||
helpText?: string; | ||
}; | ||
import type { CodeListItem } from '@studio/components'; | ||
|
||
export type Option<T extends string | boolean | number = string | boolean | number> = | ||
CodeListItem<T>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
...editor/src/components/config/editModal/EditOptions/EditCodeList/CodeListEditor.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
.manualTabModal[open] { | ||
max-width: unset; | ||
width: min(80vw, 64rem); | ||
} | ||
|
||
.modalTrigger { | ||
margin-top: var(--fds-spacing-2); | ||
} |
100 changes: 100 additions & 0 deletions
100
...x-editor/src/components/config/editModal/EditOptions/EditCodeList/CodeListEditor.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import React from 'react'; | ||
import { screen, waitForElementToBeRemoved } from '@testing-library/react'; | ||
import { ComponentType } from 'app-shared/types/ComponentType'; | ||
import type { FormComponent } from '../../../../../types/FormComponent'; | ||
import { createQueryClientMock } from 'app-shared/mocks/queryClientMock'; | ||
import { CodeListEditor } from './CodeListEditor'; | ||
import { textMock } from '@studio/testing/mocks/i18nMock'; | ||
import userEvent, { type UserEvent } from '@testing-library/user-event'; | ||
import { componentMocks } from '@altinn/ux-editor/testing/componentMocks'; | ||
import type { Option } from 'app-shared/types/Option'; | ||
import { renderWithProviders } from '@altinn/ux-editor/testing/mocks'; | ||
|
||
// Test data: | ||
const mockComponent: FormComponent<ComponentType.Dropdown> = componentMocks[ComponentType.Dropdown]; | ||
mockComponent.optionsId = 'test'; | ||
|
||
const optionsList = new Map([ | ||
[ | ||
'text', | ||
[{ value: 'test', label: 'label text', description: 'description', helpText: 'help text' }], | ||
], | ||
['number', [{ value: 2, label: 'label number' }]], | ||
['boolean', [{ value: true, label: 'label boolean' }]], | ||
]); | ||
const queriesMock = { | ||
getOptionLists: jest | ||
.fn() | ||
.mockImplementation(() => Promise.resolve<Map<string, Option[]>>(optionsList)), | ||
}; | ||
const queryClientMock = createQueryClientMock(); | ||
|
||
describe('CodeListTableEditor', () => { | ||
afterEach(() => { | ||
queryClientMock.clear(); | ||
}); | ||
|
||
it('should render the component', async () => { | ||
await renderCodeListTableEditor(); | ||
|
||
expect( | ||
screen.getByRole('button', { | ||
name: textMock('ux_editor.modal_properties_code_list_open_editor'), | ||
}), | ||
).toBeInTheDocument(); | ||
}); | ||
|
||
it('should open Dialog', async () => { | ||
const user = userEvent.setup(); | ||
await renderCodeListTableEditor(); | ||
await openModal(user); | ||
|
||
expect(screen.getByRole('dialog')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should close Dialog', async () => { | ||
const user = userEvent.setup(); | ||
await renderCodeListTableEditor(); | ||
await openModal(user); | ||
|
||
await user.click(screen.getByRole('button', { name: 'close modal' })); // Todo: Replace "close modal" with defaultDialogProps.closeButtonTitle when https://github.com/digdir/designsystemet/issues/2195 is fixed | ||
|
||
expect(screen.queryByRole('dialog')).not.toBeInTheDocument(); | ||
}); | ||
|
||
it('should call handClose when closing Dialog', async () => { | ||
const user = userEvent.setup(); | ||
const doReloadPreview = jest.fn(); | ||
await renderCodeListTableEditor({ previewContextProps: { doReloadPreview } }); | ||
await openModal(user); | ||
|
||
await user.click(screen.getByRole('button', { name: 'close modal' })); // Todo: Replace "close modal" with defaultDialogProps.closeButtonTitle when https://github.com/digdir/designsystemet/issues/2195 is fixed | ||
|
||
expect(screen.queryByRole('dialog')).not.toBeInTheDocument(); | ||
expect(doReloadPreview).toHaveBeenCalledTimes(1); | ||
}); | ||
}); | ||
|
||
const openModal = async (user: UserEvent) => { | ||
const btnOpen = screen.getByRole('button', { | ||
name: textMock('ux_editor.modal_properties_code_list_open_editor'), | ||
}); | ||
await user.click(btnOpen); | ||
}; | ||
|
||
const renderCodeListTableEditor = async ({ previewContextProps = {} } = {}) => { | ||
const view = renderWithProviders( | ||
<CodeListEditor | ||
component={{ | ||
...mockComponent, | ||
}} | ||
/>, | ||
{ | ||
queries: queriesMock, | ||
queryClient: queryClientMock, | ||
previewContextProps: previewContextProps, | ||
}, | ||
); | ||
await waitForElementToBeRemoved(screen.queryByTestId('studio-spinner-test-id')); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you decide to keep the waitForElementToBeRemoved method we should use the text on it instead of test Id I think 🤔 |
||
return view; | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two comments here:
2.1: we can set the optionList directly on the cache if we anyway always will wait for the spinner to removed before executing the tests.
2.2: we can actually test that the spinner is there when it suppose to be. There are also two ways to implement that. Either you can set the cache in the renderMethod if data is passed to the renderMethod. Or you can use adapt the queries and have the waitForSpinnerTobeRemoved in a separete renderMethod. We have examples of both approcahes around the codebase. Let me know if you need help to find it 🤗