Skip to content

Commit

Permalink
feat: make it possible to remove parent
Browse files Browse the repository at this point in the history
  • Loading branch information
hegeaal committed Oct 10, 2023
1 parent 95d685f commit 01270d3
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
.codeTree {
border-radius: 5px;
flex-basis: 50%;
height: 506px;
}

.node {
Expand Down
10 changes: 6 additions & 4 deletions apps/catalog-admin/components/codes-editor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}));
};

Expand Down Expand Up @@ -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 (
<>
<div className={styles.editorContainer}>
<InfoCard className={styles.codeTree}>
<InfoCard>
<InfoCard.Item>
<div>
<div className={styles.codeTree}>
<Tree<TreeNode>
data={convertCodeListToTreeNodes(codes)}
idAccessor={(node) => node.value}
Expand Down
2 changes: 1 addition & 1 deletion libs/utils/src/lib/code-list/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
});
Expand Down

0 comments on commit 01270d3

Please sign in to comment.