Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(editor): Add sections to create node panel (#7831)
This PR sets the stage for the node creator to handle sections within subcategories. No visible changes result from this PR; the next PR will define sections and assign nodes accordingly. Sections are configurable in `packages/editor-ui/src/components/Node/NodeCreator/viewsData.ts`: ``` { type: 'subcategory', key: FILES_SUBCATEGORY, category: CORE_NODES_CATEGORY, properties: { title: FILES_SUBCATEGORY, icon: 'file-alt', sections: [ { key: 'popular', title: i18n.baseText('nodeCreator.sectionNames.popular'), items: ['n8n-nodes-base.readBinaryFiles', 'n8n-nodes-base.compression'], }, ], }, }, ``` For example: <img width="302" alt="image" src="https://github.com/n8n-io/n8n/assets/8850410/74470c07-f4ea-4306-bd4a-8d33bd769b86"> --------- Co-authored-by: Michael Kret <michael.k@radency.com>
- Loading branch information
1 parent
485a0c7
commit 39fa8d2
Showing
12 changed files
with
273 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
packages/editor-ui/src/components/Node/NodeCreator/__tests__/utils.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import type { SectionCreateElement } from '@/Interface'; | ||
import { groupItemsInSections } from '../utils'; | ||
import { mockNodeCreateElement } from './utils'; | ||
|
||
describe('NodeCreator - utils', () => { | ||
describe('groupItemsInSections', () => { | ||
it('should handle multiple sections (with "other" section)', () => { | ||
const node1 = mockNodeCreateElement({ key: 'popularNode' }); | ||
const node2 = mockNodeCreateElement({ key: 'newNode' }); | ||
const node3 = mockNodeCreateElement({ key: 'otherNode' }); | ||
const result = groupItemsInSections( | ||
[node1, node2, node3], | ||
[ | ||
{ key: 'popular', title: 'Popular', items: [node1.key] }, | ||
{ key: 'new', title: 'New', items: [node2.key] }, | ||
], | ||
) as SectionCreateElement[]; | ||
expect(result.length).toEqual(3); | ||
expect(result[0].title).toEqual('Popular'); | ||
expect(result[0].children).toEqual([node1]); | ||
expect(result[1].title).toEqual('New'); | ||
expect(result[1].children).toEqual([node2]); | ||
expect(result[2].title).toEqual('Other'); | ||
expect(result[2].children).toEqual([node3]); | ||
}); | ||
|
||
it('should handle no sections', () => { | ||
const node1 = mockNodeCreateElement({ key: 'popularNode' }); | ||
const node2 = mockNodeCreateElement({ key: 'newNode' }); | ||
const node3 = mockNodeCreateElement({ key: 'otherNode' }); | ||
const result = groupItemsInSections([node1, node2, node3], []); | ||
expect(result).toEqual([node1, node2, node3]); | ||
}); | ||
|
||
it('should handle only empty sections', () => { | ||
const node1 = mockNodeCreateElement({ key: 'popularNode' }); | ||
const node2 = mockNodeCreateElement({ key: 'newNode' }); | ||
const node3 = mockNodeCreateElement({ key: 'otherNode' }); | ||
const result = groupItemsInSections( | ||
[node1, node2, node3], | ||
[ | ||
{ key: 'popular', title: 'Popular', items: [] }, | ||
{ key: 'new', title: 'New', items: ['someOtherNodeType'] }, | ||
], | ||
); | ||
expect(result).toEqual([node1, node2, node3]); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.