refactor(editor): Fix types issues in src/components/Node/* (no-changelog) (#9444)

Signed-off-by: Oleg Ivaniv <me@olegivaniv.com>
This commit is contained in:
oleg
2024-05-17 14:46:11 +02:00
committed by GitHub
parent aac19d3285
commit 69bb745cac
18 changed files with 183 additions and 111 deletions

View File

@@ -86,16 +86,20 @@ export function flattenCreateElements(items: INodeCreateElement[]): INodeCreateE
export function groupItemsInSections(
items: INodeCreateElement[],
sections: NodeViewItemSection[],
sections: string[] | NodeViewItemSection[],
): INodeCreateElement[] {
const filteredSections = sections.filter(
(section): section is NodeViewItemSection => typeof section === 'object',
);
const itemsBySection = items.reduce((acc: Record<string, INodeCreateElement[]>, item) => {
const section = sections.find((s) => s.items.includes(item.key));
const section = filteredSections.find((s) => s.items.includes(item.key));
const key = section?.key ?? 'other';
acc[key] = [...(acc[key] ?? []), item];
return acc;
}, {});
const result: SectionCreateElement[] = sections
const result: SectionCreateElement[] = filteredSections
.map(
(section): SectionCreateElement => ({
type: 'section',