-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add codeListEditor in config options (#13953)
Co-authored-by: Tomas Engebretsen <[email protected]>
- Loading branch information
1 parent
002b6e4
commit d339dfc
Showing
43 changed files
with
568 additions
and
227 deletions.
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
1 change: 1 addition & 0 deletions
1
frontend/libs/studio-components/src/components/StudioCodelistEditor/index.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,5 +1,6 @@ | ||
export type { StudioCodeListEditorProps } from './StudioCodeListEditor'; | ||
export { StudioCodeListEditor } from './StudioCodeListEditor'; | ||
export type { CodeListEditorTexts } from './types/CodeListEditorTexts'; | ||
export type { CodeListItemValue } from './types/CodeListItemValue'; | ||
export type { CodeListItem } from './types/CodeListItem'; | ||
export type { CodeList } from './types/CodeList'; |
6 changes: 4 additions & 2 deletions
6
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,8 @@ | ||
export type CodeListItem = { | ||
import type { CodeListItemValue } from './CodeListItemValue'; | ||
|
||
export type CodeListItem<T extends CodeListItemValue = CodeListItemValue> = { | ||
description?: string; | ||
helpText?: string; | ||
label: string; | ||
value: string; | ||
value: T; | ||
}; |
1 change: 1 addition & 0 deletions
1
...end/libs/studio-components/src/components/StudioCodelistEditor/types/CodeListItemValue.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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export type CodeListItemValue = string | boolean | number; |
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
24 changes: 24 additions & 0 deletions
24
frontend/packages/shared/src/hooks/mutations/useUpdateOptionListMutation.test.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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { app, org } from '@studio/testing/testids'; | ||
import { queriesMock } from 'app-shared/mocks/queriesMock'; | ||
import { renderHookWithProviders } from 'app-shared/mocks/renderHookWithProviders'; | ||
import { | ||
type UpdateOptionListMutationArgs, | ||
useUpdateOptionListMutation, | ||
} from './useUpdateOptionListMutation'; | ||
import type { Option } from 'app-shared/types/Option'; | ||
|
||
// Test data: | ||
const optionListId = 'test'; | ||
const optionsList: Option[] = [{ value: 'test', label: 'test' }]; | ||
const args: UpdateOptionListMutationArgs = { optionListId: optionListId, optionsList: optionsList }; | ||
|
||
describe('useUpdateOptionListMutation', () => { | ||
test('Calls useUpdateOptionList with correct parameters', async () => { | ||
const renderUpdateOptionListMutationResult = renderHookWithProviders(() => | ||
useUpdateOptionListMutation(org, app), | ||
).result; | ||
await renderUpdateOptionListMutationResult.current.mutateAsync(args); | ||
expect(queriesMock.updateOptionList).toHaveBeenCalledTimes(1); | ||
expect(queriesMock.updateOptionList).toHaveBeenCalledWith(org, app, optionListId, optionsList); | ||
}); | ||
}); |
29 changes: 29 additions & 0 deletions
29
frontend/packages/shared/src/hooks/mutations/useUpdateOptionListMutation.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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import type { MutationMeta } from '@tanstack/react-query'; | ||
import { QueryKey } from 'app-shared/types/QueryKey'; | ||
import type { Option } from 'app-shared/types/Option'; | ||
import type { OptionsLists } from 'app-shared/types/api/OptionsLists'; | ||
import { useQueryClient, useMutation } from '@tanstack/react-query'; | ||
import { useServicesContext } from 'app-shared/contexts/ServicesContext'; | ||
|
||
export interface UpdateOptionListMutationArgs { | ||
optionListId: string; | ||
optionsList: Option[]; | ||
} | ||
|
||
export const useUpdateOptionListMutation = (org: string, app: string, meta?: MutationMeta) => { | ||
const queryClient = useQueryClient(); | ||
const { updateOptionList } = useServicesContext(); | ||
|
||
return useMutation<Option[], Error, UpdateOptionListMutationArgs>({ | ||
mutationFn: ({ optionListId, optionsList }: UpdateOptionListMutationArgs) => { | ||
return updateOptionList(org, app, optionListId, optionsList); | ||
}, | ||
onSuccess: (updatedOptionList: Option[], { optionListId }) => { | ||
const oldData: OptionsLists = queryClient.getQueryData([QueryKey.OptionLists, org, app]); | ||
const newData = { ...oldData }; | ||
newData[optionListId] = updatedOptionList; | ||
queryClient.setQueryData([QueryKey.OptionLists, org, app], newData); | ||
}, | ||
meta, | ||
}); | ||
}; |
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,3 @@ | ||
export type Option<T extends string | boolean | number = string | boolean | number> = { | ||
label: string; | ||
value: T; | ||
description?: string; | ||
helpText?: string; | ||
}; | ||
import type { CodeListItem, CodeListItemValue } from '@studio/components'; | ||
|
||
export type Option<T extends CodeListItemValue = CodeListItemValue> = 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import type { Option } from 'app-shared/types/Option'; | ||
|
||
export type OptionsLists = Record<string, Option[]>; |
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
Oops, something went wrong.