Skip to content

Commit

Permalink
fix(editor): SchemaView renders duplicate structures properly (#12943)
Browse files Browse the repository at this point in the history
  • Loading branch information
r00gm authored Jan 30, 2025
1 parent 6258f0c commit 0d8a544
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
23 changes: 23 additions & 0 deletions packages/editor-ui/src/composables/useDataSchema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -684,4 +684,27 @@ describe('useFlattenSchema', () => {
}).length,
).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);
});
});
8 changes: 5 additions & 3 deletions packages/editor-ui/src/composables/useDataSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,8 @@ export const useFlattenSchema = () => {
path: schema.path,
});

const id = `${node.name}-${expression}`;

if (Array.isArray(schema.value)) {
const items: RenderItem[] = [];

Expand All @@ -293,14 +295,14 @@ export const useFlattenSchema = () => {
depth,
level,
icon: getIconBySchemaType(schema.type),
id: expression,
id,
collapsable: true,
nodeType: node.type,
type: 'item',
});
}

if (closedNodes.value.has(expression)) {
if (closedNodes.value.has(id)) {
return items;
}

Expand All @@ -327,7 +329,7 @@ export const useFlattenSchema = () => {
level,
depth,
value: shorten(schema.value, 600, 0),
id: expression,
id,
icon: getIconBySchemaType(schema.type),
collapsable: false,
nodeType: node.type,
Expand Down

0 comments on commit 0d8a544

Please sign in to comment.