Skip to content

Commit 6b89cc1

Browse files
committed
refactor
1 parent a064d1e commit 6b89cc1

File tree

3 files changed

+19
-23
lines changed

3 files changed

+19
-23
lines changed

frontend/packages/shared/src/api/queries.ts

+16-20
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ import type { OptionListReferences } from 'app-shared/types/OptionListReferences
9898
import type { LayoutSetsModel } from '../types/api/dto/LayoutSetsModel';
9999
import type { AccessPackageResource, PolicyAccessPackageAreaGroup } from 'app-shared/types/PolicyAccessPackages';
100100
import type { DataType } from '../types/DataType';
101-
import type { CodeList } from '@studio/components';
102101

103102
export const getIsLoggedInWithAnsattporten = () => get<{ isLoggedIn: boolean }>(authStatusAnsattporten());
104103
export const getMaskinportenScopes = (org: string, app: string) => get<MaskinportenScopes>(availableMaskinportenScopesPath(org, app));
@@ -177,37 +176,34 @@ export const getProcessTaskType = (org: string, app: string, taskId: string) =>
177176
export const fetchBelongsToGiteaOrg = () => get(belongsToOrg());
178177

179178
// Org level code lists
180-
181-
const orgLevelCodeListsMock: CodeList[] = [
179+
const orgLevelCodeListsMock: OptionListsResponse[] = [
182180
[
183181
{
184-
description: 'description1',
185-
helpText: 'helpText1',
186-
label: 'label1',
187-
value: 'value1',
182+
title: 'title1',
183+
data: [
184+
{ label: 'label1', value: 'value1' },
185+
{ label: 'label2', value: 'value2' },
186+
],
187+
hasError: false,
188188
},
189189
{
190-
description: 'description2',
191-
helpText: 'helpText2',
192-
label: 'label2',
193-
value: true,
190+
title: 'title2',
191+
data: [],
192+
hasError: false,
194193
},
195194
],
196195
[
197196
{
198-
description: 'description3',
199-
helpText: 'helpText3',
200-
label: 'label3',
201-
value: 3,
197+
title: 'title3',
198+
data: [],
199+
hasError: false,
202200
},
203201
],
204202
];
205-
export const getOrgLevelCodeLists = async (): Promise<CodeList[]> =>
206-
// TODO: Replace with endpoint when it is ready in backend.
203+
export const getOrgLevelCodeLists = async (org: string): Promise<OptionListsResponse[]> =>
204+
// TODO: Replace with endpoint when it is ready in backend. https://github.com/Altinn/altinn-studio/issues/14482
207205
new Promise((resolve) => {
208206
setTimeout(() => {
209-
// Replace the two resolves to test with empty list
210-
// resolve([]);
211207
resolve(orgLevelCodeListsMock);
212-
}, 1000);
208+
}, 200);
213209
});

frontend/packages/shared/src/hooks/queries/useOrgLevelCodeListsQuery.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { waitFor } from '@testing-library/react';
44
import { useOrgLevelCodeListsQuery } from './useOrgLevelCodeListsQuery';
55

66
describe('useOrgLevelCodeListsQuery', () => {
7-
it('calls getOptionListsReferences with the correct parameters', () => {
7+
it('calls getOrgLevelCodeLists with the correct parameters', () => {
88
render();
99
expect(queriesMock.getOrgLevelCodeLists).toHaveBeenCalledWith();
1010
expect(queriesMock.getOrgLevelCodeLists).toHaveBeenCalledTimes(1);

frontend/packages/shared/src/hooks/queries/useOrgLevelCodeListsQuery.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { useQuery } from '@tanstack/react-query';
22
import { QueryKey } from 'app-shared/types/QueryKey';
33
import { useServicesContext } from 'app-shared/contexts/ServicesContext';
4-
import type { CodeList } from '@studio/components';
4+
import type { OptionListsResponse } from 'app-shared/types/api/OptionListsResponse';
55

66
export const useOrgLevelCodeListsQuery = () => {
77
const { getOrgLevelCodeLists } = useServicesContext();
8-
return useQuery<CodeList[]>({
8+
return useQuery<OptionListsResponse[]>({
99
queryKey: [QueryKey.OrgLevelCodeLists],
1010
queryFn: () => getOrgLevelCodeLists(),
1111
});

0 commit comments

Comments
 (0)