123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237 |
- /*
- * Copyright 2018-2022 Elyra Authors
- *
- * Licensed 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.
- */
- function toCommonProperties(items: any) {
- let commonProperties: any = {
- current_parameters: {},
- parameters: [],
- uihints: {
- id: "nodeProperties",
- parameter_info: [],
- action_info: [],
- group_info: [
- {
- id: "nodeGroupInfo",
- type: "panels",
- group_info: [],
- },
- ],
- },
- resources: {},
- };
- for (const item of items) {
- switch (item.type) {
- case "boolean":
- commonProperties.current_parameters[item.id] = item.default ?? false;
- commonProperties.parameters.push({
- id: item.id,
- });
- commonProperties.uihints.parameter_info.push({
- control: "custom",
- custom_control_id: "BooleanControl",
- parameter_ref: item.id,
- label: {
- default: item.label,
- },
- data: {
- helperText: item.description,
- required: false,
- },
- });
- commonProperties.uihints.group_info[0].group_info.push({
- id: item.id,
- type: "controls",
- parameter_refs: [item.id],
- });
- break;
- case "file":
- commonProperties.current_parameters[item.id] = item.default ?? "";
- commonProperties.parameters.push({
- id: item.id,
- });
- commonProperties.uihints.parameter_info.push({
- control: "custom",
- custom_control_id: "StringControl",
- parameter_ref: item.id,
- label: {
- default: item.label,
- },
- description: item.description
- ? {
- default: item.description,
- placement: "on_panel",
- }
- : undefined,
- data: {
- format: "file",
- required: item.required ?? false,
- },
- });
- commonProperties.uihints.group_info[0].group_info.push({
- id: item.id,
- type: "controls",
- parameter_refs: [item.id],
- });
- break;
- case "string":
- commonProperties.current_parameters[item.id] = item.default ?? "";
- if (item.enum) {
- commonProperties.parameters.push({
- id: item.id,
- });
- commonProperties.uihints.parameter_info.push({
- parameter_ref: item.id,
- label: {
- default: item.label,
- },
- control: "custom",
- custom_control_id: "EnumControl",
- description: item.description
- ? {
- default: item.description,
- placement: "on_panel",
- }
- : undefined,
- data: {
- items: item.enum,
- required: item.required ?? false,
- },
- });
- } else {
- commonProperties.parameters.push({
- id: item.id,
- });
- commonProperties.uihints.parameter_info.push({
- control: "custom",
- custom_control_id: "StringControl",
- parameter_ref: item.id,
- label: {
- default: item.label,
- },
- // description: item.description
- // ? {
- // default: item.description,
- // placement: "on_panel",
- // }
- // : undefined,
- data: {
- placeholder: item.placeholder,
- format: item.format || "",
- required: item.required ?? false,
- },
- });
- }
- commonProperties.uihints.group_info[0].group_info.push({
- id: item.id,
- type: "controls",
- parameter_refs: [item.id],
- });
- break;
- case "string[]":
- commonProperties.current_parameters[item.id] = item.default ?? [];
- commonProperties.parameters.push({
- id: item.id,
- });
- commonProperties.uihints.parameter_info.push({
- control: "custom",
- custom_control_id: "StringArrayControl",
- parameter_ref: item.id,
- label: {
- default: item.label,
- },
- description: item.description
- ? {
- default: item.description,
- placement: "on_panel",
- }
- : undefined,
- data: {
- placeholder: item.placeholder,
- required: item.required ?? false,
- },
- });
- commonProperties.uihints.group_info[0].group_info.push({
- id: item.id,
- type: "controls",
- parameter_refs: [item.id],
- });
- break;
- default:
- break;
- }
- }
- return commonProperties;
- }
- export function createNode({
- op,
- description,
- properties,
- label,
- nadeLabel,
- image,
- ...rest
- }: any) {
- return {
- op,
- description,
- id: "",
- type: "execution_node",
- label,
- inputs: [
- {
- id: "inPort",
- app_data: {
- ui_data: {
- cardinality: {
- min: 0,
- max: -1,
- },
- label: "Input Port",
- },
- },
- },
- ],
- outputs: [
- {
- id: "outPort",
- app_data: {
- ui_data: {
- cardinality: {
- min: 0,
- max: -1,
- },
- label: "Output Port",
- },
- },
- },
- ],
- parameters: {},
- app_data: {
- ...rest,
- properties: toCommonProperties(properties),
- ui_data: {
- label: nadeLabel,
- image,
- x_pos: 0,
- y_pos: 0,
- },
- },
- };
- }
|