Skip to content

Commit

Permalink
refactor: add 'page' suffix to the library page components (#14279)
Browse files Browse the repository at this point in the history
Co-authored-by: Tomas Engebretsen <[email protected]>
  • Loading branch information
standeren and TomasEng authored Dec 16, 2024
1 parent 2345ba1 commit 634f838
Show file tree
Hide file tree
Showing 32 changed files with 40 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ const updateCodeListButtonTextMock = 'Update Code List';
const codeListNameMock = 'codeListNameMock';
const codeListMock: CodeList = [{ value: '', label: '' }];
jest.mock(
'../../../libs/studio-content-library/src/ContentLibrary/LibraryBody/pages/CodeList',
'../../../libs/studio-content-library/src/ContentLibrary/LibraryBody/pages/CodeListPage',
() => ({
CodeList: ({ onUpdateCodeList, onUploadCodeList }: any) => (
CodeListPage: ({ onUpdateCodeList, onUploadCodeList }: any) => (
<div>
<button
onClick={() =>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import type { CodeListProps, CodeListWithMetadata } from './CodeList';
import { CodeList } from './CodeList';
import type { CodeListPageProps, CodeListWithMetadata } from './CodeListPage';
import { CodeListPage } from './CodeListPage';
import { textMock } from '@studio/testing/mocks/i18nMock';

const onUpdateCodeListMock = jest.fn();
Expand All @@ -12,7 +12,7 @@ const codeListMock: CodeListWithMetadata = {
codeList: [{ value: 'value', label: 'label' }],
};

describe('CodeList', () => {
describe('CodeListPage', () => {
it('renders the codeList heading', () => {
renderCodeList();
const codeListHeading = screen.getByRole('heading', {
Expand Down Expand Up @@ -56,7 +56,7 @@ describe('CodeList', () => {
});
});

const defaultCodeListProps: CodeListProps = {
const defaultCodeListProps: CodeListPageProps = {
codeLists: [codeListMock],
onUpdateCodeList: onUpdateCodeListMock,
onUploadCodeList: onUploadCodeListMock,
Expand All @@ -68,9 +68,9 @@ const renderCodeList = ({
onUpdateCodeList,
onUploadCodeList,
fetchDataError,
}: Partial<CodeListProps> = defaultCodeListProps) => {
}: Partial<CodeListPageProps> = defaultCodeListProps) => {
render(
<CodeList
<CodeListPage
codeLists={codeLists}
onUpdateCodeList={onUpdateCodeList}
onUploadCodeList={onUploadCodeList}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,26 @@ import { useTranslation } from 'react-i18next';
import { CodeListsActionsBar } from './CodeListsActionsBar';
import { CodeLists } from './CodeLists';
import { CodeListsCounterMessage } from './CodeListsCounterMessage';
import classes from './CodeList.module.css';
import classes from './CodeListPage.module.css';
import { ArrayUtils } from '@studio/pure-functions';

export type CodeListWithMetadata = {
codeList: StudioComponentCodeList;
title: string;
};

export type CodeListProps = {
export type CodeListPageProps = {
codeLists: CodeListWithMetadata[];
onUpdateCodeList: (updatedCodeList: CodeListWithMetadata) => void;
onUploadCodeList: (uploadedCodeList: File) => void;
fetchDataError: boolean;
};
export function CodeList({
export function CodeListPage({
codeLists,
onUpdateCodeList,
onUploadCodeList,
fetchDataError,
}: CodeListProps): React.ReactElement {
}: CodeListPageProps): React.ReactElement {
const { t } = useTranslation();

if (fetchDataError)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { render, screen } from '@testing-library/react';
import type { CodeListsProps } from './CodeLists';
import { updateCodeListWithMetadata, CodeLists } from './CodeLists';
import { textMock } from '@studio/testing/mocks/i18nMock';
import type { CodeListWithMetadata } from '../CodeList';
import type { CodeListWithMetadata } from '../CodeListPage';
import type { UserEvent } from '@testing-library/user-event';
import type { RenderResult } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import type { CodeListWithMetadata } from '../CodeList';
import type { CodeListWithMetadata } from '../CodeListPage';
import { Accordion } from '@digdir/designsystemet-react';
import { StudioCodeListEditor } from '@studio/components';
import type { CodeList as StudioComponentsCodeList, CodeListEditorTexts } from '@studio/components';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Search } from '@digdir/designsystemet-react';
import { StudioFileUploader } from '@studio/components';
import classes from './CodeListsActionsBar.module.css';
import { useTranslation } from 'react-i18next';
import type { CodeListWithMetadata } from '../CodeList';
import type { CodeListWithMetadata } from '../CodeListPage';
import { CreateNewCodeListModal } from './CreateNewCodeListModal/CreateNewCodeListModal';
import { FileNameUtils } from '@studio/pure-functions';
import { useUploadCodeListNameErrorMessage } from '../hooks/useUploadCodeListNameErrorMessage';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { useTranslation } from 'react-i18next';
import { useOptionListEditorTexts } from '../../hooks/useCodeListEditorTexts';
import { CheckmarkIcon } from '@studio/icons';
import classes from './CreateNewCodeListModal.module.css';
import type { CodeListWithMetadata } from '../../CodeList';
import type { CodeListWithMetadata } from '../../CodeListPage';
import { FileNameUtils } from '@studio/pure-functions';
import { useInputCodeListNameErrorMessage } from '../../hooks/useInputCodeListNameErrorMessage';

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { CodeListPage } from './CodeListPage';
export type { CodeListWithMetadata, CodeListPageProps } from './CodeListPage';

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ import React from 'react';
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { textMock } from '@studio/testing/mocks/i18nMock';
import type { Image, ImagesProps } from './Images';
import { Images } from './Images';
import type { Image, ImagesPageProps } from './ImagesPage';
import { ImagesPage } from './ImagesPage';

const onUpdateImageMock = jest.fn();
const imageMock: Image = {
title: 'image',
imageSrc: 'www.external-image-url.com',
};

describe('Images', () => {
describe('ImagesPage', () => {
it('renders the images heading', () => {
renderImages();
const imagesHeading = screen.getByRole('heading', {
Expand All @@ -36,11 +36,11 @@ describe('Images', () => {
});
});

const defaultImagesProps: ImagesProps = {
const defaultImagesProps: ImagesPageProps = {
images: [imageMock],
onUpdateImage: onUpdateImageMock,
};

const renderImages = (imagesProps: ImagesProps = defaultImagesProps) => {
render(<Images {...imagesProps} />);
const renderImages = (imagesProps: ImagesPageProps = defaultImagesProps) => {
render(<ImagesPage {...imagesProps} />);
};
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ export type Image = {
imageSrc: string;
};

export type ImagesProps = {
export type ImagesPageProps = {
images: Image[];
onUpdateImage: (updatedImage: Image) => void;
};

export function Images({ images, onUpdateImage }: ImagesProps): React.ReactElement {
export function ImagesPage({ images, onUpdateImage }: ImagesPageProps): React.ReactElement {
const { t } = useTranslation();

const noExistingImages = images.length === 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './ImagesPage';
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export type { CodeListWithMetadata } from './CodeList';
export type { CodeListWithMetadata } from './CodeListPage';
8 changes: 4 additions & 4 deletions frontend/libs/studio-content-library/src/types/PagesProps.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { CodeListProps } from '../ContentLibrary/LibraryBody/pages/CodeList';
import type { CodeListPageProps } from '../ContentLibrary/LibraryBody/pages/CodeListPage';
import type { PageName } from './PageName';
import type { ImagesProps } from '../ContentLibrary/LibraryBody/pages/Images';
import type { ImagesPageProps } from '../ContentLibrary/LibraryBody/pages/ImagesPage';

export type PagePropsMap<P extends PageName> = {
landingPage: {};
codeList: CodeListProps;
images: ImagesProps;
codeList: CodeListPageProps;
images: ImagesPageProps;
}[P];

type GlobalPageConfig<T> = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { RouterRouteMapperImpl } from './RouterRouteMapper';
import { LandingPage } from '../../ContentLibrary/LibraryBody/pages/LandingPage';
import { CodeList } from '../../ContentLibrary/LibraryBody/pages/CodeList';
import { CodeListPage } from '../../ContentLibrary/LibraryBody/pages/CodeListPage';
import { mockPagesConfig } from '../../../mocks/mockPagesConfig';

describe('RouterRouteMapperImpl', () => {
Expand All @@ -11,7 +11,7 @@ describe('RouterRouteMapperImpl', () => {
expect(routes.has('landingPage')).toBeTruthy();
expect(routes.has('codeList')).toBeTruthy();
expect(routes.get('landingPage')).toBe(LandingPage);
expect(routes.get('codeList')).toBe(CodeList);
expect(routes.get('codeList')).toBe(CodeListPage);
});

it('should always include landingPage even when noe pages are passed', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { type ComponentProps, type ReactElement } from 'react';
import { CodeList } from '../../ContentLibrary/LibraryBody/pages/CodeList';
import { CodeListPage } from '../../ContentLibrary/LibraryBody/pages/CodeListPage';
import type { PageName } from '../../types/PageName';
import { LandingPage } from '../../ContentLibrary/LibraryBody/pages/LandingPage';
import type { PagesConfig } from '../../types/PagesProps';
import { Images } from '../../ContentLibrary/LibraryBody/pages/Images';
import { ImagesPage } from '../../ContentLibrary/LibraryBody/pages/ImagesPage';

type PageProps =
| ComponentProps<typeof LandingPage>
| ComponentProps<typeof CodeList>
| ComponentProps<typeof Images>;
| ComponentProps<typeof CodeListPage>
| ComponentProps<typeof ImagesPage>;

export type PageComponent<P = PageProps> = (props: P) => ReactElement;

Expand Down Expand Up @@ -36,10 +36,10 @@ export class RouterRouteMapperImpl implements RouterRouteMapper {

Object.keys(pages).forEach((page: PageName) => {
if (page === 'codeList') {
pageMap.set('codeList', CodeList);
pageMap.set('codeList', CodeListPage);
}
if (page === 'images') {
pageMap.set('images', Images);
pageMap.set('images', ImagesPage);
}
});

Expand Down

0 comments on commit 634f838

Please sign in to comment.