// Available variables: // - Machine // - interpret // - assign // - send // - sendParent // - spawn // - raise // - actions // - XState (all XState exports) const fetchMachine = Machine({ id: 'order-sequencing', type: "parallel", states: { calendar: { type: "parallel", states: { mode: { initial: 'week', states: { day: { on: { SHOW_WEEK: { target: "week", actions: ["setFilterToWeek", send("LOAD")] }, SHOW_TODAY: { actions: ["setFilterToToday", send("LOAD")] }, BEFORE: { actions: ["setFilterToDayBefore", send("LOAD")] }, AFTER: { actions: ["setFilterToDayAfter", send("LOAD")] } } }, week: { on: { SHOW_DAY: { target: "day", actions: ["setFilterToBeginningOfWeek", send("LOAD")] }, SHOW_TODAY: { actions: ["setFilterToToday", send("LOAD")] }, BEFORE: { actions: ["setFilterToWeekBefore", send("LOAD")] }, AFTER: { actions: ["setFilterToWeekAfter", send("LOAD")] } } } } }, // data for listing production schedule items for currently set filer data: { initial: "idle", states: { idle: { on: { LOAD: "loading" }, after: { 10000: "loading" } }, loading: { onEntry: [send("LOAD")], on: { LOAD: { actions: ["loadProductionScheduleItemsForCurrentFilter"] }, LOAD_SUCCESS: "success", LOAD_ERROR: "error" } }, success: { onEntry: ["setListOfProductionScheduleItems"], on: { "": "idle" } }, error: { onEntry: ["showErrorToUser"] } } } } }, workflow: { type: "parallel", states: { mode: { initial: "read", states: { read: { on: { START_EDITING: "write" } }, write: { type: "parallel", on: { STOP_EDITING: "read" }, states: { production_orders: { initial: "empty", states: { empty: { on: { SELECTION_UPDATED: "selection" } }, selection: { on: { SELECTION_UPDATED: [ { target: "empty", cond: "emptySelection" } ] } } } }, production_schedule_item: { initial: "empty", states: { empty: { on: { CLICKED_ITEM: { target: "selection" } } }, selection: { onEntry: ["setItem"], on: { CLICKED_ITEM: [{ target: "empty", cond: "isSameItem" }, { target: "selection" }], MOVE_UP: { actions: ["moveUp", send("SAVE")] }, MOVE_DOWN: { actions: ["moveDown", send("SAVE")] }, REMOVE_FROM_PLANNING: { target: "empty", actions: ["removeFromPlanning", send("SAVE")] } } } } } } } } }, data: { initial: "idle", states: { idle: { on: { SAVE: { target: "saving" } } }, saving: { onEntry: ["save"], on: { SAVE_SUCCESS: "success", SAVE_ERROR: "error" } }, success: { onEntry: ["load", send("LOAD")], on: { "": "idle" } }, error: {} } } } } } });