// Available variables: // - Machine // - interpret // - assign // - send // - sendParent // - spawn // - raise // - actions // - XState (all XState exports) const createAttackMachine = Machine({ id: "create-attack", initial: "loading", context: { targetType: "HOST", target: {}, impact: {}, schedule: {}, retries: 0 }, states: { error: { on: { RETRY: { target: "loading", actions: assign({ retries: (context, event) => context.retries + 1 }) } } }, loading: { on: { SUCCESS: "attackTypeSelection", ERROR: "error" } }, attackTypeSelection: { on: { SELECT_HOST: 'hostTarget', SELECT_CONTAINER: 'containerTarget', SELECT_KUBERNETES: "kubernetesTarget" } }, hostTarget: { on: { SUBMIT: { target: "impact", actions: assign({ target: (_, event) => event.value }) } } }, containerTarget: { on: { SUBMIT: { target: "impact", actions: assign({ target: (_, event) => event.value }) } } }, kubernetesTarget: { on: { SUBMIT: { target: "impact", actions: assign({ target: (_, event) => event.value }) } } }, impact: { on: { SUBMIT: { target: "review", actions: assign({ impact: (_, event) => event.value }) } } }, schedule: { on: { SUBMIT: { target: "review", actions: assign({ schedule: (_, event) => event.value }) } } }, review: { on: { SUBMIT: "saving", OPEN_TARGET: "attackTypeSelection", OPEN_IMPACT: "impact", OPEN_SCHEDULE: "schedule" } }, saving: { on: { SUCCESS: { target: "attackTypeSelection" }, ERROR: { target: "review" } } } } }, { guards: { isHostTarget: (context) => { return context.targetType === "HOST"; }, isContainerTarget: (context) => { return context.targetType === "CONTAINER"; }, isKubernetesTarget: (context) => { return context.targetType === "KUBERNETES"; }, verifyHostTarget: (context) => { return context.targetType === "HOST"; }, verifyContainerTarget: (context) => { return context.targetType === "CONTAINER"; }, verifyKubernetesTarget: (context) => { return context.targetType === "KUBERNETES"; } } });