@olenbetong/synergi-react 5.4.0 → 5.6.0
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.
- package/dist/styles/styles.css +1 -1
- package/dist/styles/styles.css.map +1 -1
- package/es/charts/CallOffDeliveries/TicketScanDialog.d.ts +7 -0
- package/es/charts/CallOffDeliveries/TicketScanDialog.js +47 -0
- package/es/charts/CallOffDeliveries/chartOptions.d.ts +8 -0
- package/es/charts/CallOffDeliveries/chartOptions.js +138 -0
- package/es/charts/CallOffDeliveries/data.d.ts +35 -0
- package/es/charts/CallOffDeliveries/data.js +30 -0
- package/es/charts/CallOffDeliveries/index.css +1 -0
- package/es/charts/CallOffDeliveries/index.d.ts +24 -0
- package/es/charts/CallOffDeliveries/index.js +115 -0
- package/es/charts/CallOffDeliveries/model.d.ts +37 -0
- package/es/charts/CallOffDeliveries/model.js +59 -0
- package/es/charts/ProductionPlan/PlanValueDialog.d.ts +14 -0
- package/es/charts/ProductionPlan/PlanValueDialog.js +47 -0
- package/es/charts/ProductionPlan/chartOptions.d.ts +20 -0
- package/es/charts/ProductionPlan/chartOptions.js +353 -0
- package/es/charts/ProductionPlan/data.d.ts +105 -0
- package/es/charts/ProductionPlan/data.js +61 -0
- package/es/charts/ProductionPlan/index.css +1 -0
- package/es/charts/ProductionPlan/index.d.ts +31 -0
- package/es/charts/ProductionPlan/index.js +203 -0
- package/es/charts/ProductionPlan/model.d.ts +29 -0
- package/es/charts/ProductionPlan/model.js +65 -0
- package/es/charts/Pumping/chartOptions.d.ts +12 -0
- package/es/charts/Pumping/chartOptions.js +197 -0
- package/es/charts/Pumping/data.d.ts +65 -0
- package/es/charts/Pumping/data.js +20 -0
- package/es/charts/Pumping/index.css +1 -0
- package/es/charts/Pumping/index.d.ts +27 -0
- package/es/charts/Pumping/index.js +124 -0
- package/es/charts/Pumping/model.d.ts +34 -0
- package/es/charts/Pumping/model.js +88 -0
- package/es/charts/UnboundPreview/chartOptions.d.ts +3 -0
- package/es/charts/UnboundPreview/chartOptions.js +126 -0
- package/es/charts/UnboundPreview/index.css +1 -0
- package/es/charts/UnboundPreview/index.d.ts +20 -0
- package/es/charts/UnboundPreview/index.js +55 -0
- package/es/charts/UnboundPreview/model.d.ts +49 -0
- package/es/charts/UnboundPreview/model.js +67 -0
- package/es/charts/VehicleDeliveries/chartOptions.d.ts +13 -0
- package/es/charts/VehicleDeliveries/chartOptions.js +270 -0
- package/es/charts/VehicleDeliveries/data.d.ts +71 -0
- package/es/charts/VehicleDeliveries/data.js +20 -0
- package/es/charts/VehicleDeliveries/deliveryXRange.d.ts +4 -0
- package/es/charts/VehicleDeliveries/deliveryXRange.js +62 -0
- package/es/charts/VehicleDeliveries/index.css +1 -0
- package/es/charts/VehicleDeliveries/index.d.ts +24 -0
- package/es/charts/VehicleDeliveries/index.js +129 -0
- package/es/charts/VehicleDeliveries/model.d.ts +24 -0
- package/es/charts/VehicleDeliveries/model.js +106 -0
- package/es/charts/format.d.ts +12 -0
- package/es/charts/format.js +34 -0
- package/es/charts/index.d.ts +5 -0
- package/es/charts/index.js +5 -0
- package/es/charts/storage.d.ts +5 -0
- package/es/charts/storage.js +35 -0
- package/es/chrome/assistant.d.ts +75 -0
- package/es/chrome/assistant.js +116 -0
- package/es/components/ColorCard/index.css +8 -8
- package/es/index.css +1 -1
- package/es/index.d.ts +1 -0
- package/es/index.js +1 -0
- package/es/vehicles/VehicleInfoDialog/OutOfServiceForm.d.ts +4 -0
- package/es/vehicles/VehicleInfoDialog/OutOfServiceForm.js +51 -0
- package/es/vehicles/VehicleInfoDialog/data/dsDeliveryTickets.d.ts +99 -0
- package/es/vehicles/VehicleInfoDialog/data/dsDeliveryTickets.js +499 -0
- package/es/vehicles/VehicleInfoDialog/data/dsDriverStatus.d.ts +13 -0
- package/es/vehicles/VehicleInfoDialog/data/dsDriverStatus.js +69 -0
- package/es/vehicles/VehicleInfoDialog/data/dsVehicleInfo.d.ts +33 -0
- package/es/vehicles/VehicleInfoDialog/data/dsVehicleInfo.js +164 -0
- package/es/vehicles/VehicleInfoDialog/data/dsVehicleInfoLog.d.ts +15 -0
- package/es/vehicles/VehicleInfoDialog/data/dsVehicleInfoLog.js +80 -0
- package/es/vehicles/VehicleInfoDialog/formatting.d.ts +13 -0
- package/es/vehicles/VehicleInfoDialog/formatting.js +48 -0
- package/es/vehicles/VehicleInfoDialog/index.css +1 -0
- package/es/vehicles/VehicleInfoDialog/index.d.ts +11 -0
- package/es/vehicles/VehicleInfoDialog/index.js +46 -0
- package/es/vehicles/VehicleInfoDialog/tabs.d.ts +6 -0
- package/es/vehicles/VehicleInfoDialog/tabs.js +85 -0
- package/es/vehicles/index.d.ts +1 -0
- package/es/vehicles/index.js +1 -0
- package/package.json +17 -8
- package/src/charts/CallOffDeliveries/TicketScanDialog.tsx +79 -0
- package/src/charts/CallOffDeliveries/chartOptions.ts +160 -0
- package/src/charts/CallOffDeliveries/data.ts +67 -0
- package/src/charts/CallOffDeliveries/index.scss +51 -0
- package/src/charts/CallOffDeliveries/index.tsx +217 -0
- package/src/charts/CallOffDeliveries/model.test.ts +90 -0
- package/src/charts/CallOffDeliveries/model.ts +87 -0
- package/src/charts/ProductionPlan/PlanValueDialog.tsx +107 -0
- package/src/charts/ProductionPlan/chartOptions.ts +406 -0
- package/src/charts/ProductionPlan/data.ts +170 -0
- package/src/charts/ProductionPlan/index.scss +148 -0
- package/src/charts/ProductionPlan/index.tsx +432 -0
- package/src/charts/ProductionPlan/model.test.ts +132 -0
- package/src/charts/ProductionPlan/model.ts +102 -0
- package/src/charts/Pumping/chartOptions.ts +224 -0
- package/src/charts/Pumping/data.ts +91 -0
- package/src/charts/Pumping/index.scss +42 -0
- package/src/charts/Pumping/index.tsx +222 -0
- package/src/charts/Pumping/model.test.ts +122 -0
- package/src/charts/Pumping/model.ts +104 -0
- package/src/charts/UnboundPreview/chartOptions.ts +137 -0
- package/src/charts/UnboundPreview/index.scss +17 -0
- package/src/charts/UnboundPreview/index.tsx +100 -0
- package/src/charts/UnboundPreview/model.test.ts +129 -0
- package/src/charts/UnboundPreview/model.ts +110 -0
- package/src/charts/VehicleDeliveries/chartOptions.ts +311 -0
- package/src/charts/VehicleDeliveries/data.ts +98 -0
- package/src/charts/VehicleDeliveries/deliveryXRange.ts +80 -0
- package/src/charts/VehicleDeliveries/index.scss +43 -0
- package/src/charts/VehicleDeliveries/index.tsx +262 -0
- package/src/charts/VehicleDeliveries/model.test.ts +117 -0
- package/src/charts/VehicleDeliveries/model.ts +139 -0
- package/src/charts/format.ts +38 -0
- package/src/charts/index.ts +20 -0
- package/src/charts/storage.ts +36 -0
- package/src/chrome/assistant.test.tsx +106 -0
- package/src/chrome/assistant.ts +178 -0
- package/src/components/ColorCard/index.css +8 -8
- package/src/index.ts +9 -0
- package/src/vehicles/VehicleInfoDialog/OutOfServiceForm.tsx +127 -0
- package/src/vehicles/VehicleInfoDialog/data/dsDeliveryTickets.ts +600 -0
- package/src/vehicles/VehicleInfoDialog/data/dsDriverStatus.ts +84 -0
- package/src/vehicles/VehicleInfoDialog/data/dsVehicleInfo.ts +198 -0
- package/src/vehicles/VehicleInfoDialog/data/dsVehicleInfoLog.ts +97 -0
- package/src/vehicles/VehicleInfoDialog/formatting.test.ts +57 -0
- package/src/vehicles/VehicleInfoDialog/formatting.ts +58 -0
- package/src/vehicles/VehicleInfoDialog/index.scss +131 -0
- package/src/vehicles/VehicleInfoDialog/index.tsx +106 -0
- package/src/vehicles/VehicleInfoDialog/tabs.tsx +188 -0
- package/src/vehicles/index.ts +1 -0
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { act, render } from "@testing-library/react";
|
|
2
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
3
|
+
|
|
4
|
+
import { useAssistantContext, useAssistantInstructions, useAssistantTool } from "./assistant";
|
|
5
|
+
|
|
6
|
+
let globals = globalThis as { ob?: unknown };
|
|
7
|
+
|
|
8
|
+
function fakeAssistant(enabled = true) {
|
|
9
|
+
let tools = new Map<string, any>();
|
|
10
|
+
let assistant = {
|
|
11
|
+
enabled,
|
|
12
|
+
tools,
|
|
13
|
+
instructions: null as string | null,
|
|
14
|
+
context: null as unknown,
|
|
15
|
+
registerTool: vi.fn((tool: any) => {
|
|
16
|
+
tools.set(tool.name, tool);
|
|
17
|
+
return () => tools.delete(tool.name);
|
|
18
|
+
}),
|
|
19
|
+
setInstructions: vi.fn((value: string | null) => {
|
|
20
|
+
assistant.instructions = value;
|
|
21
|
+
}),
|
|
22
|
+
setContext: vi.fn((value: unknown) => {
|
|
23
|
+
assistant.context = value;
|
|
24
|
+
}),
|
|
25
|
+
open: vi.fn(),
|
|
26
|
+
close: vi.fn(),
|
|
27
|
+
};
|
|
28
|
+
return assistant;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function Tool({ title }: { title: string }) {
|
|
32
|
+
useAssistantTool({
|
|
33
|
+
name: "get_title",
|
|
34
|
+
description: "The title",
|
|
35
|
+
handler: () => title,
|
|
36
|
+
});
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
afterEach(() => {
|
|
41
|
+
delete globals.ob;
|
|
42
|
+
vi.restoreAllMocks();
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
describe("useAssistantTool", () => {
|
|
46
|
+
it("registers while mounted and uses the latest handler without registering again", async () => {
|
|
47
|
+
let assistant = fakeAssistant();
|
|
48
|
+
globals.ob = { chrome: { assistant } };
|
|
49
|
+
|
|
50
|
+
let view = render(<Tool title="Første" />);
|
|
51
|
+
view.rerender(<Tool title="Andre" />);
|
|
52
|
+
|
|
53
|
+
expect(assistant.registerTool).toHaveBeenCalledTimes(1);
|
|
54
|
+
expect(await assistant.tools.get("get_title").handler({})).toBe("Andre");
|
|
55
|
+
|
|
56
|
+
view.unmount();
|
|
57
|
+
expect(assistant.tools.size).toBe(0);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("waits for the chrome when the app starts first", () => {
|
|
61
|
+
let view = render(<Tool title="x" />);
|
|
62
|
+
let assistant = fakeAssistant();
|
|
63
|
+
globals.ob = { chrome: { assistant } };
|
|
64
|
+
|
|
65
|
+
act(() => {
|
|
66
|
+
window.dispatchEvent(new CustomEvent("ob:chrome-ready"));
|
|
67
|
+
});
|
|
68
|
+
expect(assistant.tools.has("get_title")).toBe(true);
|
|
69
|
+
view.unmount();
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("does nothing when the assistant is off", () => {
|
|
73
|
+
let assistant = fakeAssistant(false);
|
|
74
|
+
globals.ob = { chrome: { assistant } };
|
|
75
|
+
render(<Tool title="x" />);
|
|
76
|
+
expect(assistant.registerTool).not.toHaveBeenCalled();
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it("does nothing without the chrome", () => {
|
|
80
|
+
expect(() => render(<Tool title="x" />)).not.toThrow();
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
describe("useAssistantInstructions and useAssistantContext", () => {
|
|
85
|
+
function Both({ document }: { document: string }) {
|
|
86
|
+
useAssistantInstructions("Skriv på bokmål.");
|
|
87
|
+
useAssistantContext({ document });
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
it("sets them while mounted and clears them after", () => {
|
|
92
|
+
let assistant = fakeAssistant();
|
|
93
|
+
globals.ob = { chrome: { assistant } };
|
|
94
|
+
|
|
95
|
+
let view = render(<Both document="HMS" />);
|
|
96
|
+
expect(assistant.instructions).toBe("Skriv på bokmål.");
|
|
97
|
+
expect(assistant.context).toEqual({ document: "HMS" });
|
|
98
|
+
|
|
99
|
+
view.rerender(<Both document="Avvik" />);
|
|
100
|
+
expect(assistant.context).toEqual({ document: "Avvik" });
|
|
101
|
+
|
|
102
|
+
view.unmount();
|
|
103
|
+
expect(assistant.instructions).toBeNull();
|
|
104
|
+
expect(assistant.context).toBeNull();
|
|
105
|
+
});
|
|
106
|
+
});
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { useEffect, useLayoutEffect, useRef } from "react";
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Apps offer the site chrome's assistant their own tools, instructions and context. The
|
|
5
|
+
* assistant lives in the `@olenbetong/synergi-chrome` bundle the 2026 templates load, so an app
|
|
6
|
+
* never bundles it: these hooks forward to `window.ob.chrome.assistant`, waiting for the chrome
|
|
7
|
+
* to mount (`ob:chrome-ready`) when the app starts first. On a page without the chrome, or where
|
|
8
|
+
* the article feature `assistant` is off, they do nothing.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/** A JSON Schema object describing a tool's arguments. */
|
|
12
|
+
export type AssistantToolParameters = {
|
|
13
|
+
type: "object";
|
|
14
|
+
properties?: Record<string, unknown>;
|
|
15
|
+
required?: string[];
|
|
16
|
+
[key: string]: unknown;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* A tool the app offers the assistant. The handler runs in the page with the user's own
|
|
21
|
+
* permissions; what it returns (JSON-serialisable) is what the model sees.
|
|
22
|
+
*/
|
|
23
|
+
export type AssistantTool<TArgs = Record<string, unknown>> = {
|
|
24
|
+
/** Letters, digits, `_` and `-`, at most 64 characters; unique on the page. */
|
|
25
|
+
name: string;
|
|
26
|
+
/** What the tool does and when to use it. The model reads this to decide. */
|
|
27
|
+
description: string;
|
|
28
|
+
/**
|
|
29
|
+
* A few words for the user, shown in the panel when the tool has run ("Read the open document"),
|
|
30
|
+
* in their language. Never sent to the model. Without it the panel shows the name.
|
|
31
|
+
*/
|
|
32
|
+
label?: string;
|
|
33
|
+
/** The arguments, as a JSON Schema object. Leave out for a tool without arguments. */
|
|
34
|
+
parameters?: AssistantToolParameters;
|
|
35
|
+
handler: (args: TArgs) => unknown | Promise<unknown>;
|
|
36
|
+
/**
|
|
37
|
+
* Ask the user before running: `true` for a generic question, or a function returning the
|
|
38
|
+
* question for these arguments. Use it for every tool that changes something.
|
|
39
|
+
*/
|
|
40
|
+
confirm?: boolean | ((args: TArgs) => string);
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
type AssistantApi = {
|
|
44
|
+
readonly enabled: boolean;
|
|
45
|
+
registerTool: (tool: AssistantTool<any>) => () => void;
|
|
46
|
+
setInstructions?: (instructions: string | null) => void;
|
|
47
|
+
setContext: (context: unknown) => void;
|
|
48
|
+
open: () => void;
|
|
49
|
+
close: () => void;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const CHROME_READY_EVENT = "ob:chrome-ready";
|
|
53
|
+
|
|
54
|
+
function currentAssistant(): AssistantApi | undefined {
|
|
55
|
+
return (globalThis as { ob?: { chrome?: { assistant?: AssistantApi } } }).ob?.chrome?.assistant;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function hasChrome() {
|
|
59
|
+
return Boolean((globalThis as { ob?: { chrome?: unknown } }).ob?.chrome);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Calls `use` with the assistant once the chrome is on the page - at once when it already is -
|
|
64
|
+
* and returns a function that undoes it (or stops waiting). Skipped when the assistant is off.
|
|
65
|
+
*/
|
|
66
|
+
export function withAssistant(use: (assistant: AssistantApi) => void | (() => void)): () => void {
|
|
67
|
+
let cleanup: void | (() => void);
|
|
68
|
+
let run = () => {
|
|
69
|
+
let assistant = currentAssistant();
|
|
70
|
+
if (assistant?.enabled) cleanup = use(assistant);
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
if (hasChrome() || typeof window === "undefined") {
|
|
74
|
+
run();
|
|
75
|
+
return () => cleanup?.();
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
window.addEventListener(CHROME_READY_EVENT, run, { once: true });
|
|
79
|
+
return () => {
|
|
80
|
+
window.removeEventListener(CHROME_READY_EVENT, run);
|
|
81
|
+
cleanup?.();
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** Whether the assistant is enabled on this page (the chrome is mounted and the feature is on). */
|
|
86
|
+
export function isAssistantEnabled() {
|
|
87
|
+
return currentAssistant()?.enabled === true;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** Opens the assistant panel, when the assistant is enabled. */
|
|
91
|
+
export function openAssistant() {
|
|
92
|
+
currentAssistant()?.open();
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Offers a tool to the assistant while the component is mounted. The handler and confirm text
|
|
97
|
+
* always use the latest render's values; the tool is only registered again when its name,
|
|
98
|
+
* description, label, parameters or whether it confirms change.
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* ```tsx
|
|
102
|
+
* useAssistantTool({
|
|
103
|
+
* name: "get_document",
|
|
104
|
+
* description: "The open document: title, summary and text as Markdown.",
|
|
105
|
+
* handler: () => ({ title, summary, markdown }),
|
|
106
|
+
* });
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
export function useAssistantTool<TArgs = Record<string, unknown>>(
|
|
110
|
+
tool: AssistantTool<TArgs> | null | false | undefined,
|
|
111
|
+
) {
|
|
112
|
+
// The handler is called long after the render that registered it; it reads the latest tool.
|
|
113
|
+
let latest = useRef(tool);
|
|
114
|
+
useLayoutEffect(() => {
|
|
115
|
+
latest.current = tool;
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
let key = tool
|
|
119
|
+
? JSON.stringify([tool.name, tool.description, tool.label ?? null, tool.parameters ?? null, Boolean(tool.confirm)])
|
|
120
|
+
: null;
|
|
121
|
+
|
|
122
|
+
useEffect(() => {
|
|
123
|
+
let current = latest.current;
|
|
124
|
+
if (!key || !current) return;
|
|
125
|
+
let { name, description, label, parameters, confirm } = current;
|
|
126
|
+
|
|
127
|
+
return withAssistant((assistant) =>
|
|
128
|
+
assistant.registerTool({
|
|
129
|
+
name,
|
|
130
|
+
description,
|
|
131
|
+
label,
|
|
132
|
+
parameters,
|
|
133
|
+
handler: (args: TArgs) => {
|
|
134
|
+
let live = latest.current;
|
|
135
|
+
if (!live) throw new Error(`The tool "${name}" is no longer available.`);
|
|
136
|
+
return live.handler(args);
|
|
137
|
+
},
|
|
138
|
+
confirm: confirm
|
|
139
|
+
? (args: TArgs) => {
|
|
140
|
+
let live = latest.current ? latest.current.confirm : undefined;
|
|
141
|
+
return typeof live === "function" ? live(args) : "";
|
|
142
|
+
}
|
|
143
|
+
: undefined,
|
|
144
|
+
}),
|
|
145
|
+
);
|
|
146
|
+
}, [key]);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Gives the assistant the app's own instructions (its purpose, terms and conventions) while the
|
|
151
|
+
* component is mounted. They are placed under the server's fixed rules, which they cannot
|
|
152
|
+
* override. At most 8000 characters.
|
|
153
|
+
*/
|
|
154
|
+
export function useAssistantInstructions(instructions: string | null | undefined) {
|
|
155
|
+
useEffect(() => {
|
|
156
|
+
if (!instructions) return;
|
|
157
|
+
return withAssistant((assistant) => {
|
|
158
|
+
assistant.setInstructions?.(instructions);
|
|
159
|
+
return () => assistant.setInstructions?.(null);
|
|
160
|
+
});
|
|
161
|
+
}, [instructions]);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Tells the assistant what the user is looking at (the open record, the filter) while the
|
|
166
|
+
* component is mounted. Data, never followed as instructions. Pass something JSON-serialisable;
|
|
167
|
+
* it is sent again whenever its JSON changes.
|
|
168
|
+
*/
|
|
169
|
+
export function useAssistantContext(context: unknown) {
|
|
170
|
+
let json = context == null ? null : JSON.stringify(context);
|
|
171
|
+
useEffect(() => {
|
|
172
|
+
if (json == null) return;
|
|
173
|
+
return withAssistant((assistant) => {
|
|
174
|
+
assistant.setContext(JSON.parse(json));
|
|
175
|
+
return () => assistant.setContext(null);
|
|
176
|
+
});
|
|
177
|
+
}, [json]);
|
|
178
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
.ObColorCard-root {
|
|
2
2
|
--bg-color-border: black;
|
|
3
|
-
--bg-color-main: white;
|
|
3
|
+
--bg-color-main: var(--ds-color-neutral-background-default, white);
|
|
4
4
|
--bg-size: var(--ds-size-3, 0.75rem);
|
|
5
5
|
--card-color: rgb(0, 0, 0);
|
|
6
6
|
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
box-shadow:
|
|
13
13
|
0 1px 12px rgba(0, 0, 0, 0.15),
|
|
14
14
|
0 1px 6px rgba(0, 0, 0, 0.25);
|
|
15
|
-
color: #666;
|
|
15
|
+
color: var(--ds-color-neutral-text-subtle, #666);
|
|
16
16
|
background-image: linear-gradient(
|
|
17
17
|
to right,
|
|
18
18
|
var(--bg-color-border),
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
|
|
46
46
|
&:hover,
|
|
47
47
|
&:focus {
|
|
48
|
-
--bg-color-main: #f5f5f5;
|
|
48
|
+
--bg-color-main: var(--ds-color-neutral-surface-hover, #f5f5f5);
|
|
49
49
|
box-shadow:
|
|
50
50
|
0 3px 18px rgba(0, 0, 0, 0.15),
|
|
51
51
|
0 3px 12px rgba(0, 0, 0, 0.25);
|
|
@@ -73,7 +73,7 @@
|
|
|
73
73
|
|
|
74
74
|
&.ObColorCard-minor {
|
|
75
75
|
flex: 0 0 calc(var(--ds-size-8, 2rem) * 2);
|
|
76
|
-
border-right: 1px solid #e3e3e3;
|
|
76
|
+
border-right: 1px solid var(--ds-color-neutral-border-subtle, #e3e3e3);
|
|
77
77
|
transition: margin ease-in-out 300ms;
|
|
78
78
|
|
|
79
79
|
@media screen and (min-width: 48rem) {
|
|
@@ -83,11 +83,11 @@
|
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
.ObColorCard-detailValue {
|
|
86
|
-
color: #555555;
|
|
86
|
+
color: var(--ds-color-neutral-text-default, #555555);
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
.ObColorCard-detailLabel {
|
|
90
|
-
color: #696969;
|
|
90
|
+
color: var(--ds-color-neutral-text-subtle, #696969);
|
|
91
91
|
font-size: var(--ds-font-size-1, 0.8rem);
|
|
92
92
|
text-transform: uppercase;
|
|
93
93
|
}
|
|
@@ -136,7 +136,7 @@
|
|
|
136
136
|
|
|
137
137
|
width: 0.6em;
|
|
138
138
|
height: 0.6em;
|
|
139
|
-
background: white;
|
|
139
|
+
background: var(--ds-color-neutral-background-default, white);
|
|
140
140
|
border: 2px solid var(--bg-color-border, #999);
|
|
141
141
|
border-radius: 50%;
|
|
142
142
|
box-sizing: border-box;
|
|
@@ -149,6 +149,6 @@
|
|
|
149
149
|
top: calc(0.25em + 0.6em + 0.15em); /* dot top + dot height + 0.15em spacing */
|
|
150
150
|
left: calc(0.3em - 1px); /* half of the circle width minus half the border width */
|
|
151
151
|
height: calc(100% - 0.95em + var(--ds-size-4, 1rem) + 0.0625em); /* height of container - top + gap */
|
|
152
|
-
border-left: 2px dotted #999;
|
|
152
|
+
border-left: 2px dotted var(--ds-color-neutral-border-default, #999);
|
|
153
153
|
z-index: 0;
|
|
154
154
|
}
|
package/src/index.ts
CHANGED
|
@@ -48,6 +48,15 @@ export {
|
|
|
48
48
|
type MergeProgressDialogDsProps,
|
|
49
49
|
} from "./components/MergeProgressDialog/MergeProgressDialogDs.js";
|
|
50
50
|
export { type MergeJobOptions, type MergePhase, useMergeJob } from "./components/MergeProgressDialog/useMergeJob.js";
|
|
51
|
+
export {
|
|
52
|
+
type AssistantTool,
|
|
53
|
+
type AssistantToolParameters,
|
|
54
|
+
isAssistantEnabled,
|
|
55
|
+
openAssistant,
|
|
56
|
+
useAssistantContext,
|
|
57
|
+
useAssistantInstructions,
|
|
58
|
+
useAssistantTool,
|
|
59
|
+
} from "./chrome/assistant.js";
|
|
51
60
|
export { type OpenReportOptions, openReport } from "./chrome/openReport.js";
|
|
52
61
|
export {
|
|
53
62
|
BannerImage as PageBannerImage,
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { Alert, Button, Dialog, Heading, Textarea, Textfield } from "@digdir/designsystemet-react";
|
|
2
|
+
import { ResponsiveDialog } from "@olenbetong/appframe-ds";
|
|
3
|
+
import { useCurrentRow } from "@olenbetong/appframe-react";
|
|
4
|
+
import { type FormEvent, useId, useState } from "react";
|
|
5
|
+
|
|
6
|
+
import { getLocalizedString } from "../../i18n.js";
|
|
7
|
+
import { dsVehicleInfoLog } from "./data/dsVehicleInfoLog.js";
|
|
8
|
+
import { fromInputs, toDateInput, toTimeInput } from "./formatting.js";
|
|
9
|
+
|
|
10
|
+
function DateTimeFields({
|
|
11
|
+
field,
|
|
12
|
+
dateLabel,
|
|
13
|
+
timeLabel,
|
|
14
|
+
}: {
|
|
15
|
+
field: "FromDateTime" | "ToDateTime";
|
|
16
|
+
dateLabel: string;
|
|
17
|
+
timeLabel: string;
|
|
18
|
+
}) {
|
|
19
|
+
let row = useCurrentRow(dsVehicleInfoLog);
|
|
20
|
+
let value = row[field] as Date | null;
|
|
21
|
+
let date = value ? toDateInput(value) : "";
|
|
22
|
+
let time = value ? toTimeInput(value) : "";
|
|
23
|
+
|
|
24
|
+
function update(nextDate: string, nextTime: string) {
|
|
25
|
+
let next = fromInputs(nextDate, nextTime);
|
|
26
|
+
if (next) dsVehicleInfoLog.currentRow(field, next);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return (
|
|
30
|
+
<div className="ObVehicleInfo-period">
|
|
31
|
+
<Textfield type="date" required label={dateLabel} value={date} onChange={(e) => update(e.target.value, time)} />
|
|
32
|
+
<Textfield type="time" required label={timeLabel} value={time} onChange={(e) => update(date, e.target.value)} />
|
|
33
|
+
</div>
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function CommentField() {
|
|
38
|
+
let row = useCurrentRow(dsVehicleInfoLog);
|
|
39
|
+
// The data object reports a change after the input has rendered, which would move the caret.
|
|
40
|
+
let [focusedValue, setFocusedValue] = useState<string | null>(null);
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<div>
|
|
44
|
+
<label>
|
|
45
|
+
{getLocalizedString("Reason")}
|
|
46
|
+
<Textarea
|
|
47
|
+
rows={2}
|
|
48
|
+
value={focusedValue ?? row.Comment ?? ""}
|
|
49
|
+
onFocus={() => setFocusedValue(row.Comment ?? "")}
|
|
50
|
+
onBlur={() => setFocusedValue(null)}
|
|
51
|
+
onChange={(event) => {
|
|
52
|
+
setFocusedValue(event.target.value);
|
|
53
|
+
dsVehicleInfoLog.currentRow("Comment", event.target.value);
|
|
54
|
+
}}
|
|
55
|
+
/>
|
|
56
|
+
</label>
|
|
57
|
+
</div>
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function OutOfServiceForm({ onClose, onSaved }: { onClose: () => void; onSaved: () => void }) {
|
|
62
|
+
let [error, setError] = useState<string | null>(null);
|
|
63
|
+
let formId = useId();
|
|
64
|
+
|
|
65
|
+
async function run(action: () => Promise<unknown>) {
|
|
66
|
+
try {
|
|
67
|
+
await action();
|
|
68
|
+
onSaved();
|
|
69
|
+
} catch (reason) {
|
|
70
|
+
setError(reason instanceof Error ? reason.message : String(reason));
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function save(event: FormEvent) {
|
|
75
|
+
event.preventDefault();
|
|
76
|
+
run(() => dsVehicleInfoLog.endEdit());
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function cancel() {
|
|
80
|
+
dsVehicleInfoLog.cancelEdit();
|
|
81
|
+
onClose();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return (
|
|
85
|
+
<ResponsiveDialog open onClose={cancel} maxWidth="xs">
|
|
86
|
+
<Dialog.Block>
|
|
87
|
+
<Heading level={2} data-size="xs">
|
|
88
|
+
{getLocalizedString("Set inactive period")}
|
|
89
|
+
</Heading>
|
|
90
|
+
</Dialog.Block>
|
|
91
|
+
<Dialog.Block>
|
|
92
|
+
<form id={formId} className="ObVehicleInfo-form" onSubmit={save}>
|
|
93
|
+
<DateTimeFields
|
|
94
|
+
field="FromDateTime"
|
|
95
|
+
dateLabel={getLocalizedString("From date")}
|
|
96
|
+
timeLabel={getLocalizedString("From time")}
|
|
97
|
+
/>
|
|
98
|
+
<DateTimeFields
|
|
99
|
+
field="ToDateTime"
|
|
100
|
+
dateLabel={getLocalizedString("To date")}
|
|
101
|
+
timeLabel={getLocalizedString("To time")}
|
|
102
|
+
/>
|
|
103
|
+
<CommentField />
|
|
104
|
+
{error && <Alert data-color="danger">{error}</Alert>}
|
|
105
|
+
</form>
|
|
106
|
+
</Dialog.Block>
|
|
107
|
+
<Dialog.Block className="ObVehicleInfo-actions">
|
|
108
|
+
{dsVehicleInfoLog.getCurrentIndex() >= 0 && (
|
|
109
|
+
<Button
|
|
110
|
+
variant="tertiary"
|
|
111
|
+
data-color="danger"
|
|
112
|
+
className="ObVehicleInfo-actions-start"
|
|
113
|
+
onClick={() => run(() => dsVehicleInfoLog.deleteCurrentRow())}
|
|
114
|
+
>
|
|
115
|
+
{getLocalizedString("Delete")}
|
|
116
|
+
</Button>
|
|
117
|
+
)}
|
|
118
|
+
<Button variant="tertiary" onClick={cancel}>
|
|
119
|
+
{getLocalizedString("Cancel")}
|
|
120
|
+
</Button>
|
|
121
|
+
<Button type="submit" form={formId}>
|
|
122
|
+
{getLocalizedString("Save")}
|
|
123
|
+
</Button>
|
|
124
|
+
</Dialog.Block>
|
|
125
|
+
</ResponsiveDialog>
|
|
126
|
+
);
|
|
127
|
+
}
|