Skip to content

Commit

Permalink
fix: fix issue for null values in the alignFields util
Browse files Browse the repository at this point in the history
  • Loading branch information
yvonneyx committed Aug 8, 2024
1 parent 117d451 commit a495b28
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
42 changes: 42 additions & 0 deletions packages/g6/__tests__/bugs/plugin-history-align-fields.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { createGraph } from '@@/utils';

describe('bug: plugin-history-align-fields', () => {
it('fix alignFields util', async () => {
const graph = createGraph({
plugins: [{ type: 'history', key: 'history' }],
data: {
nodes: [
{
id: 'node-1',
type: 'rect',
style: { x: 50, y: 100 },
data: {
aaa: {
bbb: false,
ccc: true,
ddd: '1234',
},
},
},
],
},
});

await graph.render();

expect(graph.getNodeData('node-1').style).toEqual({ x: 50, y: 100 });
expect(graph.getNodeData('node-1').data!.aaa).toEqual({
bbb: false,
ccc: true,
ddd: '1234',
});

await graph.translateElementBy('node-1', [100, 100]);
expect(graph.getNodeData('node-1').style).toEqual({ x: 150, y: 200, z: 0 });
expect(graph.getNodeData('node-1').data!.aaa).toEqual({
bbb: false,
ccc: true,
ddd: '1234',
});
});
});
2 changes: 1 addition & 1 deletion packages/g6/src/plugins/history/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function alignFields(refObject: Record<string, any>, targetObject: Record
if (isObject(refObject[key]) && !Array.isArray(refObject[key]) && refObject[key] !== null) {
if (!targetObject[key]) targetObject[key] = {};
alignFields(refObject[key], targetObject[key]);
} else if (!targetObject[key]) {
} else if (targetObject[key] === undefined) {
targetObject[key] = inferDefaultValue(key);
}
}
Expand Down

0 comments on commit a495b28

Please sign in to comment.