diff --git a/apps/catalog-admin/components/codes-editor/codes-editor.module.css b/apps/catalog-admin/components/codes-editor/codes-editor.module.css index b82747e83..a24fb31fd 100644 --- a/apps/catalog-admin/components/codes-editor/codes-editor.module.css +++ b/apps/catalog-admin/components/codes-editor/codes-editor.module.css @@ -7,6 +7,7 @@ .codeTree { border-radius: 5px; flex-basis: 50%; + height: 506px; } .node { diff --git a/apps/catalog-admin/components/codes-editor/index.tsx b/apps/catalog-admin/components/codes-editor/index.tsx index 0e374633d..de261ea3d 100644 --- a/apps/catalog-admin/components/codes-editor/index.tsx +++ b/apps/catalog-admin/components/codes-editor/index.tsx @@ -59,9 +59,10 @@ export const CodesEditor = ({ codeList: dbCodeList }: Props) => { }; const updateCodeParent = (value: string) => { + const convertedValue = value !== null ? +value : null; setSelectedCode((prevSelectedCode) => ({ ...prevSelectedCode, - parentID: +value, + parentID: convertedValue, })); }; @@ -203,15 +204,16 @@ export const CodesEditor = ({ codeList: dbCodeList }: Props) => { .map((code: Code) => ({ label: String(getTranslateText(code.name)), value: code.id.toString(), - })); + })) + .concat({ label: localization.catalogAdmin.noParentCode, value: null }); } return ( <>
- + -
+
data={convertCodeListToTreeNodes(codes)} idAccessor={(node) => node.value} diff --git a/libs/utils/src/lib/code-list/index.ts b/libs/utils/src/lib/code-list/index.ts index 99f4a4f06..3bc2a253d 100644 --- a/libs/utils/src/lib/code-list/index.ts +++ b/libs/utils/src/lib/code-list/index.ts @@ -106,7 +106,7 @@ export const convertCodeListToTreeNodes = (codes: Code[] | undefined): TreeNode[ export const getAllChildrenCodes = (codeId: number, codeList: CodeList) => { const children: Code[] = []; - (codeList.codes?.filter((code) => code.parentID === codeId) ?? []).forEach((code) => { + (codeList?.codes?.filter((code) => code.parentID === codeId) ?? []).forEach((code) => { children.push(code); children.push(...getAllChildrenCodes(code.id, codeList)); });