@olenbetong/synergi-react 2.8.0 → 3.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.
- package/dist/styles/styles.css.map +1 -1
- package/es/chrome/AppShell/index.d.ts +8 -0
- package/es/chrome/AppShell/index.js +10 -130
- package/es/components/ImageEditor/ImageEditor.css +10 -0
- package/es/components/ImageEditor/ImageEditor.d.ts +12 -0
- package/es/components/ImageEditor/ImageEditor.js +27 -6
- package/es/components/ImageEditor/index.d.ts +3 -0
- package/es/components/ImageEditor/index.js +3 -0
- package/es/components/ImageEditor/plugins/cropPlugin/CropOverlay.js +27 -5
- package/es/components/ImageEditor/plugins/cropPlugin/CropToolbar.js +4 -3
- package/es/components/ImageEditor/plugins/cropPlugin/useCropTool.d.ts +20 -3
- package/es/components/ImageEditor/plugins/cropPlugin/useCropTool.js +216 -33
- package/es/components/ImageEditor/plugins/zoomPlugin/ZoomContext.d.ts +5 -0
- package/es/components/ImageEditor/plugins/zoomPlugin/ZoomContext.js +7 -0
- package/es/components/ImageEditor/plugins/zoomPlugin/ZoomControls.js +1 -1
- package/es/components/ImageEditor/useEdgeDetection.d.ts +0 -2
- package/es/components/ImageEditor/useEdgeDetection.js +11 -30
- package/es/components/ImageEditor/useImageHistory.d.ts +6 -1
- package/es/components/ImageEditor/useImageHistory.js +21 -23
- package/es/components/ImageEditor/useOpenCV.d.ts +26 -1
- package/es/components/ImageEditor/useOpenCV.js +108 -42
- package/es/components/SplitContainer/index.js +2 -4
- package/es/elements/ElementDamage/DamageFormButtons.d.ts +2 -3
- package/es/elements/ElementDamage/DamageFormButtons.js +1 -1
- package/es/elements/ElementDamage/TransportElementSelect.d.ts +1 -2
- package/es/elements/index.d.ts +5 -0
- package/es/elements/index.js +5 -0
- package/es/filter/ChipListInput.d.ts +13 -0
- package/es/filter/ChipListInput.js +34 -0
- package/es/filter/FilterBuilder.css +152 -0
- package/es/filter/FilterBuilder.d.ts +115 -0
- package/es/filter/FilterBuilder.js +146 -0
- package/es/filter/FilterBuilder.test.d.ts +1 -0
- package/es/filter/FilterBuilder.test.js +120 -0
- package/es/filter/FilterEditor.css +231 -0
- package/es/filter/FilterEditor.d.ts +17 -0
- package/es/filter/FilterEditor.js +38 -0
- package/es/filter/FilterEditor.test.d.ts +1 -0
- package/es/filter/FilterEditor.test.js +183 -0
- package/es/filter/FilterGroupEditor.d.ts +22 -0
- package/es/filter/FilterGroupEditor.js +34 -0
- package/es/filter/FilterNameDialog.css +22 -0
- package/es/filter/FilterNameDialog.d.ts +18 -0
- package/es/filter/FilterNameDialog.js +32 -0
- package/es/filter/FilterRow.d.ts +14 -0
- package/es/filter/FilterRow.js +32 -0
- package/es/filter/FilterShareDialog.css +28 -0
- package/es/filter/FilterShareDialog.d.ts +23 -0
- package/es/filter/FilterShareDialog.js +63 -0
- package/es/filter/FilterStringField.d.ts +15 -0
- package/es/filter/FilterStringField.js +37 -0
- package/es/filter/FilterValueEditor.d.ts +16 -0
- package/es/filter/FilterValueEditor.js +85 -0
- package/es/filter/SavedFilterTree.css +107 -0
- package/es/filter/SavedFilterTree.d.ts +45 -0
- package/es/filter/SavedFilterTree.js +44 -0
- package/es/filter/SavedFilterTree.test.d.ts +1 -0
- package/es/filter/SavedFilterTree.test.js +75 -0
- package/es/filter/index.d.ts +11 -0
- package/es/filter/index.js +10 -0
- package/es/filter/types.d.ts +34 -0
- package/es/filter/types.js +1 -0
- package/es/index.d.ts +2 -1
- package/es/index.js +6 -1
- package/es/mui/MuiThemeProvider.d.ts +24 -0
- package/es/mui/MuiThemeProvider.js +152 -0
- package/es/mui/index.d.ts +1 -0
- package/es/mui/index.js +1 -0
- package/es/report/ReportLauncher.css +147 -0
- package/es/report/ReportLauncher.d.ts +55 -0
- package/es/report/ReportLauncher.js +142 -0
- package/es/report/ReportLauncher.test.d.ts +1 -0
- package/es/report/ReportLauncher.test.js +231 -0
- package/es/report/ReportParameters.css +29 -0
- package/es/report/ReportParameters.d.ts +46 -0
- package/es/report/ReportParameters.js +65 -0
- package/es/report/ReportParameters.test.d.ts +1 -0
- package/es/report/ReportParameters.test.js +84 -0
- package/es/report/index.d.ts +2 -0
- package/es/report/index.js +2 -0
- package/es/test/setup.d.ts +1 -0
- package/es/test/setup.js +6 -0
- package/package.json +22 -7
- package/src/chrome/AppShell/index.tsx +34 -171
- package/src/components/ImageEditor/ImageEditor.css +10 -0
- package/src/components/ImageEditor/ImageEditor.tsx +40 -5
- package/src/components/ImageEditor/index.ts +1 -0
- package/src/components/ImageEditor/plugins/cropPlugin/CropOverlay.tsx +66 -20
- package/src/components/ImageEditor/plugins/cropPlugin/CropToolbar.tsx +19 -3
- package/src/components/ImageEditor/plugins/cropPlugin/useCropTool.ts +266 -39
- package/src/components/ImageEditor/plugins/zoomPlugin/ZoomContext.tsx +8 -0
- package/src/components/ImageEditor/useEdgeDetection.ts +11 -51
- package/src/components/ImageEditor/useImageHistory.ts +27 -19
- package/src/components/ImageEditor/useOpenCV.ts +112 -62
- package/src/components/LinkedCardList/index.scss +4 -2
- package/src/components/ProgressBar/index.scss +4 -2
- package/src/components/SplitContainer/index.tsx +3 -4
- package/src/filter/ChipListInput.tsx +79 -0
- package/src/filter/FilterBuilder.css +152 -0
- package/src/filter/FilterBuilder.test.tsx +153 -0
- package/src/filter/FilterBuilder.tsx +435 -0
- package/src/filter/FilterEditor.css +231 -0
- package/src/filter/FilterEditor.test.tsx +259 -0
- package/src/filter/FilterEditor.tsx +74 -0
- package/src/filter/FilterGroupEditor.tsx +160 -0
- package/src/filter/FilterNameDialog.css +22 -0
- package/src/filter/FilterNameDialog.tsx +81 -0
- package/src/filter/FilterRow.tsx +117 -0
- package/src/filter/FilterShareDialog.css +28 -0
- package/src/filter/FilterShareDialog.tsx +201 -0
- package/src/filter/FilterStringField.tsx +77 -0
- package/src/filter/FilterValueEditor.tsx +220 -0
- package/src/filter/SavedFilterTree.css +107 -0
- package/src/filter/SavedFilterTree.test.tsx +94 -0
- package/src/filter/SavedFilterTree.tsx +222 -0
- package/src/filter/index.ts +11 -0
- package/src/filter/types.ts +38 -0
- package/src/index.ts +39 -1
- package/src/mui/MuiThemeProvider.tsx +174 -0
- package/src/mui/index.ts +1 -0
- package/src/report/ReportLauncher.css +147 -0
- package/src/report/ReportLauncher.test.tsx +281 -0
- package/src/report/ReportLauncher.tsx +421 -0
- package/src/report/ReportParameters.css +29 -0
- package/src/report/ReportParameters.test.tsx +133 -0
- package/src/report/ReportParameters.tsx +198 -0
- package/src/report/index.ts +2 -0
- package/src/test/setup.ts +8 -0
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { StyledEngineProvider, ThemeProvider } from "@mui/material";
|
|
2
|
+
import { createTheme as muiCreateTheme } from "@mui/material/styles";
|
|
3
|
+
import { type ReactNode, useEffect, useState } from "react";
|
|
4
|
+
|
|
5
|
+
function getColorScheme(): "light" | "dark" {
|
|
6
|
+
let scheme = document.body?.dataset.colorScheme ?? document.documentElement?.dataset.colorScheme ?? "light";
|
|
7
|
+
|
|
8
|
+
if (scheme === "auto") {
|
|
9
|
+
return globalThis.matchMedia?.("(prefers-color-scheme: dark)").matches ? "dark" : "light";
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return scheme === "dark" ? "dark" : "light";
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Tracks the color scheme Designsystemet is rendering with. The article template
|
|
17
|
+
* sets `data-color-scheme` on `<body>`, so watch that attribute as well as the
|
|
18
|
+
* OS preference (used when the scheme is `auto`).
|
|
19
|
+
*/
|
|
20
|
+
function useColorScheme() {
|
|
21
|
+
let [scheme, setScheme] = useState<"light" | "dark">(() => getColorScheme());
|
|
22
|
+
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
function update() {
|
|
25
|
+
setScheme(getColorScheme());
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
update();
|
|
29
|
+
|
|
30
|
+
let observer = new MutationObserver(update);
|
|
31
|
+
observer.observe(document.body, { attributes: true, attributeFilter: ["data-color-scheme"] });
|
|
32
|
+
observer.observe(document.documentElement, { attributes: true, attributeFilter: ["data-color-scheme"] });
|
|
33
|
+
|
|
34
|
+
let media = globalThis.matchMedia?.("(prefers-color-scheme: dark)");
|
|
35
|
+
media?.addEventListener("change", update);
|
|
36
|
+
|
|
37
|
+
return () => {
|
|
38
|
+
observer.disconnect();
|
|
39
|
+
media?.removeEventListener("change", update);
|
|
40
|
+
};
|
|
41
|
+
}, []);
|
|
42
|
+
|
|
43
|
+
return scheme;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function buildMuiTheme(mode: "light" | "dark") {
|
|
47
|
+
const s = getComputedStyle(document.body);
|
|
48
|
+
const get = (v: string) => s.getPropertyValue(v).trim();
|
|
49
|
+
const isDark = mode === "dark";
|
|
50
|
+
|
|
51
|
+
return muiCreateTheme({
|
|
52
|
+
palette: {
|
|
53
|
+
mode,
|
|
54
|
+
primary: {
|
|
55
|
+
main: get("--ds-color-brand-base-default") || "#116069",
|
|
56
|
+
dark: get("--ds-color-brand-base-hover") || "#0d4b52",
|
|
57
|
+
contrastText: get("--ds-color-brand-base-contrast-default") || "#ffffff",
|
|
58
|
+
},
|
|
59
|
+
secondary: {
|
|
60
|
+
main: get("--ds-color-brand-light-base-default") || "#1a95a2",
|
|
61
|
+
},
|
|
62
|
+
background: {
|
|
63
|
+
default: get("--ds-color-neutral-background-default") || (isDark ? "#17181a" : "#ffffff"),
|
|
64
|
+
paper: get("--ds-color-neutral-background-default") || (isDark ? "#17181a" : "#ffffff"),
|
|
65
|
+
},
|
|
66
|
+
text: {
|
|
67
|
+
primary: get("--ds-color-neutral-text-default") || (isDark ? "#e5e6e7" : "#292c30"),
|
|
68
|
+
secondary: get("--ds-color-neutral-text-subtle") || (isDark ? "#b3b5b7" : "#5b5f64"),
|
|
69
|
+
},
|
|
70
|
+
divider: get("--ds-color-neutral-border-subtle") || (isDark ? "#4e5052" : "#bbbcbd"),
|
|
71
|
+
},
|
|
72
|
+
typography: {
|
|
73
|
+
fontFamily: [
|
|
74
|
+
"-apple-system",
|
|
75
|
+
"BlinkMacSystemFont",
|
|
76
|
+
'"Segoe UI"',
|
|
77
|
+
"Roboto",
|
|
78
|
+
'"Helvetica Neue"',
|
|
79
|
+
"Arial",
|
|
80
|
+
"sans-serif",
|
|
81
|
+
'"Apple Color Emoji"',
|
|
82
|
+
'"Segoe UI Emoji"',
|
|
83
|
+
'"Segoe UI Symbol"',
|
|
84
|
+
].join(","),
|
|
85
|
+
},
|
|
86
|
+
components: {
|
|
87
|
+
MuiTypography: {
|
|
88
|
+
styleOverrides: {
|
|
89
|
+
h1: { fontSize: "2.488rem" },
|
|
90
|
+
h2: { fontSize: "2.074rem" },
|
|
91
|
+
h3: { fontSize: "1.728rem" },
|
|
92
|
+
h4: { fontSize: "1.44rem" },
|
|
93
|
+
h5: { fontSize: "1.2rem" },
|
|
94
|
+
h6: { fontSize: "1rem" },
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
MuiAppBar: {
|
|
98
|
+
styleOverrides: {
|
|
99
|
+
root: {
|
|
100
|
+
"& .MuiTypography-h1": {
|
|
101
|
+
fontSize: "1.25rem",
|
|
102
|
+
fontWeight: "500",
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
MuiButton: {
|
|
108
|
+
styleOverrides: {
|
|
109
|
+
root: { borderRadius: 2 },
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
MuiDialogTitle: {
|
|
113
|
+
styleOverrides: {
|
|
114
|
+
root: {
|
|
115
|
+
fontSize: "1.2rem",
|
|
116
|
+
fontWeight: 500,
|
|
117
|
+
paddingLeft: 16,
|
|
118
|
+
paddingRight: 16,
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
MuiFormLabel: {
|
|
123
|
+
styleOverrides: {
|
|
124
|
+
root: { color: get("--ds-color-neutral-text-subtle") || "rgba(0, 0, 0, 0.72)" },
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
MuiTextField: { defaultProps: { variant: "filled" } },
|
|
128
|
+
MuiSelect: { defaultProps: { variant: "filled" } },
|
|
129
|
+
MuiFormControl: { defaultProps: { variant: "filled" } },
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export type MuiThemeProviderProps = {
|
|
135
|
+
children: ReactNode;
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Bridges Designsystemet's colour tokens into a MUI theme, so MUI components
|
|
140
|
+
* (most notably the data grid) follow Designsystemet instead of MUI defaults.
|
|
141
|
+
*
|
|
142
|
+
* This lives in a separate entry point (`@olenbetong/synergi-react/mui`) so apps
|
|
143
|
+
* that have migrated to Designsystemet don't pull ~160 kB of MUI and Emotion
|
|
144
|
+
* into their bundle just by using `AppShell`. Wrap `AppShell` with it in apps
|
|
145
|
+
* that still render MUI components:
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* ```tsx
|
|
149
|
+
* import { AppShell } from "@olenbetong/synergi-react";
|
|
150
|
+
* import { MuiThemeProvider } from "@olenbetong/synergi-react/mui";
|
|
151
|
+
*
|
|
152
|
+
* <MuiThemeProvider>
|
|
153
|
+
* <AppShell>{children}</AppShell>
|
|
154
|
+
* </MuiThemeProvider>
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
export function MuiThemeProvider({ children }: MuiThemeProviderProps) {
|
|
158
|
+
const colorScheme = useColorScheme();
|
|
159
|
+
|
|
160
|
+
// Rebuilt whenever the color scheme changes so MUI components (notably the
|
|
161
|
+
// data grid) follow Designsystemet instead of staying stuck in light mode.
|
|
162
|
+
// Also re-read after mount, since the stylesheets are imported from JS and
|
|
163
|
+
// the CSS variables aren't necessarily resolved during the first render.
|
|
164
|
+
const [theme, setTheme] = useState(() => buildMuiTheme(colorScheme));
|
|
165
|
+
useEffect(() => {
|
|
166
|
+
setTheme(buildMuiTheme(colorScheme));
|
|
167
|
+
}, [colorScheme]);
|
|
168
|
+
|
|
169
|
+
return (
|
|
170
|
+
<StyledEngineProvider injectFirst>
|
|
171
|
+
<ThemeProvider theme={theme}>{children}</ThemeProvider>
|
|
172
|
+
</StyledEngineProvider>
|
|
173
|
+
);
|
|
174
|
+
}
|
package/src/mui/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { MuiThemeProvider, type MuiThemeProviderProps } from "./MuiThemeProvider.js";
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Colours use the contextual `--ds-color-*` aliases so the launcher follows the
|
|
3
|
+
* active colour scheme. Never add hex fallbacks.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
.ObReportLauncher-root {
|
|
7
|
+
display: flex;
|
|
8
|
+
flex-direction: column;
|
|
9
|
+
gap: var(--ds-size-4);
|
|
10
|
+
block-size: 100%;
|
|
11
|
+
min-block-size: 0;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/*
|
|
15
|
+
* The filter builder is the part that grows: its criteria editor scrolls, and
|
|
16
|
+
* the report fields it hosts keep their natural height.
|
|
17
|
+
*/
|
|
18
|
+
.ObReportLauncher-root > .ObFilterBuilder-root {
|
|
19
|
+
flex: 1 1 auto;
|
|
20
|
+
min-block-size: 0;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/*
|
|
24
|
+
* The tabs, the open panel and the report options share the column next to the
|
|
25
|
+
* saved-filter list. Only the panel grows; the tab list and the options keep
|
|
26
|
+
* their natural height.
|
|
27
|
+
*/
|
|
28
|
+
.ObReportLauncher-main {
|
|
29
|
+
display: flex;
|
|
30
|
+
flex-direction: column;
|
|
31
|
+
gap: var(--ds-size-3);
|
|
32
|
+
min-block-size: 0;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.ObReportLauncher-tabs {
|
|
36
|
+
flex: 0 0 auto;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/*
|
|
40
|
+
* The criteria editor scrolls its own conditions, so the panel holding it must
|
|
41
|
+
* not scroll as well. The parameters have no such arrangement and get their
|
|
42
|
+
* scrolling from the panel.
|
|
43
|
+
*/
|
|
44
|
+
.ObReportLauncher-panel {
|
|
45
|
+
display: flex;
|
|
46
|
+
flex-direction: column;
|
|
47
|
+
flex: 1 1 auto;
|
|
48
|
+
min-block-size: 0;
|
|
49
|
+
overflow: hidden;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.ObReportLauncher-panel--scroll {
|
|
53
|
+
gap: var(--ds-size-3);
|
|
54
|
+
overflow: auto;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.ObReportLauncher-panel > .ObFilterEditor-root {
|
|
58
|
+
flex: 1 1 auto;
|
|
59
|
+
min-block-size: 0;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
.ObReportLauncher-options {
|
|
63
|
+
display: flex;
|
|
64
|
+
flex-direction: column;
|
|
65
|
+
flex: 0 0 auto;
|
|
66
|
+
gap: var(--ds-size-2);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
.ObReportLauncher-status {
|
|
70
|
+
margin: 0;
|
|
71
|
+
color: var(--ds-color-text-subtle);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
.ObReportLauncher-error {
|
|
75
|
+
margin: 0;
|
|
76
|
+
color: var(--ds-color-danger-text-default);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/* The action row of the Windows dialog: save, preview, print, close. */
|
|
80
|
+
.ObReportLauncher-actions {
|
|
81
|
+
display: flex;
|
|
82
|
+
flex-wrap: wrap;
|
|
83
|
+
align-items: center;
|
|
84
|
+
justify-content: flex-end;
|
|
85
|
+
gap: var(--ds-size-2);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
.ObReportLauncher-progress {
|
|
89
|
+
margin-inline-end: auto;
|
|
90
|
+
color: var(--ds-color-text-subtle);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/* The save button and its format menu read as one control. */
|
|
94
|
+
.ObReportLauncher-saveGroup {
|
|
95
|
+
display: flex;
|
|
96
|
+
align-items: stretch;
|
|
97
|
+
gap: var(--ds-border-width-default);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
.ObReportLauncher-saveGroup > :first-child {
|
|
101
|
+
border-start-end-radius: 0;
|
|
102
|
+
border-end-end-radius: 0;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
.ObReportLauncher-saveGroup > :last-child:not(:first-child) {
|
|
106
|
+
border-start-start-radius: 0;
|
|
107
|
+
border-end-start-radius: 0;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/*
|
|
111
|
+
* As with the filter builder, `Dialog` caps itself at `--dsc-dialog-max-width`,
|
|
112
|
+
* so the variables have to be raised rather than the width set.
|
|
113
|
+
*/
|
|
114
|
+
.ObReportLauncher-dialog {
|
|
115
|
+
--dsc-dialog-max-width: 84rem;
|
|
116
|
+
--dsc-dialog-max-height: 90dvh;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/*
|
|
120
|
+
* Taller than the filter builder: the column next to the saved-filter list has
|
|
121
|
+
* to fit the tabs, a panel worth scrolling and the report options below it.
|
|
122
|
+
*/
|
|
123
|
+
.ObReportLauncher-dialog[open] {
|
|
124
|
+
display: flex;
|
|
125
|
+
flex-direction: column;
|
|
126
|
+
block-size: min(58rem, 90dvh);
|
|
127
|
+
overflow: hidden;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
.ObReportLauncher-dialogHeader {
|
|
131
|
+
display: flex;
|
|
132
|
+
align-items: center;
|
|
133
|
+
justify-content: space-between;
|
|
134
|
+
gap: var(--ds-size-2);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
.ObReportLauncher-dialogBody {
|
|
138
|
+
flex: 1 1 auto;
|
|
139
|
+
min-block-size: 0;
|
|
140
|
+
overflow: hidden;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
@media (width < 48rem) {
|
|
144
|
+
.ObReportLauncher-dialogBody {
|
|
145
|
+
overflow: auto;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
import type { Report, ReportParameter, ReportParameterValues, SavedFilter } from "@olenbetong/appframe-core";
|
|
2
|
+
import { render, screen, waitFor, within } from "@testing-library/react";
|
|
3
|
+
import userEvent from "@testing-library/user-event";
|
|
4
|
+
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
5
|
+
|
|
6
|
+
const download = vi.fn(async () => undefined);
|
|
7
|
+
const openRendered = vi.fn(async () => undefined);
|
|
8
|
+
const print = vi.fn(async () => undefined);
|
|
9
|
+
const save = vi.fn(async () => undefined);
|
|
10
|
+
const convertFilter = vi.fn(async () => ({ filterObject: null, filterString: "", whereClause: "" }));
|
|
11
|
+
|
|
12
|
+
let report: Report | null = null;
|
|
13
|
+
let parameters: ReportParameter[] = [];
|
|
14
|
+
let defaultValues: ReportParameterValues = {};
|
|
15
|
+
let savedFilters: SavedFilter[] = [];
|
|
16
|
+
let initialFilter: string | null = null;
|
|
17
|
+
|
|
18
|
+
vi.mock("@olenbetong/appframe-core", async (importOriginal) => ({
|
|
19
|
+
...(await importOriginal<Record<string, unknown>>()),
|
|
20
|
+
convertFilter: (...args: unknown[]) => convertFilter(...(args as [])),
|
|
21
|
+
}));
|
|
22
|
+
|
|
23
|
+
vi.mock("@olenbetong/appframe-react", async (importOriginal) => ({
|
|
24
|
+
...(await importOriginal<Record<string, unknown>>()),
|
|
25
|
+
setNamedFilter: vi.fn(),
|
|
26
|
+
useFilterFields: () => ({ fields: [], loading: false, error: null, refresh: vi.fn() }),
|
|
27
|
+
useFilterConversion: () => ({
|
|
28
|
+
filterString: "[ProjectID] = 1",
|
|
29
|
+
isConverting: false,
|
|
30
|
+
error: null,
|
|
31
|
+
parseFilterString: vi.fn(async () => null),
|
|
32
|
+
}),
|
|
33
|
+
useReport: () => ({
|
|
34
|
+
report,
|
|
35
|
+
parameters,
|
|
36
|
+
initialFilter,
|
|
37
|
+
defaultValues,
|
|
38
|
+
loading: false,
|
|
39
|
+
error: null,
|
|
40
|
+
refresh: vi.fn(),
|
|
41
|
+
}),
|
|
42
|
+
useReportRender: () => ({
|
|
43
|
+
open: openRendered,
|
|
44
|
+
print,
|
|
45
|
+
download,
|
|
46
|
+
render: vi.fn(),
|
|
47
|
+
cancel: vi.fn(),
|
|
48
|
+
isRendering: false,
|
|
49
|
+
progress: null,
|
|
50
|
+
error: null,
|
|
51
|
+
}),
|
|
52
|
+
useSavedFilters: () => ({
|
|
53
|
+
filters: savedFilters,
|
|
54
|
+
mine: savedFilters,
|
|
55
|
+
shared: [],
|
|
56
|
+
loading: false,
|
|
57
|
+
error: null,
|
|
58
|
+
refresh: vi.fn(),
|
|
59
|
+
save,
|
|
60
|
+
rename: vi.fn(),
|
|
61
|
+
remove: vi.fn(),
|
|
62
|
+
setCrossDomain: vi.fn(),
|
|
63
|
+
}),
|
|
64
|
+
}));
|
|
65
|
+
|
|
66
|
+
const { ReportLauncher } = await import("./ReportLauncher.js");
|
|
67
|
+
|
|
68
|
+
function makeReport(overrides: Partial<Report> = {}): Report {
|
|
69
|
+
return {
|
|
70
|
+
reportId: "arpt_Test_Report",
|
|
71
|
+
shortId: 4711,
|
|
72
|
+
title: "Test report",
|
|
73
|
+
description: null,
|
|
74
|
+
viewName: "aviw_Test_View",
|
|
75
|
+
initialFilter: null,
|
|
76
|
+
hasTitle: true,
|
|
77
|
+
hasHeader: true,
|
|
78
|
+
formats: ["PDF", "XLSX"],
|
|
79
|
+
timeout: null,
|
|
80
|
+
...overrides,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function savedFilter(overrides: Partial<SavedFilter> = {}): SavedFilter {
|
|
85
|
+
return {
|
|
86
|
+
filterId: 1,
|
|
87
|
+
primKey: "pk-1",
|
|
88
|
+
name: "Mitt filter",
|
|
89
|
+
criteria: "[ProjectID] = 1",
|
|
90
|
+
dbObjectId: "aviw_Test_View",
|
|
91
|
+
accessLevel: "Manager",
|
|
92
|
+
createdByUser: true,
|
|
93
|
+
createdBy: "bvh",
|
|
94
|
+
domain: "OB",
|
|
95
|
+
crossDomain: false,
|
|
96
|
+
isPersonallyShared: false,
|
|
97
|
+
hideCriteria: true,
|
|
98
|
+
headerText: "Lagret overskrift",
|
|
99
|
+
comment: null,
|
|
100
|
+
parameters: '<Parameters Version="1"><Parameter Name="Period" Type="Integer">202601</Parameter></Parameters>',
|
|
101
|
+
reportTitle: null,
|
|
102
|
+
created: null,
|
|
103
|
+
updated: null,
|
|
104
|
+
...overrides,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function numberParameter(overrides: Partial<ReportParameter> = {}): ReportParameter {
|
|
109
|
+
return {
|
|
110
|
+
name: "Period",
|
|
111
|
+
label: "Periode",
|
|
112
|
+
description: null,
|
|
113
|
+
type: "Integer",
|
|
114
|
+
editor: "number",
|
|
115
|
+
defaultValue: null,
|
|
116
|
+
items: [],
|
|
117
|
+
recordSource: null,
|
|
118
|
+
valueMember: null,
|
|
119
|
+
displayMember: null,
|
|
120
|
+
sortOrder: 0,
|
|
121
|
+
lookupWidth: null,
|
|
122
|
+
lookupHeight: null,
|
|
123
|
+
...overrides,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function renderLauncher(props: Record<string, unknown> = {}) {
|
|
128
|
+
return render(<ReportLauncher reportId="arpt_Test_Report" variant="inline" {...props} />);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
describe("ReportLauncher", () => {
|
|
132
|
+
beforeEach(() => {
|
|
133
|
+
vi.clearAllMocks();
|
|
134
|
+
report = makeReport();
|
|
135
|
+
parameters = [];
|
|
136
|
+
defaultValues = {};
|
|
137
|
+
savedFilters = [];
|
|
138
|
+
initialFilter = null;
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it("tells the user when the report is not available to them", () => {
|
|
142
|
+
report = null;
|
|
143
|
+
renderLauncher();
|
|
144
|
+
|
|
145
|
+
expect(screen.getByRole("alert").textContent).toContain("do not have access");
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
it("shows the report option fields the report has bands for", () => {
|
|
149
|
+
renderLauncher();
|
|
150
|
+
|
|
151
|
+
expect(screen.getByLabelText("Report name")).toHaveValue("Test report");
|
|
152
|
+
expect(screen.getByLabelText("Optional text (at the top of every page)")).toBeInTheDocument();
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it("puts the parameters and the criteria in a tab each, with the options below both", async () => {
|
|
156
|
+
parameters = [numberParameter()];
|
|
157
|
+
defaultValues = { Period: null };
|
|
158
|
+
renderLauncher();
|
|
159
|
+
|
|
160
|
+
expect(screen.getByLabelText("Periode")).toBeInTheDocument();
|
|
161
|
+
expect(screen.queryByLabelText("Filter string")).toBeNull();
|
|
162
|
+
|
|
163
|
+
await userEvent.click(screen.getByText("Filter"));
|
|
164
|
+
|
|
165
|
+
expect(screen.queryByLabelText("Periode")).toBeNull();
|
|
166
|
+
expect(screen.getByLabelText("Filter string")).toBeInTheDocument();
|
|
167
|
+
// The options apply to the report whichever tab is open.
|
|
168
|
+
expect(screen.getByLabelText("Report name")).toBeInTheDocument();
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
it("can start on the filter tab", () => {
|
|
172
|
+
parameters = [numberParameter()];
|
|
173
|
+
renderLauncher({ defaultTab: "filter" });
|
|
174
|
+
|
|
175
|
+
expect(screen.getByLabelText("Filter string")).toBeInTheDocument();
|
|
176
|
+
expect(screen.queryByLabelText("Periode")).toBeNull();
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
it("names the report and its number in the dialog heading", () => {
|
|
180
|
+
render(<ReportLauncher reportId="arpt_Test_Report" />);
|
|
181
|
+
|
|
182
|
+
expect(screen.getByRole("heading").textContent).toBe("Report: Test report (ID: 4711)");
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it("hides the title and header fields when the report has no such bands", () => {
|
|
186
|
+
report = makeReport({ hasTitle: false, hasHeader: false });
|
|
187
|
+
renderLauncher();
|
|
188
|
+
|
|
189
|
+
expect(screen.queryByLabelText("Report name")).toBeNull();
|
|
190
|
+
expect(screen.queryByLabelText("Optional text (at the top of every page)")).toBeNull();
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
it("offers the report's first format on the save button and the rest in a menu", async () => {
|
|
194
|
+
renderLauncher();
|
|
195
|
+
|
|
196
|
+
await userEvent.click(screen.getByRole("button", { name: "Save as PDF" }));
|
|
197
|
+
|
|
198
|
+
expect(download).toHaveBeenCalledWith(
|
|
199
|
+
expect.objectContaining({ format: "PDF", fileName: "Test report", filter: "[ProjectID] = 1" }),
|
|
200
|
+
);
|
|
201
|
+
expect(screen.getByRole("button", { name: "More formats" })).toBeInTheDocument();
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it("does not offer a format menu for a report with a single format", () => {
|
|
205
|
+
report = makeReport({ formats: ["PDF"] });
|
|
206
|
+
renderLauncher();
|
|
207
|
+
|
|
208
|
+
expect(screen.queryByRole("button", { name: "More formats" })).toBeNull();
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
it("previews and prints as PDF", async () => {
|
|
212
|
+
renderLauncher();
|
|
213
|
+
|
|
214
|
+
await userEvent.click(screen.getByRole("button", { name: "Preview" }));
|
|
215
|
+
await userEvent.click(screen.getByRole("button", { name: "Print" }));
|
|
216
|
+
|
|
217
|
+
expect(openRendered).toHaveBeenCalledWith(expect.objectContaining({ format: "PDF" }));
|
|
218
|
+
expect(print).toHaveBeenCalledWith(expect.objectContaining({ format: "PDF" }));
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
it("cannot preview or print a report that has no PDF format", () => {
|
|
222
|
+
report = makeReport({ formats: ["CSV"] });
|
|
223
|
+
renderLauncher();
|
|
224
|
+
|
|
225
|
+
expect(screen.getByRole("button", { name: "Preview" }).hasAttribute("disabled")).toBe(true);
|
|
226
|
+
expect(screen.getByRole("button", { name: "Print" }).hasAttribute("disabled")).toBe(true);
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
it("sends the header text and the hide-criteria flag with the render", async () => {
|
|
230
|
+
renderLauncher();
|
|
231
|
+
|
|
232
|
+
await userEvent.type(screen.getByLabelText("Optional text (at the top of every page)"), "Hei");
|
|
233
|
+
await userEvent.click(screen.getByLabelText("Do not show the filter criteria at the top of the pages"));
|
|
234
|
+
await userEvent.click(screen.getByRole("button", { name: "Save as PDF" }));
|
|
235
|
+
|
|
236
|
+
expect(download).toHaveBeenCalledWith(expect.objectContaining({ headerText: "Hei", hideFilterString: true }));
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
it("restores the report options stored with a saved filter", async () => {
|
|
240
|
+
parameters = [numberParameter()];
|
|
241
|
+
defaultValues = { Period: null };
|
|
242
|
+
savedFilters = [savedFilter()];
|
|
243
|
+
renderLauncher();
|
|
244
|
+
|
|
245
|
+
await userEvent.click(screen.getByRole("button", { name: "Mitt filter" }));
|
|
246
|
+
|
|
247
|
+
await waitFor(() => expect(screen.getByLabelText("Periode")).toHaveValue(202601));
|
|
248
|
+
expect(screen.getByLabelText("Optional text (at the top of every page)")).toHaveValue("Lagret overskrift");
|
|
249
|
+
expect(
|
|
250
|
+
(screen.getByLabelText("Do not show the filter criteria at the top of the pages") as HTMLInputElement).checked,
|
|
251
|
+
).toBe(true);
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
it("stores the report options on the filter when it is saved", async () => {
|
|
255
|
+
parameters = [];
|
|
256
|
+
// "Save as" is only offered for a filter with conditions, so the launcher
|
|
257
|
+
// starts from the report's own filter.
|
|
258
|
+
convertFilter.mockResolvedValue({
|
|
259
|
+
filterObject: {
|
|
260
|
+
type: "group",
|
|
261
|
+
mode: "and",
|
|
262
|
+
items: [{ type: "expression", column: "ProjectID", operator: "equals", value: 1, valueType: "number" }],
|
|
263
|
+
},
|
|
264
|
+
filterString: "[ProjectID] = 1",
|
|
265
|
+
whereClause: "",
|
|
266
|
+
} as never);
|
|
267
|
+
initialFilter = "[ProjectID] = 1";
|
|
268
|
+
renderLauncher();
|
|
269
|
+
|
|
270
|
+
await userEvent.type(screen.getByLabelText("Optional text (at the top of every page)"), "Hei");
|
|
271
|
+
await userEvent.click(screen.getByRole("button", { name: "Save as" }));
|
|
272
|
+
|
|
273
|
+
let dialog = screen.getByRole("dialog");
|
|
274
|
+
await userEvent.type(within(dialog).getByRole("textbox", { name: "Filter name" }), "Nytt filter");
|
|
275
|
+
await userEvent.click(within(dialog).getByRole("button", { name: "Save" }));
|
|
276
|
+
|
|
277
|
+
await waitFor(() =>
|
|
278
|
+
expect(save).toHaveBeenCalledWith(expect.objectContaining({ headerText: "Hei", hideCriteria: false })),
|
|
279
|
+
);
|
|
280
|
+
});
|
|
281
|
+
});
|