@seedtactics/insight-client 17.0.1-beta.9 → 17.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/README.md +16 -4
  2. package/dist/assets/ProgramHighlight-mKbZxoXO.js +3 -0
  3. package/dist/assets/index-Cjt4dPv7.js +367 -0
  4. package/dist/cell-status/current-status.d.ts +1 -0
  5. package/dist/cell-status/current-status.js +46 -51
  6. package/dist/cell-status/loading.d.ts +13 -2
  7. package/dist/cell-status/loading.js +39 -7
  8. package/dist/cell-status/material-details.d.ts +2 -2
  9. package/dist/cell-status/material-details.js +33 -14
  10. package/dist/components/App.d.ts +0 -5
  11. package/dist/components/App.js +1 -1
  12. package/dist/components/ChooseMode.js +15 -3
  13. package/dist/components/ErrorsAndLoading.js +2 -1
  14. package/dist/components/LoadingIcon.js +3 -1
  15. package/dist/components/analysis/BufferChart.js +3 -2
  16. package/dist/components/operations/AllMaterial.js +9 -12
  17. package/dist/components/operations/RecentCycleChart.js +16 -21
  18. package/dist/components/quality/QualityMaterial.js +3 -12
  19. package/dist/components/station-monitor/BasketLoadStationWork.d.ts +4 -7
  20. package/dist/components/station-monitor/BasketLoadStationWork.js +97 -44
  21. package/dist/components/station-monitor/CancelLoadButton.js +8 -3
  22. package/dist/components/station-monitor/InvalidateCycle.js +26 -25
  23. package/dist/components/station-monitor/LoadStation.d.ts +0 -5
  24. package/dist/components/station-monitor/LoadStation.js +88 -115
  25. package/dist/components/station-monitor/Material.d.ts +6 -1
  26. package/dist/components/station-monitor/Material.js +22 -9
  27. package/dist/components/station-monitor/MoveMaterialArrows.js +9 -0
  28. package/dist/components/station-monitor/PrintedLabel.js +15 -19
  29. package/dist/components/station-monitor/QuarantineButton.js +21 -29
  30. package/dist/components/station-monitor/QueuesAddMaterial.js +2 -5
  31. package/dist/components/station-monitor/SystemOverview.js +59 -19
  32. package/dist/components/station-monitor/Whiteboard.js +14 -15
  33. package/dist/data/material-operation-policy.d.ts +6 -0
  34. package/dist/data/material-operation-policy.js +26 -2
  35. package/dist/data/move-arrows.d.ts +7 -0
  36. package/dist/data/move-arrows.js +107 -24
  37. package/dist/data/queue-material.d.ts +1 -0
  38. package/dist/data/queue-material.js +55 -48
  39. package/dist/extension.d.ts +1 -1
  40. package/dist/extension.js +1 -0
  41. package/dist/index.html +2 -39
  42. package/dist/index.js +1 -6
  43. package/dist/network/api-errors.d.ts +8 -0
  44. package/dist/network/api-errors.js +77 -0
  45. package/dist/network/api.d.ts +20 -34
  46. package/dist/network/api.js +68 -64
  47. package/dist/network/backend-mock.js +3 -0
  48. package/dist/network/backend.d.ts +3 -2
  49. package/dist/network/current-status-session.d.ts +27 -0
  50. package/dist/network/current-status-session.js +65 -0
  51. package/dist/network/websocket.d.ts +4 -0
  52. package/dist/network/websocket.js +176 -37
  53. package/dist/util/parseISODuration.js +10 -9
  54. package/docs/material-quarantine.md +5 -4
  55. package/docs/mazak.md +11 -14
  56. package/docs/operator-procedures.md +14 -0
  57. package/docs/server-config.md +20 -12
  58. package/package.json +25 -20
  59. package/dist/assets/ProgramHighlight-C6zSEXCX.js +0 -3
  60. package/dist/assets/index-MFZreX-b.js +0 -388
  61. package/dist/components/station-monitor/BasketMovementArrival.d.ts +0 -40
  62. package/dist/components/station-monitor/BasketMovementArrival.js +0 -165
@@ -5,6 +5,7 @@ export declare const currentStatus: Atom<ICurrentStatus>;
5
5
  export declare const secondsSinceEpochAtom: import("jotai").PrimitiveAtom<number> & {
6
6
  init: number;
7
7
  };
8
+ export declare const minutesSinceEpochAtom: Atom<number>;
8
9
  export declare const setJobComment: import("jotai").WritableAtom<null, [uniq: string, newVal: string | null], void> & {
9
10
  init: null;
10
11
  };
@@ -34,8 +34,10 @@ import { JobsBackend, LogBackend } from "../network/backend.js";
34
34
  import { InProcessMaterial, LogType, LocType, ActiveJob, WorkorderComment, ActiveWorkorder, InProcessMaterialLocation, } from "../network/api.js";
35
35
  import { last30JobComment } from "./scheduled-jobs.js";
36
36
  import { atom } from "jotai";
37
+ import { HashSet } from "@seedtactics/immutable-collections";
37
38
  import { currentOperator } from "../data/operators.js";
38
39
  const currentStatusRW = atom({
40
+ revision: 0,
39
41
  timeOfCurrentStatusUTC: new Date(),
40
42
  jobs: {},
41
43
  pallets: {},
@@ -51,6 +53,8 @@ secondsSinceEpochAtom.onMount = (setSelf) => {
51
53
  }, 1000);
52
54
  return () => clearInterval(interval);
53
55
  };
56
+ // Minute precision keeps report time windows current without redrawing charts every second.
57
+ export const minutesSinceEpochAtom = atom((get) => Math.floor(get(secondsSinceEpochAtom) / 60));
54
58
  export const setJobComment = atom(null, (_, set, uniq, newVal) => {
55
59
  const newComment = newVal === null ? "" : newVal;
56
60
  set(currentStatusRW, (st) => {
@@ -98,59 +102,50 @@ export const updateCurrentStatus = atom(null, (_, set, { evt }) => {
98
102
  });
99
103
  function processEventsIntoCurrentStatus(entry) {
100
104
  return (curSt) => {
101
- const mats = new Map();
102
- function adjustMat(id, f) {
103
- if (mats.size === 0) {
104
- for (const m of curSt.material) {
105
- mats.set(m.materialID, m);
106
- }
107
- }
108
- const oldMat = mats.get(id);
109
- if (oldMat !== undefined) {
110
- mats.set(id, new InProcessMaterial(f(oldMat)));
111
- }
112
- }
113
- switch (entry.type) {
114
- case LogType.PartMark:
115
- for (const m of entry.material) {
116
- adjustMat(m.id, (inmat) => ({ ...inmat, serial: entry.result }));
117
- }
118
- break;
119
- case LogType.OrderAssignment:
120
- for (const m of entry.material) {
121
- adjustMat(m.id, (inmat) => ({ ...inmat, workorderId: entry.result }));
122
- }
123
- break;
124
- case LogType.Inspection:
125
- case LogType.InspectionForce:
126
- if (entry.result.toLowerCase() === "true" || entry.result === "1") {
127
- let inspType;
128
- if (entry.type === LogType.InspectionForce) {
129
- inspType = entry.program;
130
- }
131
- else {
132
- inspType = (entry.details || {}).InspectionType;
133
- }
134
- if (inspType) {
135
- for (const m of entry.material) {
136
- adjustMat(m.id, (inmat) => ({
137
- ...inmat,
138
- signaledInspections: [...inmat.signaledInspections, inspType],
139
- }));
105
+ if (entry.type !== LogType.PartMark &&
106
+ entry.type !== LogType.OrderAssignment &&
107
+ entry.type !== LogType.Inspection &&
108
+ entry.type !== LogType.InspectionForce)
109
+ return curSt;
110
+ const materialIds = HashSet.from(entry.material.map((m) => m.id));
111
+ // Anonymous raw material can repeat ID -1, including several pieces in the same slot. A log
112
+ // updates identified material in place; it must never rebuild these targets through an ID map.
113
+ const material = curSt.material.map((mat) => {
114
+ if (mat.materialID < 0 || !materialIds.has(mat.materialID))
115
+ return mat;
116
+ const data = mat;
117
+ switch (entry.type) {
118
+ case LogType.PartMark:
119
+ return mat.serial === entry.result
120
+ ? mat
121
+ : new InProcessMaterial({ ...data, serial: entry.result });
122
+ case LogType.OrderAssignment:
123
+ return mat.workorderId === entry.result
124
+ ? mat
125
+ : new InProcessMaterial({ ...data, workorderId: entry.result });
126
+ case LogType.Inspection:
127
+ case LogType.InspectionForce:
128
+ if (entry.result.toLowerCase() === "true" || entry.result === "1") {
129
+ let inspType;
130
+ if (entry.type === LogType.InspectionForce) {
131
+ inspType = entry.program;
132
+ }
133
+ else {
134
+ inspType = (entry.details || {}).InspectionType;
140
135
  }
136
+ if (inspType && !mat.signaledInspections.includes(inspType))
137
+ return new InProcessMaterial({
138
+ ...data,
139
+ signaledInspections: [...mat.signaledInspections, inspType],
140
+ });
141
141
  }
142
- }
143
- break;
144
- }
145
- if (mats.size === 0) {
146
- return curSt;
147
- }
148
- else {
149
- return {
150
- ...curSt,
151
- material: Array.from(mats.values()),
152
- };
153
- }
142
+ break;
143
+ }
144
+ return mat;
145
+ });
146
+ return material.every((mat, idx) => mat === curSt.material[idx])
147
+ ? curSt
148
+ : { ...curSt, material };
154
149
  };
155
150
  }
156
151
  export const reorderQueuedMatInCurrentStatus = atom(null, (_, set, { queue, matId, newIdx }) => {
@@ -1,4 +1,6 @@
1
- import { ICurrentStatus, IHistoricData, ILogEntry, IRecentHistoricData, IServerEvent } from "../network/api.js";
1
+ import { IHistoricData, ILogEntry, IRecentHistoricData, IServerEvent } from "../network/api.js";
2
+ export { onLoadCurrentSt } from "../network/current-status-session.js";
3
+ import * as currentSt from "./current-status.js";
2
4
  import { Atom } from "jotai";
3
5
  export interface ServerEventAndTime {
4
6
  readonly evt: Readonly<IServerEvent>;
@@ -6,6 +8,12 @@ export interface ServerEventAndTime {
6
8
  readonly expire: boolean;
7
9
  }
8
10
  export declare const lastEventCounter: Atom<number | null>;
11
+ export declare const onLiveServerEvent: import("jotai").WritableAtom<null, [evt: ServerEventAndTime], void> & {
12
+ init: null;
13
+ };
14
+ export declare const onHistoricalServerEvent: import("jotai").WritableAtom<null, [evt: ServerEventAndTime], void> & {
15
+ init: null;
16
+ };
9
17
  export declare const onServerEvent: import("jotai").WritableAtom<null, [evt: ServerEventAndTime], void> & {
10
18
  init: null;
11
19
  };
@@ -15,7 +23,10 @@ export declare const onLoadLast30Jobs: import("jotai").WritableAtom<null, [histo
15
23
  export declare const onLoadLast30Log: import("jotai").WritableAtom<null, [log: readonly Readonly<ILogEntry>[]], void> & {
16
24
  init: null;
17
25
  };
18
- export declare const onLoadCurrentSt: import("jotai").WritableAtom<null, [curSt: Readonly<ICurrentStatus>], void> & {
26
+ export interface QueuedMatMove extends currentSt.QueueReordering {
27
+ readonly operator: string | null;
28
+ }
29
+ export declare const moveQueuedMatInCurrentStatus: import("jotai").WritableAtom<null, [QueuedMatMove], Promise<void>> & {
19
30
  init: null;
20
31
  };
21
32
  export declare const onLoadSpecificMonthJobs: import("jotai").WritableAtom<null, [historicData: Readonly<IHistoricData>], void> & {
@@ -30,6 +30,10 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30
30
  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31
31
  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
32
  */
33
+ import { QueuePosition, } from "../network/api.js";
34
+ import { acceptCurrentStatusSnapshot, currentStatusSessionAtom, onLoadCurrentSt, } from "../network/current-status-session.js";
35
+ export { onLoadCurrentSt } from "../network/current-status-session.js";
36
+ import { JobsBackend } from "../network/backend.js";
33
37
  import { LazySeq } from "@seedtactics/immutable-collections";
34
38
  import * as simProd from "./sim-production.js";
35
39
  import * as simUse from "./sim-station-use.js";
@@ -50,16 +54,20 @@ import * as simDayUsage from "./sim-day-usage.js";
50
54
  import * as rebookings from "./rebookings.js";
51
55
  import { atom } from "jotai";
52
56
  const lastEventCounterRW = atom(null);
57
+ // Highest counter applied to historical projections. Buffered websocket events do not advance it.
58
+ // This is a reconnect cursor, not proof that lower counters cannot arrive later on the socket.
53
59
  export const lastEventCounter = lastEventCounterRW;
54
- export const onServerEvent = atom(null, (_, set, evt) => {
60
+ export const onLiveServerEvent = atom(null, (_, set, evt) => {
55
61
  if (evt.evt.newCurrentStatus) {
56
62
  set(customSt.replaceCustomState, evt.evt.newCurrentStatus.customState ?? null);
57
63
  }
64
+ set(currentSt.updateCurrentStatus, evt);
65
+ });
66
+ export const onHistoricalServerEvent = atom(null, (_, set, evt) => {
58
67
  set(simProd.updateLast30JobProduction, evt);
59
68
  set(simUse.updateLast30SimStatUse, evt);
60
69
  set(schJobs.updateLast30Jobs, evt);
61
70
  set(buffers.updateLast30Buffer, evt);
62
- set(currentSt.updateCurrentStatus, evt);
63
71
  set(mats.updateLast30MatSummary, evt);
64
72
  set(insp.updateLast30Inspections, evt);
65
73
  set(names.updateNames, evt);
@@ -72,9 +80,13 @@ export const onServerEvent = atom(null, (_, set, evt) => {
72
80
  set(simDayUsage.updateLatestSimDayUsage, evt);
73
81
  if (evt.evt.logEntry) {
74
82
  const newCntr = evt.evt.logEntry.counter;
75
- set(lastEventCounterRW, (old) => (old === null ? old : Math.max(old, newCntr)));
83
+ set(lastEventCounterRW, (old) => Math.max(old ?? newCntr, newCntr));
76
84
  }
77
85
  });
86
+ export const onServerEvent = atom(null, (_, set, evt) => {
87
+ set(onLiveServerEvent, evt);
88
+ set(onHistoricalServerEvent, evt);
89
+ });
78
90
  export const onLoadLast30Jobs = atom(null, (get, set, historicData) => {
79
91
  const filtered = schJobs.filterExistingJobs(get(schJobs.last30SchIds), historicData);
80
92
  set(simUse.setLast30SimStatUse, filtered);
@@ -99,10 +111,30 @@ export const onLoadLast30Log = atom(null, (_, set, log) => {
99
111
  const newCntr = LazySeq.of(log).maxBy((x) => x.counter)?.counter ?? null;
100
112
  set(lastEventCounterRW, (oldCntr) => oldCntr === null ? newCntr : Math.max(oldCntr, newCntr ?? -1));
101
113
  });
102
- export const onLoadCurrentSt = atom(null, (_, set, curSt) => {
103
- set(currentSt.setCurrentStatus, curSt);
104
- set(customSt.replaceCustomState, curSt.customState ?? null);
105
- set(names.setNamesFromCurrentStatus, curSt);
114
+ // Show queue drops immediately. Recovery must not replace intervening live updates or drags.
115
+ export const moveQueuedMatInCurrentStatus = atom(null, async (get, set, { operator, ...move }) => {
116
+ const before = get(currentSt.currentStatus);
117
+ set(currentSt.reorderQueuedMatInCurrentStatus, move);
118
+ const optimistic = get(currentSt.currentStatus);
119
+ try {
120
+ await JobsBackend.setMaterialInQueue(move.matId, operator, new QueuePosition({ queue: move.queue, position: move.newIdx }));
121
+ }
122
+ catch (error) {
123
+ const session = get(currentStatusSessionAtom).id;
124
+ const beforeReload = get(currentSt.currentStatus);
125
+ try {
126
+ const refreshed = await JobsBackend.currentStatus();
127
+ if (get(currentSt.currentStatus) === beforeReload)
128
+ set(acceptCurrentStatusSnapshot, session, refreshed, "http");
129
+ }
130
+ catch {
131
+ // If the server is unreachable, undo only this move's untouched optimistic snapshot.
132
+ if (get(currentStatusSessionAtom).id === session &&
133
+ get(currentSt.currentStatus) === optimistic)
134
+ set(onLoadCurrentSt, before);
135
+ }
136
+ throw error;
137
+ }
106
138
  });
107
139
  export const onLoadSpecificMonthJobs = atom(null, (_, set, historicData) => {
108
140
  set(simUse.setSpecificMonthSimStatUse, historicData);
@@ -44,7 +44,7 @@ export declare const barcodePotentialNewMaterial: Atom<Promise<Readonly<IScanned
44
44
  export declare const materialInDialogInfo: Atom<Promise<MaterialToShowInfo | null>>;
45
45
  export declare const materialInDialogInfoUnwrapped: Atom<MaterialToShowInfo | null>;
46
46
  export declare const materialInDialogInfoState: Atom<AsyncAtomState<MaterialToShowInfo | null>>;
47
- export declare const inProcessMaterialInDialog: Atom<Promise<IInProcessMaterial | null>>;
47
+ export declare const inProcessMaterialInDialog: Atom<IInProcessMaterial | Promise<IInProcessMaterial | null> | null>;
48
48
  export declare const serialInMaterialDialog: Atom<Promise<string | null>>;
49
49
  export declare const serialInMaterialDialogUnwrapped: Atom<string | null>;
50
50
  export declare const serialInMaterialDialogState: Atom<AsyncAtomState<string | null>>;
@@ -61,7 +61,7 @@ export interface MaterialToShowInspections {
61
61
  readonly completedInspections: ReadonlyArray<string>;
62
62
  }
63
63
  export declare const materialInDialogInspections: Atom<MaterialToShowInspections>;
64
- export declare const possibleWorkordersForMaterialInDialog: Atom<Promise<readonly IActiveWorkorder[]>>;
64
+ export declare const possibleWorkordersForMaterialInDialog: Atom<Promise<readonly IActiveWorkorder[]> | readonly IActiveWorkorder[]>;
65
65
  export interface ForceInspectionData {
66
66
  readonly mat: MaterialToShowInfo;
67
67
  readonly inspType: string;
@@ -116,18 +116,38 @@ function asyncAtomState(source) {
116
116
  return unwrap(atom((get) => get(source).then((data) => ({ state: "hasData", data }), (error) => ({ state: "hasError", error }))), () => ({ state: "loading" }));
117
117
  }
118
118
  export const materialInDialogInfoState = asyncAtomState(materialInDialogInfo);
119
- export const inProcessMaterialInDialog = atom(async (get) => {
120
- const status = get(currentStatus);
119
+ // Some cells publish current status every second. Dialog atoms that combine current status with the
120
+ // dialog material must not suspend on each status update, since that hides the dialog content behind
121
+ // its loading fallback. They compute synchronously once the dialog material is known and suspend
122
+ // only while it is still loading (e.g., a barcode or serial lookup).
123
+ function withDialogMaterial(get, compute) {
124
+ const info = get(materialInDialogInfoState);
125
+ switch (info.state) {
126
+ case "hasData":
127
+ return compute(info.data);
128
+ case "hasError":
129
+ throw info.error;
130
+ case "loading":
131
+ return get(materialInDialogInfo).then(compute);
132
+ }
133
+ }
134
+ export const inProcessMaterialInDialog = atom((get) => {
121
135
  const toShow = get(matToShow);
122
136
  if (toShow === null)
123
137
  return null;
138
+ const status = get(currentStatus);
124
139
  if (toShow.type === "InProcMat") {
125
- return status.material.find((m) => m.materialID === toShow.inproc.materialID) ?? null;
140
+ return (status.material.find((m) => m.materialID === toShow.inproc.materialID &&
141
+ (m.materialID >= 0 ||
142
+ (m.action.loadCancellationId === toShow.inproc.action.loadCancellationId &&
143
+ m.action.workId === toShow.inproc.action.workId &&
144
+ m.action.loadToBasketSlot === toShow.inproc.action.loadToBasketSlot &&
145
+ m.action.loadToBasketId === toShow.inproc.action.loadToBasketId &&
146
+ m.jobUnique === toShow.inproc.jobUnique))) ?? null);
126
147
  }
127
- const matId = (await get(materialInDialogInfo))?.materialID ?? null;
128
- return matId !== null && matId >= 0
129
- ? (status.material.find((m) => m.materialID === matId) ?? null)
130
- : null;
148
+ return withDialogMaterial(get, (mat) => mat !== null && mat.materialID >= 0
149
+ ? (status.material.find((m) => m.materialID === mat.materialID) ?? null)
150
+ : null);
131
151
  });
132
152
  export const serialInMaterialDialog = atom(async (get) => {
133
153
  const toShow = get(matToShow);
@@ -278,14 +298,13 @@ export const materialInDialogInspections = atom((get) => {
278
298
  //--------------------------------------------------------------------------------
279
299
  // Workorders
280
300
  //--------------------------------------------------------------------------------
281
- export const possibleWorkordersForMaterialInDialog = atom(async (get) => {
282
- const mat = await get(materialInDialogInfo);
283
- if (mat === null || mat.partName === "")
284
- return [];
301
+ export const possibleWorkordersForMaterialInDialog = atom((get) => {
285
302
  const works = get(currentStatus)?.workorders ?? [];
286
- return LazySeq.of(works)
287
- .filter((w) => w.part === mat.partName)
288
- .toSortedArray((w) => w.dueDate.getTime(), (w) => -w.priority);
303
+ return withDialogMaterial(get, (mat) => mat === null || mat.partName === ""
304
+ ? []
305
+ : LazySeq.of(works)
306
+ .filter((w) => w.part === mat.partName)
307
+ .toSortedArray((w) => w.dueDate.getTime(), (w) => -w.priority));
289
308
  });
290
309
  export function useForceInspection() {
291
310
  const [updating, setUpdating] = useState(false);
@@ -1,8 +1,6 @@
1
1
  import { ReactNode, ComponentType } from "react";
2
2
  import { ChooseModeItem } from "./ChooseMode.js";
3
3
  import * as serverSettings from "../network/server-settings.js";
4
- import type { SubmitBasketLoadStationCommand } from "./station-monitor/BasketLoadStationWork.js";
5
- import type { SubmitBasketLocationCorrection, SubmitBasketMovementCompletion } from "./station-monitor/BasketMovementArrival.js";
6
4
  export declare function NavTabs({ children }: {
7
5
  children?: ReactNode;
8
6
  }): import("react").JSX.Element;
@@ -12,9 +10,6 @@ export interface AppProps {
12
10
  readonly page: ReactNode;
13
11
  };
14
12
  readonly chooseModes?: (i: serverSettings.FMSInfoAndUser) => ReadonlyArray<ChooseModeItem> | null;
15
- readonly submitBasketLoadStationCommand?: SubmitBasketLoadStationCommand;
16
- readonly submitBasketMovementCompletion?: SubmitBasketMovementCompletion;
17
- readonly submitBasketLocationCorrection?: SubmitBasketLocationCorrection;
18
13
  }
19
14
  declare const App: import("react").MemoExoticComponent<(props: AppProps) => import("react").JSX.Element>;
20
15
  export default App;
@@ -310,7 +310,7 @@ const App = memo(function App(props) {
310
310
  else {
311
311
  switch (route.route) {
312
312
  case routes.RouteLocation.Station_LoadMonitor:
313
- page = (_jsx(LoadStation, { loadNum: route.loadNum, queues: route.queues, completed: route.completed, submitBasketLoadStationCommand: props.submitBasketLoadStationCommand, submitBasketMovementCompletion: props.submitBasketMovementCompletion, submitBasketLocationCorrection: props.submitBasketLocationCorrection }, route.loadNum));
313
+ page = (_jsx(LoadStation, { loadNum: route.loadNum, queues: route.queues, completed: route.completed }, route.loadNum));
314
314
  nav1 = StationToolbar;
315
315
  nav2 = StationToolbarOverviewButton;
316
316
  showOperator = true;
@@ -31,7 +31,7 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31
31
  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32
32
  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
33
  */
34
- import { ListItem, ListItemButton, Paper } from "@mui/material";
34
+ import { Alert, AlertTitle, ListItem, ListItemButton, Paper } from "@mui/material";
35
35
  import { List } from "@mui/material";
36
36
  import { ListItemIcon } from "@mui/material";
37
37
  import { ListSubheader } from "@mui/material";
@@ -39,6 +39,11 @@ import { ListItemText } from "@mui/material";
39
39
  import { Typography } from "@mui/material";
40
40
  import { Build as BuildIcon, ShoppingBasket, Directions as DirectionsIcon, StarRate as StarIcon, InsertChart as ChartIcon, Extension as ExtensionIcon, Info as InfoIcon, Opacity as OpacityIcon, Memory as MemoryIcon, CalendarViewMonth, Paid as SalesIcon, } from "@mui/icons-material";
41
41
  import { RouteLocation } from "./routes.js";
42
+ import { useAtomValue } from "jotai";
43
+ import { LazySeq } from "@seedtactics/immutable-collections";
44
+ import { currentStatus } from "../cell-status/current-status.js";
45
+ import { errorLoadingLast30 } from "../network/websocket.js";
46
+ import { errorLoadingSpecificMonthData } from "../network/load-specific-month.js";
42
47
  export const defaultChooseModes = [
43
48
  { type: "Subheader", caption: "Shop Floor" },
44
49
  {
@@ -130,12 +135,19 @@ export const defaultChooseModes = [
130
135
  },
131
136
  ];
132
137
  export function ChooseMode(p) {
138
+ const status = useAtomValue(currentStatus);
139
+ const recentError = useAtomValue(errorLoadingLast30);
140
+ const monthError = useAtomValue(errorLoadingSpecificMonthData);
141
+ const errors = LazySeq.of([...status.alarms, recentError, monthError])
142
+ .filter((error) => error !== null && error.length > 0)
143
+ .distinct()
144
+ .toRArray();
133
145
  const navList = (_jsx(Paper, { children: _jsx(List, { component: "nav", dense: true, children: (p.modes ?? defaultChooseModes).map((mode, idx) => mode.type === "Subheader" ? (_jsx(ListSubheader, { children: mode.caption }, idx)) : (_jsx(ListItem, { children: _jsxs(ListItemButton, { onClick: () => p.setRoute(mode.route), children: [_jsx(ListItemIcon, { children: mode.icon }), _jsx(ListItemText, { children: mode.label })] }) }, idx))) }) }));
134
- return (_jsx("main", { style: { display: "flex", justifyContent: "center" }, children: _jsxs("div", { children: [_jsxs("div", { style: { textAlign: "center" }, children: [_jsx(Typography, { variant: "h4", style: { marginTop: "2em" }, children: "Select user and computer location" }), _jsxs(Typography, { variant: "caption", style: {
146
+ return (_jsx("main", { style: { display: "flex", justifyContent: "center" }, children: _jsxs("div", { style: { maxWidth: "50em", padding: "0 1em" }, children: [_jsxs("div", { style: { textAlign: "center" }, children: [_jsx(Typography, { variant: "h4", style: { marginTop: "2em" }, children: "Select user and computer location" }), _jsxs(Typography, { variant: "caption", style: {
135
147
  marginBottom: "2em",
136
148
  maxWidth: "30em",
137
149
  marginLeft: "auto",
138
150
  marginRight: "auto",
139
- }, children: ["We recommend that after selecting one of the following modes, you bookmark the page and visit it directly.", _jsx("a", { href: "https://fms-insight.seedtactics.com/docs/client-dashboard.html", children: "Learn More" })] })] }), navList] }) }));
151
+ }, children: ["We recommend that after selecting one of the following modes, you bookmark the page and visit it directly.", _jsx("a", { href: "https://fms-insight.seedtactics.com/docs/client-dashboard.html", children: "Learn More" })] })] }), errors.length > 0 ? (_jsxs(Alert, { severity: "error", sx: { margin: "1em 0" }, children: [_jsx(AlertTitle, { children: "FMS Insight errors" }), errors.map((error) => (_jsx("p", { children: error }, error)))] })) : undefined, navList] }) }));
140
152
  }
141
153
  export default ChooseMode;
@@ -37,6 +37,7 @@ import { Card } from "@mui/material";
37
37
  import { CardContent } from "@mui/material";
38
38
  import { ErrorBoundary } from "react-error-boundary";
39
39
  import { ApiException } from "../network/api.js";
40
+ import { apiErrorMessage } from "../network/api-errors.js";
40
41
  function displayUnknownError(error) {
41
42
  if (typeof error === "string") {
42
43
  return error;
@@ -53,7 +54,7 @@ export function DisplayError({ error }) {
53
54
  if (error === undefined)
54
55
  return _jsx(_Fragment, {});
55
56
  if (ApiException.isApiException(error)) {
56
- return (_jsx(Card, { children: _jsxs(CardContent, { children: [_jsx("h3", { children: "FMS Insight Server Error" }), _jsx("p", { children: error.response })] }) }));
57
+ return (_jsx(Card, { children: _jsxs(CardContent, { children: [_jsx("h3", { children: "FMS Insight Server Error" }), _jsx("p", { children: apiErrorMessage(error) })] }) }));
57
58
  }
58
59
  else if (error instanceof Error) {
59
60
  return (_jsx(Card, { children: _jsx(CardContent, { children: error.message }) }));
@@ -38,11 +38,13 @@ import { Tooltip } from "@mui/material";
38
38
  import { errorLoadingLast30, websocketReconnecting } from "../network/websocket.js";
39
39
  import { errorLoadingSpecificMonthData, loadingSpecificMonthData, } from "../network/load-specific-month.js";
40
40
  import { useAtomValue } from "jotai";
41
+ import { currentRoute, RouteLocation } from "./routes.js";
41
42
  export const LoadingIcon = memo(function LoadingIcon() {
42
43
  const websocketLoading = useAtomValue(websocketReconnecting);
43
44
  const specificMonthLoading = useAtomValue(loadingSpecificMonthData);
44
45
  const last30Error = useAtomValue(errorLoadingLast30);
45
46
  const specificMonthError = useAtomValue(errorLoadingSpecificMonthData);
47
+ const errorsInline = useAtomValue(currentRoute).route === RouteLocation.ChooseMode;
46
48
  const [dialogOpen, setDialogOpen] = useState(false);
47
- return (_jsxs(_Fragment, { children: [last30Error != null || specificMonthError != null ? (_jsx(Tooltip, { title: "Error", children: _jsx(IconButton, { onClick: () => setDialogOpen(true), size: "large", children: _jsx(ErrorIcon, {}) }) })) : undefined, websocketLoading || specificMonthLoading ? (_jsx(Tooltip, { title: "Loading", children: _jsx(CircularProgress, { "data-testid": "loading-icon", color: "secondary" }) })) : undefined, _jsxs(Dialog, { open: dialogOpen, onClose: () => setDialogOpen(false), children: [_jsx(DialogTitle, { children: "Error" }), _jsxs(DialogContent, { children: [last30Error !== null ? _jsx("p", { children: last30Error }) : undefined, specificMonthError !== null ? _jsx("p", { children: specificMonthError }) : undefined] }), _jsx(DialogActions, { children: _jsx(Button, { onClick: () => setDialogOpen(false), children: "Close" }) })] })] }));
49
+ return (_jsxs(_Fragment, { children: [!errorsInline && (last30Error != null || specificMonthError != null) ? (_jsx(Tooltip, { title: "Error", children: _jsx(IconButton, { "aria-label": "Error", onClick: () => setDialogOpen(true), size: "large", children: _jsx(ErrorIcon, {}) }) })) : undefined, websocketLoading || specificMonthLoading ? (_jsx(Tooltip, { title: "Loading", children: _jsx(CircularProgress, { "data-testid": "loading-icon", color: "secondary" }) })) : undefined, _jsxs(Dialog, { open: dialogOpen && !errorsInline, onClose: () => setDialogOpen(false), children: [_jsx(DialogTitle, { children: "Error" }), _jsxs(DialogContent, { children: [last30Error !== null ? _jsx("p", { children: last30Error }) : undefined, specificMonthError !== null ? _jsx("p", { children: specificMonthError }) : undefined] }), _jsx(DialogActions, { children: _jsx(Button, { onClick: () => setDialogOpen(false), children: "Close" }) })] })] }));
48
50
  });
@@ -74,6 +74,7 @@ const marginBottom = 50;
74
74
  const marginTop = 20;
75
75
  const marginRight = 20;
76
76
  function BufferChartSVG({ width, height, series, disabled, }) {
77
+ const [emptyDate] = useState(() => new Date());
77
78
  const [dateMin, dateMax] = useMemo(() => {
78
79
  let min = null;
79
80
  let max = null;
@@ -87,8 +88,8 @@ function BufferChartSVG({ width, height, series, disabled, }) {
87
88
  }
88
89
  }
89
90
  }
90
- return [min ?? new Date(), max ?? new Date()];
91
- }, [series]);
91
+ return [min ?? emptyDate, max ?? emptyDate];
92
+ }, [series, emptyDate]);
92
93
  const xScale = useMemo(() => scaleTime()
93
94
  .range([0, width - marginLeft - marginRight])
94
95
  .domain([dateMin, dateMax]), [width, dateMin, dateMax]);
@@ -33,8 +33,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
33
  */
34
34
  import { forwardRef, memo, PureComponent, useState, useCallback, useMemo, } from "react";
35
35
  import { selectAllMaterialIntoBins, MaterialBinType, moveMaterialBin, currentMaterialBinOrder, moveMaterialInBin, findMaterialInQuarantineQueues, findQueueInQuarantineQueues, } from "../../data/all-material-bins.js";
36
- import * as matDetails from "../../cell-status/material-details.js";
37
36
  import * as currentSt from "../../cell-status/current-status.js";
37
+ import { moveQueuedMatInCurrentStatus } from "../../cell-status/loading.js";
38
38
  import { Box } from "@mui/material";
39
39
  import { Typography } from "@mui/material";
40
40
  import { LazySeq } from "@seedtactics/immutable-collections";
@@ -48,6 +48,7 @@ import { useSetTitle } from "../routes.js";
48
48
  import { useAtom, useAtomValue, useSetAtom } from "jotai";
49
49
  import { fmsInformation } from "../../network/server-settings.js";
50
50
  import { basketDisplayName, loadStationDisplayName } from "../../cell-status/station-cycles.js";
51
+ import { canSetMaterialInQueue } from "../../data/material-operation-policy.js";
51
52
  const ColumnWithTitle = forwardRef(function MaterialBin(props, ref) {
52
53
  return (_jsxs(Box, { sx: {
53
54
  margin: props.isDragOverlay ? undefined : "0.75em",
@@ -187,8 +188,7 @@ export function AllMaterial(props) {
187
188
  useSetTitle("All Material");
188
189
  const st = useAtomValue(currentSt.currentStatus);
189
190
  const [matBinOrder, setMatBinOrder] = useAtom(currentMaterialBinOrder);
190
- const [addExistingMatToQueue] = matDetails.useAddExistingMaterialToQueue();
191
- const reorderQueuedMat = useSetAtom(currentSt.reorderQueuedMatInCurrentStatus);
191
+ const moveQueuedMat = useSetAtom(moveQueuedMatInCurrentStatus);
192
192
  const [activeDrag, setActiveDrag] = useState(null);
193
193
  const allBins = useMemo(() => {
194
194
  const bins = selectAllMaterialIntoBins(st, matBinOrder);
@@ -232,6 +232,8 @@ export function AllMaterial(props) {
232
232
  : findMaterialInQuarantineQueues(over.id, allBins);
233
233
  if (!overCol)
234
234
  return;
235
+ if (!canSetMaterialInQueue(activeDrag.mat, overCol.bin.queueName))
236
+ return;
235
237
  if (overCol.bin.binId !== activeDrag.curOverBinId) {
236
238
  setActiveDrag({
237
239
  ...activeDrag,
@@ -258,18 +260,13 @@ export function AllMaterial(props) {
258
260
  const overCol = typeof over.id === "string"
259
261
  ? findQueueInQuarantineQueues(over.id, allBins)
260
262
  : findMaterialInQuarantineQueues(over.id, allBins);
261
- if (overCol) {
262
- void addExistingMatToQueue({
263
- materialId: activeDrag.mat.materialID,
264
- queue: overCol.bin.queueName,
265
- queuePosition: overCol.idx,
266
- operator: null,
267
- }).catch(console.error);
268
- reorderQueuedMat({
263
+ if (overCol && canSetMaterialInQueue(activeDrag.mat, overCol.bin.queueName)) {
264
+ moveQueuedMat({
269
265
  queue: overCol.bin.queueName,
270
266
  matId: activeDrag.mat.materialID,
271
267
  newIdx: overCol.idx,
272
- });
268
+ operator: null,
269
+ }).catch(console.error);
273
270
  }
274
271
  }
275
272
  setActiveDrag(null);
@@ -31,7 +31,7 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31
31
  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32
32
  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
33
  */
34
- import { useMemo, useCallback, useState, useRef, useEffect, } from "react";
34
+ import { useMemo, useCallback, useRef } from "react";
35
35
  import { last30StationCycles } from "../../cell-status/station-cycles.js";
36
36
  import { last30EstimatedCycleTimes } from "../../cell-status/estimated-cycle-times.js";
37
37
  import { recentCycles } from "../../data/results.cycles.js";
@@ -43,7 +43,7 @@ import { localPoint } from "../../util/chart-helpers.js";
43
43
  import { Stack } from "@mui/material";
44
44
  import { Tooltip } from "../ChartTooltip.js";
45
45
  import { currentCycles } from "../../data/current-cycles.js";
46
- import { currentStatus } from "../../cell-status/current-status.js";
46
+ import { currentStatus, minutesSinceEpochAtom } from "../../cell-status/current-status.js";
47
47
  import { last30Jobs } from "../../cell-status/scheduled-jobs.js";
48
48
  import { atom, useAtomValue, useSetAtom } from "jotai";
49
49
  import { fmsInformation } from "../../network/server-settings.js";
@@ -56,11 +56,12 @@ const occupiedNonOutlierColor = green[900];
56
56
  const occupiedOutlierColor = red[700];
57
57
  const simColor = grey[400];
58
58
  const downtimeColor = grey[100];
59
- function useSimCycles() {
59
+ const chartTime = atom((get) => Math.floor(get(minutesSinceEpochAtom) / 5) * 5 * 60000);
60
+ function useSimCycles(now) {
60
61
  const jobs = useAtomValue(last30Jobs);
61
62
  const statUse = useAtomValue(last30SimStationUse);
62
63
  return useMemo(() => {
63
- const cutoff = addHours(new Date(), -12);
64
+ const cutoff = addHours(now, -12);
64
65
  return (LazySeq.of(statUse)
65
66
  .filter((s) => s.end >= cutoff)
66
67
  // make sure all planned downtimes come last so they are drawn over the top of any cycles
@@ -81,7 +82,7 @@ function useSimCycles() {
81
82
  .toRArray(),
82
83
  }))
83
84
  .toRArray());
84
- }, [jobs, statUse]);
85
+ }, [jobs, statUse, now]);
85
86
  }
86
87
  const tooltipData = atom(null);
87
88
  const stationFontSize = 14;
@@ -213,30 +214,24 @@ function NowLine({ now, xScale, yScale, }) {
213
214
  export function RecentCycleChart({ height, width }) {
214
215
  const last30Cycles = useAtomValue(last30StationCycles);
215
216
  const estimated = useAtomValue(last30EstimatedCycleTimes);
216
- const sim = useSimCycles();
217
217
  const currentSt = useAtomValue(currentStatus);
218
+ const time = useAtomValue(chartTime);
219
+ // Keep history filtering independent of frequent status updates.
220
+ const historyNow = useMemo(() => new Date(time), [time]);
221
+ // Align the axis and now marker with cycles started after the chart's last clock tick.
222
+ const displayNow = useMemo(() => new Date(Math.max(time, currentSt.timeOfCurrentStatusUTC.getTime())), [time, currentSt.timeOfCurrentStatusUTC]);
223
+ const sim = useSimCycles(historyNow);
218
224
  const fmsInfo = useAtomValue(fmsInformation);
219
225
  const cycles = useMemo(() => {
220
- const cutoff = addHours(new Date(), -12);
226
+ const cutoff = addHours(historyNow, -12);
221
227
  return recentCycles(last30Cycles.valuesToLazySeq().filter((e) => e.endTime >= cutoff));
222
- }, [last30Cycles]);
228
+ }, [last30Cycles, historyNow]);
223
229
  const current = useMemo(() => {
224
230
  return currentCycles(currentSt, estimated, fmsInfo.loadStationNames);
225
231
  }, [currentSt, estimated, fmsInfo.loadStationNames]);
226
- // ensure a re-render at least every 5 minutes, but reset the timer if the data changes
227
- const now = new Date();
228
- const [, forceRerender] = useState(0);
229
- const refreshRef = useRef(null);
230
- useEffect(() => {
231
- if (refreshRef.current !== null)
232
- clearTimeout(refreshRef.current);
233
- refreshRef.current = setTimeout(() => {
234
- forceRerender((x) => x + 1);
235
- }, 5 * 60 * 1000);
236
- });
237
- const { xScale, yScale, actualPlannedScale, marginLeft } = useScales(cycles, current, now, width, height);
232
+ const { xScale, yScale, actualPlannedScale, marginLeft } = useScales(cycles, current, displayNow, width, height);
238
233
  const hideTooltipRef = useRef(null);
239
234
  if (height <= 0 || width <= 0)
240
235
  return null;
241
- return (_jsxs("div", { style: { position: "relative", overflow: "hidden" }, children: [_jsx("svg", { height: height, width: width, children: _jsxs("g", { transform: `translate(${marginLeft}, ${marginTop})`, children: [_jsx("clipPath", { id: "recent-cycle-clip-body", children: _jsx("rect", { x: 0, y: 0, width: width - marginRight - marginLeft, height: height - marginBottom - marginTop }) }), _jsx(AxisAndGrid, { xScale: xScale, yScale: yScale }), _jsxs("g", { clipPath: "url(#recent-cycle-clip-body)", children: [_jsx(RecentSeries, { cycles: cycles, xScale: xScale, yScale: yScale, hideTooltipRef: hideTooltipRef, actualPlannedScale: actualPlannedScale }), _jsx(CurrentSeries, { now: now, cycles: current, xScale: xScale, yScale: yScale, hideTooltipRef: hideTooltipRef, actualPlannedScale: actualPlannedScale }), _jsx(SimSeries, { sim: sim, xScale: xScale, yScale: yScale, actualPlannedScale: actualPlannedScale, hideTooltipRef: hideTooltipRef })] }), _jsx(NowLine, { now: now, xScale: xScale, yScale: yScale })] }) }), _jsx(Tooltip, { chartHeight: height, chartWidth: width, atom: tooltipData, TooltipContent: RecentTooltip })] }));
236
+ return (_jsxs("div", { style: { position: "relative", overflow: "hidden" }, children: [_jsx("svg", { height: height, width: width, children: _jsxs("g", { transform: `translate(${marginLeft}, ${marginTop})`, children: [_jsx("clipPath", { id: "recent-cycle-clip-body", children: _jsx("rect", { x: 0, y: 0, width: width - marginRight - marginLeft, height: height - marginBottom - marginTop }) }), _jsx(AxisAndGrid, { xScale: xScale, yScale: yScale }), _jsxs("g", { clipPath: "url(#recent-cycle-clip-body)", children: [_jsx(RecentSeries, { cycles: cycles, xScale: xScale, yScale: yScale, hideTooltipRef: hideTooltipRef, actualPlannedScale: actualPlannedScale }), _jsx(CurrentSeries, { now: displayNow, cycles: current, xScale: xScale, yScale: yScale, hideTooltipRef: hideTooltipRef, actualPlannedScale: actualPlannedScale }), _jsx(SimSeries, { sim: sim, xScale: xScale, yScale: yScale, actualPlannedScale: actualPlannedScale, hideTooltipRef: hideTooltipRef })] }), _jsx(NowLine, { now: displayNow, xScale: xScale, yScale: yScale })] }) }), _jsx(Tooltip, { chartHeight: height, chartWidth: width, atom: tooltipData, TooltipContent: RecentTooltip })] }));
242
237
  }