-
Notifications
You must be signed in to change notification settings - Fork 80
Expand file tree
/
Copy pathInputNode.ts
More file actions
176 lines (165 loc) · 7.06 KB
/
InputNode.ts
File metadata and controls
176 lines (165 loc) · 7.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/**
* Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com) All Rights Reserved.
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import { Point } from "@projectstorm/geometry";
import { useDMCollapsedFieldsStore, useDMExpandedFieldsStore, useDMSearchStore } from "../../../../store/store";
import { IDataMapperContext } from "../../../../utils/DataMapperContext/DataMapperContext";
import { DataMapperNodeModel } from "../commons/DataMapperNode";
import { IOType, TypeKind } from "@wso2/ballerina-core";
import { getSearchFilteredInput } from "../../utils/search-utils";
export const INPUT_NODE_TYPE = "datamapper-node-input";
const NODE_ID = "input-node";
export class InputNode extends DataMapperNodeModel {
public filteredInputType: IOType;
public numberOfFields: number;
public x: number;
private identifier: string;
constructor(
public context: IDataMapperContext,
public inputType: IOType,
public hasNoMatchingFields?: boolean
) {
super(
`${NODE_ID}-${inputType?.id}`,
context,
INPUT_NODE_TYPE
);
this.numberOfFields = 1;
this.identifier = this.inputType?.id;
}
async initPorts() {
this.filteredInputType = this.getSearchFilteredType();
this.hasNoMatchingFields = !this.filteredInputType;
this.numberOfFields = 1;
if (this.filteredInputType) {
const collapsedFields = useDMCollapsedFieldsStore.getState().fields;
const expandedFields = useDMExpandedFieldsStore.getState().fields;
const focusedFieldFQNs = [
...this.context.views.flatMap(view => view.sourceFields).filter(Boolean),
...(this.context.model.query?.inputs || [])
];
const parentPort = this.addPortsForHeader({
dmType: this.filteredInputType,
name: this.identifier,
portType: "OUT",
portPrefix: undefined,
focusedFieldFQNs,
collapsedFields,
expandedFields
});
if (this.filteredInputType.kind === TypeKind.Record) {
const fields = this.filteredInputType.fields?.filter(f => !!f);
for (const subField of fields) {
this.numberOfFields += await this.addPortsForInputField({
field: subField,
portType: "OUT",
parentId: this.identifier,
unsafeParentId: this.identifier,
parent: parentPort,
collapsedFields,
expandedFields,
hidden: parentPort.attributes.collapsed,
isOptional: subField.optional,
focusedFieldFQNs
});
}
} else if (this.filteredInputType.kind === TypeKind.Tuple) {
const members = this.filteredInputType.members?.filter(m => !!m);
for (const member of members) {
this.numberOfFields += await this.addPortsForInputField({
field: member,
portType: "OUT",
parentId: this.identifier,
unsafeParentId: this.identifier,
parent: parentPort,
collapsedFields,
expandedFields,
hidden: parentPort.attributes.collapsed,
isOptional: member.optional,
focusedFieldFQNs
});
}
} else if (this.filteredInputType.kind === TypeKind.Enum) {
for (const member of this.filteredInputType.members ?? []) {
this.numberOfFields += await this.addPortsForInputField({
field: member,
portType: "OUT",
parentId: this.identifier,
unsafeParentId: this.identifier,
parent: parentPort,
collapsedFields,
expandedFields,
hidden: parentPort.attributes.collapsed,
isOptional: member?.optional,
focusedFieldFQNs
});
}
} else if (this.filteredInputType.kind === TypeKind.Array) {
this.numberOfFields += await this.addPortsForInputField({
field: this.filteredInputType?.member,
portType: "OUT",
parentId: this.identifier,
unsafeParentId: this.identifier,
parent: parentPort,
collapsedFields,
expandedFields,
hidden: parentPort.attributes.collapsed,
isOptional: this.filteredInputType?.member?.optional,
focusedFieldFQNs
});
} else {
await this.addPortsForInputField({
field: this.filteredInputType,
portType: "OUT",
parentId: this.identifier,
unsafeParentId: this.identifier,
parent: parentPort,
collapsedFields,
expandedFields,
hidden: parentPort.attributes.collapsed,
isOptional: this.filteredInputType.optional,
focusedFieldFQNs
});
}
}
}
async initLinks() {
// Links are always created from "IN" ports by backtracing the inputs.
}
public getSearchFilteredType() {
// TODO: Include variableName for inputTypes (Currently only available for variables)
const variableName = this.inputType.name || this.inputType.id;
if (variableName) {
const searchValue = useDMSearchStore.getState().inputSearch;
const matchesParamName = variableName.includes(searchValue?.toLowerCase());
const type = matchesParamName
? this.inputType
: getSearchFilteredInput(this.inputType, variableName);
return type;
}
}
setPosition(point: Point): void;
setPosition(x: number, y: number): void;
setPosition(x: unknown, y?: unknown): void {
if (typeof x === 'number' && typeof y === 'number'){
if (!this.x){
this.x = x;
}
super.setPosition(this.x, y);
}
}
}