@olenbetong/synergi-react 4.3.0 → 5.0.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.
Files changed (81) hide show
  1. package/dist/styles/styles.css +1 -1
  2. package/dist/styles/styles.css.map +1 -1
  3. package/es/components/CodeEditor/CodeEditor.css +6 -6
  4. package/es/components/MergeProgressDialog/MergeProgressDialogDs.d.ts +7 -0
  5. package/es/components/MergeProgressDialog/MergeProgressDialogDs.js +20 -0
  6. package/es/components/MergeProgressDialog/index.d.ts +3 -8
  7. package/es/components/MergeProgressDialog/index.js +4 -113
  8. package/es/components/MergeProgressDialog/useMergeJob.d.ts +36 -0
  9. package/es/components/MergeProgressDialog/useMergeJob.js +141 -0
  10. package/es/components/ProgressBar/index.css +1 -1
  11. package/es/components/Toolbar/Toolbar.css +137 -137
  12. package/es/elements/ElementLookupDialog/BarcodeScanner/BarcodeScanner.css +81 -0
  13. package/es/elements/ElementLookupDialog/BarcodeScanner/DeadIcon.d.ts +2 -2
  14. package/es/elements/ElementLookupDialog/BarcodeScanner/DeadIcon.js +1 -2
  15. package/es/elements/ElementLookupDialog/BarcodeScanner/Error.js +3 -29
  16. package/es/elements/ElementLookupDialog/BarcodeScanner/index.d.ts +1 -0
  17. package/es/elements/ElementLookupDialog/BarcodeScanner/index.js +3 -28
  18. package/es/index.css +1 -1
  19. package/es/index.d.ts +2 -1
  20. package/es/index.js +2 -1
  21. package/es/mui/index.d.ts +1 -0
  22. package/es/mui/index.js +1 -0
  23. package/es/test/setup.d.ts +5 -0
  24. package/package.json +21 -14
  25. package/src/chrome/AppShell/index.tsx +29 -29
  26. package/src/chrome/openReport.ts +34 -34
  27. package/src/colorScheme.ts +125 -125
  28. package/src/components/CodeEditor/CodeEditor.css +6 -6
  29. package/src/components/CodeEditor/CodeEditor.tsx +173 -173
  30. package/src/components/CodeEditor/index.ts +1 -1
  31. package/src/components/DateNavigator/index.tsx +186 -186
  32. package/src/components/FilePond.tsx +312 -312
  33. package/src/components/ImageEditor/ImageEditor.tsx +348 -348
  34. package/src/components/ImageEditor/index.ts +9 -9
  35. package/src/components/ImageEditor/plugins/cropPlugin/CropOverlay.tsx +165 -165
  36. package/src/components/ImageEditor/plugins/cropPlugin/CropToolbar.tsx +48 -48
  37. package/src/components/ImageEditor/plugins/cropPlugin/useCropTool.ts +405 -405
  38. package/src/components/ImageEditor/plugins/redactPlugin/RedactToolbar.tsx +47 -47
  39. package/src/components/ImageEditor/plugins/zoomPlugin/ZoomContext.tsx +23 -23
  40. package/src/components/ImageEditor/plugins/zoomPlugin/ZoomControls.tsx +40 -40
  41. package/src/components/ImageEditor/useActiveTool.ts +21 -21
  42. package/src/components/ImageEditor/useEdgeDetection.ts +319 -319
  43. package/src/components/ImageEditor/useImageHistory.ts +197 -197
  44. package/src/components/ImageEditor/useOpenCV.ts +184 -184
  45. package/src/components/LinkedCardList/index.scss +95 -95
  46. package/src/components/MergeProgressDialog/MergeProgressDialogDs.tsx +91 -0
  47. package/src/components/MergeProgressDialog/index.tsx +5 -136
  48. package/src/components/MergeProgressDialog/useMergeJob.ts +169 -0
  49. package/src/components/PageBanner/index.tsx +80 -80
  50. package/src/components/PdfViewer/PdfViewer.tsx +158 -158
  51. package/src/components/ProgressBar/index.scss +23 -54
  52. package/src/components/SplitContainer/index.tsx +333 -333
  53. package/src/components/Toolbar/Toolbar.css +137 -137
  54. package/src/components/Toolbar/index.tsx +265 -265
  55. package/src/designsystemet-web-types.d.ts +24 -24
  56. package/src/elements/ElementDamage/DamageFormButtons.tsx +35 -35
  57. package/src/elements/ElementDamage/DescriptionInput.tsx +120 -120
  58. package/src/elements/ElementDamage/DuplicateDamage/DesktopView.tsx +82 -82
  59. package/src/elements/ElementDamage/DuplicateDamage/DublicateElementDamageDialog.tsx +67 -67
  60. package/src/elements/ElementDamage/DuplicateDamage/PhoneView.tsx +45 -45
  61. package/src/elements/ElementDamage/ElementNumberTextField.tsx +41 -41
  62. package/src/elements/ElementDamage/RegisterFix.tsx +100 -100
  63. package/src/elements/ElementDamage/SubmitButtons.tsx +40 -40
  64. package/src/elements/ElementDamage/TransportElementSelect.tsx +52 -52
  65. package/src/elements/ElementLookup.tsx +123 -123
  66. package/src/elements/ElementLookupDialog/BarcodeScanner/BarcodeScanner.css +81 -0
  67. package/src/elements/ElementLookupDialog/BarcodeScanner/DeadIcon.tsx +4 -4
  68. package/src/elements/ElementLookupDialog/BarcodeScanner/Error.tsx +7 -36
  69. package/src/elements/ElementLookupDialog/BarcodeScanner/index.tsx +20 -49
  70. package/src/elements/ElementLookupDialog/HIDScanner/index.tsx +67 -67
  71. package/src/elements/ElementLookupDialog/Manual/ManualForm.tsx +141 -141
  72. package/src/elements/ElementLookupDialog/index.tsx +226 -226
  73. package/src/elements/ElementLookupDialog/utils/Giai.ts +209 -209
  74. package/src/elements/ProjectSelect.tsx +130 -130
  75. package/src/elements/index.ts +15 -15
  76. package/src/filter/index.ts +34 -34
  77. package/src/i18n.ts +13 -13
  78. package/src/index.ts +5 -1
  79. package/src/mui/MuiThemeProvider.tsx +135 -135
  80. package/src/mui/index.ts +1 -0
  81. package/src/test/setup.ts +23 -8
@@ -1,209 +1,209 @@
1
- import { getLocalizedString } from "../../../i18n.js";
2
-
3
- export type GiaiProps = {
4
- assetReference: string | number | bigint;
5
- companyPrefix: string | number | bigint;
6
- filter?: string | number | undefined;
7
- };
8
-
9
- /**
10
- * GIAI-96 encoder and decoder as defined by the GS1 EPC Tag data standard
11
- */
12
- export default class Giai {
13
- /// Bit lengths for company prefix given partition equal to index.
14
- ///
15
- /// Partition Company prefix Individual asset reference
16
- /// Bits Digits Bits Digits
17
- /// 0 40 12 42 13
18
- /// 1 37 11 45 14
19
- /// 2 34 10 48 15
20
- /// 3 30 9 52 16
21
- /// 4 27 8 55 17
22
- /// 5 24 7 58 18
23
- /// 6 20 6 62 19
24
- static PARTITION_TABLE = [40, 37, 34, 30, 27, 24, 20];
25
- // EPC header for GIAI-96 coding scheme
26
- static EPC_HEADER = "00110100";
27
- // Prefix for GS1 key used in barcodes;
28
- static BARCODE_PREFIX = "8004";
29
- // Group separator used to separate company prefix and asset reference (FNC1 in GS1-128 barcodes)
30
- static GROUP_SEPARATOR = String.fromCodePoint(0x001d);
31
-
32
- static URN_PREFIX = "urn:epc:id:giai:";
33
-
34
- static fromHex = (hexIdentifier: string) => {
35
- const bitIdentifier = hexToBitString(hexIdentifier);
36
-
37
- if (bitIdentifier.substring(0, 8) !== Giai.EPC_HEADER) {
38
- throw new Error("EPC value is not a valid GIAI value.");
39
- }
40
-
41
- const partition = Number.parseInt(bitIdentifier.substr(11, 3), 2);
42
- const companyPrefixLength = Giai.PARTITION_TABLE[partition];
43
- const filter = Number.parseInt(bitIdentifier.substring(8, 11), 2);
44
- const companyPrefix = BigInt(`0b${bitIdentifier.substring(14, 14 + companyPrefixLength)}`);
45
- const assetReference = BigInt(`0b${bitIdentifier.substring(14 + companyPrefixLength)}`);
46
-
47
- return new Giai({ assetReference, companyPrefix, filter });
48
- };
49
-
50
- /**
51
- *
52
- * @param {string | null | undefined} barcodeString
53
- * @returns
54
- */
55
- static fromBarcode = (barcodeString: string) => {
56
- const prefixLength = Giai.BARCODE_PREFIX.length;
57
-
58
- if (barcodeString[0] === Giai.GROUP_SEPARATOR) {
59
- barcodeString = barcodeString.substr(1);
60
- }
61
-
62
- if (barcodeString.substr(0, prefixLength) !== Giai.BARCODE_PREFIX) {
63
- throw new Error(`Barcode is not a valid GIAI barcode. (${Giai.BARCODE_PREFIX} prefix expected)`);
64
- }
65
-
66
- let giaiString = barcodeString.substring(prefixLength);
67
- const gsIndex = giaiString.indexOf(Giai.GROUP_SEPARATOR);
68
-
69
- if (gsIndex >= 0) {
70
- return new Giai({
71
- assetReference: giaiString.substring(gsIndex + 1),
72
- companyPrefix: giaiString.substring(0, gsIndex),
73
- });
74
- }
75
-
76
- // If no separator is found, assume a company prefix length of 7
77
- return new Giai({
78
- assetReference: giaiString.substring(7),
79
- companyPrefix: giaiString.substring(0, 7),
80
- });
81
- };
82
-
83
- /**
84
- * Creates a GIAI instance from a purse identity URI (urn:epc:giai:[companyprefix].[assetreference])
85
- * @param {string} uri EPC GIAI pure identity URI
86
- */
87
- static fromEpcPureIdentityUri(uri: string) {
88
- if (!uri.startsWith(Giai.URN_PREFIX)) {
89
- throw Error("URI is not a valid GIAI URI");
90
- }
91
-
92
- let [companyPrefix, assetReference] = uri.substring(Giai.URN_PREFIX.length).split(".");
93
-
94
- return new Giai({
95
- assetReference,
96
- companyPrefix,
97
- });
98
- }
99
-
100
- /**
101
- * Attempt to create a GIAI instance from a string with unknown format. Could be either a URN, barcode value
102
- * or EPC value.
103
- * @param {string} value
104
- * @returns
105
- */
106
- static fromString(value: string, ignoreError?: false): Giai;
107
- static fromString(value: string, ignoreError: true): Giai | undefined;
108
- static fromString(value: string, ignoreError = false) {
109
- try {
110
- if (value.startsWith("0x")) {
111
- value = value.replace("0x", "");
112
- return Giai.fromHex(value.substring(0, 24));
113
- // return Giai.fromHex(value.substring(6, value.length - 4));
114
- } else if (value.startsWith(Giai.URN_PREFIX)) {
115
- return Giai.fromEpcPureIdentityUri(value);
116
- } else if (value.startsWith(Giai.BARCODE_PREFIX)) {
117
- return Giai.fromBarcode(value);
118
- } else if (value.length === 24) {
119
- return Giai.fromHex(value);
120
- }
121
- } catch (ex) {
122
- if (!ignoreError) {
123
- throw ex;
124
- }
125
- }
126
-
127
- if (!ignoreError) {
128
- throw Error(
129
- getLocalizedString(
130
- "Can't create GIAI from string. Failed to match value '{value}' with known input formats.",
131
- ).replace("{value}", value),
132
- );
133
- }
134
-
135
- return undefined;
136
- }
137
-
138
- /**
139
- * @type {string | number | bigint}
140
- */
141
- #assetReference;
142
- /**
143
- * @type {string | number | bigint}
144
- */
145
- #companyPrefix;
146
-
147
- /**
148
- *
149
- * @param {GiaiProps} options
150
- */
151
- constructor({ assetReference, companyPrefix }: GiaiProps) {
152
- this.#assetReference = assetReference;
153
- this.#companyPrefix = companyPrefix;
154
- }
155
-
156
- get assetReference() {
157
- return this.#assetReference;
158
- }
159
-
160
- get companyPrefix() {
161
- return this.#companyPrefix;
162
- }
163
-
164
- // Returns the EPC pure identity uri for this identifier - as used by EPCIS.
165
- toEpcPureIdentityUri() {
166
- return `${Giai.URN_PREFIX}${this.companyPrefix}.${this.assetReference}`;
167
- }
168
-
169
- toGiaiBarcode() {
170
- return Giai.BARCODE_PREFIX + this.companyPrefix + Giai.GROUP_SEPARATOR + this.assetReference;
171
- }
172
-
173
- toEpcHex() {
174
- let bitIdentifier = Giai.EPC_HEADER;
175
- bitIdentifier += "000"; // Filter
176
- bitIdentifier += (5).toString(2).padStart(3, "0"); // Partition
177
- let companyPrefix = ["bigint", "number"].includes(typeof this.#companyPrefix)
178
- ? this.#companyPrefix
179
- : BigInt(this.#companyPrefix);
180
- let assetReference = ["bigint", "number"].includes(typeof this.#assetReference)
181
- ? this.#assetReference
182
- : BigInt(this.#assetReference);
183
- bitIdentifier += companyPrefix.toString(2).padStart(24, "0");
184
- bitIdentifier += assetReference.toString(2).padStart(58, "0");
185
-
186
- return BigInt(`0b${bitIdentifier}`).toString(16).toUpperCase();
187
- }
188
- }
189
-
190
- export function hexToBitString(hexString: string) {
191
- let bitString = "";
192
-
193
- for (let i = 0; i < hexString.length; i += 2) {
194
- const byteString = hexString.substr(i, 2);
195
- const byteBits = Number.parseInt(byteString, 16).toString(2);
196
-
197
- bitString += byteBits.padStart(8, "0");
198
- }
199
-
200
- return bitString;
201
- }
202
-
203
- declare global {
204
- interface Window {
205
- Giai: typeof Giai | undefined;
206
- }
207
- }
208
-
209
- window.Giai = Giai;
1
+ import { getLocalizedString } from "../../../i18n.js";
2
+
3
+ export type GiaiProps = {
4
+ assetReference: string | number | bigint;
5
+ companyPrefix: string | number | bigint;
6
+ filter?: string | number | undefined;
7
+ };
8
+
9
+ /**
10
+ * GIAI-96 encoder and decoder as defined by the GS1 EPC Tag data standard
11
+ */
12
+ export default class Giai {
13
+ /// Bit lengths for company prefix given partition equal to index.
14
+ ///
15
+ /// Partition Company prefix Individual asset reference
16
+ /// Bits Digits Bits Digits
17
+ /// 0 40 12 42 13
18
+ /// 1 37 11 45 14
19
+ /// 2 34 10 48 15
20
+ /// 3 30 9 52 16
21
+ /// 4 27 8 55 17
22
+ /// 5 24 7 58 18
23
+ /// 6 20 6 62 19
24
+ static PARTITION_TABLE = [40, 37, 34, 30, 27, 24, 20];
25
+ // EPC header for GIAI-96 coding scheme
26
+ static EPC_HEADER = "00110100";
27
+ // Prefix for GS1 key used in barcodes;
28
+ static BARCODE_PREFIX = "8004";
29
+ // Group separator used to separate company prefix and asset reference (FNC1 in GS1-128 barcodes)
30
+ static GROUP_SEPARATOR = String.fromCodePoint(0x001d);
31
+
32
+ static URN_PREFIX = "urn:epc:id:giai:";
33
+
34
+ static fromHex = (hexIdentifier: string) => {
35
+ const bitIdentifier = hexToBitString(hexIdentifier);
36
+
37
+ if (bitIdentifier.substring(0, 8) !== Giai.EPC_HEADER) {
38
+ throw new Error("EPC value is not a valid GIAI value.");
39
+ }
40
+
41
+ const partition = Number.parseInt(bitIdentifier.substr(11, 3), 2);
42
+ const companyPrefixLength = Giai.PARTITION_TABLE[partition];
43
+ const filter = Number.parseInt(bitIdentifier.substring(8, 11), 2);
44
+ const companyPrefix = BigInt(`0b${bitIdentifier.substring(14, 14 + companyPrefixLength)}`);
45
+ const assetReference = BigInt(`0b${bitIdentifier.substring(14 + companyPrefixLength)}`);
46
+
47
+ return new Giai({ assetReference, companyPrefix, filter });
48
+ };
49
+
50
+ /**
51
+ *
52
+ * @param {string | null | undefined} barcodeString
53
+ * @returns
54
+ */
55
+ static fromBarcode = (barcodeString: string) => {
56
+ const prefixLength = Giai.BARCODE_PREFIX.length;
57
+
58
+ if (barcodeString[0] === Giai.GROUP_SEPARATOR) {
59
+ barcodeString = barcodeString.substr(1);
60
+ }
61
+
62
+ if (barcodeString.substr(0, prefixLength) !== Giai.BARCODE_PREFIX) {
63
+ throw new Error(`Barcode is not a valid GIAI barcode. (${Giai.BARCODE_PREFIX} prefix expected)`);
64
+ }
65
+
66
+ let giaiString = barcodeString.substring(prefixLength);
67
+ const gsIndex = giaiString.indexOf(Giai.GROUP_SEPARATOR);
68
+
69
+ if (gsIndex >= 0) {
70
+ return new Giai({
71
+ assetReference: giaiString.substring(gsIndex + 1),
72
+ companyPrefix: giaiString.substring(0, gsIndex),
73
+ });
74
+ }
75
+
76
+ // If no separator is found, assume a company prefix length of 7
77
+ return new Giai({
78
+ assetReference: giaiString.substring(7),
79
+ companyPrefix: giaiString.substring(0, 7),
80
+ });
81
+ };
82
+
83
+ /**
84
+ * Creates a GIAI instance from a purse identity URI (urn:epc:giai:[companyprefix].[assetreference])
85
+ * @param {string} uri EPC GIAI pure identity URI
86
+ */
87
+ static fromEpcPureIdentityUri(uri: string) {
88
+ if (!uri.startsWith(Giai.URN_PREFIX)) {
89
+ throw Error("URI is not a valid GIAI URI");
90
+ }
91
+
92
+ let [companyPrefix, assetReference] = uri.substring(Giai.URN_PREFIX.length).split(".");
93
+
94
+ return new Giai({
95
+ assetReference,
96
+ companyPrefix,
97
+ });
98
+ }
99
+
100
+ /**
101
+ * Attempt to create a GIAI instance from a string with unknown format. Could be either a URN, barcode value
102
+ * or EPC value.
103
+ * @param {string} value
104
+ * @returns
105
+ */
106
+ static fromString(value: string, ignoreError?: false): Giai;
107
+ static fromString(value: string, ignoreError: true): Giai | undefined;
108
+ static fromString(value: string, ignoreError = false) {
109
+ try {
110
+ if (value.startsWith("0x")) {
111
+ value = value.replace("0x", "");
112
+ return Giai.fromHex(value.substring(0, 24));
113
+ // return Giai.fromHex(value.substring(6, value.length - 4));
114
+ } else if (value.startsWith(Giai.URN_PREFIX)) {
115
+ return Giai.fromEpcPureIdentityUri(value);
116
+ } else if (value.startsWith(Giai.BARCODE_PREFIX)) {
117
+ return Giai.fromBarcode(value);
118
+ } else if (value.length === 24) {
119
+ return Giai.fromHex(value);
120
+ }
121
+ } catch (ex) {
122
+ if (!ignoreError) {
123
+ throw ex;
124
+ }
125
+ }
126
+
127
+ if (!ignoreError) {
128
+ throw Error(
129
+ getLocalizedString(
130
+ "Can't create GIAI from string. Failed to match value '{value}' with known input formats.",
131
+ ).replace("{value}", value),
132
+ );
133
+ }
134
+
135
+ return undefined;
136
+ }
137
+
138
+ /**
139
+ * @type {string | number | bigint}
140
+ */
141
+ #assetReference;
142
+ /**
143
+ * @type {string | number | bigint}
144
+ */
145
+ #companyPrefix;
146
+
147
+ /**
148
+ *
149
+ * @param {GiaiProps} options
150
+ */
151
+ constructor({ assetReference, companyPrefix }: GiaiProps) {
152
+ this.#assetReference = assetReference;
153
+ this.#companyPrefix = companyPrefix;
154
+ }
155
+
156
+ get assetReference() {
157
+ return this.#assetReference;
158
+ }
159
+
160
+ get companyPrefix() {
161
+ return this.#companyPrefix;
162
+ }
163
+
164
+ // Returns the EPC pure identity uri for this identifier - as used by EPCIS.
165
+ toEpcPureIdentityUri() {
166
+ return `${Giai.URN_PREFIX}${this.companyPrefix}.${this.assetReference}`;
167
+ }
168
+
169
+ toGiaiBarcode() {
170
+ return Giai.BARCODE_PREFIX + this.companyPrefix + Giai.GROUP_SEPARATOR + this.assetReference;
171
+ }
172
+
173
+ toEpcHex() {
174
+ let bitIdentifier = Giai.EPC_HEADER;
175
+ bitIdentifier += "000"; // Filter
176
+ bitIdentifier += (5).toString(2).padStart(3, "0"); // Partition
177
+ let companyPrefix = ["bigint", "number"].includes(typeof this.#companyPrefix)
178
+ ? this.#companyPrefix
179
+ : BigInt(this.#companyPrefix);
180
+ let assetReference = ["bigint", "number"].includes(typeof this.#assetReference)
181
+ ? this.#assetReference
182
+ : BigInt(this.#assetReference);
183
+ bitIdentifier += companyPrefix.toString(2).padStart(24, "0");
184
+ bitIdentifier += assetReference.toString(2).padStart(58, "0");
185
+
186
+ return BigInt(`0b${bitIdentifier}`).toString(16).toUpperCase();
187
+ }
188
+ }
189
+
190
+ export function hexToBitString(hexString: string) {
191
+ let bitString = "";
192
+
193
+ for (let i = 0; i < hexString.length; i += 2) {
194
+ const byteString = hexString.substr(i, 2);
195
+ const byteBits = Number.parseInt(byteString, 16).toString(2);
196
+
197
+ bitString += byteBits.padStart(8, "0");
198
+ }
199
+
200
+ return bitString;
201
+ }
202
+
203
+ declare global {
204
+ interface Window {
205
+ Giai: typeof Giai | undefined;
206
+ }
207
+ }
208
+
209
+ window.Giai = Giai;
@@ -1,130 +1,130 @@
1
- import { Autocomplete, ListItem, ListItemText, type SxProps, TextField, type Theme } from "@mui/material";
2
- import { useDataWithFilter, useDebounce } from "@olenbetong/appframe-react";
3
- import { useMemo, useRef, useState } from "react";
4
- import { dsProjects, type ProjectsRecord } from "./data/dsProjects";
5
- import { dsReportProjects } from "./data/dsReportProjects";
6
- import { getLocalizedString } from "../i18n.js";
7
-
8
- type ProjectSelectProps = {
9
- className?: string;
10
- disabled?: boolean;
11
- id?: string;
12
- names?: {
13
- domain?: string;
14
- projectId?: string;
15
- name?: string;
16
- };
17
- nullable?: boolean;
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
- sx?: SxProps<Theme> | undefined;
25
- report?: boolean;
26
- };
27
-
28
- export function ProjectSelect({
29
- className,
30
- disabled,
31
- id,
32
- names,
33
- onChange,
34
- readOnly,
35
- required,
36
- defaultValue,
37
- value,
38
- label,
39
- sx,
40
- report,
41
- }: ProjectSelectProps) {
42
- let [selected, setSelected] = useState<Partial<ProjectsRecord | null>>(defaultValue ?? null);
43
- let [query, setQuery] = useState("");
44
- let search = useDebounce(query);
45
- let projects = useDataWithFilter(
46
- report ? dsReportProjects : dsProjects,
47
- search ? `[SearchColumn] LIKE '%${search}%'` : "",
48
- );
49
-
50
- let highlightRef = useRef<Partial<ProjectsRecord | null>>(null);
51
-
52
- function handleSelect(value: Partial<ProjectsRecord> | null) {
53
- highlightRef.current = null;
54
-
55
- if (!disabled && !readOnly) {
56
- if (onChange) {
57
- onChange(value);
58
- } else {
59
- setSelected(value);
60
- }
61
- }
62
- }
63
-
64
- let current = value === undefined ? selected : value;
65
-
66
- const duplicatedNames = useMemo(() => {
67
- const nameCount = new Map<string, number>();
68
- projects.forEach((opt) => {
69
- nameCount.set(opt.ProjectName, (nameCount.get(opt.ProjectName) || 0) + 1);
70
- });
71
-
72
- return new Set([...nameCount.entries()].filter(([, count]) => count > 1).map(([name]) => name));
73
- }, [projects]);
74
-
75
- return (
76
- <>
77
- <Autocomplete<Partial<ProjectsRecord>>
78
- sx={sx}
79
- autoHighlight
80
- autoSelect
81
- clearOnEscape
82
- className={className}
83
- options={projects}
84
- disabled={disabled}
85
- getOptionLabel={(option) =>
86
- option?.ProjectID !== undefined ? `${option.ProjectID}: ${option.ProjectName}` : ""
87
- }
88
- isOptionEqualToValue={(option, value) => option.Domain === value.Domain && option.ProjectID === value.ProjectID}
89
- onChange={(_, value) => handleSelect(value)}
90
- onClose={() => setQuery("")}
91
- value={value !== undefined ? value : selected}
92
- renderInput={(params) => (
93
- <TextField
94
- {...(params as any)}
95
- label={label ? label : getLocalizedString("Project ID")}
96
- id={id ?? "ProjectLookup"}
97
- fullWidth
98
- slotProps={{
99
- input: params.slotProps?.input,
100
- inputLabel: params.slotProps?.inputLabel,
101
- htmlInput: {
102
- readOnly,
103
- ...params.slotProps?.htmlInput,
104
- },
105
- }}
106
- autoComplete="off"
107
- variant="filled"
108
- required={required}
109
- onChange={(evt) => setQuery(evt.target.value)}
110
- value={query}
111
- />
112
- )}
113
- renderOption={(props, option) => {
114
- let isDuplicated = option.ProjectName && duplicatedNames.has(option.ProjectName);
115
- return (
116
- <ListItem {...props}>
117
- <ListItemText
118
- primary={isDuplicated ? `${option.ProjectName} (${option.Domain})` : option.ProjectName}
119
- secondary={option.ProjectID}
120
- />
121
- </ListItem>
122
- );
123
- }}
124
- />
125
- <input name={names?.domain ?? "Domain"} type="hidden" value={current?.Domain ?? ""} />
126
- <input name={names?.name ?? "ProjectName"} type="hidden" value={current?.ProjectName ?? ""} />
127
- <input name={names?.projectId ?? "ProjectID"} type="hidden" value={current?.ProjectID ?? ""} />
128
- </>
129
- );
130
- }
1
+ import { Autocomplete, ListItem, ListItemText, type SxProps, TextField, type Theme } from "@mui/material";
2
+ import { useDataWithFilter, useDebounce } from "@olenbetong/appframe-react";
3
+ import { useMemo, useRef, useState } from "react";
4
+ import { dsProjects, type ProjectsRecord } from "./data/dsProjects";
5
+ import { dsReportProjects } from "./data/dsReportProjects";
6
+ import { getLocalizedString } from "../i18n.js";
7
+
8
+ type ProjectSelectProps = {
9
+ className?: string;
10
+ disabled?: boolean;
11
+ id?: string;
12
+ names?: {
13
+ domain?: string;
14
+ projectId?: string;
15
+ name?: string;
16
+ };
17
+ nullable?: boolean;
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
+ sx?: SxProps<Theme> | undefined;
25
+ report?: boolean;
26
+ };
27
+
28
+ export function ProjectSelect({
29
+ className,
30
+ disabled,
31
+ id,
32
+ names,
33
+ onChange,
34
+ readOnly,
35
+ required,
36
+ defaultValue,
37
+ value,
38
+ label,
39
+ sx,
40
+ report,
41
+ }: ProjectSelectProps) {
42
+ let [selected, setSelected] = useState<Partial<ProjectsRecord | null>>(defaultValue ?? null);
43
+ let [query, setQuery] = useState("");
44
+ let search = useDebounce(query);
45
+ let projects = useDataWithFilter(
46
+ report ? dsReportProjects : dsProjects,
47
+ search ? `[SearchColumn] LIKE '%${search}%'` : "",
48
+ );
49
+
50
+ let highlightRef = useRef<Partial<ProjectsRecord | null>>(null);
51
+
52
+ function handleSelect(value: Partial<ProjectsRecord> | null) {
53
+ highlightRef.current = null;
54
+
55
+ if (!disabled && !readOnly) {
56
+ if (onChange) {
57
+ onChange(value);
58
+ } else {
59
+ setSelected(value);
60
+ }
61
+ }
62
+ }
63
+
64
+ let current = value === undefined ? selected : value;
65
+
66
+ const duplicatedNames = useMemo(() => {
67
+ const nameCount = new Map<string, number>();
68
+ projects.forEach((opt) => {
69
+ nameCount.set(opt.ProjectName, (nameCount.get(opt.ProjectName) || 0) + 1);
70
+ });
71
+
72
+ return new Set([...nameCount.entries()].filter(([, count]) => count > 1).map(([name]) => name));
73
+ }, [projects]);
74
+
75
+ return (
76
+ <>
77
+ <Autocomplete<Partial<ProjectsRecord>>
78
+ sx={sx}
79
+ autoHighlight
80
+ autoSelect
81
+ clearOnEscape
82
+ className={className}
83
+ options={projects}
84
+ disabled={disabled}
85
+ getOptionLabel={(option) =>
86
+ option?.ProjectID !== undefined ? `${option.ProjectID}: ${option.ProjectName}` : ""
87
+ }
88
+ isOptionEqualToValue={(option, value) => option.Domain === value.Domain && option.ProjectID === value.ProjectID}
89
+ onChange={(_, value) => handleSelect(value)}
90
+ onClose={() => setQuery("")}
91
+ value={value !== undefined ? value : selected}
92
+ renderInput={(params) => (
93
+ <TextField
94
+ {...(params as any)}
95
+ label={label ? label : getLocalizedString("Project ID")}
96
+ id={id ?? "ProjectLookup"}
97
+ fullWidth
98
+ slotProps={{
99
+ input: params.slotProps?.input,
100
+ inputLabel: params.slotProps?.inputLabel,
101
+ htmlInput: {
102
+ readOnly,
103
+ ...params.slotProps?.htmlInput,
104
+ },
105
+ }}
106
+ autoComplete="off"
107
+ variant="filled"
108
+ required={required}
109
+ onChange={(evt) => setQuery(evt.target.value)}
110
+ value={query}
111
+ />
112
+ )}
113
+ renderOption={(props, option) => {
114
+ let isDuplicated = option.ProjectName && duplicatedNames.has(option.ProjectName);
115
+ return (
116
+ <ListItem {...props}>
117
+ <ListItemText
118
+ primary={isDuplicated ? `${option.ProjectName} (${option.Domain})` : option.ProjectName}
119
+ secondary={option.ProjectID}
120
+ />
121
+ </ListItem>
122
+ );
123
+ }}
124
+ />
125
+ <input name={names?.domain ?? "Domain"} type="hidden" value={current?.Domain ?? ""} />
126
+ <input name={names?.name ?? "ProjectName"} type="hidden" value={current?.ProjectName ?? ""} />
127
+ <input name={names?.projectId ?? "ProjectID"} type="hidden" value={current?.ProjectID ?? ""} />
128
+ </>
129
+ );
130
+ }