mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
fix(editor): SchemaView renders duplicate structures properly (#12943)
This commit is contained in:
parent
6258f0c9dd
commit
0d8a544975
|
@ -684,4 +684,27 @@ describe('useFlattenSchema', () => {
|
||||||
}).length,
|
}).length,
|
||||||
).toBe(3);
|
).toBe(3);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('items ids should be unique', () => {
|
||||||
|
const { flattenSchema } = useFlattenSchema();
|
||||||
|
const schema: Schema = {
|
||||||
|
path: '',
|
||||||
|
type: 'object',
|
||||||
|
value: [
|
||||||
|
{
|
||||||
|
key: 'index',
|
||||||
|
type: 'number',
|
||||||
|
value: '0',
|
||||||
|
path: '.index',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
const node1 = { name: 'First Node', type: 'any' };
|
||||||
|
const node2 = { name: 'Second Node', type: 'any' };
|
||||||
|
|
||||||
|
const node1Schema = flattenSchema({ schema, node: node1, depth: 1 });
|
||||||
|
const node2Schema = flattenSchema({ schema, node: node2, depth: 1 });
|
||||||
|
|
||||||
|
expect(node1Schema[0].id).not.toBe(node2Schema[0].id);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -282,6 +282,8 @@ export const useFlattenSchema = () => {
|
||||||
path: schema.path,
|
path: schema.path,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const id = `${node.name}-${expression}`;
|
||||||
|
|
||||||
if (Array.isArray(schema.value)) {
|
if (Array.isArray(schema.value)) {
|
||||||
const items: RenderItem[] = [];
|
const items: RenderItem[] = [];
|
||||||
|
|
||||||
|
@ -293,14 +295,14 @@ export const useFlattenSchema = () => {
|
||||||
depth,
|
depth,
|
||||||
level,
|
level,
|
||||||
icon: getIconBySchemaType(schema.type),
|
icon: getIconBySchemaType(schema.type),
|
||||||
id: expression,
|
id,
|
||||||
collapsable: true,
|
collapsable: true,
|
||||||
nodeType: node.type,
|
nodeType: node.type,
|
||||||
type: 'item',
|
type: 'item',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (closedNodes.value.has(expression)) {
|
if (closedNodes.value.has(id)) {
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -327,7 +329,7 @@ export const useFlattenSchema = () => {
|
||||||
level,
|
level,
|
||||||
depth,
|
depth,
|
||||||
value: shorten(schema.value, 600, 0),
|
value: shorten(schema.value, 600, 0),
|
||||||
id: expression,
|
id,
|
||||||
icon: getIconBySchemaType(schema.type),
|
icon: getIconBySchemaType(schema.type),
|
||||||
collapsable: false,
|
collapsable: false,
|
||||||
nodeType: node.type,
|
nodeType: node.type,
|
||||||
|
|
Loading…
Reference in a new issue