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: Clean up imports by moving layoutset hooks from ux-editor to shared #13587

Merged
merged 5 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion frontend/app-development/layout/PageHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ import { TopBarMenu } from 'app-shared/enums/TopBarMenu';
import type { User } from 'app-shared/types/Repository';
import { PackagesRouter } from 'app-shared/navigation/PackagesRouter';
import { RepositoryType } from 'app-shared/types/global';
import { useSelectedFormLayoutSetName, useSelectedFormLayoutName } from '@altinn/ux-editor/hooks';
import { useStudioEnvironmentParams } from 'app-shared/hooks/useStudioEnvironmentParams';
import { usePreviewContext } from 'app-development/contexts/PreviewContext';
import { useRepoMetadataQuery } from 'app-shared/hooks/queries';
import { useSelectedFormLayoutName } from 'app-shared/hooks/useSelectedFormLayoutName';
import { useSelectedFormLayoutSetName } from 'app-shared/hooks/useSelectedFormLayoutSetName';

type SubMenuContentProps = {
hasRepoError?: boolean;
Expand Down
8 changes: 3 additions & 5 deletions frontend/app-preview/src/views/LandingPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@ import { AppPreviewSubMenu } from '../components/AppPreviewSubMenu';
import { useStudioEnvironmentParams } from 'app-shared/hooks/useStudioEnvironmentParams';
import { previewPage } from 'app-shared/api/paths';
import { PreviewLimitationsInfo } from 'app-shared/components/PreviewLimitationsInfo/PreviewLimitationsInfo';
import {
useSelectedFormLayoutName,
useSelectedFormLayoutSetName,
useSelectedTaskId,
} from '@altinn/ux-editor/hooks';
import { useSelectedFormLayoutName } from 'app-shared/hooks/useSelectedFormLayoutName';
import { useSelectedFormLayoutSetName } from 'app-shared/hooks/useSelectedFormLayoutSetName';
import { useSelectedTaskId } from 'app-shared/hooks/useSelectedTaskId';

export interface LandingPageProps {
variant?: AltinnHeaderVariant;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import type { ReactNode } from 'react';
import React from 'react';
import { useSelectedFormLayoutName } from './';
import { layout1NameMock } from '../testing/layoutMock';
import { layoutSet1NameMock } from '../testing/layoutSetsMock';
import { renderHook } from '@testing-library/react';
import type { ServicesContextProps } from 'app-shared/contexts/ServicesContext';
import { ServicesContextProvider } from 'app-shared/contexts/ServicesContext';
Expand All @@ -12,9 +9,11 @@ import { createQueryClientMock } from 'app-shared/mocks/queryClientMock';
import type { QueryClient } from '@tanstack/react-query';
import { QueryKey } from 'app-shared/types/QueryKey';
import { app, org } from '@studio/testing/testids';
import { useSelectedFormLayoutName } from './useSelectedFormLayoutName';

// Test data:
const selectedLayoutSet = layoutSet1NameMock;
const selectedLayoutSet: string = 'selectedLayoutSet';
const layout1NameMock: string = 'Side1';

const mockSetSearchParams = jest.fn();
const mockSearchParams = { layout: layout1NameMock };
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useSearchParamsState } from 'app-shared/hooks/useSearchParamsState';
import { useFormLayoutSettingsQuery } from './queries/useFormLayoutSettingsQuery';
import { useFormLayoutSettingsQuery } from '../../../ux-editor/src/hooks/queries/useFormLayoutSettingsQuery';
import { useStudioEnvironmentParams } from 'app-shared/hooks/useStudioEnvironmentParams';

export type UseSelectedFormLayoutNameResult = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import type { ReactNode } from 'react';
import React from 'react';
import { useSelectedFormLayoutSetName } from './';
import { layoutSet1NameMock, layoutSetsMock } from '../testing/layoutSetsMock';
import { renderHook } from '@testing-library/react';
import type { ServicesContextProps } from 'app-shared/contexts/ServicesContext';
import { ServicesContextProvider } from 'app-shared/contexts/ServicesContext';
Expand All @@ -12,9 +10,26 @@ import type { QueryClient } from '@tanstack/react-query';
import { QueryKey } from 'app-shared/types/QueryKey';
import { app, org } from '@studio/testing/testids';
import { typedLocalStorage } from '@studio/components/src/hooks/webStorage';
import { useSelectedFormLayoutSetName } from './useSelectedFormLayoutSetName';
import { type LayoutSets } from 'app-shared/types/api/LayoutSetsResponse';

// Test data:
const selectedLayoutSet = layoutSet1NameMock;
export const layoutSet1NameMock = 'test-layout-set';
export const layoutSet2NameMock = 'test-layout-set-2';
export const layoutSetsMock: LayoutSets = {
sets: [
{
id: layoutSet1NameMock,
dataType: 'data-model',
tasks: ['Task_1'],
},
{
id: layoutSet2NameMock,
dataType: 'data-model-2',
tasks: ['Task_2'],
},
],
};

const wrapper = ({
children,
Expand Down Expand Up @@ -70,6 +85,6 @@ describe('useSelectedFormLayoutSetName', () => {
},
});

expect(result.current.selectedFormLayoutSetName).toEqual(selectedLayoutSet);
expect(result.current.selectedFormLayoutSetName).toEqual(layoutSet1NameMock);
});
});
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import type { ReactNode } from 'react';
import React from 'react';
import { useSelectedTaskId } from './';
import { layout1NameMock } from '../testing/layoutMock';
import { layoutSet1NameMock } from '../testing/layoutSetsMock';
import { renderHook } from '@testing-library/react';
import type { ServicesContextProps } from 'app-shared/contexts/ServicesContext';
import { ServicesContextProvider } from 'app-shared/contexts/ServicesContext';
Expand All @@ -13,9 +10,11 @@ import type { QueryClient } from '@tanstack/react-query';
import { QueryKey } from 'app-shared/types/QueryKey';
import { TASKID_FOR_STATELESS_APPS } from 'app-shared/constants';
import { app, org } from '@studio/testing/testids';
import { useSelectedTaskId } from './useSelectedTaskId';

// Test data:
const selectedLayoutSet = layoutSet1NameMock;
export const layoutSet1NameMock = 'test-layout-set';
export const layout1NameMock = 'Side1';

const mockSetSearchParams = jest.fn();
const mockSearchParams = { layout: layout1NameMock };
Expand Down Expand Up @@ -56,7 +55,7 @@ describe('useSelectedTaskId', () => {
afterEach(jest.clearAllMocks);

it('should return the default task id when it does not exist', async () => {
const { result } = renderHook(() => useSelectedTaskId(selectedLayoutSet), { wrapper });
const { result } = renderHook(() => useSelectedTaskId(layoutSet1NameMock), { wrapper });
expect(result.current).toEqual(TASKID_FOR_STATELESS_APPS);
});

Expand All @@ -67,13 +66,13 @@ describe('useSelectedTaskId', () => {
client.setQueryData([QueryKey.LayoutSets, org, app], {
sets: [
{
id: selectedLayoutSet,
id: layoutSet1NameMock,
tasks: [taskTest],
},
],
});

const { result } = renderHook(() => useSelectedTaskId(selectedLayoutSet), {
const { result } = renderHook(() => useSelectedTaskId(layoutSet1NameMock), {
wrapper: ({ children }) => {
return wrapper({ children, client });
},
Expand Down
3 changes: 2 additions & 1 deletion frontend/packages/ux-editor/src/AppContext.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import type { MutableRefObject } from 'react';
import React, { useMemo, useRef, createContext, useCallback } from 'react';
import type { QueryClient, QueryKey as TanStackQueryKey } from '@tanstack/react-query';
import { useSelectedFormLayoutName, useSelectedFormLayoutSetName } from './hooks';
import { useStudioEnvironmentParams } from 'app-shared/hooks/useStudioEnvironmentParams';
import { QueryKey } from 'app-shared/types/QueryKey';
import { useSelectedFormLayoutName } from 'app-shared/hooks/useSelectedFormLayoutName';
import { useSelectedFormLayoutSetName } from 'app-shared/hooks/useSelectedFormLayoutSetName';

export interface WindowWithQueryClient extends Window {
queryClient?: QueryClient;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import classes from './Preview.module.css';
import { useStudioEnvironmentParams } from 'app-shared/hooks/useStudioEnvironmentParams';
import cn from 'classnames';
import { useTranslation } from 'react-i18next';
import { useAppContext, useSelectedTaskId } from '../../hooks';
import { useAppContext } from '../../hooks';
import { useChecksum } from '../../hooks/useChecksum.ts';
import { previewPage } from 'app-shared/api/paths';
import { Paragraph } from '@digdir/designsystemet-react';
Expand All @@ -12,6 +12,7 @@ import type { SupportedView } from './ViewToggler/ViewToggler';
import { ViewToggler } from './ViewToggler/ViewToggler';
import { ShrinkIcon } from '@studio/icons';
import { PreviewLimitationsInfo } from 'app-shared/components/PreviewLimitationsInfo/PreviewLimitationsInfo';
import { useSelectedTaskId } from 'app-shared/hooks/useSelectedTaskId';

export type PreviewProps = {
collapsed: boolean;
Expand Down
3 changes: 0 additions & 3 deletions frontend/packages/ux-editor/src/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,3 @@ export type { ComponentValidationResult, ErrorCode } from './useValidateComponen
export { useValidateComponent } from './useValidateComponent';
export { useComponentPropertyLabel } from './useComponentPropertyLabel';
export { useAppContext } from './useAppContext';
export { useSelectedFormLayoutSetName } from './useSelectedFormLayoutSetName';
export { useSelectedFormLayoutName } from './useSelectedFormLayoutName';
export { useSelectedTaskId } from './useSelectedTaskId';
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { useSelectedFormLayoutWithName, useSelectedTaskId } from '../';
import { useSelectedFormLayoutWithName } from '../';
import { useMutation } from '@tanstack/react-query';
import { ComponentType } from 'app-shared/types/ComponentType';
import { useFormLayoutMutation } from './useFormLayoutMutation';
import { useAddAppAttachmentMetadataMutation } from './useAddAppAttachmentMetadataMutation';
import type { FormFileUploaderComponent } from '../../types/FormComponent';
import { addItemOfType } from '../../utils/formLayoutUtils';
import { useSelectedTaskId } from 'app-shared/hooks/useSelectedTaskId';

export interface AddFormItemMutationArgs {
componentType: ComponentType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ import { useUpdateAppAttachmentMetadataMutation } from './useUpdateAppAttachment
import { switchSelectedFieldId } from '../../utils/ruleConfigUtils';
import { useRuleConfigQuery } from '../queries/useRuleConfigQuery';
import { useRuleConfigMutation } from './useRuleConfigMutation';
import { useFormLayout, useSelectedTaskId } from '../';
import { useFormLayout } from '../';
import { ObjectUtils } from '@studio/pure-functions';
import { useFormLayoutMutation } from './useFormLayoutMutation';
import type { FormComponent, FormFileUploaderComponent } from '../../types/FormComponent';
import { useUpdateBpmn } from 'app-shared/hooks/useUpdateBpmn';
import { updateDataTypeIdsToSign } from 'app-shared/utils/bpmnUtils';
import { useSelectedTaskId } from 'app-shared/hooks/useSelectedTaskId';

export interface UpdateFormComponentMutationArgs {
updatedComponent: FormComponent;
Expand Down