@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,157 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Styles for the Designsystemet element components. The package is not scanned by the apps'
|
|
3
|
+
* Tailwind, so everything is a plain class here.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
@property --ob-hid-angle {
|
|
7
|
+
syntax: "<angle>";
|
|
8
|
+
inherits: false;
|
|
9
|
+
initial-value: 0deg;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
@keyframes ObElementsHidScanner-move {
|
|
13
|
+
0% {
|
|
14
|
+
--ob-hid-angle: 0deg;
|
|
15
|
+
}
|
|
16
|
+
50% {
|
|
17
|
+
--ob-hid-angle: 180deg;
|
|
18
|
+
}
|
|
19
|
+
100% {
|
|
20
|
+
--ob-hid-angle: 360deg;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.ObElementsHidScanner-root {
|
|
25
|
+
height: 100%;
|
|
26
|
+
min-height: 12rem;
|
|
27
|
+
display: flex;
|
|
28
|
+
align-items: center;
|
|
29
|
+
justify-content: center;
|
|
30
|
+
background-color: var(--ds-color-neutral-surface-tinted);
|
|
31
|
+
|
|
32
|
+
&[data-enabled] {
|
|
33
|
+
background-image: linear-gradient(
|
|
34
|
+
var(--ob-hid-angle),
|
|
35
|
+
var(--ds-color-neutral-border-default),
|
|
36
|
+
var(--ds-color-neutral-surface-active),
|
|
37
|
+
var(--ds-color-neutral-border-default)
|
|
38
|
+
);
|
|
39
|
+
animation: ObElementsHidScanner-move 8s linear infinite;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.ObElementsLookupDialog-body {
|
|
44
|
+
display: flex;
|
|
45
|
+
flex-direction: column;
|
|
46
|
+
padding: 0;
|
|
47
|
+
min-height: 0;
|
|
48
|
+
overflow: hidden;
|
|
49
|
+
|
|
50
|
+
/* One height for every tab, so the dialog does not jump when the tab changes. */
|
|
51
|
+
@media (min-width: 600px) {
|
|
52
|
+
height: min(40rem, 85dvh);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.ObElementsLookupDialog-tabs > [role="tablist"] > * {
|
|
57
|
+
flex: 1;
|
|
58
|
+
flex-direction: column;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.ObElementsLookupDialog-source {
|
|
62
|
+
flex: 1 2 14rem;
|
|
63
|
+
min-height: 0;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/* The manual form keeps its full height; the element list below gives way first. */
|
|
67
|
+
.ObElementsLookupDialog-manual {
|
|
68
|
+
flex: 0 1 auto;
|
|
69
|
+
min-height: 0;
|
|
70
|
+
padding: var(--ds-size-4);
|
|
71
|
+
overflow-y: auto;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
.ObElementsLookupDialog-list {
|
|
75
|
+
flex: 3 1 6rem;
|
|
76
|
+
overflow-y: auto;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
.ObElementsLookupDialog-item {
|
|
80
|
+
transition: background-color 200ms ease-out;
|
|
81
|
+
|
|
82
|
+
&[data-recent] {
|
|
83
|
+
background-color: var(--ds-color-brand-surface-active);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
.ObElementsLookupDialog-actions,
|
|
88
|
+
.ObElements-buttons {
|
|
89
|
+
display: flex;
|
|
90
|
+
flex-wrap: wrap;
|
|
91
|
+
justify-content: flex-end;
|
|
92
|
+
gap: var(--ds-size-2);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
.ObElements-form {
|
|
96
|
+
display: flex;
|
|
97
|
+
flex-direction: column;
|
|
98
|
+
align-items: stretch;
|
|
99
|
+
gap: var(--ds-size-4);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
.ObElements-subtle {
|
|
103
|
+
color: var(--ds-color-neutral-text-subtle);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
.ObElements-option {
|
|
107
|
+
display: flex;
|
|
108
|
+
flex-direction: column;
|
|
109
|
+
|
|
110
|
+
& > :last-child {
|
|
111
|
+
font-size: 0.875em;
|
|
112
|
+
color: var(--ds-color-neutral-text-subtle);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
.ObElementsDuplicate-table {
|
|
117
|
+
width: 100%;
|
|
118
|
+
|
|
119
|
+
& td {
|
|
120
|
+
white-space: pre-line;
|
|
121
|
+
vertical-align: top;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
.ObElementsDuplicate-cards {
|
|
126
|
+
display: flex;
|
|
127
|
+
flex-direction: column;
|
|
128
|
+
gap: var(--ds-size-3);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
.ObElementsDuplicate-wide {
|
|
132
|
+
@media (max-width: 899.98px) {
|
|
133
|
+
display: none;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
.ObElementsDuplicate-narrow {
|
|
138
|
+
@media (min-width: 900px) {
|
|
139
|
+
display: none;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
.ObElementsDuplicate-card dl {
|
|
144
|
+
display: grid;
|
|
145
|
+
grid-template-columns: auto 1fr;
|
|
146
|
+
gap: var(--ds-size-1) var(--ds-size-3);
|
|
147
|
+
margin: 0;
|
|
148
|
+
|
|
149
|
+
& dt {
|
|
150
|
+
font-weight: 500;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
& dd {
|
|
154
|
+
margin: 0;
|
|
155
|
+
white-space: pre-line;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import "./elements-ds.css";
|
|
2
|
+
export * from "../elements/data/index.js";
|
|
3
|
+
export { dsReportProjects } from "../elements/data/dsReportProjects.js";
|
|
4
|
+
export type { AddElementSource, ElementDetails } from "../elements/ElementLookupDialog/getElement.js";
|
|
5
|
+
export * from "./DescriptionInput.js";
|
|
6
|
+
export * from "./DuplicateElementDamage.js";
|
|
7
|
+
export * from "./ElementLookup.js";
|
|
8
|
+
export * from "./ElementLookupDialog.js";
|
|
9
|
+
export * from "./FormFields.js";
|
|
10
|
+
export * from "./HIDScanner.js";
|
|
11
|
+
export * from "./ManualForm.js";
|
|
12
|
+
export * from "./ProjectSelect.js";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// The element lookup and element damage components on Designsystemet, for apps on the 2026
|
|
2
|
+
// template. Nothing here imports MUI or appframe-mui; "@olenbetong/synergi-react/elements" keeps
|
|
3
|
+
// the MUI versions for the apps that still use them.
|
|
4
|
+
import "./elements-ds.css";
|
|
5
|
+
export * from "../elements/data/index.js";
|
|
6
|
+
export { dsReportProjects } from "../elements/data/dsReportProjects.js";
|
|
7
|
+
export * from "./DescriptionInput.js";
|
|
8
|
+
export * from "./DuplicateElementDamage.js";
|
|
9
|
+
export * from "./ElementLookup.js";
|
|
10
|
+
export * from "./ElementLookupDialog.js";
|
|
11
|
+
export * from "./FormFields.js";
|
|
12
|
+
export * from "./HIDScanner.js";
|
|
13
|
+
export * from "./ManualForm.js";
|
|
14
|
+
export * from "./ProjectSelect.js";
|
|
@@ -12,14 +12,16 @@ async function translateText(text, target, apiKey) {
|
|
|
12
12
|
let result = await fetch(url, options);
|
|
13
13
|
let json = await result.json();
|
|
14
14
|
let { data } = json;
|
|
15
|
-
if (data?.translations) {
|
|
15
|
+
if (data?.translations?.length) {
|
|
16
16
|
let [translation] = data.translations;
|
|
17
17
|
return {
|
|
18
18
|
from: translation.detectedSourceLanguage,
|
|
19
19
|
translation: translation.translatedText,
|
|
20
20
|
};
|
|
21
21
|
}
|
|
22
|
-
|
|
22
|
+
// An error answer (invalid key, quota) carries no translations; report it rather than leave
|
|
23
|
+
// the caller translating forever.
|
|
24
|
+
throw new Error(json?.error?.message ?? "The translation service returned no translation.");
|
|
23
25
|
}
|
|
24
26
|
export function useTranslation(text, targetLanguage, apiKey) {
|
|
25
27
|
let [translation, setTranslation] = useState("");
|
|
@@ -41,7 +43,7 @@ export function useTranslation(text, targetLanguage, apiKey) {
|
|
|
41
43
|
setIsTranslating(true);
|
|
42
44
|
try {
|
|
43
45
|
let result = await translateText(text, targetLanguage, apiKey);
|
|
44
|
-
if (
|
|
46
|
+
if (textRef.current === text) {
|
|
45
47
|
let { from, translation } = result;
|
|
46
48
|
setSourceLang(from);
|
|
47
49
|
setTranslation(translation);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@olenbetong/synergi-react",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.1.0",
|
|
4
4
|
"description": "Standalone React component for SynergiWeb and Partner Portal",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -12,6 +12,10 @@
|
|
|
12
12
|
"types": "./es/elements/index.d.ts",
|
|
13
13
|
"import": "./es/elements/index.js"
|
|
14
14
|
},
|
|
15
|
+
"./elements-ds": {
|
|
16
|
+
"types": "./es/elements-ds/index.d.ts",
|
|
17
|
+
"import": "./es/elements-ds/index.js"
|
|
18
|
+
},
|
|
15
19
|
"./mui": {
|
|
16
20
|
"types": "./es/mui/index.d.ts",
|
|
17
21
|
"import": "./es/mui/index.js"
|
|
@@ -49,7 +53,7 @@
|
|
|
49
53
|
"@mui/material": "9.5.0",
|
|
50
54
|
"@olenbetong/appframe-core": "^2.15.2",
|
|
51
55
|
"@olenbetong/appframe-data": "^1.8.4",
|
|
52
|
-
"@olenbetong/appframe-ds": "^1.7.
|
|
56
|
+
"@olenbetong/appframe-ds": "^1.7.2",
|
|
53
57
|
"@olenbetong/appframe-mui": "^7.0.13",
|
|
54
58
|
"@olenbetong/appframe-react": "^2.2.8",
|
|
55
59
|
"clsx": "^2.1.1",
|
|
@@ -81,14 +85,20 @@
|
|
|
81
85
|
]
|
|
82
86
|
},
|
|
83
87
|
"devDependencies": {
|
|
88
|
+
"@digdir/designsystemet-css": "1.23.0",
|
|
84
89
|
"@digdir/designsystemet-react": "1.23.0",
|
|
90
|
+
"@digdir/designsystemet-web": "1.23.0",
|
|
85
91
|
"@navikt/aksel-icons": "8.20.0",
|
|
86
92
|
"@testing-library/dom": "^10.4.2",
|
|
87
93
|
"@testing-library/jest-dom": "^7.0.1",
|
|
88
94
|
"@testing-library/react": "16.3.3",
|
|
89
95
|
"@testing-library/user-event": "^14.6.8",
|
|
96
|
+
"@vitest/browser": "5.0.5",
|
|
97
|
+
"@vitest/browser-playwright": "5.0.5",
|
|
98
|
+
"@vitest/coverage-v8": "5.0.5",
|
|
90
99
|
"dynamsoft-javascript-barcode": "6.5.4",
|
|
91
100
|
"happy-dom": "21.0.4",
|
|
101
|
+
"playwright": "^1.64.1",
|
|
92
102
|
"replace-in-files": "^3.0.0",
|
|
93
103
|
"sass": "1.106.1",
|
|
94
104
|
"typescript": "7.0.2",
|
|
@@ -101,6 +111,8 @@
|
|
|
101
111
|
"build:sass:components": "node ./scripts/buildSassComponents.mjs",
|
|
102
112
|
"build:tsc:post": "node ./scripts/replaceCss.mjs",
|
|
103
113
|
"build:tsc": "node --no-warnings ../../scripts/clean.ts ./es tsconfig.build.tsbuildinfo && tsc -p tsconfig.build.json",
|
|
104
|
-
"test": "vitest run"
|
|
114
|
+
"test": "tsc -p tsconfig.test.json && vitest run",
|
|
115
|
+
"test:browser": "vitest run --config vitest.browser.config.ts",
|
|
116
|
+
"test:coverage": "vitest run --coverage"
|
|
105
117
|
}
|
|
106
118
|
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { render, screen } from "@testing-library/react";
|
|
2
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
3
|
+
|
|
4
|
+
import { AppShell, hasSiteChrome } from "./index";
|
|
5
|
+
|
|
6
|
+
afterEach(() => {
|
|
7
|
+
delete document.documentElement.dataset.obChrome;
|
|
8
|
+
vi.restoreAllMocks();
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
describe("AppShell", () => {
|
|
12
|
+
it("renders the app", () => {
|
|
13
|
+
render(
|
|
14
|
+
<AppShell>
|
|
15
|
+
<p>Inbox</p>
|
|
16
|
+
</AppShell>,
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
expect(screen.getByText("Inbox")).toBeInTheDocument();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("shows the error page instead of a blank page when the app throws", () => {
|
|
23
|
+
vi.spyOn(console, "error").mockImplementation(() => {});
|
|
24
|
+
function Broken(): never {
|
|
25
|
+
throw new Error("Grid failed to load");
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
render(
|
|
29
|
+
<AppShell>
|
|
30
|
+
<Broken />
|
|
31
|
+
</AppShell>,
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
expect(screen.getByRole("heading", { name: "Something went terribly wrong!" })).toBeInTheDocument();
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
describe("hasSiteChrome", () => {
|
|
39
|
+
it("is false on a page whose template did not load the chrome", () => {
|
|
40
|
+
expect(hasSiteChrome()).toBe(false);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("is true when the template marks <html data-ob-chrome>", () => {
|
|
44
|
+
document.documentElement.dataset.obChrome = "1";
|
|
45
|
+
|
|
46
|
+
expect(hasSiteChrome()).toBe(true);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
import { AppErrorBoundary } from "@olenbetong/appframe-ds";
|
|
2
|
-
import type { ReactNode } from "react";
|
|
3
|
-
|
|
4
|
-
export type AppShellProps = {
|
|
5
|
-
children: ReactNode;
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Standard Synergi app shell: the error boundary around the app.
|
|
10
|
-
*
|
|
11
|
-
* The site chrome (app menu, user menu, colour scheme, service worker update)
|
|
12
|
-
* is no longer part of the app. It is rendered by the `@olenbetong/synergi-chrome`
|
|
13
|
-
* bundle the `ob.2026.application` template loads, which marks the page with
|
|
14
|
-
* `<html data-ob-chrome="1">`. Toolbar slots stay app owned through
|
|
15
|
-
* `ToolbarPortal` and `ToolbarBreadcrumbs`.
|
|
16
|
-
*
|
|
17
|
-
* This component is Designsystemet-only. Apps that still render MUI components
|
|
18
|
-
* should additionally wrap it in `MuiThemeProvider` from
|
|
19
|
-
* `@olenbetong/synergi-react/mui`, which bridges the Designsystemet colour
|
|
20
|
-
* tokens into a MUI theme.
|
|
21
|
-
*/
|
|
22
|
-
export function AppShell({ children }: AppShellProps) {
|
|
23
|
-
return <AppErrorBoundary>{children}</AppErrorBoundary>;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/** Whether the page's template loaded the site chrome (`<html data-ob-chrome="1">`). */
|
|
27
|
-
export function hasSiteChrome() {
|
|
28
|
-
return typeof document !== "undefined" && document.documentElement.dataset.obChrome !== undefined;
|
|
29
|
-
}
|
|
1
|
+
import { AppErrorBoundary } from "@olenbetong/appframe-ds";
|
|
2
|
+
import type { ReactNode } from "react";
|
|
3
|
+
|
|
4
|
+
export type AppShellProps = {
|
|
5
|
+
children: ReactNode;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Standard Synergi app shell: the error boundary around the app.
|
|
10
|
+
*
|
|
11
|
+
* The site chrome (app menu, user menu, colour scheme, service worker update)
|
|
12
|
+
* is no longer part of the app. It is rendered by the `@olenbetong/synergi-chrome`
|
|
13
|
+
* bundle the `ob.2026.application` template loads, which marks the page with
|
|
14
|
+
* `<html data-ob-chrome="1">`. Toolbar slots stay app owned through
|
|
15
|
+
* `ToolbarPortal` and `ToolbarBreadcrumbs`.
|
|
16
|
+
*
|
|
17
|
+
* This component is Designsystemet-only. Apps that still render MUI components
|
|
18
|
+
* should additionally wrap it in `MuiThemeProvider` from
|
|
19
|
+
* `@olenbetong/synergi-react/mui`, which bridges the Designsystemet colour
|
|
20
|
+
* tokens into a MUI theme.
|
|
21
|
+
*/
|
|
22
|
+
export function AppShell({ children }: AppShellProps) {
|
|
23
|
+
return <AppErrorBoundary>{children}</AppErrorBoundary>;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Whether the page's template loaded the site chrome (`<html data-ob-chrome="1">`). */
|
|
27
|
+
export function hasSiteChrome() {
|
|
28
|
+
return typeof document !== "undefined" && document.documentElement.dataset.obChrome !== undefined;
|
|
29
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { openReport } from "./openReport";
|
|
4
|
+
|
|
5
|
+
let globals = globalThis as { ob?: unknown };
|
|
6
|
+
|
|
7
|
+
afterEach(() => {
|
|
8
|
+
delete globals.ob;
|
|
9
|
+
vi.restoreAllMocks();
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
describe("openReport", () => {
|
|
13
|
+
it("forwards the report and its options to the chrome's report launcher", () => {
|
|
14
|
+
let launch = vi.fn();
|
|
15
|
+
globals.ob = { chrome: { openReport: launch } };
|
|
16
|
+
|
|
17
|
+
openReport("arpt_Production_ElementsDaily", { initialFilter: "[ProjectID] = 'PT19-1004'", defaultTab: "filter" });
|
|
18
|
+
|
|
19
|
+
expect(launch).toHaveBeenCalledExactlyOnceWith("arpt_Production_ElementsDaily", {
|
|
20
|
+
initialFilter: "[ProjectID] = 'PT19-1004'",
|
|
21
|
+
defaultTab: "filter",
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("passes an empty filter through, so the launcher starts without one", () => {
|
|
26
|
+
let launch = vi.fn();
|
|
27
|
+
globals.ob = { chrome: { openReport: launch } };
|
|
28
|
+
|
|
29
|
+
openReport("arpt_Production_ElementsDaily", { initialFilter: "" });
|
|
30
|
+
|
|
31
|
+
expect(launch).toHaveBeenCalledWith("arpt_Production_ElementsDaily", { initialFilter: "" });
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("warns instead of throwing on a page without the chrome", () => {
|
|
35
|
+
let warn = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
36
|
+
|
|
37
|
+
expect(() => openReport("arpt_Production_ElementsDaily")).not.toThrow();
|
|
38
|
+
expect(warn).toHaveBeenCalledOnce();
|
|
39
|
+
expect(warn.mock.calls[0][0]).toContain("arpt_Production_ElementsDaily");
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it("warns when the chrome is loaded but has no report launcher", () => {
|
|
43
|
+
let warn = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
44
|
+
globals.ob = { chrome: {} };
|
|
45
|
+
|
|
46
|
+
openReport("arpt_Production_ElementsDaily");
|
|
47
|
+
|
|
48
|
+
expect(warn).toHaveBeenCalledOnce();
|
|
49
|
+
});
|
|
50
|
+
});
|
package/src/chrome/openReport.ts
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
export type OpenReportOptions = {
|
|
2
|
-
/**
|
|
3
|
-
* Overrides the filter the report was designed with, as a criteria string.
|
|
4
|
-
* An empty string starts the launcher with no filter at all.
|
|
5
|
-
*/
|
|
6
|
-
initialFilter?: string | null;
|
|
7
|
-
/** The tab shown first. */
|
|
8
|
-
defaultTab?: "parameters" | "filter";
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
type ChromeWithReports = {
|
|
12
|
-
openReport?: (reportId: string, options?: OpenReportOptions) => void;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Opens a report in the site chrome's report launcher, the way the app menu does.
|
|
17
|
-
*
|
|
18
|
-
* The launcher lives in the `@olenbetong/synergi-chrome` bundle the 2026 templates load,
|
|
19
|
-
* so an app never bundles it; this only forwards to `window.ob.chrome.openReport`.
|
|
20
|
-
* On a page without the chrome (a legacy template) the call is logged and ignored.
|
|
21
|
-
*
|
|
22
|
-
* @example
|
|
23
|
-
* ```ts
|
|
24
|
-
* openReport("arpt_Production_ElementsDaily", { initialFilter: `[ProjectID] = '${projectId}'` });
|
|
25
|
-
* ```
|
|
26
|
-
*/
|
|
27
|
-
export function openReport(reportId: string, options?: OpenReportOptions) {
|
|
28
|
-
let chrome = (globalThis as { ob?: { chrome?: ChromeWithReports } }).ob?.chrome;
|
|
29
|
-
if (chrome?.openReport) {
|
|
30
|
-
chrome.openReport(reportId, options);
|
|
31
|
-
} else {
|
|
32
|
-
console.warn(`openReport(${reportId}): the site chrome is not on this page, so there is no report launcher.`);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
1
|
+
export type OpenReportOptions = {
|
|
2
|
+
/**
|
|
3
|
+
* Overrides the filter the report was designed with, as a criteria string.
|
|
4
|
+
* An empty string starts the launcher with no filter at all.
|
|
5
|
+
*/
|
|
6
|
+
initialFilter?: string | null;
|
|
7
|
+
/** The tab shown first. */
|
|
8
|
+
defaultTab?: "parameters" | "filter";
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
type ChromeWithReports = {
|
|
12
|
+
openReport?: (reportId: string, options?: OpenReportOptions) => void;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Opens a report in the site chrome's report launcher, the way the app menu does.
|
|
17
|
+
*
|
|
18
|
+
* The launcher lives in the `@olenbetong/synergi-chrome` bundle the 2026 templates load,
|
|
19
|
+
* so an app never bundles it; this only forwards to `window.ob.chrome.openReport`.
|
|
20
|
+
* On a page without the chrome (a legacy template) the call is logged and ignored.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* openReport("arpt_Production_ElementsDaily", { initialFilter: `[ProjectID] = '${projectId}'` });
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export function openReport(reportId: string, options?: OpenReportOptions) {
|
|
28
|
+
let chrome = (globalThis as { ob?: { chrome?: ChromeWithReports } }).ob?.chrome;
|
|
29
|
+
if (chrome?.openReport) {
|
|
30
|
+
chrome.openReport(reportId, options);
|
|
31
|
+
} else {
|
|
32
|
+
console.warn(`openReport(${reportId}): the site chrome is not on this page, so there is no report launcher.`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { act, renderHook } from "@testing-library/react";
|
|
2
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
COLOR_SCHEME_CHANGE_EVENT,
|
|
6
|
+
getColorSchemePreference,
|
|
7
|
+
getResolvedColorScheme,
|
|
8
|
+
setColorSchemePreference,
|
|
9
|
+
useColorSchemePreference,
|
|
10
|
+
useResolvedColorScheme,
|
|
11
|
+
} from "./colorScheme";
|
|
12
|
+
|
|
13
|
+
function setCookie(name: string, value: string) {
|
|
14
|
+
document.cookie = `${name}=${value};path=/`;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function clearCookie(name: string) {
|
|
18
|
+
document.cookie = `${name}=;path=/;max-age=0`;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Stubs the OS preference that `auto` resolves to. */
|
|
22
|
+
function stubSystemScheme(dark: boolean) {
|
|
23
|
+
let listeners = new Set<() => void>();
|
|
24
|
+
let media = {
|
|
25
|
+
matches: dark,
|
|
26
|
+
addEventListener: (_type: string, listener: () => void) => listeners.add(listener),
|
|
27
|
+
removeEventListener: (_type: string, listener: () => void) => listeners.delete(listener),
|
|
28
|
+
};
|
|
29
|
+
vi.stubGlobal(
|
|
30
|
+
"matchMedia",
|
|
31
|
+
vi.fn(() => media),
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
change(nextDark: boolean) {
|
|
36
|
+
media.matches = nextDark;
|
|
37
|
+
for (let listener of listeners) listener();
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
afterEach(() => {
|
|
43
|
+
for (let name of ["ob-color-scheme", "other", "x-ob-color-scheme"]) clearCookie(name);
|
|
44
|
+
delete document.documentElement.dataset.colorScheme;
|
|
45
|
+
delete document.body.dataset.colorScheme;
|
|
46
|
+
vi.unstubAllGlobals();
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
describe("getColorSchemePreference", () => {
|
|
50
|
+
it("defaults to auto when nothing is stored", () => {
|
|
51
|
+
expect(getColorSchemePreference()).toBe("auto");
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("reads its own cookie among others", () => {
|
|
55
|
+
setCookie("other", "1");
|
|
56
|
+
setCookie("x-ob-color-scheme", "light");
|
|
57
|
+
setCookie("ob-color-scheme", "dark");
|
|
58
|
+
|
|
59
|
+
expect(getColorSchemePreference()).toBe("dark");
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it("ignores a value it does not know", () => {
|
|
63
|
+
setCookie("ob-color-scheme", "sepia");
|
|
64
|
+
|
|
65
|
+
expect(getColorSchemePreference()).toBe("auto");
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
describe("setColorSchemePreference", () => {
|
|
70
|
+
it("stores the preference, applies it to <html> and <body> and tells the other toggles", () => {
|
|
71
|
+
let listener = vi.fn();
|
|
72
|
+
window.addEventListener(COLOR_SCHEME_CHANGE_EVENT, listener);
|
|
73
|
+
|
|
74
|
+
setColorSchemePreference("dark");
|
|
75
|
+
|
|
76
|
+
window.removeEventListener(COLOR_SCHEME_CHANGE_EVENT, listener);
|
|
77
|
+
expect(getColorSchemePreference()).toBe("dark");
|
|
78
|
+
expect(document.documentElement.dataset.colorScheme).toBe("dark");
|
|
79
|
+
expect(document.body.dataset.colorScheme).toBe("dark");
|
|
80
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
81
|
+
expect((listener.mock.calls[0][0] as CustomEvent).detail).toBe("dark");
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it("ignores an unknown value instead of storing it", () => {
|
|
85
|
+
setColorSchemePreference("light");
|
|
86
|
+
let listener = vi.fn();
|
|
87
|
+
window.addEventListener(COLOR_SCHEME_CHANGE_EVENT, listener);
|
|
88
|
+
|
|
89
|
+
setColorSchemePreference("sepia" as never);
|
|
90
|
+
|
|
91
|
+
window.removeEventListener(COLOR_SCHEME_CHANGE_EVENT, listener);
|
|
92
|
+
expect(getColorSchemePreference()).toBe("light");
|
|
93
|
+
expect(document.body.dataset.colorScheme).toBe("light");
|
|
94
|
+
expect(listener).not.toHaveBeenCalled();
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
describe("useColorSchemePreference", () => {
|
|
99
|
+
it("starts from the stored preference", () => {
|
|
100
|
+
setCookie("ob-color-scheme", "light");
|
|
101
|
+
|
|
102
|
+
let { result } = renderHook(() => useColorSchemePreference());
|
|
103
|
+
|
|
104
|
+
expect(result.current[0]).toBe("light");
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it("keeps every toggle on the page in step", () => {
|
|
108
|
+
let first = renderHook(() => useColorSchemePreference());
|
|
109
|
+
let second = renderHook(() => useColorSchemePreference());
|
|
110
|
+
|
|
111
|
+
act(() => first.result.current[1]("dark"));
|
|
112
|
+
|
|
113
|
+
expect(first.result.current[0]).toBe("dark");
|
|
114
|
+
expect(second.result.current[0]).toBe("dark");
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it("follows a change the site chrome makes", () => {
|
|
118
|
+
let { result } = renderHook(() => useColorSchemePreference());
|
|
119
|
+
|
|
120
|
+
act(() => {
|
|
121
|
+
setCookie("ob-color-scheme", "dark");
|
|
122
|
+
window.dispatchEvent(new CustomEvent(COLOR_SCHEME_CHANGE_EVENT, { detail: "dark" }));
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
expect(result.current[0]).toBe("dark");
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it("picks up a change made in another tab when the page becomes visible again", () => {
|
|
129
|
+
let { result } = renderHook(() => useColorSchemePreference());
|
|
130
|
+
|
|
131
|
+
act(() => {
|
|
132
|
+
setCookie("ob-color-scheme", "light");
|
|
133
|
+
document.dispatchEvent(new Event("visibilitychange"));
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
expect(result.current[0]).toBe("light");
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
describe("getResolvedColorScheme", () => {
|
|
141
|
+
it("is light when nothing is set", () => {
|
|
142
|
+
expect(getResolvedColorScheme()).toBe("light");
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it("uses the scheme on <body> before the one on <html>", () => {
|
|
146
|
+
document.documentElement.dataset.colorScheme = "light";
|
|
147
|
+
document.body.dataset.colorScheme = "dark";
|
|
148
|
+
|
|
149
|
+
expect(getResolvedColorScheme()).toBe("dark");
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it("resolves auto from the OS preference", () => {
|
|
153
|
+
document.body.dataset.colorScheme = "auto";
|
|
154
|
+
|
|
155
|
+
stubSystemScheme(true);
|
|
156
|
+
expect(getResolvedColorScheme()).toBe("dark");
|
|
157
|
+
|
|
158
|
+
stubSystemScheme(false);
|
|
159
|
+
expect(getResolvedColorScheme()).toBe("light");
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
describe("useResolvedColorScheme", () => {
|
|
164
|
+
it("follows the scheme the template or chrome sets on <body>", async () => {
|
|
165
|
+
document.body.dataset.colorScheme = "light";
|
|
166
|
+
let { result } = renderHook(() => useResolvedColorScheme());
|
|
167
|
+
expect(result.current).toBe("light");
|
|
168
|
+
|
|
169
|
+
await act(async () => {
|
|
170
|
+
document.body.dataset.colorScheme = "dark";
|
|
171
|
+
// MutationObserver callbacks run after the current task.
|
|
172
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
expect(result.current).toBe("dark");
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it("follows the OS preference while the scheme is auto", () => {
|
|
179
|
+
let system = stubSystemScheme(false);
|
|
180
|
+
document.body.dataset.colorScheme = "auto";
|
|
181
|
+
let { result } = renderHook(() => useResolvedColorScheme());
|
|
182
|
+
expect(result.current).toBe("light");
|
|
183
|
+
|
|
184
|
+
act(() => system.change(true));
|
|
185
|
+
|
|
186
|
+
expect(result.current).toBe("dark");
|
|
187
|
+
});
|
|
188
|
+
});
|