-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Clean up option list typing (#14429)
Co-authored-by: Erling Hauan <[email protected]>
- Loading branch information
1 parent
81889bc
commit 5dda0fd
Showing
32 changed files
with
227 additions
and
247 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
20 changes: 0 additions & 20 deletions
20
...pp-development/features/appContentLibrary/utils/convertOptionsListsDataToCodeListsData.ts
This file was deleted.
Oops, something went wrong.
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
11 changes: 11 additions & 0 deletions
11
frontend/app-development/features/appContentLibrary/utils/mapToCodeListDataList.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,11 @@ | ||
import type { OptionListData } from 'app-shared/types/OptionList'; | ||
import type { CodeListData } from '@studio/content-library'; | ||
|
||
export const mapToCodeListDataList = (optionListDataList: OptionListData[]): CodeListData[] => | ||
optionListDataList.map(convertOptionListDataToCodeListData); | ||
|
||
const convertOptionListDataToCodeListData = (optionListData: OptionListData): CodeListData => ({ | ||
title: optionListData.title, | ||
data: optionListData.data, | ||
hasError: optionListData.hasError, | ||
}); |
35 changes: 35 additions & 0 deletions
35
frontend/app-development/features/appContentLibrary/utils/mapToCodeListUsages.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,35 @@ | ||
import type { CodeListIdSource } from '@studio/content-library'; | ||
import { mapToCodeListUsages } from './mapToCodeListUsages'; | ||
import type { OptionListReferences } from 'app-shared/types/OptionListReferences'; | ||
|
||
const optionListId: string = 'optionListId'; | ||
const optionListIdSources: CodeListIdSource[] = [ | ||
{ | ||
layoutSetId: 'layoutSetId', | ||
layoutName: 'layoutName', | ||
componentIds: ['componentId1', 'componentId2'], | ||
}, | ||
]; | ||
const optionListUsages: OptionListReferences = [ | ||
{ | ||
optionListId, | ||
optionListIdSources, | ||
}, | ||
]; | ||
|
||
describe('mapToCodeListUsages', () => { | ||
it('maps optionListsUsages to codeListUsages', () => { | ||
const codeListUsages = mapToCodeListUsages(optionListUsages); | ||
expect(codeListUsages).toEqual([ | ||
{ | ||
codeListId: optionListId, | ||
codeListIdSources: optionListIdSources, | ||
}, | ||
]); | ||
}); | ||
|
||
it('maps undefined optionListUsages to empty array', () => { | ||
const codeListUsages = mapToCodeListUsages(undefined); | ||
expect(codeListUsages).toEqual([]); | ||
}); | ||
}); |
12 changes: 12 additions & 0 deletions
12
frontend/app-development/features/appContentLibrary/utils/mapToCodeListUsages.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,12 @@ | ||
import type { OptionListReferences } from 'app-shared/types/OptionListReferences'; | ||
import type { CodeListReference } from '@studio/content-library'; | ||
|
||
export const mapToCodeListUsages = ( | ||
optionListUsages: OptionListReferences, | ||
): CodeListReference[] => { | ||
if (!optionListUsages) return []; | ||
return optionListUsages.map((optionListsUsage) => ({ | ||
codeListId: optionListsUsage.optionListId, | ||
codeListIdSources: optionListsUsage.optionListIdSources, | ||
})); | ||
}; |
35 changes: 0 additions & 35 deletions
35
frontend/app-development/features/appContentLibrary/utils/mapToCodeListsUsage.test.ts
This file was deleted.
Oops, something went wrong.
20 changes: 0 additions & 20 deletions
20
frontend/app-development/features/appContentLibrary/utils/mapToCodeListsUsage.ts
This file was deleted.
Oops, something went wrong.
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.