Skip to content

Commit

Permalink
Fix ignored data of port defined in component settings when is not de…
Browse files Browse the repository at this point in the history
…fined in node state
  • Loading branch information
tokarchyn committed Sep 11, 2022
1 parent 85fdc88 commit e3452e5
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
41 changes: 41 additions & 0 deletions lib/src/states/__tests__/portState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,45 @@ describe('Port state', () => {
expect(port.data).toEqual('data');
expect(port.label).toEqual('new label');
});

test('Port data is not defined node in component but exists in component', () => {
const defaultComponent =
store.nodesSettings.visualComponents.getComponent('default');
defaultComponent.import({
component: defaultComponent.component,
settings: {
ports: [
{
id: '1',
data: 'new data',
},
],
},
});

store.nodesStore.import([
{
id: 'mynode',
position: [0, 10],
ports: [
{
id: '1',
},
],
},
]);

const node = store.nodesStore.getNode('mynode')!;
expect(node).toBeDefined();
const port = node.getPortOrThrowException('1');
expect(port.id).toEqual('1');
expect(port.data).toEqual('new data');
expect(port.isConnectionEnabled).toEqual(true);
expect(port.label).toBeUndefined();
expect(port.linkDirection).toBeUndefined();
expect(port.offsetFromNodeCenter).toBeUndefined();
expect(port.offsetFromOrigin).toBeUndefined();
expect(port.position).toBeUndefined();
expect(port.type).toEqual('default');
});
});
4 changes: 3 additions & 1 deletion lib/src/states/portState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,9 @@ export class PortState {
});

get data() {
return this._data;
return this._data === undefined
? this.nodeComponentPortState?.data
: this._data;
}

setData = (value: any) => {
Expand Down

0 comments on commit e3452e5

Please sign in to comment.