Skip to content

Commit

Permalink
split code
Browse files Browse the repository at this point in the history
  • Loading branch information
standeren committed Jan 1, 2025
1 parent c3f79bb commit 9da552c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,7 @@ export function CodeLists({
));
}

type CodeListProps = {
codeListData: CodeListData;
onUpdateCodeListId: (codeListId: string, newCodeListId: string) => void;
onUpdateCodeList: (updatedCodeList: CodeListWithMetadata) => void;
codeListInEditMode: string | undefined;
codeListNames: string[];
};
type CodeListProps = Omit<CodeListsProps, 'codeListsData'> & { codeListData: CodeListData };

function CodeList({
codeListData,
Expand All @@ -59,26 +53,46 @@ function CodeList({
>
{codeListData.title}
</Accordion.Header>
<Accordion.Content>
{codeListData.hasError ? (
<StudioAlert size='small' severity='danger'>
{t('app_content_library.code_lists.fetch_error')}
</StudioAlert>
) : (
<EditCodeList
codeList={codeListData.data}
codeListTitle={codeListData.title}
onUpdateCodeListId={onUpdateCodeListId}
onUpdateCodeList={onUpdateCodeList}
codeListNames={codeListNames}
/>
)}
</Accordion.Content>
<CodeListAccordionContent
codeListData={codeListData}
onUpdateCodeListId={onUpdateCodeListId}
onUpdateCodeList={onUpdateCodeList}
codeListNames={codeListNames}
/>
</Accordion.Item>
</Accordion>
);
}

type CodeListAccordionContentProps = Omit<CodeListProps, 'codeListInEditMode'>;

function CodeListAccordionContent({
codeListData,
onUpdateCodeListId,
onUpdateCodeList,
codeListNames,
}: CodeListAccordionContentProps): React.ReactElement {
const { t } = useTranslation();

return (
<Accordion.Content>
{codeListData.hasError ? (
<StudioAlert size='small' severity='danger'>
{t('app_content_library.code_lists.fetch_error')}
</StudioAlert>
) : (
<EditCodeList
codeList={codeListData.data}
codeListTitle={codeListData.title}
onUpdateCodeListId={onUpdateCodeListId}
onUpdateCodeList={onUpdateCodeList}
codeListNames={codeListNames}
/>
)}
</Accordion.Content>
);
}

export const updateCodeListWithMetadata = (
currentCodeListWithMetadata: CodeListWithMetadata,
updatedCodeList: StudioComponentsCodeList,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { CodeList, CodeListEditorTexts } from '@studio/components';
import { StudioCodeListEditor, StudioToggleableTextfield } from '@studio/components';
import React from 'react';
import { useTranslation } from 'react-i18next';
import type {CodeListData, CodeListWithMetadata} from '../../CodeListPage';
import type { CodeListWithMetadata } from '../../CodeListPage';
import { useOptionListEditorTexts } from '../../hooks/useCodeListEditorTexts';
import { KeyVerticalIcon } from '@studio/icons';
import { updateCodeListWithMetadata } from '../CodeLists';
Expand Down

0 comments on commit 9da552c

Please sign in to comment.