Skip to content

Commit

Permalink
fix PR comments and use findError function from pure-functions
Browse files Browse the repository at this point in the history
  • Loading branch information
standeren committed Dec 11, 2024
1 parent 5978178 commit a9f9da3
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import type { UserEvent } from '@testing-library/user-event';
import type { CodeListProps, CodeListWithMetadata } from './CodeList';
import { CodeList } from './CodeList';
import { textMock } from '@studio/testing/mocks/i18nMock';
import type { CodeList as StudioComponentCodeList } from '@studio/components';

const onUpdateCodeListIdMock = jest.fn();
const onUpdateCodeListMock = jest.fn();
const onUploadCodeListMock = jest.fn();
const codeListName = 'codeList';
const codeListMock = [{ value: 'value', label: 'label' }];
const codeListMock: StudioComponentCodeList = [{ value: 'value', label: 'label' }];
const codeListWithMetadataMock: CodeListWithMetadata = {
title: codeListName,
codeList: codeListMock,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ export function CodeList({
const codeListTitles = ArrayUtils.mapByKey<CodeListWithMetadata, 'title'>(codeLists, 'title');

const handleUploadCodeList = (uploadedCodeList: File) => {
onUploadCodeList(uploadedCodeList);
setCodeListInEditMode(FileNameUtils.removeExtension(uploadedCodeList.name));
onUploadCodeList(uploadedCodeList);
};

const handleUpdateCodeListId = (codeListId: string, newCodeListId: string) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ export function CodeListsActionsBar({
const getInvalidUploadFileNameErrorMessage = useUploadCodeListNameErrorMessage();

const onSubmit = (file: File) => {
const fileNameError = getFileNameError(file.name, codeListNames);
const fileNameError = FileNameUtils.findFileNameError(
FileNameUtils.removeExtension(file.name),
codeListNames,
);
if (fileNameError) {
return toast.error(getInvalidUploadFileNameErrorMessage(fileNameError));
}
Expand All @@ -49,6 +52,3 @@ export function CodeListsActionsBar({
</div>
);
}

const getFileNameError = (fileName: string, invalidFileNames: string[]) =>
FileNameUtils.findFileNameError(FileNameUtils.removeExtension(fileName), invalidFileNames);

0 comments on commit a9f9da3

Please sign in to comment.