stitch-ui
Version:
51 lines (44 loc) • 1.13 kB
JavaScript
import { Record, Map } from "immutable";
import JSONState from "./JSONState";
import PipelineStage from "./PipelineStage";
export default class PipelineStageEditState extends Record({
service: "",
action: "",
initArgsInput: {},
argsInput: JSONState.fromRaw({}),
letInput: undefined,
letEnabled: false,
dirty: false
}) {
toRaw() {
return {
service: this.service,
action: this.action,
argsInput: this.argsInput,
letInput: this.letInput,
letEnabled: this.letEnabled
};
}
get error() {
return (
this.argsInput.get("error") ||
(this.letInput && this.letInput.get("error"))
);
}
parseInput() {
const parsedArgs = this.argsInput.parseInput();
let parsedLet;
if (this.letEnabled) {
parsedLet = this.letInput.parseInput();
}
return this.set("argsInput", parsedArgs).set("letInput", parsedLet);
}
toStage() {
return new PipelineStage({
service: this.service,
action: this.action,
args: new Map(this.argsInput.data),
let: this.letInput ? new Map(this.letInput.data) : undefined
});
}
}