@olenbetong/synergi-react 4.2.1 → 4.2.4
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/package.json +8 -8
- package/src/chrome/AppShell/index.tsx +29 -29
- package/src/chrome/openReport.ts +34 -34
- package/src/colorScheme.ts +81 -81
- package/src/components/DateNavigator/index.tsx +186 -186
- package/src/components/FilePond.tsx +312 -312
- 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.ts +405 -405
- package/src/components/ImageEditor/plugins/redactPlugin/RedactToolbar.tsx +47 -47
- package/src/components/ImageEditor/plugins/zoomPlugin/ZoomContext.tsx +23 -23
- package/src/components/ImageEditor/plugins/zoomPlugin/ZoomControls.tsx +40 -40
- package/src/components/ImageEditor/useActiveTool.ts +21 -21
- package/src/components/ImageEditor/useEdgeDetection.ts +319 -319
- package/src/components/ImageEditor/useImageHistory.ts +197 -197
- package/src/components/ImageEditor/useOpenCV.ts +184 -184
- package/src/components/LinkedCardList/index.scss +95 -95
- package/src/components/MergeProgressDialog/index.tsx +249 -249
- package/src/components/PageBanner/index.tsx +80 -80
- package/src/components/PdfViewer/PdfViewer.tsx +158 -158
- package/src/components/ProgressBar/index.scss +96 -96
- package/src/components/SplitContainer/index.tsx +333 -333
- package/src/components/Toolbar/index.tsx +232 -232
- 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/decoder.ts +32 -32
- package/src/elements/ElementLookupDialog/BarcodeScanner/decoders/dbr.ts +118 -118
- package/src/elements/ElementLookupDialog/BarcodeScanner/decoders/native.ts +103 -103
- package/src/elements/ElementLookupDialog/BarcodeScanner/decoders/zxing.ts +95 -95
- package/src/elements/ElementLookupDialog/BarcodeScanner/decoders.test.ts +118 -118
- package/src/elements/ElementLookupDialog/BarcodeScanner/duplicateFilter.ts +21 -21
- package/src/elements/ElementLookupDialog/BarcodeScanner/index.tsx +90 -90
- package/src/elements/ElementLookupDialog/BarcodeScanner/useScanner.ts +280 -280
- package/src/elements/ElementLookupDialog/HIDScanner/index.tsx +67 -67
- package/src/elements/ElementLookupDialog/Manual/ManualForm.tsx +141 -141
- package/src/elements/ElementLookupDialog/index.tsx +226 -226
- 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/filter/index.ts +34 -34
- package/src/i18n.ts +13 -13
- package/src/index.ts +77 -77
- package/src/mui/MuiThemeProvider.tsx +174 -174
- package/src/mui/index.ts +1 -1
- package/src/test/setup.ts +8 -8
|
@@ -1,226 +1,226 @@
|
|
|
1
|
-
import Add from "@mui/icons-material/Add";
|
|
2
|
-
import DeleteForeverOutlined from "@mui/icons-material/DeleteForeverOutlined";
|
|
3
|
-
import Edit from "@mui/icons-material/Edit";
|
|
4
|
-
import QrCodeScanner from "@mui/icons-material/QrCodeScanner";
|
|
5
|
-
import TapAndPlay from "@mui/icons-material/TapAndPlay";
|
|
6
|
-
import { Alert, Box, Button, DialogActions, List, ListItem, ListItemText, Tab, Tabs } from "@mui/material";
|
|
7
|
-
import { ResponsiveDialog } from "@olenbetong/appframe-mui";
|
|
8
|
-
import { type ReactNode, useEffect, useState } from "react";
|
|
9
|
-
import { flushSync } from "react-dom";
|
|
10
|
-
import { BarcodeScanner, type DecoderFactory } from "./BarcodeScanner";
|
|
11
|
-
import { type AddElementSource, type ElementDetails, getElement } from "./getElement";
|
|
12
|
-
import { AddElementHIDScanner } from "./HIDScanner";
|
|
13
|
-
import { AddElementManualForm } from "./Manual/ManualForm";
|
|
14
|
-
import { useBeeper } from "./utils/beep";
|
|
15
|
-
import Giai from "./utils/Giai";
|
|
16
|
-
import { getLocalizedString, localize } from "../../i18n.js";
|
|
17
|
-
|
|
18
|
-
export type AddElement = {
|
|
19
|
-
element: ElementDetails;
|
|
20
|
-
mode: AddElementSource;
|
|
21
|
-
scanTime?: number;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
type InitialTabProps = "camera" | "scanner" | "manual";
|
|
25
|
-
|
|
26
|
-
export type ElementLookupDialogSharedProps = {
|
|
27
|
-
open: boolean;
|
|
28
|
-
onClose: () => void;
|
|
29
|
-
initialTab?: InitialTabProps | null;
|
|
30
|
-
useSearch?: boolean;
|
|
31
|
-
allowEmptyElement?: boolean;
|
|
32
|
-
/** Engine for the camera tab. Defaults to zxing-wasm. */
|
|
33
|
-
decoder?: DecoderFactory;
|
|
34
|
-
/** Extra controls in the camera tab footer, e.g. an engine picker. */
|
|
35
|
-
scannerActions?: ReactNode;
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
export type ElementLookupDialogSingleModeProps = ElementLookupDialogSharedProps & {
|
|
39
|
-
mode: "single" | "search";
|
|
40
|
-
onAdd: (element: AddElement) => Promise<void>;
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
export type ElementLookupDialogMultiModeProps = ElementLookupDialogSharedProps & {
|
|
44
|
-
mode: "multi";
|
|
45
|
-
onAdd: (element: AddElement[]) => Promise<void>;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
export type ElementLookupDialogProps = ElementLookupDialogSingleModeProps | ElementLookupDialogMultiModeProps;
|
|
49
|
-
|
|
50
|
-
export function ElementLookupDialog(props: ElementLookupDialogProps) {
|
|
51
|
-
let { open, onClose, initialTab, decoder, scannerActions } = props;
|
|
52
|
-
let [tab, setTab] = useState<"camera" | "scanner" | "manual">("camera");
|
|
53
|
-
let [elements, setElements] = useState<Array<AddElement>>([]);
|
|
54
|
-
let [adding, setAdding] = useState(false);
|
|
55
|
-
let beeper = useBeeper();
|
|
56
|
-
|
|
57
|
-
useEffect(() => {
|
|
58
|
-
if (open && initialTab) {
|
|
59
|
-
setTab(initialTab);
|
|
60
|
-
}
|
|
61
|
-
}, [open, initialTab]);
|
|
62
|
-
|
|
63
|
-
async function handleElementAdd(element: string | ElementDetails, mode: AddElementSource) {
|
|
64
|
-
try {
|
|
65
|
-
let record = typeof element === "string" ? await getElement(element.replace("\u001d", ""), { mode }) : element;
|
|
66
|
-
|
|
67
|
-
// Flush changes to DOM to be able to query newly added elements and animate their background
|
|
68
|
-
flushSync(() => {
|
|
69
|
-
setElements((current) => {
|
|
70
|
-
let now = Date.now();
|
|
71
|
-
let exists = current.some((e) => e.element.ElementID === record.ElementID);
|
|
72
|
-
let updated: Array<AddElement>;
|
|
73
|
-
|
|
74
|
-
if (exists) {
|
|
75
|
-
updated = current.map((e) => (e.element.ElementID === record.ElementID ? { ...e, scanTime: now } : e));
|
|
76
|
-
} else {
|
|
77
|
-
beeper();
|
|
78
|
-
updated =
|
|
79
|
-
props.mode === "multi"
|
|
80
|
-
? [{ element: record, mode, scanTime: now }, ...current]
|
|
81
|
-
: [{ element: record, mode, scanTime: now }];
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
if (props.mode === "multi") {
|
|
85
|
-
updated.sort((a, b) => (b.scanTime ?? 0) - (a.scanTime ?? 0));
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
return updated;
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
let addedDomElement = document.querySelector(`[data-elementid="${record.ElementID}"]`);
|
|
93
|
-
if (addedDomElement) {
|
|
94
|
-
addedDomElement.animate(
|
|
95
|
-
[
|
|
96
|
-
{ backgroundColor: "var(--brand-light)", offset: 0 },
|
|
97
|
-
{ backgroundColor: "var(--brand-light)", offset: 0.2 },
|
|
98
|
-
{ backgroundColor: "transparent" },
|
|
99
|
-
],
|
|
100
|
-
{
|
|
101
|
-
duration: 1000,
|
|
102
|
-
easing: "ease-out",
|
|
103
|
-
},
|
|
104
|
-
);
|
|
105
|
-
}
|
|
106
|
-
} catch (error) {
|
|
107
|
-
alert((error as Error).message);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
if (tab === "manual" && props.mode === "search") {
|
|
112
|
-
tab = "camera";
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
return (
|
|
116
|
-
<ResponsiveDialog
|
|
117
|
-
open={open}
|
|
118
|
-
onClose={onClose}
|
|
119
|
-
slotProps={{
|
|
120
|
-
paper: { sx: { overflow: "hidden" } },
|
|
121
|
-
}}
|
|
122
|
-
>
|
|
123
|
-
<Box sx={{ display: "flex", flexDirection: "column", maxHeight: "100%", overflow: "hidden", flexGrow: 1 }}>
|
|
124
|
-
<Tabs value={tab} onChange={(_, newTab) => setTab(newTab)} variant="fullWidth" sx={{ flexShrink: 0 }}>
|
|
125
|
-
{props.mode !== "search" && <Tab icon={<Edit />} label={getLocalizedString("Manual")} value="manual" />}
|
|
126
|
-
<Tab icon={<TapAndPlay />} label={getLocalizedString("Scanner")} value="scanner" />
|
|
127
|
-
<Tab icon={<QrCodeScanner />} label={getLocalizedString("Camera")} value="camera" />
|
|
128
|
-
</Tabs>
|
|
129
|
-
{tab === "camera" && (
|
|
130
|
-
<Box sx={{ flexBasis: "12rem", flexGrow: 1, flexShrink: 2 }}>
|
|
131
|
-
<BarcodeScanner
|
|
132
|
-
decoder={decoder}
|
|
133
|
-
actions={scannerActions}
|
|
134
|
-
onRead={(element) => handleElementAdd(element, "camera-barcode")}
|
|
135
|
-
/>
|
|
136
|
-
</Box>
|
|
137
|
-
)}
|
|
138
|
-
{tab === "manual" && (
|
|
139
|
-
<Box sx={{ p: 2 }}>
|
|
140
|
-
<AddElementManualForm
|
|
141
|
-
onAdd={(element) => handleElementAdd(element, "manual")}
|
|
142
|
-
allowEmptyElement={props.allowEmptyElement}
|
|
143
|
-
/>
|
|
144
|
-
</Box>
|
|
145
|
-
)}
|
|
146
|
-
{tab === "scanner" && (
|
|
147
|
-
<Box sx={{ flexBasis: "12rem", flexGrow: 1, flexShrink: 2 }}>
|
|
148
|
-
<AddElementHIDScanner
|
|
149
|
-
onScan={(element) =>
|
|
150
|
-
handleElementAdd(element, element.startsWith(Giai.BARCODE_PREFIX) ? "hid-barcode" : "hid-rfid")
|
|
151
|
-
}
|
|
152
|
-
/>
|
|
153
|
-
</Box>
|
|
154
|
-
)}
|
|
155
|
-
|
|
156
|
-
<Box sx={{ flex: "3 1 14rem", overflow: "auto" }}>
|
|
157
|
-
{props.mode === "multi" && (
|
|
158
|
-
<Alert
|
|
159
|
-
icon={false}
|
|
160
|
-
severity="info"
|
|
161
|
-
sx={{ justifyContent: "center", py: 0, position: "sticky", top: 0, zIndex: 1 }}
|
|
162
|
-
slotProps={{
|
|
163
|
-
message: { sx: { py: 0.5 } },
|
|
164
|
-
}}
|
|
165
|
-
>{localize`${elements.length} elements selected`}</Alert>
|
|
166
|
-
)}
|
|
167
|
-
<List disablePadding>
|
|
168
|
-
{elements.map(({ element }) => (
|
|
169
|
-
<ListItem
|
|
170
|
-
key={element.ElementID}
|
|
171
|
-
data-elementid={element.ElementID}
|
|
172
|
-
secondaryAction={
|
|
173
|
-
<Button
|
|
174
|
-
color="error"
|
|
175
|
-
variant="outlined"
|
|
176
|
-
onClick={() => {
|
|
177
|
-
setElements((current) =>
|
|
178
|
-
props.mode === "multi" ? current.filter((e) => e.element.ElementID !== element.ElementID) : [],
|
|
179
|
-
);
|
|
180
|
-
}}
|
|
181
|
-
>
|
|
182
|
-
<DeleteForeverOutlined />
|
|
183
|
-
</Button>
|
|
184
|
-
}
|
|
185
|
-
>
|
|
186
|
-
<ListItemText
|
|
187
|
-
primary={element.DisplayName || element.ProjectName}
|
|
188
|
-
secondary={element.ElementID || element.ProjectID}
|
|
189
|
-
/>
|
|
190
|
-
</ListItem>
|
|
191
|
-
))}
|
|
192
|
-
</List>
|
|
193
|
-
</Box>
|
|
194
|
-
|
|
195
|
-
<DialogActions sx={{ flexShrink: 0 }}>
|
|
196
|
-
<Button onClick={onClose}>{getLocalizedString("Cancel")}</Button>
|
|
197
|
-
<Button
|
|
198
|
-
variant="contained"
|
|
199
|
-
loading={adding}
|
|
200
|
-
onClick={async () => {
|
|
201
|
-
try {
|
|
202
|
-
setAdding(true);
|
|
203
|
-
if (props.mode === "multi") {
|
|
204
|
-
await props.onAdd(elements);
|
|
205
|
-
} else {
|
|
206
|
-
await props.onAdd(elements[0]!);
|
|
207
|
-
}
|
|
208
|
-
setElements([]);
|
|
209
|
-
setAdding(false);
|
|
210
|
-
onClose();
|
|
211
|
-
} catch (error) {
|
|
212
|
-
setAdding(false);
|
|
213
|
-
alert((error as Error).message);
|
|
214
|
-
}
|
|
215
|
-
}}
|
|
216
|
-
startIcon={<Add />}
|
|
217
|
-
loadingPosition="start"
|
|
218
|
-
disabled={!elements.length}
|
|
219
|
-
>
|
|
220
|
-
{props.mode === "search" ? getLocalizedString("Search for element") : getLocalizedString("Add element")}
|
|
221
|
-
</Button>
|
|
222
|
-
</DialogActions>
|
|
223
|
-
</Box>
|
|
224
|
-
</ResponsiveDialog>
|
|
225
|
-
);
|
|
226
|
-
}
|
|
1
|
+
import Add from "@mui/icons-material/Add";
|
|
2
|
+
import DeleteForeverOutlined from "@mui/icons-material/DeleteForeverOutlined";
|
|
3
|
+
import Edit from "@mui/icons-material/Edit";
|
|
4
|
+
import QrCodeScanner from "@mui/icons-material/QrCodeScanner";
|
|
5
|
+
import TapAndPlay from "@mui/icons-material/TapAndPlay";
|
|
6
|
+
import { Alert, Box, Button, DialogActions, List, ListItem, ListItemText, Tab, Tabs } from "@mui/material";
|
|
7
|
+
import { ResponsiveDialog } from "@olenbetong/appframe-mui";
|
|
8
|
+
import { type ReactNode, useEffect, useState } from "react";
|
|
9
|
+
import { flushSync } from "react-dom";
|
|
10
|
+
import { BarcodeScanner, type DecoderFactory } from "./BarcodeScanner";
|
|
11
|
+
import { type AddElementSource, type ElementDetails, getElement } from "./getElement";
|
|
12
|
+
import { AddElementHIDScanner } from "./HIDScanner";
|
|
13
|
+
import { AddElementManualForm } from "./Manual/ManualForm";
|
|
14
|
+
import { useBeeper } from "./utils/beep";
|
|
15
|
+
import Giai from "./utils/Giai";
|
|
16
|
+
import { getLocalizedString, localize } from "../../i18n.js";
|
|
17
|
+
|
|
18
|
+
export type AddElement = {
|
|
19
|
+
element: ElementDetails;
|
|
20
|
+
mode: AddElementSource;
|
|
21
|
+
scanTime?: number;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
type InitialTabProps = "camera" | "scanner" | "manual";
|
|
25
|
+
|
|
26
|
+
export type ElementLookupDialogSharedProps = {
|
|
27
|
+
open: boolean;
|
|
28
|
+
onClose: () => void;
|
|
29
|
+
initialTab?: InitialTabProps | null;
|
|
30
|
+
useSearch?: boolean;
|
|
31
|
+
allowEmptyElement?: boolean;
|
|
32
|
+
/** Engine for the camera tab. Defaults to zxing-wasm. */
|
|
33
|
+
decoder?: DecoderFactory;
|
|
34
|
+
/** Extra controls in the camera tab footer, e.g. an engine picker. */
|
|
35
|
+
scannerActions?: ReactNode;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export type ElementLookupDialogSingleModeProps = ElementLookupDialogSharedProps & {
|
|
39
|
+
mode: "single" | "search";
|
|
40
|
+
onAdd: (element: AddElement) => Promise<void>;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export type ElementLookupDialogMultiModeProps = ElementLookupDialogSharedProps & {
|
|
44
|
+
mode: "multi";
|
|
45
|
+
onAdd: (element: AddElement[]) => Promise<void>;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export type ElementLookupDialogProps = ElementLookupDialogSingleModeProps | ElementLookupDialogMultiModeProps;
|
|
49
|
+
|
|
50
|
+
export function ElementLookupDialog(props: ElementLookupDialogProps) {
|
|
51
|
+
let { open, onClose, initialTab, decoder, scannerActions } = props;
|
|
52
|
+
let [tab, setTab] = useState<"camera" | "scanner" | "manual">("camera");
|
|
53
|
+
let [elements, setElements] = useState<Array<AddElement>>([]);
|
|
54
|
+
let [adding, setAdding] = useState(false);
|
|
55
|
+
let beeper = useBeeper();
|
|
56
|
+
|
|
57
|
+
useEffect(() => {
|
|
58
|
+
if (open && initialTab) {
|
|
59
|
+
setTab(initialTab);
|
|
60
|
+
}
|
|
61
|
+
}, [open, initialTab]);
|
|
62
|
+
|
|
63
|
+
async function handleElementAdd(element: string | ElementDetails, mode: AddElementSource) {
|
|
64
|
+
try {
|
|
65
|
+
let record = typeof element === "string" ? await getElement(element.replace("\u001d", ""), { mode }) : element;
|
|
66
|
+
|
|
67
|
+
// Flush changes to DOM to be able to query newly added elements and animate their background
|
|
68
|
+
flushSync(() => {
|
|
69
|
+
setElements((current) => {
|
|
70
|
+
let now = Date.now();
|
|
71
|
+
let exists = current.some((e) => e.element.ElementID === record.ElementID);
|
|
72
|
+
let updated: Array<AddElement>;
|
|
73
|
+
|
|
74
|
+
if (exists) {
|
|
75
|
+
updated = current.map((e) => (e.element.ElementID === record.ElementID ? { ...e, scanTime: now } : e));
|
|
76
|
+
} else {
|
|
77
|
+
beeper();
|
|
78
|
+
updated =
|
|
79
|
+
props.mode === "multi"
|
|
80
|
+
? [{ element: record, mode, scanTime: now }, ...current]
|
|
81
|
+
: [{ element: record, mode, scanTime: now }];
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (props.mode === "multi") {
|
|
85
|
+
updated.sort((a, b) => (b.scanTime ?? 0) - (a.scanTime ?? 0));
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return updated;
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
let addedDomElement = document.querySelector(`[data-elementid="${record.ElementID}"]`);
|
|
93
|
+
if (addedDomElement) {
|
|
94
|
+
addedDomElement.animate(
|
|
95
|
+
[
|
|
96
|
+
{ backgroundColor: "var(--brand-light)", offset: 0 },
|
|
97
|
+
{ backgroundColor: "var(--brand-light)", offset: 0.2 },
|
|
98
|
+
{ backgroundColor: "transparent" },
|
|
99
|
+
],
|
|
100
|
+
{
|
|
101
|
+
duration: 1000,
|
|
102
|
+
easing: "ease-out",
|
|
103
|
+
},
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
} catch (error) {
|
|
107
|
+
alert((error as Error).message);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (tab === "manual" && props.mode === "search") {
|
|
112
|
+
tab = "camera";
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return (
|
|
116
|
+
<ResponsiveDialog
|
|
117
|
+
open={open}
|
|
118
|
+
onClose={onClose}
|
|
119
|
+
slotProps={{
|
|
120
|
+
paper: { sx: { overflow: "hidden" } },
|
|
121
|
+
}}
|
|
122
|
+
>
|
|
123
|
+
<Box sx={{ display: "flex", flexDirection: "column", maxHeight: "100%", overflow: "hidden", flexGrow: 1 }}>
|
|
124
|
+
<Tabs value={tab} onChange={(_, newTab) => setTab(newTab)} variant="fullWidth" sx={{ flexShrink: 0 }}>
|
|
125
|
+
{props.mode !== "search" && <Tab icon={<Edit />} label={getLocalizedString("Manual")} value="manual" />}
|
|
126
|
+
<Tab icon={<TapAndPlay />} label={getLocalizedString("Scanner")} value="scanner" />
|
|
127
|
+
<Tab icon={<QrCodeScanner />} label={getLocalizedString("Camera")} value="camera" />
|
|
128
|
+
</Tabs>
|
|
129
|
+
{tab === "camera" && (
|
|
130
|
+
<Box sx={{ flexBasis: "12rem", flexGrow: 1, flexShrink: 2 }}>
|
|
131
|
+
<BarcodeScanner
|
|
132
|
+
decoder={decoder}
|
|
133
|
+
actions={scannerActions}
|
|
134
|
+
onRead={(element) => handleElementAdd(element, "camera-barcode")}
|
|
135
|
+
/>
|
|
136
|
+
</Box>
|
|
137
|
+
)}
|
|
138
|
+
{tab === "manual" && (
|
|
139
|
+
<Box sx={{ p: 2 }}>
|
|
140
|
+
<AddElementManualForm
|
|
141
|
+
onAdd={(element) => handleElementAdd(element, "manual")}
|
|
142
|
+
allowEmptyElement={props.allowEmptyElement}
|
|
143
|
+
/>
|
|
144
|
+
</Box>
|
|
145
|
+
)}
|
|
146
|
+
{tab === "scanner" && (
|
|
147
|
+
<Box sx={{ flexBasis: "12rem", flexGrow: 1, flexShrink: 2 }}>
|
|
148
|
+
<AddElementHIDScanner
|
|
149
|
+
onScan={(element) =>
|
|
150
|
+
handleElementAdd(element, element.startsWith(Giai.BARCODE_PREFIX) ? "hid-barcode" : "hid-rfid")
|
|
151
|
+
}
|
|
152
|
+
/>
|
|
153
|
+
</Box>
|
|
154
|
+
)}
|
|
155
|
+
|
|
156
|
+
<Box sx={{ flex: "3 1 14rem", overflow: "auto" }}>
|
|
157
|
+
{props.mode === "multi" && (
|
|
158
|
+
<Alert
|
|
159
|
+
icon={false}
|
|
160
|
+
severity="info"
|
|
161
|
+
sx={{ justifyContent: "center", py: 0, position: "sticky", top: 0, zIndex: 1 }}
|
|
162
|
+
slotProps={{
|
|
163
|
+
message: { sx: { py: 0.5 } },
|
|
164
|
+
}}
|
|
165
|
+
>{localize`${elements.length} elements selected`}</Alert>
|
|
166
|
+
)}
|
|
167
|
+
<List disablePadding>
|
|
168
|
+
{elements.map(({ element }) => (
|
|
169
|
+
<ListItem
|
|
170
|
+
key={element.ElementID}
|
|
171
|
+
data-elementid={element.ElementID}
|
|
172
|
+
secondaryAction={
|
|
173
|
+
<Button
|
|
174
|
+
color="error"
|
|
175
|
+
variant="outlined"
|
|
176
|
+
onClick={() => {
|
|
177
|
+
setElements((current) =>
|
|
178
|
+
props.mode === "multi" ? current.filter((e) => e.element.ElementID !== element.ElementID) : [],
|
|
179
|
+
);
|
|
180
|
+
}}
|
|
181
|
+
>
|
|
182
|
+
<DeleteForeverOutlined />
|
|
183
|
+
</Button>
|
|
184
|
+
}
|
|
185
|
+
>
|
|
186
|
+
<ListItemText
|
|
187
|
+
primary={element.DisplayName || element.ProjectName}
|
|
188
|
+
secondary={element.ElementID || element.ProjectID}
|
|
189
|
+
/>
|
|
190
|
+
</ListItem>
|
|
191
|
+
))}
|
|
192
|
+
</List>
|
|
193
|
+
</Box>
|
|
194
|
+
|
|
195
|
+
<DialogActions sx={{ flexShrink: 0 }}>
|
|
196
|
+
<Button onClick={onClose}>{getLocalizedString("Cancel")}</Button>
|
|
197
|
+
<Button
|
|
198
|
+
variant="contained"
|
|
199
|
+
loading={adding}
|
|
200
|
+
onClick={async () => {
|
|
201
|
+
try {
|
|
202
|
+
setAdding(true);
|
|
203
|
+
if (props.mode === "multi") {
|
|
204
|
+
await props.onAdd(elements);
|
|
205
|
+
} else {
|
|
206
|
+
await props.onAdd(elements[0]!);
|
|
207
|
+
}
|
|
208
|
+
setElements([]);
|
|
209
|
+
setAdding(false);
|
|
210
|
+
onClose();
|
|
211
|
+
} catch (error) {
|
|
212
|
+
setAdding(false);
|
|
213
|
+
alert((error as Error).message);
|
|
214
|
+
}
|
|
215
|
+
}}
|
|
216
|
+
startIcon={<Add />}
|
|
217
|
+
loadingPosition="start"
|
|
218
|
+
disabled={!elements.length}
|
|
219
|
+
>
|
|
220
|
+
{props.mode === "search" ? getLocalizedString("Search for element") : getLocalizedString("Add element")}
|
|
221
|
+
</Button>
|
|
222
|
+
</DialogActions>
|
|
223
|
+
</Box>
|
|
224
|
+
</ResponsiveDialog>
|
|
225
|
+
);
|
|
226
|
+
}
|