@olenbetong/synergi-react 5.3.1 → 5.5.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/components/ColorCard/index.css +8 -8
- package/es/components/ImageEditor/ImageEditor.d.ts +6 -0
- package/es/components/ImageEditor/ImageEditor.js +6 -2
- package/es/components/ImageEditor/ResponsiveButton.d.ts +2 -1
- package/es/components/ImageEditor/ResponsiveButton.js +3 -3
- package/es/components/ImageEditor/plugins/cropPlugin/CropContext.d.ts +2 -1
- package/es/components/ImageEditor/plugins/cropPlugin/CropContext.js +2 -2
- package/es/components/ImageEditor/plugins/cropPlugin/CropToolbar.js +27 -7
- package/es/components/ImageEditor/types.d.ts +5 -0
- package/es/index.css +1 -1
- 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 +19 -10
- 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/components/ColorCard/index.css +8 -8
- package/src/components/ImageEditor/ImageEditor.test.tsx +103 -0
- package/src/components/ImageEditor/ImageEditor.tsx +18 -2
- package/src/components/ImageEditor/ResponsiveButton.tsx +4 -3
- package/src/components/ImageEditor/plugins/cropPlugin/CropContext.tsx +5 -2
- package/src/components/ImageEditor/plugins/cropPlugin/CropToolbar.test.tsx +118 -0
- package/src/components/ImageEditor/plugins/cropPlugin/CropToolbar.tsx +52 -18
- package/src/components/ImageEditor/types.ts +5 -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
|
@@ -63,6 +63,7 @@ function toolPlugin(id: string, label: string) {
|
|
|
63
63
|
<>
|
|
64
64
|
<button onClick={() => tool?.onApply(applied, [{ type: id, params: { n: 1 } }])}>Apply {id}</button>
|
|
65
65
|
<button onClick={() => tool?.onCancel()}>Cancel {id}</button>
|
|
66
|
+
{tool?.onFinish && <button onClick={() => void tool.onFinish?.(applied)}>Finish {id}</button>}
|
|
66
67
|
</>
|
|
67
68
|
);
|
|
68
69
|
},
|
|
@@ -210,6 +211,108 @@ describe("ImageEditor", () => {
|
|
|
210
211
|
});
|
|
211
212
|
});
|
|
212
213
|
|
|
214
|
+
describe("finishWithTool", () => {
|
|
215
|
+
it("hands the result of the tool to the app without another confirmation", async () => {
|
|
216
|
+
let onConfirm = vi.fn();
|
|
217
|
+
let crop = toolPlugin("crop", "Crop");
|
|
218
|
+
render(
|
|
219
|
+
<ImageEditor
|
|
220
|
+
imageUrl={SOURCE}
|
|
221
|
+
plugins={[crop.plugin]}
|
|
222
|
+
initialTool="crop"
|
|
223
|
+
finishWithTool="crop"
|
|
224
|
+
onConfirm={onConfirm}
|
|
225
|
+
/>,
|
|
226
|
+
);
|
|
227
|
+
|
|
228
|
+
fireEvent.click(button("Finish crop"));
|
|
229
|
+
|
|
230
|
+
await waitFor(() => expect(onConfirm).toHaveBeenCalledOnce());
|
|
231
|
+
expect(await (onConfirm.mock.calls[0][0] as Blob).text()).toBe("crop result");
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
it("applying the tool instead keeps editing, so the other tools can follow the crop", async () => {
|
|
235
|
+
let onConfirm = vi.fn();
|
|
236
|
+
let rotate = actionPlugin("rotate-cw", "Rotate right");
|
|
237
|
+
let crop = toolPlugin("crop", "Crop");
|
|
238
|
+
render(
|
|
239
|
+
<ImageEditor
|
|
240
|
+
imageUrl={SOURCE}
|
|
241
|
+
plugins={[rotate, crop.plugin]}
|
|
242
|
+
initialTool="crop"
|
|
243
|
+
finishWithTool="crop"
|
|
244
|
+
onConfirm={onConfirm}
|
|
245
|
+
/>,
|
|
246
|
+
);
|
|
247
|
+
|
|
248
|
+
fireEvent.click(button("Apply crop"));
|
|
249
|
+
|
|
250
|
+
expect(image()).toHaveAttribute("src", "blob:edit-1");
|
|
251
|
+
expect(onConfirm).not.toHaveBeenCalled();
|
|
252
|
+
|
|
253
|
+
fireEvent.click(button("Rotate right"));
|
|
254
|
+
await waitFor(() => expect(image()).toHaveAttribute("src", "blob:edit-2"));
|
|
255
|
+
fireEvent.click(button("Done"));
|
|
256
|
+
|
|
257
|
+
await waitFor(() => expect(onConfirm).toHaveBeenCalledOnce());
|
|
258
|
+
expect(await (onConfirm.mock.calls[0][0] as Blob).text()).toBe("rotate-cw(blob:edit-1)");
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
it("only offers finishing on the tool that was named", () => {
|
|
262
|
+
let props: Record<string, ToolProviderProps> = {};
|
|
263
|
+
let spy = (id: string, plugin: ToolPlugin): ToolPlugin => ({
|
|
264
|
+
...plugin,
|
|
265
|
+
Provider: (toolProps: ToolProviderProps) => {
|
|
266
|
+
props[id] = toolProps;
|
|
267
|
+
return <plugin.Provider {...toolProps} />;
|
|
268
|
+
},
|
|
269
|
+
});
|
|
270
|
+
render(
|
|
271
|
+
<ImageEditor
|
|
272
|
+
imageUrl={SOURCE}
|
|
273
|
+
plugins={[
|
|
274
|
+
spy("crop", toolPlugin("crop", "Crop").plugin),
|
|
275
|
+
spy("redact", toolPlugin("redact", "Redact").plugin),
|
|
276
|
+
]}
|
|
277
|
+
finishWithTool="crop"
|
|
278
|
+
onConfirm={() => {}}
|
|
279
|
+
/>,
|
|
280
|
+
);
|
|
281
|
+
|
|
282
|
+
fireEvent.click(button("Redact"));
|
|
283
|
+
expect(props.redact.onFinish).toBeUndefined();
|
|
284
|
+
fireEvent.click(button("Cancel redact"));
|
|
285
|
+
|
|
286
|
+
fireEvent.click(button("Crop"));
|
|
287
|
+
expect(props.crop.onFinish).toBeInstanceOf(Function);
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
it("shows the usual Done button once the tool is cancelled", () => {
|
|
291
|
+
let crop = toolPlugin("crop", "Crop");
|
|
292
|
+
render(
|
|
293
|
+
<ImageEditor
|
|
294
|
+
imageUrl={SOURCE}
|
|
295
|
+
plugins={[crop.plugin]}
|
|
296
|
+
initialTool="crop"
|
|
297
|
+
finishWithTool="crop"
|
|
298
|
+
onConfirm={() => {}}
|
|
299
|
+
/>,
|
|
300
|
+
);
|
|
301
|
+
expect(screen.queryByRole("button", { name: "Done" })).not.toBeInTheDocument();
|
|
302
|
+
|
|
303
|
+
fireEvent.click(button("Cancel crop"));
|
|
304
|
+
|
|
305
|
+
expect(button("Done")).toBeInTheDocument();
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
it("keeps the tool an ordinary one when the app takes no result", () => {
|
|
309
|
+
let crop = toolPlugin("crop", "Crop");
|
|
310
|
+
render(<ImageEditor imageUrl={SOURCE} plugins={[crop.plugin]} initialTool="crop" finishWithTool="crop" />);
|
|
311
|
+
|
|
312
|
+
expect(screen.queryByRole("button", { name: "Finish crop" })).not.toBeInTheDocument();
|
|
313
|
+
});
|
|
314
|
+
});
|
|
315
|
+
|
|
213
316
|
describe("ref (external toolbars, as in the delivery ticket scans app)", () => {
|
|
214
317
|
it("runs actions one after another, each on the previous result", async () => {
|
|
215
318
|
let ref = createRef<ImageEditorRef>();
|
|
@@ -51,6 +51,12 @@ interface Props {
|
|
|
51
51
|
* plain image. Cancelling the tool returns to the plain image as usual.
|
|
52
52
|
*/
|
|
53
53
|
initialTool?: string;
|
|
54
|
+
/**
|
|
55
|
+
* Id of a tool plugin (e.g. `"crop"`) that also offers a Done button, which applies the tool and hands the
|
|
56
|
+
* result to `onConfirm` so the user does not confirm twice. Its apply button still returns to the plain
|
|
57
|
+
* image, for the other tools and the floating Done button.
|
|
58
|
+
*/
|
|
59
|
+
finishWithTool?: string;
|
|
54
60
|
/**
|
|
55
61
|
* How the image is handed out (default JPEG at 0.92, any size). Edits are kept lossless in between and
|
|
56
62
|
* encoded once, here, so repeated rotations or crops do not lose quality step by step. When set, it applies
|
|
@@ -67,7 +73,7 @@ interface Props {
|
|
|
67
73
|
* Supports undo/redo: each applied transformation is recorded with its EditAction list.
|
|
68
74
|
*/
|
|
69
75
|
export const ImageEditor = forwardRef<ImageEditorRef, Props>(function ImageEditor(
|
|
70
|
-
{ imageUrl, onConfirm, onCancel, plugins, viewPlugin, initialTool, output }: Props,
|
|
76
|
+
{ imageUrl, onConfirm, onCancel, plugins, viewPlugin, initialTool, finishWithTool, output }: Props,
|
|
71
77
|
ref,
|
|
72
78
|
) {
|
|
73
79
|
let registry = useMemo(() => buildActionRegistry(plugins), [plugins]);
|
|
@@ -121,6 +127,11 @@ export const ImageEditor = forwardRef<ImageEditorRef, Props>(function ImageEdito
|
|
|
121
127
|
deactivateTool();
|
|
122
128
|
}
|
|
123
129
|
|
|
130
|
+
// The history never sees this result: the editor closes on it, so it goes straight out.
|
|
131
|
+
async function handleToolFinish(blob: Blob) {
|
|
132
|
+
onConfirm?.(await encodeImage(blob, outputOptions()));
|
|
133
|
+
}
|
|
134
|
+
|
|
124
135
|
function outputOptions(options?: ImageOutputOptions): ImageOutputOptions {
|
|
125
136
|
return { ...output, ...options };
|
|
126
137
|
}
|
|
@@ -274,7 +285,12 @@ export const ImageEditor = forwardRef<ImageEditorRef, Props>(function ImageEdito
|
|
|
274
285
|
if (activePlugin) {
|
|
275
286
|
let ActiveProvider = activePlugin.Provider;
|
|
276
287
|
inner = (
|
|
277
|
-
<ActiveProvider
|
|
288
|
+
<ActiveProvider
|
|
289
|
+
imageUrl={history.currentImageUrl}
|
|
290
|
+
onApply={handleToolApply}
|
|
291
|
+
onCancel={deactivateTool}
|
|
292
|
+
onFinish={onConfirm && activePlugin.id === finishWithTool ? handleToolFinish : undefined}
|
|
293
|
+
>
|
|
278
294
|
{inner}
|
|
279
295
|
</ActiveProvider>
|
|
280
296
|
);
|
|
@@ -6,15 +6,16 @@ interface Props {
|
|
|
6
6
|
label: string;
|
|
7
7
|
onClick: () => void;
|
|
8
8
|
disabled?: boolean;
|
|
9
|
+
pressed?: boolean;
|
|
9
10
|
isSmall: boolean;
|
|
10
11
|
}
|
|
11
12
|
|
|
12
13
|
/** Renders a labelled button on large screens and a tooltipped icon button on small ones. */
|
|
13
|
-
export function ResponsiveButton({ icon, label, onClick, disabled, isSmall }: Props) {
|
|
14
|
+
export function ResponsiveButton({ icon, label, onClick, disabled, pressed, isSmall }: Props) {
|
|
14
15
|
if (isSmall) {
|
|
15
16
|
return (
|
|
16
17
|
<Tooltip content={label}>
|
|
17
|
-
<Button icon variant="tertiary" aria-label={label} onClick={onClick} disabled={disabled}>
|
|
18
|
+
<Button icon variant="tertiary" aria-label={label} aria-pressed={pressed} onClick={onClick} disabled={disabled}>
|
|
18
19
|
{icon}
|
|
19
20
|
</Button>
|
|
20
21
|
</Tooltip>
|
|
@@ -22,7 +23,7 @@ export function ResponsiveButton({ icon, label, onClick, disabled, isSmall }: Pr
|
|
|
22
23
|
}
|
|
23
24
|
|
|
24
25
|
return (
|
|
25
|
-
<Button variant="tertiary" onClick={onClick} disabled={disabled}>
|
|
26
|
+
<Button variant="tertiary" aria-pressed={pressed} onClick={onClick} disabled={disabled}>
|
|
26
27
|
{icon}
|
|
27
28
|
{label}
|
|
28
29
|
</Button>
|
|
@@ -8,13 +8,16 @@ interface CropContextValue extends CropToolState {
|
|
|
8
8
|
imageUrl: string;
|
|
9
9
|
onApply: (blob: Blob, actions: EditAction[]) => void;
|
|
10
10
|
onCancel: () => void;
|
|
11
|
+
onFinish?: (blob: Blob) => Promise<void>;
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
let CropContext = createContext<CropContextValue | null>(null);
|
|
14
15
|
|
|
15
|
-
export function CropProvider({ imageUrl, onApply, onCancel, children }: ToolProviderProps) {
|
|
16
|
+
export function CropProvider({ imageUrl, onApply, onCancel, onFinish, children }: ToolProviderProps) {
|
|
16
17
|
let state = useCropTool(imageUrl, true);
|
|
17
|
-
return
|
|
18
|
+
return (
|
|
19
|
+
<CropContext.Provider value={{ ...state, imageUrl, onApply, onCancel, onFinish }}>{children}</CropContext.Provider>
|
|
20
|
+
);
|
|
18
21
|
}
|
|
19
22
|
|
|
20
23
|
export function useCropContext(): CropContextValue {
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { act, fireEvent, render, screen, waitFor } from "@testing-library/react";
|
|
2
|
+
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
3
|
+
|
|
4
|
+
import { CropToolbar } from "./CropToolbar";
|
|
5
|
+
|
|
6
|
+
const context = vi.hoisted(() => ({
|
|
7
|
+
applyCrop: vi.fn(),
|
|
8
|
+
cropping: false,
|
|
9
|
+
mode: "corners",
|
|
10
|
+
hasSelection: true,
|
|
11
|
+
startRectMode: vi.fn(),
|
|
12
|
+
cancelRectMode: vi.fn(),
|
|
13
|
+
onApply: vi.fn(),
|
|
14
|
+
onCancel: vi.fn(),
|
|
15
|
+
onFinish: undefined as undefined | ((blob: Blob) => Promise<void>),
|
|
16
|
+
}));
|
|
17
|
+
const small = vi.hoisted(() => ({ value: false }));
|
|
18
|
+
|
|
19
|
+
vi.mock("./CropContext.js", () => ({ useCropContext: () => context }));
|
|
20
|
+
vi.mock("../../useIsSmall.js", () => ({ useIsSmall: () => small.value }));
|
|
21
|
+
|
|
22
|
+
const cropped = new Blob(["cropped"]);
|
|
23
|
+
const actions = [{ type: "crop", params: {} }];
|
|
24
|
+
|
|
25
|
+
function button(name: string) {
|
|
26
|
+
return screen.getByRole("button", { name });
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
beforeEach(() => {
|
|
30
|
+
// The spinner synchronises its animation, which jsdom does not have.
|
|
31
|
+
document.getAnimations = () => [];
|
|
32
|
+
vi.clearAllMocks();
|
|
33
|
+
context.applyCrop.mockResolvedValue({ blob: cropped, actions });
|
|
34
|
+
context.mode = "corners";
|
|
35
|
+
context.hasSelection = true;
|
|
36
|
+
context.onFinish = undefined;
|
|
37
|
+
small.value = false;
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
describe("CropToolbar", () => {
|
|
41
|
+
it("only applies when the crop does not finish the editing", async () => {
|
|
42
|
+
render(<CropToolbar />);
|
|
43
|
+
|
|
44
|
+
expect(screen.queryByRole("button", { name: "Done" })).not.toBeInTheDocument();
|
|
45
|
+
fireEvent.click(button("Apply crop"));
|
|
46
|
+
|
|
47
|
+
await waitFor(() => expect(context.onApply).toHaveBeenCalledWith(cropped, actions));
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
describe("when the crop can finish the editing", () => {
|
|
51
|
+
beforeEach(() => {
|
|
52
|
+
context.onFinish = vi.fn(async () => {});
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("Done hands the crop out", async () => {
|
|
56
|
+
render(<CropToolbar />);
|
|
57
|
+
|
|
58
|
+
fireEvent.click(button("Done"));
|
|
59
|
+
|
|
60
|
+
await waitFor(() => expect(context.onFinish).toHaveBeenCalledWith(cropped));
|
|
61
|
+
expect(context.onApply).not.toHaveBeenCalled();
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it("Apply crop keeps editing", async () => {
|
|
65
|
+
render(<CropToolbar />);
|
|
66
|
+
|
|
67
|
+
fireEvent.click(button("Apply crop"));
|
|
68
|
+
|
|
69
|
+
await waitFor(() => expect(context.onApply).toHaveBeenCalledWith(cropped, actions));
|
|
70
|
+
expect(context.onFinish).not.toHaveBeenCalled();
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it("does nothing with a crop that failed", async () => {
|
|
74
|
+
context.applyCrop.mockResolvedValue(null);
|
|
75
|
+
render(<CropToolbar />);
|
|
76
|
+
|
|
77
|
+
await act(async () => {
|
|
78
|
+
fireEvent.click(button("Done"));
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
expect(context.onFinish).not.toHaveBeenCalled();
|
|
82
|
+
expect(button("Done")).toBeEnabled();
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it("blocks both buttons while a crop is running, so it cannot be applied twice", async () => {
|
|
86
|
+
let finish!: () => void;
|
|
87
|
+
context.onFinish = vi.fn(() => new Promise<void>((resolve) => (finish = resolve)));
|
|
88
|
+
render(<CropToolbar />);
|
|
89
|
+
|
|
90
|
+
fireEvent.click(button("Done"));
|
|
91
|
+
await waitFor(() => expect(context.onFinish).toHaveBeenCalled());
|
|
92
|
+
|
|
93
|
+
expect(button("Done")).toBeDisabled();
|
|
94
|
+
expect(button("Apply crop")).toBeDisabled();
|
|
95
|
+
|
|
96
|
+
await act(async () => finish());
|
|
97
|
+
expect(button("Done")).toBeEnabled();
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it("cannot apply or finish without a selection", () => {
|
|
101
|
+
context.hasSelection = false;
|
|
102
|
+
render(<CropToolbar />);
|
|
103
|
+
|
|
104
|
+
expect(button("Done")).toBeDisabled();
|
|
105
|
+
expect(button("Apply crop")).toBeDisabled();
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it("keeps the buttons reachable by name when they collapse to icons on a phone", () => {
|
|
109
|
+
small.value = true;
|
|
110
|
+
render(<CropToolbar />);
|
|
111
|
+
|
|
112
|
+
expect(button("Apply crop")).toHaveTextContent("");
|
|
113
|
+
expect(button("Draw rectangle")).toHaveAttribute("aria-pressed", "false");
|
|
114
|
+
expect(button("Done")).toHaveTextContent("Done");
|
|
115
|
+
expect(button("Cancel")).toHaveTextContent("Cancel");
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
});
|
|
@@ -1,41 +1,75 @@
|
|
|
1
1
|
import { Button, Spinner } from "@digdir/designsystemet-react";
|
|
2
|
-
import { CheckmarkIcon, ExpandIcon, SquareIcon, XMarkIcon } from "@navikt/aksel-icons";
|
|
2
|
+
import { CheckmarkIcon, ExpandIcon, ScissorsIcon, SquareIcon, XMarkIcon } from "@navikt/aksel-icons";
|
|
3
|
+
import { useState } from "react";
|
|
3
4
|
|
|
4
5
|
import { useCropContext } from "./CropContext.js";
|
|
5
6
|
import { getLocalizedString } from "../../../../i18n.js";
|
|
7
|
+
import { ResponsiveButton } from "../../ResponsiveButton.js";
|
|
8
|
+
import { useIsSmall } from "../../useIsSmall.js";
|
|
6
9
|
|
|
7
10
|
/** Toolbar shown while the crop tool is active. Reads state from CropContext. */
|
|
8
11
|
export function CropToolbar() {
|
|
9
|
-
let { applyCrop, cropping, mode, hasSelection, startRectMode, cancelRectMode, onApply, onCancel } =
|
|
12
|
+
let { applyCrop, cropping, mode, hasSelection, startRectMode, cancelRectMode, onApply, onCancel, onFinish } =
|
|
13
|
+
useCropContext();
|
|
10
14
|
let inRectMode = mode === "rect";
|
|
15
|
+
// Covers the crop and whatever the editor does with the result, so a second click cannot apply it twice.
|
|
16
|
+
let [running, setRunning] = useState<"apply" | "finish" | null>(null);
|
|
17
|
+
let busy = cropping || running !== null;
|
|
18
|
+
// With Done as well there are too many labelled buttons for a phone.
|
|
19
|
+
let compact = useIsSmall() && !!onFinish;
|
|
11
20
|
|
|
12
|
-
async function
|
|
13
|
-
|
|
14
|
-
|
|
21
|
+
async function run(kind: "apply" | "finish") {
|
|
22
|
+
setRunning(kind);
|
|
23
|
+
try {
|
|
24
|
+
let result = await applyCrop();
|
|
25
|
+
if (!result) return;
|
|
26
|
+
if (kind === "finish") await onFinish?.(result.blob);
|
|
27
|
+
else onApply(result.blob, result.actions);
|
|
28
|
+
} finally {
|
|
29
|
+
setRunning(null);
|
|
30
|
+
}
|
|
15
31
|
}
|
|
16
32
|
|
|
33
|
+
let spinner = <Spinner aria-hidden data-size="xs" />;
|
|
34
|
+
let cannotApply = busy || inRectMode || !hasSelection;
|
|
35
|
+
|
|
17
36
|
return (
|
|
18
37
|
<>
|
|
19
38
|
<div className="image-editor__toolbar-group">
|
|
20
|
-
<Button variant="tertiary" onClick={onCancel} disabled={
|
|
39
|
+
<Button variant="tertiary" onClick={onCancel} disabled={busy}>
|
|
21
40
|
<XMarkIcon aria-hidden />
|
|
22
41
|
{getLocalizedString("Cancel")}
|
|
23
42
|
</Button>
|
|
24
43
|
</div>
|
|
25
44
|
<div className="image-editor__toolbar-group">
|
|
26
|
-
<
|
|
27
|
-
|
|
28
|
-
|
|
45
|
+
<ResponsiveButton
|
|
46
|
+
icon={inRectMode ? <ExpandIcon aria-hidden /> : <SquareIcon aria-hidden />}
|
|
47
|
+
label={inRectMode ? getLocalizedString("Adjust corners") : getLocalizedString("Draw rectangle")}
|
|
29
48
|
onClick={inRectMode ? cancelRectMode : startRectMode}
|
|
30
|
-
disabled={
|
|
31
|
-
|
|
32
|
-
{
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
49
|
+
disabled={busy}
|
|
50
|
+
pressed={inRectMode}
|
|
51
|
+
isSmall={compact}
|
|
52
|
+
/>
|
|
53
|
+
{onFinish ? (
|
|
54
|
+
<>
|
|
55
|
+
<ResponsiveButton
|
|
56
|
+
icon={running === "apply" ? spinner : <ScissorsIcon aria-hidden />}
|
|
57
|
+
label={getLocalizedString("Apply crop")}
|
|
58
|
+
onClick={() => void run("apply")}
|
|
59
|
+
disabled={cannotApply}
|
|
60
|
+
isSmall={compact}
|
|
61
|
+
/>
|
|
62
|
+
<Button variant="primary" onClick={() => void run("finish")} disabled={cannotApply}>
|
|
63
|
+
{running === "finish" ? spinner : <CheckmarkIcon aria-hidden />}
|
|
64
|
+
{getLocalizedString("Done")}
|
|
65
|
+
</Button>
|
|
66
|
+
</>
|
|
67
|
+
) : (
|
|
68
|
+
<Button variant="primary" onClick={() => void run("apply")} disabled={cannotApply}>
|
|
69
|
+
{running === "apply" ? spinner : <CheckmarkIcon aria-hidden />}
|
|
70
|
+
{getLocalizedString("Apply crop")}
|
|
71
|
+
</Button>
|
|
72
|
+
)}
|
|
39
73
|
</div>
|
|
40
74
|
</>
|
|
41
75
|
);
|
|
@@ -23,6 +23,11 @@ export interface ToolProviderProps {
|
|
|
23
23
|
/** Called when the tool has produced a transformed image. */
|
|
24
24
|
onApply: (blob: Blob, actions: EditAction[]) => void;
|
|
25
25
|
onCancel: () => void;
|
|
26
|
+
/**
|
|
27
|
+
* Set when the app lets this tool finish the editing. The tool should then offer it next to applying, and
|
|
28
|
+
* call this instead of `onApply`. Settles once the result has been handed out.
|
|
29
|
+
*/
|
|
30
|
+
onFinish?: (blob: Blob) => Promise<void>;
|
|
26
31
|
children: ReactNode;
|
|
27
32
|
}
|
|
28
33
|
|
|
@@ -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
|
+
}
|