@olenbetong/synergi-react 5.0.0 → 5.1.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/es/components/Checkbox/index.js +1 -9
- package/es/components/CodeEditor/CodeEditor.css +6 -6
- package/es/components/FilePond.js +3 -12
- package/es/components/ImageEditor/plugins/redactPlugin/useRedactTool.js +18 -14
- package/es/components/ImageEditor/useImageHistory.js +13 -1
- package/es/components/MergeProgressDialog/MergeProgressDialogDs.js +1 -1
- package/es/components/MergeProgressDialog/useMergeJob.js +5 -4
- package/es/components/Portal/index.js +20 -20
- package/es/components/SplitContainer/index.js +3 -1
- package/es/components/Toolbar/Toolbar.css +137 -137
- package/es/components/Toolbar/index.js +6 -1
- package/es/elements/ElementLookupDialog/BarcodeScanner/decoders/zxing.js +8 -0
- package/es/elements/ElementLookupDialog/HIDScanner/useHIDScanner.js +3 -1
- package/es/elements-ds/DescriptionInput.d.ts +16 -0
- package/es/elements-ds/DescriptionInput.js +41 -0
- package/es/elements-ds/DuplicateElementDamage.d.ts +40 -0
- package/es/elements-ds/DuplicateElementDamage.js +57 -0
- package/es/elements-ds/ElementLookup.d.ts +23 -0
- package/es/elements-ds/ElementLookup.js +35 -0
- package/es/elements-ds/ElementLookupDialog.d.ts +7 -0
- package/es/elements-ds/ElementLookupDialog.js +84 -0
- package/es/elements-ds/FormFields.d.ts +43 -0
- package/es/elements-ds/FormFields.js +67 -0
- package/es/elements-ds/HIDScanner.d.ts +7 -0
- package/es/elements-ds/HIDScanner.js +36 -0
- package/es/elements-ds/ManualForm.d.ts +7 -0
- package/es/elements-ds/ManualForm.js +70 -0
- package/es/elements-ds/ProjectSelect.d.ts +28 -0
- package/es/elements-ds/ProjectSelect.js +45 -0
- package/es/elements-ds/elements-ds.css +157 -0
- package/es/elements-ds/index.d.ts +12 -0
- package/es/elements-ds/index.js +14 -0
- package/es/useTranslation/index.js +5 -3
- package/package.json +15 -3
- package/src/chrome/AppShell/AppShell.test.tsx +48 -0
- package/src/chrome/AppShell/index.tsx +29 -29
- package/src/chrome/openReport.test.ts +50 -0
- package/src/chrome/openReport.ts +34 -34
- package/src/colorScheme.test.ts +188 -0
- package/src/colorScheme.ts +125 -125
- package/src/components/Checkbox/Checkbox.browser.test.tsx +116 -0
- package/src/components/Checkbox/index.tsx +1 -10
- package/src/components/CodeEditor/CodeEditor.css +6 -6
- package/src/components/CodeEditor/CodeEditor.tsx +173 -173
- package/src/components/CodeEditor/index.ts +1 -1
- package/src/components/ColorCard/ColorCard.test.tsx +34 -0
- package/src/components/DateNavigator/DateNavigator.test.tsx +175 -0
- package/src/components/DateNavigator/index.tsx +186 -186
- package/src/components/FilePond.browser.test.tsx +389 -0
- package/src/components/FilePond.tsx +303 -312
- package/src/components/ImageEditor/ImageEditor.browser.test.tsx +286 -0
- package/src/components/ImageEditor/ImageEditor.test.tsx +299 -0
- package/src/components/ImageEditor/ImageEditor.tsx +348 -348
- package/src/components/ImageEditor/index.ts +9 -9
- package/src/components/ImageEditor/plugins/cropPlugin/CropOverlay.tsx +165 -165
- package/src/components/ImageEditor/plugins/cropPlugin/CropToolbar.tsx +48 -48
- package/src/components/ImageEditor/plugins/cropPlugin/useCropTool.test.ts +225 -0
- package/src/components/ImageEditor/plugins/cropPlugin/useCropTool.ts +405 -405
- package/src/components/ImageEditor/plugins/plugins.browser.test.ts +252 -0
- package/src/components/ImageEditor/plugins/redactPlugin/RedactToolbar.tsx +47 -47
- package/src/components/ImageEditor/plugins/redactPlugin/useRedactTool.test.ts +89 -0
- package/src/components/ImageEditor/plugins/redactPlugin/useRedactTool.ts +16 -13
- package/src/components/ImageEditor/plugins/zoomPlugin/ZoomContext.tsx +23 -23
- package/src/components/ImageEditor/plugins/zoomPlugin/ZoomControls.tsx +40 -40
- package/src/components/ImageEditor/plugins/zoomPlugin/useZoomPan.test.ts +154 -0
- package/src/components/ImageEditor/useActiveTool.ts +21 -21
- package/src/components/ImageEditor/useEdgeDetection.test.ts +96 -0
- package/src/components/ImageEditor/useEdgeDetection.ts +319 -319
- package/src/components/ImageEditor/useImageHistory.test.ts +409 -0
- package/src/components/ImageEditor/useImageHistory.ts +206 -197
- package/src/components/ImageEditor/useOpenCV.test.ts +208 -0
- package/src/components/ImageEditor/useOpenCV.ts +184 -184
- package/src/components/LinkedCardList/index.scss +95 -95
- package/src/components/MergeProgressDialog/MergeProgressDialogDs.browser.test.tsx +156 -0
- package/src/components/MergeProgressDialog/MergeProgressDialogDs.tsx +1 -0
- package/src/components/MergeProgressDialog/useMergeJob.test.ts +326 -0
- package/src/components/MergeProgressDialog/useMergeJob.ts +4 -3
- package/src/components/PageBanner/index.tsx +80 -80
- package/src/components/PdfViewer/PdfViewer.browser.test.tsx +78 -0
- package/src/components/PdfViewer/PdfViewer.tsx +158 -158
- package/src/components/Portal/Portal.test.tsx +106 -0
- package/src/components/Portal/index.tsx +22 -25
- package/src/components/Sidebar/Sidebar.browser.test.tsx +57 -0
- package/src/components/Sidebar/Sidebar.test.tsx +123 -0
- package/src/components/SplitContainer/SplitContainer.browser.test.tsx +304 -0
- package/src/components/SplitContainer/index.tsx +335 -333
- package/src/components/Toolbar/Toolbar.css +137 -137
- package/src/components/Toolbar/Toolbar.test.tsx +216 -0
- package/src/components/Toolbar/ToolbarBreadcrumbs.browser.test.tsx +137 -0
- package/src/components/Toolbar/index.tsx +270 -265
- package/src/components/ValueToggleGroup/ValueToggleGroup.test.tsx +112 -0
- package/src/designsystemet-web-types.d.ts +24 -24
- package/src/elements/ElementDamage/DamageFormButtons.tsx +35 -35
- package/src/elements/ElementDamage/DescriptionInput.tsx +120 -120
- package/src/elements/ElementDamage/DuplicateDamage/DesktopView.tsx +82 -82
- package/src/elements/ElementDamage/DuplicateDamage/DublicateElementDamageDialog.tsx +67 -67
- package/src/elements/ElementDamage/DuplicateDamage/PhoneView.tsx +45 -45
- package/src/elements/ElementDamage/ElementNumberTextField.tsx +41 -41
- package/src/elements/ElementDamage/RegisterFix.tsx +100 -100
- package/src/elements/ElementDamage/SubmitButtons.tsx +40 -40
- package/src/elements/ElementDamage/TransportElementSelect.tsx +52 -52
- package/src/elements/ElementLookup.tsx +123 -123
- package/src/elements/ElementLookupDialog/BarcodeScanner/BarcodeScanner.browser.test.tsx +175 -0
- package/src/elements/ElementLookupDialog/BarcodeScanner/decoders/zxing.ts +8 -0
- package/src/elements/ElementLookupDialog/BarcodeScanner/engines.browser.test.ts +225 -0
- package/src/elements/ElementLookupDialog/HIDScanner/index.tsx +67 -67
- package/src/elements/ElementLookupDialog/HIDScanner/useHIDScanner.test.ts +124 -0
- package/src/elements/ElementLookupDialog/HIDScanner/useHIDScanner.ts +2 -1
- package/src/elements/ElementLookupDialog/Manual/ManualForm.tsx +141 -141
- package/src/elements/ElementLookupDialog/getElement.test.ts +133 -0
- package/src/elements/ElementLookupDialog/index.tsx +226 -226
- package/src/elements/ElementLookupDialog/utils/Giai.test.ts +53 -0
- package/src/elements/ElementLookupDialog/utils/Giai.ts +209 -209
- package/src/elements/ProjectSelect.tsx +130 -130
- package/src/elements/index.ts +15 -15
- package/src/elements-ds/DamageForm.browser.test.tsx +530 -0
- package/src/elements-ds/DescriptionInput.tsx +114 -0
- package/src/elements-ds/DuplicateElementDamage.tsx +185 -0
- package/src/elements-ds/ElementLookup.tsx +114 -0
- package/src/elements-ds/ElementLookupDialog.browser.test.tsx +207 -0
- package/src/elements-ds/ElementLookupDialog.tsx +196 -0
- package/src/elements-ds/FormFields.tsx +176 -0
- package/src/elements-ds/HIDScanner.tsx +53 -0
- package/src/elements-ds/ManualForm.tsx +129 -0
- package/src/elements-ds/ProjectSelect.tsx +120 -0
- package/src/elements-ds/elements-ds.css +157 -0
- package/src/elements-ds/index.ts +16 -0
- package/src/filter/index.ts +34 -34
- package/src/i18n.test.ts +31 -0
- package/src/i18n.ts +13 -13
- package/src/mui/MuiThemeProvider.tsx +135 -135
- package/src/test/fakeCamera.ts +98 -0
- package/src/test/fakeDataApi.ts +90 -0
- package/src/test/setup.browser.ts +21 -0
- package/src/test/setup.ts +23 -23
- package/src/useTranslation/index.ts +5 -3
- package/src/useTranslation/useTranslation.test.ts +128 -0
- package/es/elements/ElementLookupDialog/BarcodeScanner/decoders.test.d.ts +0 -1
- package/es/elements/ElementLookupDialog/BarcodeScanner/decoders.test.js +0 -103
- package/es/test/setup.d.ts +0 -6
- package/es/test/setup.js +0 -6
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { Alert, Button, Dialog, Tabs } from "@digdir/designsystemet-react";
|
|
2
|
+
import { MobileIcon, PencilIcon, PlusIcon, QrCodeScanningIcon, TrashIcon } from "@navikt/aksel-icons";
|
|
3
|
+
import { ItemList, ResponsiveDialog } from "@olenbetong/appframe-ds";
|
|
4
|
+
import { useState } from "react";
|
|
5
|
+
import { BarcodeScanner } from "../elements/ElementLookupDialog/BarcodeScanner/index.js";
|
|
6
|
+
import { type AddElementSource, type ElementDetails, getElement } from "../elements/ElementLookupDialog/getElement.js";
|
|
7
|
+
import type {
|
|
8
|
+
AddElement,
|
|
9
|
+
ElementLookupDialogMultiModeProps,
|
|
10
|
+
ElementLookupDialogProps,
|
|
11
|
+
ElementLookupDialogSharedProps,
|
|
12
|
+
ElementLookupDialogSingleModeProps,
|
|
13
|
+
} from "../elements/ElementLookupDialog/index.js";
|
|
14
|
+
import { useBeeper } from "../elements/ElementLookupDialog/utils/beep.js";
|
|
15
|
+
import Giai from "../elements/ElementLookupDialog/utils/Giai.js";
|
|
16
|
+
import { getLocalizedString, localize } from "../i18n.js";
|
|
17
|
+
import { AddElementHIDScanner } from "./HIDScanner.js";
|
|
18
|
+
import { AddElementManualForm } from "./ManualForm.js";
|
|
19
|
+
|
|
20
|
+
export type {
|
|
21
|
+
AddElement,
|
|
22
|
+
ElementLookupDialogMultiModeProps,
|
|
23
|
+
ElementLookupDialogProps,
|
|
24
|
+
ElementLookupDialogSharedProps,
|
|
25
|
+
ElementLookupDialogSingleModeProps,
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
type Tab = "camera" | "scanner" | "manual";
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Picks elements by camera, HID scanner or (outside search mode) manual entry. Designsystemet
|
|
32
|
+
* version of `ElementLookupDialog` in `@olenbetong/synergi-react/elements`, with the same props.
|
|
33
|
+
*/
|
|
34
|
+
export function ElementLookupDialog(props: ElementLookupDialogProps) {
|
|
35
|
+
let { open, onClose, initialTab, decoder, scannerActions } = props;
|
|
36
|
+
let [tab, setTab] = useState<Tab>(initialTab ?? "camera");
|
|
37
|
+
let [elements, setElements] = useState<Array<AddElement>>([]);
|
|
38
|
+
let [recent, setRecent] = useState<string | null>(null);
|
|
39
|
+
let [adding, setAdding] = useState(false);
|
|
40
|
+
let beeper = useBeeper();
|
|
41
|
+
|
|
42
|
+
// Opening the dialog selects the tab the caller asked for (and so does mounting it open, above),
|
|
43
|
+
// adjusted during render.
|
|
44
|
+
let [wasOpen, setWasOpen] = useState(open);
|
|
45
|
+
if (open !== wasOpen) {
|
|
46
|
+
setWasOpen(open);
|
|
47
|
+
if (open && initialTab) {
|
|
48
|
+
setTab(initialTab);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async function handleElementAdd(element: string | ElementDetails, mode: AddElementSource) {
|
|
53
|
+
try {
|
|
54
|
+
let record = typeof element === "string" ? await getElement(element.replace("\u001d", ""), { mode }) : element;
|
|
55
|
+
|
|
56
|
+
setElements((current) => {
|
|
57
|
+
let now = Date.now();
|
|
58
|
+
let exists = current.some((e) => e.element.ElementID === record.ElementID);
|
|
59
|
+
let updated: Array<AddElement>;
|
|
60
|
+
|
|
61
|
+
if (exists) {
|
|
62
|
+
updated = current.map((e) => (e.element.ElementID === record.ElementID ? { ...e, scanTime: now } : e));
|
|
63
|
+
} else {
|
|
64
|
+
beeper();
|
|
65
|
+
updated =
|
|
66
|
+
props.mode === "multi"
|
|
67
|
+
? [{ element: record, mode, scanTime: now }, ...current]
|
|
68
|
+
: [{ element: record, mode, scanTime: now }];
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (props.mode === "multi") {
|
|
72
|
+
updated.sort((a, b) => (b.scanTime ?? 0) - (a.scanTime ?? 0));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return updated;
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
setRecent(record.ElementID);
|
|
79
|
+
setTimeout(() => setRecent((current) => (current === record.ElementID ? null : current)), 600);
|
|
80
|
+
} catch (error) {
|
|
81
|
+
alert((error as Error).message);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
let currentTab: Tab = tab === "manual" && props.mode === "search" ? "camera" : tab;
|
|
86
|
+
|
|
87
|
+
async function handleConfirm() {
|
|
88
|
+
try {
|
|
89
|
+
setAdding(true);
|
|
90
|
+
if (props.mode === "multi") {
|
|
91
|
+
await props.onAdd(elements);
|
|
92
|
+
} else {
|
|
93
|
+
await props.onAdd(elements[0]!);
|
|
94
|
+
}
|
|
95
|
+
setElements([]);
|
|
96
|
+
setAdding(false);
|
|
97
|
+
onClose();
|
|
98
|
+
} catch (error) {
|
|
99
|
+
setAdding(false);
|
|
100
|
+
alert((error as Error).message);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return (
|
|
105
|
+
<ResponsiveDialog open={open} onClose={onClose} closeButton={false}>
|
|
106
|
+
<Dialog.Block className="ObElementsLookupDialog-body">
|
|
107
|
+
<Tabs value={currentTab} onChange={(value) => setTab(value as Tab)} className="ObElementsLookupDialog-tabs">
|
|
108
|
+
<Tabs.List>
|
|
109
|
+
{props.mode !== "search" && (
|
|
110
|
+
<Tabs.Tab value="manual">
|
|
111
|
+
<PencilIcon aria-hidden />
|
|
112
|
+
{getLocalizedString("Manual")}
|
|
113
|
+
</Tabs.Tab>
|
|
114
|
+
)}
|
|
115
|
+
<Tabs.Tab value="scanner">
|
|
116
|
+
<MobileIcon aria-hidden />
|
|
117
|
+
{getLocalizedString("Scanner")}
|
|
118
|
+
</Tabs.Tab>
|
|
119
|
+
<Tabs.Tab value="camera">
|
|
120
|
+
<QrCodeScanningIcon aria-hidden />
|
|
121
|
+
{getLocalizedString("Camera")}
|
|
122
|
+
</Tabs.Tab>
|
|
123
|
+
</Tabs.List>
|
|
124
|
+
</Tabs>
|
|
125
|
+
{currentTab === "camera" && (
|
|
126
|
+
<div className="ObElementsLookupDialog-source">
|
|
127
|
+
<BarcodeScanner
|
|
128
|
+
decoder={decoder}
|
|
129
|
+
actions={scannerActions}
|
|
130
|
+
onRead={(element) => handleElementAdd(element, "camera-barcode")}
|
|
131
|
+
/>
|
|
132
|
+
</div>
|
|
133
|
+
)}
|
|
134
|
+
{currentTab === "manual" && (
|
|
135
|
+
<div className="ObElementsLookupDialog-manual">
|
|
136
|
+
<AddElementManualForm
|
|
137
|
+
mode={props.mode === "multi" ? "multi" : "single"}
|
|
138
|
+
onAdd={(element) => handleElementAdd(element, "manual")}
|
|
139
|
+
allowEmptyElement={props.allowEmptyElement}
|
|
140
|
+
/>
|
|
141
|
+
</div>
|
|
142
|
+
)}
|
|
143
|
+
{currentTab === "scanner" && (
|
|
144
|
+
<div className="ObElementsLookupDialog-source">
|
|
145
|
+
<AddElementHIDScanner
|
|
146
|
+
onScan={(element) =>
|
|
147
|
+
handleElementAdd(element, element.startsWith(Giai.BARCODE_PREFIX) ? "hid-barcode" : "hid-rfid")
|
|
148
|
+
}
|
|
149
|
+
/>
|
|
150
|
+
</div>
|
|
151
|
+
)}
|
|
152
|
+
<div className="ObElementsLookupDialog-list">
|
|
153
|
+
{props.mode === "multi" && (
|
|
154
|
+
<Alert data-color="info" data-size="sm">{localize`${elements.length} elements selected`}</Alert>
|
|
155
|
+
)}
|
|
156
|
+
<ItemList>
|
|
157
|
+
{elements.map(({ element }) => (
|
|
158
|
+
<ItemList.Item
|
|
159
|
+
key={element.ElementID || element.ProjectID}
|
|
160
|
+
className="ObElementsLookupDialog-item"
|
|
161
|
+
data-recent={recent === element.ElementID || undefined}
|
|
162
|
+
>
|
|
163
|
+
<ItemList.ItemText
|
|
164
|
+
primary={element.DisplayName || element.ProjectName}
|
|
165
|
+
secondary={element.ElementID || element.ProjectID}
|
|
166
|
+
/>
|
|
167
|
+
<Button
|
|
168
|
+
data-color="danger"
|
|
169
|
+
variant="tertiary"
|
|
170
|
+
icon
|
|
171
|
+
aria-label={getLocalizedString("Remove")}
|
|
172
|
+
onClick={() => {
|
|
173
|
+
setElements((current) =>
|
|
174
|
+
props.mode === "multi" ? current.filter((e) => e.element.ElementID !== element.ElementID) : [],
|
|
175
|
+
);
|
|
176
|
+
}}
|
|
177
|
+
>
|
|
178
|
+
<TrashIcon aria-hidden />
|
|
179
|
+
</Button>
|
|
180
|
+
</ItemList.Item>
|
|
181
|
+
))}
|
|
182
|
+
</ItemList>
|
|
183
|
+
</div>
|
|
184
|
+
</Dialog.Block>
|
|
185
|
+
<Dialog.Block className="ObElementsLookupDialog-actions">
|
|
186
|
+
<Button variant="tertiary" onClick={onClose}>
|
|
187
|
+
{getLocalizedString("Cancel")}
|
|
188
|
+
</Button>
|
|
189
|
+
<Button variant="primary" loading={adding} disabled={!elements.length} onClick={handleConfirm}>
|
|
190
|
+
{!adding && <PlusIcon aria-hidden />}
|
|
191
|
+
{props.mode === "search" ? getLocalizedString("Search for element") : getLocalizedString("Add element")}
|
|
192
|
+
</Button>
|
|
193
|
+
</Dialog.Block>
|
|
194
|
+
</ResponsiveDialog>
|
|
195
|
+
);
|
|
196
|
+
}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { Button, Checkbox, Paragraph, Textfield } from "@digdir/designsystemet-react";
|
|
2
|
+
import { CheckmarkIcon, FloppydiskIcon, PlusIcon } from "@navikt/aksel-icons";
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
import { procApproveDamage } from "../elements/data/procApproveDamage.js";
|
|
5
|
+
import { getLocalizedString, localize } from "../i18n.js";
|
|
6
|
+
|
|
7
|
+
export { HiddenDamageFields } from "../elements/ElementDamage/HiddenDamageFields.js";
|
|
8
|
+
|
|
9
|
+
export type ElementNumberTextFieldProps = {
|
|
10
|
+
value?: string | null;
|
|
11
|
+
defaultValue?: string | null;
|
|
12
|
+
onChange?: (value: string) => void;
|
|
13
|
+
disabled?: boolean;
|
|
14
|
+
className?: string;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/** Designsystemet version of `ElementNumberTextField` in `@olenbetong/synergi-react/elements`. */
|
|
18
|
+
export function ElementNumberTextField({
|
|
19
|
+
value,
|
|
20
|
+
defaultValue,
|
|
21
|
+
onChange,
|
|
22
|
+
disabled,
|
|
23
|
+
className,
|
|
24
|
+
}: ElementNumberTextFieldProps) {
|
|
25
|
+
let [elementNumber, setElementNumber] = useState<string>(defaultValue ?? "");
|
|
26
|
+
let [initialDefault, setInitialDefault] = useState(defaultValue);
|
|
27
|
+
let elementNumberValue = value === undefined ? elementNumber : (value ?? "");
|
|
28
|
+
|
|
29
|
+
if (defaultValue && defaultValue !== initialDefault) {
|
|
30
|
+
setInitialDefault(defaultValue);
|
|
31
|
+
if (value === undefined) setElementNumber(defaultValue);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function handleChange(value: string) {
|
|
35
|
+
onChange?.(value);
|
|
36
|
+
setElementNumber(value);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
<Textfield
|
|
41
|
+
className={className}
|
|
42
|
+
name="ElementNumber"
|
|
43
|
+
id="NewElementDamage_ElementNr"
|
|
44
|
+
label={getLocalizedString("Element number")}
|
|
45
|
+
autoComplete="off"
|
|
46
|
+
value={elementNumberValue}
|
|
47
|
+
onChange={(event) => handleChange(event.currentTarget.value)}
|
|
48
|
+
disabled={disabled ?? false}
|
|
49
|
+
/>
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const formatter = new Intl.DateTimeFormat(af.userSession.culture, {
|
|
54
|
+
day: "numeric",
|
|
55
|
+
month: "long",
|
|
56
|
+
year: "numeric",
|
|
57
|
+
hour: "2-digit",
|
|
58
|
+
minute: "2-digit",
|
|
59
|
+
timeZone: "UTC",
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
export type RegisterFixType = {
|
|
63
|
+
ID: number;
|
|
64
|
+
RegisteredFixFullName: string | null;
|
|
65
|
+
RegisteredFix: Date | null;
|
|
66
|
+
RegisteredFixBy: string | null;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
type ApproveDamageProcedureRecord = {
|
|
70
|
+
Table: Array<Required<RegisterFixType>>;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
export type RegisterFixProps = {
|
|
74
|
+
value?: RegisterFixType | null;
|
|
75
|
+
defaultValue?: RegisterFixType | null;
|
|
76
|
+
onFix?: (ID: number) => void;
|
|
77
|
+
edit?: boolean;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* A "register fix" button for an existing damage, or a checkbox posted as `RegisteredFix` for a
|
|
82
|
+
* new one, and who registered the fix when. Designsystemet version of `RegisterFix` in
|
|
83
|
+
* `@olenbetong/synergi-react/elements`.
|
|
84
|
+
*/
|
|
85
|
+
export function RegisterFix({ value, defaultValue, onFix, edit }: RegisterFixProps) {
|
|
86
|
+
let [loading, setLoading] = useState(false);
|
|
87
|
+
let [fix, setFix] = useState<RegisterFixType | null>(defaultValue ?? null);
|
|
88
|
+
let [initialDefault, setInitialDefault] = useState(defaultValue);
|
|
89
|
+
let fixValue = value === undefined ? fix : value;
|
|
90
|
+
|
|
91
|
+
if (defaultValue && !initialDefault) {
|
|
92
|
+
setInitialDefault(defaultValue);
|
|
93
|
+
if (value === undefined) setFix(defaultValue);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
async function handleRegisterFix() {
|
|
97
|
+
try {
|
|
98
|
+
if (confirm(getLocalizedString("Are you sure you want to register a fix for this damage?"))) {
|
|
99
|
+
setLoading(true);
|
|
100
|
+
let record = (await procApproveDamage.execute({ ID: fixValue?.ID })) as ApproveDamageProcedureRecord;
|
|
101
|
+
|
|
102
|
+
setFix({ ...record.Table[0] });
|
|
103
|
+
setLoading(false);
|
|
104
|
+
onFix?.(fixValue?.ID ?? -1);
|
|
105
|
+
}
|
|
106
|
+
} catch (error) {
|
|
107
|
+
setLoading(false);
|
|
108
|
+
alert((error as Error).message);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return (
|
|
113
|
+
<>
|
|
114
|
+
{edit ? (
|
|
115
|
+
<div>
|
|
116
|
+
<Button
|
|
117
|
+
variant="secondary"
|
|
118
|
+
loading={loading}
|
|
119
|
+
disabled={!!fixValue?.RegisteredFix}
|
|
120
|
+
onClick={handleRegisterFix}
|
|
121
|
+
>
|
|
122
|
+
{!loading && <CheckmarkIcon aria-hidden />}
|
|
123
|
+
{getLocalizedString("Register fix")}
|
|
124
|
+
</Button>
|
|
125
|
+
</div>
|
|
126
|
+
) : (
|
|
127
|
+
<Checkbox
|
|
128
|
+
label={getLocalizedString("Register fixed")}
|
|
129
|
+
name="RegisteredFix"
|
|
130
|
+
id="NewElementDamage_RegisteredFix"
|
|
131
|
+
value="on"
|
|
132
|
+
/>
|
|
133
|
+
)}
|
|
134
|
+
|
|
135
|
+
{fixValue?.RegisteredFix && (
|
|
136
|
+
<Paragraph className="ObElements-subtle">
|
|
137
|
+
{localize`Registered fix by ${fixValue.RegisteredFixFullName ?? fixValue.RegisteredFixBy} on the ${formatter.format(fixValue.RegisteredFix)}`}
|
|
138
|
+
</Paragraph>
|
|
139
|
+
)}
|
|
140
|
+
</>
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export type SubmitButtonsProps = {
|
|
145
|
+
/**
|
|
146
|
+
* Whether the form is in edit mode. If true, the delete button is visible and the submit
|
|
147
|
+
* button's text changes.
|
|
148
|
+
*/
|
|
149
|
+
edit?: boolean;
|
|
150
|
+
/** Loading state for the submit button */
|
|
151
|
+
loading?: boolean;
|
|
152
|
+
className?: string;
|
|
153
|
+
onDelete?: () => void;
|
|
154
|
+
onCancel?: () => void;
|
|
155
|
+
onSubmit?: () => void;
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
/** Designsystemet version of `SubmitButtons` in `@olenbetong/synergi-react/elements`. */
|
|
159
|
+
export function SubmitButtons({ edit, loading, onDelete, onCancel, onSubmit, className }: SubmitButtonsProps) {
|
|
160
|
+
return (
|
|
161
|
+
<div className={className ? `ObElements-buttons ${className}` : "ObElements-buttons"}>
|
|
162
|
+
{edit && (
|
|
163
|
+
<Button variant="tertiary" data-color="danger" onClick={onDelete}>
|
|
164
|
+
{getLocalizedString("Delete")}
|
|
165
|
+
</Button>
|
|
166
|
+
)}
|
|
167
|
+
<Button variant="tertiary" onClick={onCancel}>
|
|
168
|
+
{getLocalizedString("Cancel")}
|
|
169
|
+
</Button>
|
|
170
|
+
<Button variant="primary" type="submit" loading={loading} onClick={onSubmit}>
|
|
171
|
+
{!loading && (edit ? <FloppydiskIcon aria-hidden /> : <PlusIcon aria-hidden />)}
|
|
172
|
+
{edit ? getLocalizedString("Save changes") : getLocalizedString("Register damage")}
|
|
173
|
+
</Button>
|
|
174
|
+
</div>
|
|
175
|
+
);
|
|
176
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { Button } from "@digdir/designsystemet-react";
|
|
2
|
+
import { useEffect, useRef, useState } from "react";
|
|
3
|
+
import { useHIDScanner } from "../elements/ElementLookupDialog/HIDScanner/useHIDScanner.js";
|
|
4
|
+
import { getLocalizedString } from "../i18n.js";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Listens for a keyboard-emulating (HID) scanner while it has focus. Designsystemet version of
|
|
8
|
+
* `AddElementHIDScanner` in `@olenbetong/synergi-react/elements`.
|
|
9
|
+
*/
|
|
10
|
+
export function AddElementHIDScanner({ onScan }: { onScan: (id: string) => void }) {
|
|
11
|
+
let [enabled, setEnabled] = useState(false);
|
|
12
|
+
let root = useRef<HTMLDivElement>(null);
|
|
13
|
+
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
if (!root.current) return;
|
|
16
|
+
|
|
17
|
+
let rootElem = root.current;
|
|
18
|
+
|
|
19
|
+
function handleFocus() {
|
|
20
|
+
setEnabled(true);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function handleBlur() {
|
|
24
|
+
setEnabled(false);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
rootElem.addEventListener("focus", handleFocus);
|
|
28
|
+
rootElem.addEventListener("blur", handleBlur);
|
|
29
|
+
// A modal dialog opening around the scanner moves the focus to its `autofocus` element, or
|
|
30
|
+
// else to its first control; mark the scanner so it keeps listening when the dialog opens on it.
|
|
31
|
+
rootElem.setAttribute("autofocus", "");
|
|
32
|
+
rootElem.focus();
|
|
33
|
+
|
|
34
|
+
return () => {
|
|
35
|
+
rootElem.removeEventListener("focus", handleFocus);
|
|
36
|
+
rootElem.removeEventListener("blur", handleBlur);
|
|
37
|
+
};
|
|
38
|
+
}, []);
|
|
39
|
+
|
|
40
|
+
useHIDScanner(onScan, enabled);
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<div tabIndex={0} ref={root} className="ObElementsHidScanner-root" data-enabled={enabled || undefined}>
|
|
44
|
+
{enabled ? (
|
|
45
|
+
<span>{getLocalizedString("Listening for scanned elements")}...</span>
|
|
46
|
+
) : (
|
|
47
|
+
<Button variant="primary" onClick={() => root.current?.focus()}>
|
|
48
|
+
{getLocalizedString("Start listening")}
|
|
49
|
+
</Button>
|
|
50
|
+
)}
|
|
51
|
+
</div>
|
|
52
|
+
);
|
|
53
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { Alert, Button, Textfield } from "@digdir/designsystemet-react";
|
|
2
|
+
import { PlusIcon } from "@navikt/aksel-icons";
|
|
3
|
+
import { useId, useState } from "react";
|
|
4
|
+
import type { ProjectsRecord } from "../elements/data/dsProjects.js";
|
|
5
|
+
import { type ElementDetails, getElement } from "../elements/ElementLookupDialog/getElement.js";
|
|
6
|
+
import type { AddElementManualFormProps } from "../elements/ElementLookupDialog/Manual/ManualForm.js";
|
|
7
|
+
import { getLocalizedString } from "../i18n.js";
|
|
8
|
+
import { ProjectSelect } from "./ProjectSelect.js";
|
|
9
|
+
|
|
10
|
+
const isElementsOnly = /^([a-z]{2,4}[\s]*[0-9]{4,8}[\s,]*)+$/i;
|
|
11
|
+
const matchElements = /([a-z]{2,4}[\s]*[0-9]{4,8})/gi;
|
|
12
|
+
|
|
13
|
+
export type { AddElementManualFormProps };
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Manual entry of a project and one or more element IDs. Designsystemet version of
|
|
17
|
+
* `AddElementManualForm` in `@olenbetong/synergi-react/elements`.
|
|
18
|
+
*/
|
|
19
|
+
export function AddElementManualForm({
|
|
20
|
+
onAdd,
|
|
21
|
+
mode,
|
|
22
|
+
defaultProject,
|
|
23
|
+
allowEmptyElement = false,
|
|
24
|
+
}: AddElementManualFormProps) {
|
|
25
|
+
let id = useId();
|
|
26
|
+
let [working, setWorking] = useState(false);
|
|
27
|
+
let [elementId, setElementId] = useState("");
|
|
28
|
+
let [project, setProject] = useState<Partial<ProjectsRecord> | null>(defaultProject ?? null);
|
|
29
|
+
|
|
30
|
+
async function handleSubmit(evt: React.FormEvent<HTMLFormElement>) {
|
|
31
|
+
try {
|
|
32
|
+
evt.preventDefault();
|
|
33
|
+
evt.stopPropagation();
|
|
34
|
+
let formData = new FormData(evt.currentTarget);
|
|
35
|
+
let elements = formData.get("ElementID");
|
|
36
|
+
|
|
37
|
+
if (!project?.ProjectID) {
|
|
38
|
+
alert(getLocalizedString("Project is required"));
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (!allowEmptyElement && !elements) {
|
|
43
|
+
alert(
|
|
44
|
+
getLocalizedString(
|
|
45
|
+
mode === "multi" ? "Project and elements are required" : "Project and element are required",
|
|
46
|
+
),
|
|
47
|
+
);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (elements) {
|
|
52
|
+
setWorking(true);
|
|
53
|
+
let records = (elements as string)
|
|
54
|
+
.match(matchElements)
|
|
55
|
+
?.map((elementId) => elementId.replace(/\s+/g, ""))
|
|
56
|
+
.map((elementId) => getElement({ projectId: project.ProjectID as string, elementId }, { mode: "manual" }));
|
|
57
|
+
|
|
58
|
+
if (!records) {
|
|
59
|
+
setWorking(false);
|
|
60
|
+
alert(getLocalizedString("Invalid elements"));
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
let loaded = (await Promise.all(records)).map((record) => onAdd(record));
|
|
65
|
+
await Promise.all(loaded);
|
|
66
|
+
setWorking(false);
|
|
67
|
+
} else {
|
|
68
|
+
onAdd({
|
|
69
|
+
PrimKey: "",
|
|
70
|
+
Domain: project.Domain ?? "",
|
|
71
|
+
Created: project.Created as Date,
|
|
72
|
+
ProjectID: project.ProjectID,
|
|
73
|
+
ProjectName: project.ProjectName ?? "",
|
|
74
|
+
ProjectDomain: project.Domain ?? "",
|
|
75
|
+
ElementID: "",
|
|
76
|
+
DisplayName: "",
|
|
77
|
+
GiaiUri: "",
|
|
78
|
+
} satisfies ElementDetails);
|
|
79
|
+
}
|
|
80
|
+
} catch (error) {
|
|
81
|
+
setWorking(false);
|
|
82
|
+
alert((error as Error).message);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return (
|
|
87
|
+
<form id={id} onSubmit={handleSubmit} method="post" className="ObElements-form">
|
|
88
|
+
<Alert data-color="warning">
|
|
89
|
+
{getLocalizedString(
|
|
90
|
+
"Manually entering elements is a major source of errors. Only use this as a last resort. If the camera or scanner is not working, please contact the IT department.",
|
|
91
|
+
)}
|
|
92
|
+
</Alert>
|
|
93
|
+
|
|
94
|
+
<ProjectSelect
|
|
95
|
+
id="AddElement_Project"
|
|
96
|
+
label={getLocalizedString("Project")}
|
|
97
|
+
value={project}
|
|
98
|
+
onChange={setProject}
|
|
99
|
+
names={{ domain: `${id}-Domain`, name: `${id}-ProjectName`, projectId: `${id}-ProjectID` }}
|
|
100
|
+
/>
|
|
101
|
+
|
|
102
|
+
<Textfield
|
|
103
|
+
autoComplete="off"
|
|
104
|
+
name="ElementID"
|
|
105
|
+
id="AddElement_ElementID"
|
|
106
|
+
label={getLocalizedString("Element ID")}
|
|
107
|
+
description={
|
|
108
|
+
mode === "multi"
|
|
109
|
+
? getLocalizedString("Multiple IDs can be entered if separated by space or comma")
|
|
110
|
+
: undefined
|
|
111
|
+
}
|
|
112
|
+
value={elementId}
|
|
113
|
+
onChange={(evt) => setElementId(evt.target.value)}
|
|
114
|
+
/>
|
|
115
|
+
|
|
116
|
+
<div>
|
|
117
|
+
<Button
|
|
118
|
+
type="submit"
|
|
119
|
+
variant="primary"
|
|
120
|
+
disabled={(!allowEmptyElement && !isElementsOnly.test(elementId)) || working}
|
|
121
|
+
loading={working}
|
|
122
|
+
>
|
|
123
|
+
{getLocalizedString("Add")}
|
|
124
|
+
{!working && <PlusIcon aria-hidden />}
|
|
125
|
+
</Button>
|
|
126
|
+
</div>
|
|
127
|
+
</form>
|
|
128
|
+
);
|
|
129
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { Combobox } from "@olenbetong/appframe-ds";
|
|
2
|
+
import { useDataWithFilter, useDebounce } from "@olenbetong/appframe-react";
|
|
3
|
+
import { useId, useMemo, useState } from "react";
|
|
4
|
+
import { dsProjects, type ProjectsRecord } from "../elements/data/dsProjects.js";
|
|
5
|
+
import { dsReportProjects } from "../elements/data/dsReportProjects.js";
|
|
6
|
+
import { getLocalizedString } from "../i18n.js";
|
|
7
|
+
|
|
8
|
+
export type ProjectSelectProps = {
|
|
9
|
+
className?: string;
|
|
10
|
+
style?: React.CSSProperties;
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
id?: string;
|
|
13
|
+
names?: {
|
|
14
|
+
domain?: string;
|
|
15
|
+
projectId?: string;
|
|
16
|
+
name?: string;
|
|
17
|
+
};
|
|
18
|
+
readOnly?: boolean;
|
|
19
|
+
required?: boolean;
|
|
20
|
+
onChange?: (project: Partial<ProjectsRecord> | null) => void;
|
|
21
|
+
defaultValue?: Partial<ProjectsRecord> | null;
|
|
22
|
+
value?: Partial<ProjectsRecord> | null;
|
|
23
|
+
label?: string;
|
|
24
|
+
/** Text shown in the empty input. With `hideLabel`, also the field's accessible name. */
|
|
25
|
+
placeholder?: string;
|
|
26
|
+
/** Leaves out the visible label, for a search field whose placeholder says what it is. */
|
|
27
|
+
hideLabel?: boolean;
|
|
28
|
+
report?: boolean;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Project lookup with the hidden `Domain`, `ProjectName` and `ProjectID` inputs a form posts.
|
|
33
|
+
* Designsystemet version of `ProjectSelect` in `@olenbetong/synergi-react/elements`.
|
|
34
|
+
*/
|
|
35
|
+
export function ProjectSelect({
|
|
36
|
+
className,
|
|
37
|
+
style,
|
|
38
|
+
disabled,
|
|
39
|
+
id,
|
|
40
|
+
names,
|
|
41
|
+
onChange,
|
|
42
|
+
readOnly,
|
|
43
|
+
required,
|
|
44
|
+
defaultValue,
|
|
45
|
+
value,
|
|
46
|
+
label,
|
|
47
|
+
placeholder,
|
|
48
|
+
hideLabel,
|
|
49
|
+
report,
|
|
50
|
+
}: ProjectSelectProps) {
|
|
51
|
+
let generatedId = useId();
|
|
52
|
+
let [selected, setSelected] = useState<Partial<ProjectsRecord> | null>(defaultValue ?? null);
|
|
53
|
+
let [query, setQuery] = useState("");
|
|
54
|
+
let search = useDebounce(query);
|
|
55
|
+
let projects = useDataWithFilter(
|
|
56
|
+
report ? dsReportProjects : dsProjects,
|
|
57
|
+
search ? `[SearchColumn] LIKE '%${search}%'` : "",
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
function handleSelect(value: Partial<ProjectsRecord> | null) {
|
|
61
|
+
if (!disabled && !readOnly) {
|
|
62
|
+
if (onChange) {
|
|
63
|
+
onChange(value);
|
|
64
|
+
} else {
|
|
65
|
+
setSelected(value);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
let current = value === undefined ? selected : value;
|
|
71
|
+
|
|
72
|
+
const duplicatedNames = useMemo(() => {
|
|
73
|
+
const nameCount = new Map<string, number>();
|
|
74
|
+
projects.forEach((opt) => {
|
|
75
|
+
nameCount.set(opt.ProjectName, (nameCount.get(opt.ProjectName) || 0) + 1);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
return new Set([...nameCount.entries()].filter(([, count]) => count > 1).map(([name]) => name));
|
|
79
|
+
}, [projects]);
|
|
80
|
+
|
|
81
|
+
return (
|
|
82
|
+
<>
|
|
83
|
+
<Combobox<Partial<ProjectsRecord>>
|
|
84
|
+
autoHighlight
|
|
85
|
+
className={className}
|
|
86
|
+
style={style}
|
|
87
|
+
options={projects}
|
|
88
|
+
disabled={disabled}
|
|
89
|
+
readOnly={readOnly}
|
|
90
|
+
required={required}
|
|
91
|
+
id={id ?? generatedId}
|
|
92
|
+
label={hideLabel ? undefined : (label ?? getLocalizedString("Project ID"))}
|
|
93
|
+
aria-label={hideLabel ? (label ?? placeholder ?? getLocalizedString("Project ID")) : undefined}
|
|
94
|
+
placeholder={placeholder}
|
|
95
|
+
getOptionLabel={(option) =>
|
|
96
|
+
option?.ProjectID !== undefined ? `${option.ProjectID}: ${option.ProjectName}` : ""
|
|
97
|
+
}
|
|
98
|
+
isOptionEqualToValue={(option, value) => option.Domain === value.Domain && option.ProjectID === value.ProjectID}
|
|
99
|
+
onChange={(_event, value) => handleSelect(value)}
|
|
100
|
+
onInputChange={(_event, newQuery, reason) => {
|
|
101
|
+
if (reason === "input") setQuery(newQuery);
|
|
102
|
+
else if (reason === "clear") setQuery("");
|
|
103
|
+
}}
|
|
104
|
+
value={current}
|
|
105
|
+
renderOption={(option) => {
|
|
106
|
+
let isDuplicated = option.ProjectName && duplicatedNames.has(option.ProjectName);
|
|
107
|
+
return (
|
|
108
|
+
<span className="ObElements-option">
|
|
109
|
+
<span>{isDuplicated ? `${option.ProjectName} (${option.Domain})` : option.ProjectName}</span>
|
|
110
|
+
<span>{option.ProjectID}</span>
|
|
111
|
+
</span>
|
|
112
|
+
);
|
|
113
|
+
}}
|
|
114
|
+
/>
|
|
115
|
+
<input name={names?.domain ?? "Domain"} type="hidden" value={current?.Domain ?? ""} />
|
|
116
|
+
<input name={names?.name ?? "ProjectName"} type="hidden" value={current?.ProjectName ?? ""} />
|
|
117
|
+
<input name={names?.projectId ?? "ProjectID"} type="hidden" value={current?.ProjectID ?? ""} />
|
|
118
|
+
</>
|
|
119
|
+
);
|
|
120
|
+
}
|