Skip to content

Commit

Permalink
feat: allow to display and hide then socket
Browse files Browse the repository at this point in the history
  • Loading branch information
KermanX committed Nov 10, 2023
1 parent 7c6295c commit 989201e
Showing 1 changed file with 32 additions and 8 deletions.
40 changes: 32 additions & 8 deletions packages/northstar/src/blocks/special/imp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,23 @@ import {
PATH_IN_TRIANGLE,
PATH_OUT_TRIANGLE,
SingleOutSocket,
Socket,
UseSocket,
UsedSockets,
blockCtors,
blockCtors
} from "@quasi-dev/visual-flow";
import { PropsData } from "../../utils/props";
import {
multiInSocketToOutput,
singleOutSocketToOutput,
} from "../../utils/toOutpus";
import { FuncBlockBase } from "./FuncBlockBase.r";

export class ImpBlock extends FuncBlockBase {
cloneTo(target: this): this {
super.cloneTo(target);
target.hasThen = this.hasThen;
return target;
}
type: FuncBlockTypes = "imp";

boardHeight = 80;
Expand All @@ -29,11 +34,13 @@ export class ImpBlock extends FuncBlockBase {
outputLabel = "retVal";
useTextarea = true;

hasThen = false;

get whenSocket() {
return this.getSocketByName("when") as MultiInSocket;
}
get thenSocket() {
return this.getSocketByName("then") as SingleOutSocket;
return this.getSocketByName("then") as SingleOutSocket | undefined;
}

socketUpdater(useSocket: UseSocket, usedSockets: UsedSockets): void {
Expand All @@ -43,11 +50,13 @@ export class ImpBlock extends FuncBlockBase {
path: PATH_IN_TRIANGLE,
direction: Direction.LEFT,
});
useSocket("then", SingleOutSocket, {
type: "E",
path: PATH_OUT_TRIANGLE,
direction: Direction.RIGHT,
});
if (this.hasThen) {
useSocket("then", SingleOutSocket, {
type: "E",
path: PATH_OUT_TRIANGLE,
direction: Direction.RIGHT,
});
}
usedSockets.find(([n]) => n === "output")![1].disabled =
this.inputValue.value.match(/\breturn\b/g) === null;
}
Expand All @@ -58,6 +67,21 @@ export class ImpBlock extends FuncBlockBase {
return [...matches].map((match) => match[0].slice(1));
}

getProps(): PropsData {
return [
{
name: "has then",
type: "switch",
getVal: () => {
return this.hasThen;
},
setVal: (val) => {
this.hasThen = val;
},
},
];
}

toOutput(): ImpBlockOutput {
return {
...(super.toOutput() as FuncBlockOutput),
Expand Down

0 comments on commit 989201e

Please sign in to comment.