@olenbetong/synergi-react 2.9.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/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/index.d.ts +1 -0
- package/es/components/ImageEditor/index.js +1 -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/useEdgeDetection.d.ts +0 -2
- package/es/components/ImageEditor/useEdgeDetection.js +11 -30
- 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/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/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/useOpenCV.ts +112 -62
- 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
package/es/index.js
CHANGED
|
@@ -6,10 +6,15 @@ export { CardColumn, CardDetail, CardLabel, CardStep, CardStepList, ColorCard }
|
|
|
6
6
|
export { DateNavigator } from "./components/DateNavigator/index.js";
|
|
7
7
|
export * from "./components/FilePond.js";
|
|
8
8
|
export * from "./components/ImageEditor/index.js";
|
|
9
|
+
export { ChipListInput, FilterBuilder, FilterEditor, FilterGroupEditor, FilterNameDialog, FilterRow, FilterShareDialog, FilterStringField, FilterValueEditor, SavedFilterTree, } from "./filter/index.js";
|
|
9
10
|
export { Card, LinkedList, LinkedListItem } from "./components/LinkedCardList/index.js";
|
|
10
11
|
export { MergeProgressDialog } from "./components/MergeProgressDialog/index.js";
|
|
12
|
+
export { ReportLauncher, ReportParameterField, ReportParameters, } from "./report/index.js";
|
|
11
13
|
export { BannerImage as PageBannerImage, PageBanner, Tab as PageBannerTab, TabList as PageBannerTabList, Title as PageBannerTitle, } from "./components/PageBanner/index.js";
|
|
12
|
-
|
|
14
|
+
// PdfViewer is intentionally not re-exported here. It references the pdf.js worker
|
|
15
|
+
// with `new URL(..., import.meta.url)`, which makes bundlers emit the 1.2 MB worker
|
|
16
|
+
// asset for every app that touches this barrel, even when no PDF is ever rendered.
|
|
17
|
+
// Import it from "@olenbetong/synergi-react/pdf" instead.
|
|
13
18
|
export { Portal } from "./components/Portal/index.js";
|
|
14
19
|
export { ToolbarBreadcrumbs, ToolbarPortal, } from "./components/Toolbar/index.js";
|
|
15
20
|
export { ProgressBar } from "./components/ProgressBar/index.js";
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
export type MuiThemeProviderProps = {
|
|
3
|
+
children: ReactNode;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* Bridges Designsystemet's colour tokens into a MUI theme, so MUI components
|
|
7
|
+
* (most notably the data grid) follow Designsystemet instead of MUI defaults.
|
|
8
|
+
*
|
|
9
|
+
* This lives in a separate entry point (`@olenbetong/synergi-react/mui`) so apps
|
|
10
|
+
* that have migrated to Designsystemet don't pull ~160 kB of MUI and Emotion
|
|
11
|
+
* into their bundle just by using `AppShell`. Wrap `AppShell` with it in apps
|
|
12
|
+
* that still render MUI components:
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```tsx
|
|
16
|
+
* import { AppShell } from "@olenbetong/synergi-react";
|
|
17
|
+
* import { MuiThemeProvider } from "@olenbetong/synergi-react/mui";
|
|
18
|
+
*
|
|
19
|
+
* <MuiThemeProvider>
|
|
20
|
+
* <AppShell>{children}</AppShell>
|
|
21
|
+
* </MuiThemeProvider>
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare function MuiThemeProvider({ children }: MuiThemeProviderProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { StyledEngineProvider, ThemeProvider } from "@mui/material";
|
|
3
|
+
import { createTheme as muiCreateTheme } from "@mui/material/styles";
|
|
4
|
+
import { useEffect, useState } from "react";
|
|
5
|
+
function getColorScheme() {
|
|
6
|
+
let scheme = document.body?.dataset.colorScheme ?? document.documentElement?.dataset.colorScheme ?? "light";
|
|
7
|
+
if (scheme === "auto") {
|
|
8
|
+
return globalThis.matchMedia?.("(prefers-color-scheme: dark)").matches ? "dark" : "light";
|
|
9
|
+
}
|
|
10
|
+
return scheme === "dark" ? "dark" : "light";
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Tracks the color scheme Designsystemet is rendering with. The article template
|
|
14
|
+
* sets `data-color-scheme` on `<body>`, so watch that attribute as well as the
|
|
15
|
+
* OS preference (used when the scheme is `auto`).
|
|
16
|
+
*/
|
|
17
|
+
function useColorScheme() {
|
|
18
|
+
let [scheme, setScheme] = useState(() => getColorScheme());
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
function update() {
|
|
21
|
+
setScheme(getColorScheme());
|
|
22
|
+
}
|
|
23
|
+
update();
|
|
24
|
+
let observer = new MutationObserver(update);
|
|
25
|
+
observer.observe(document.body, { attributes: true, attributeFilter: ["data-color-scheme"] });
|
|
26
|
+
observer.observe(document.documentElement, { attributes: true, attributeFilter: ["data-color-scheme"] });
|
|
27
|
+
let media = globalThis.matchMedia?.("(prefers-color-scheme: dark)");
|
|
28
|
+
media?.addEventListener("change", update);
|
|
29
|
+
return () => {
|
|
30
|
+
observer.disconnect();
|
|
31
|
+
media?.removeEventListener("change", update);
|
|
32
|
+
};
|
|
33
|
+
}, []);
|
|
34
|
+
return scheme;
|
|
35
|
+
}
|
|
36
|
+
function buildMuiTheme(mode) {
|
|
37
|
+
const s = getComputedStyle(document.body);
|
|
38
|
+
const get = (v) => s.getPropertyValue(v).trim();
|
|
39
|
+
const isDark = mode === "dark";
|
|
40
|
+
return muiCreateTheme({
|
|
41
|
+
palette: {
|
|
42
|
+
mode,
|
|
43
|
+
primary: {
|
|
44
|
+
main: get("--ds-color-brand-base-default") || "#116069",
|
|
45
|
+
dark: get("--ds-color-brand-base-hover") || "#0d4b52",
|
|
46
|
+
contrastText: get("--ds-color-brand-base-contrast-default") || "#ffffff",
|
|
47
|
+
},
|
|
48
|
+
secondary: {
|
|
49
|
+
main: get("--ds-color-brand-light-base-default") || "#1a95a2",
|
|
50
|
+
},
|
|
51
|
+
background: {
|
|
52
|
+
default: get("--ds-color-neutral-background-default") || (isDark ? "#17181a" : "#ffffff"),
|
|
53
|
+
paper: get("--ds-color-neutral-background-default") || (isDark ? "#17181a" : "#ffffff"),
|
|
54
|
+
},
|
|
55
|
+
text: {
|
|
56
|
+
primary: get("--ds-color-neutral-text-default") || (isDark ? "#e5e6e7" : "#292c30"),
|
|
57
|
+
secondary: get("--ds-color-neutral-text-subtle") || (isDark ? "#b3b5b7" : "#5b5f64"),
|
|
58
|
+
},
|
|
59
|
+
divider: get("--ds-color-neutral-border-subtle") || (isDark ? "#4e5052" : "#bbbcbd"),
|
|
60
|
+
},
|
|
61
|
+
typography: {
|
|
62
|
+
fontFamily: [
|
|
63
|
+
"-apple-system",
|
|
64
|
+
"BlinkMacSystemFont",
|
|
65
|
+
'"Segoe UI"',
|
|
66
|
+
"Roboto",
|
|
67
|
+
'"Helvetica Neue"',
|
|
68
|
+
"Arial",
|
|
69
|
+
"sans-serif",
|
|
70
|
+
'"Apple Color Emoji"',
|
|
71
|
+
'"Segoe UI Emoji"',
|
|
72
|
+
'"Segoe UI Symbol"',
|
|
73
|
+
].join(","),
|
|
74
|
+
},
|
|
75
|
+
components: {
|
|
76
|
+
MuiTypography: {
|
|
77
|
+
styleOverrides: {
|
|
78
|
+
h1: { fontSize: "2.488rem" },
|
|
79
|
+
h2: { fontSize: "2.074rem" },
|
|
80
|
+
h3: { fontSize: "1.728rem" },
|
|
81
|
+
h4: { fontSize: "1.44rem" },
|
|
82
|
+
h5: { fontSize: "1.2rem" },
|
|
83
|
+
h6: { fontSize: "1rem" },
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
MuiAppBar: {
|
|
87
|
+
styleOverrides: {
|
|
88
|
+
root: {
|
|
89
|
+
"& .MuiTypography-h1": {
|
|
90
|
+
fontSize: "1.25rem",
|
|
91
|
+
fontWeight: "500",
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
MuiButton: {
|
|
97
|
+
styleOverrides: {
|
|
98
|
+
root: { borderRadius: 2 },
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
MuiDialogTitle: {
|
|
102
|
+
styleOverrides: {
|
|
103
|
+
root: {
|
|
104
|
+
fontSize: "1.2rem",
|
|
105
|
+
fontWeight: 500,
|
|
106
|
+
paddingLeft: 16,
|
|
107
|
+
paddingRight: 16,
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
MuiFormLabel: {
|
|
112
|
+
styleOverrides: {
|
|
113
|
+
root: { color: get("--ds-color-neutral-text-subtle") || "rgba(0, 0, 0, 0.72)" },
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
MuiTextField: { defaultProps: { variant: "filled" } },
|
|
117
|
+
MuiSelect: { defaultProps: { variant: "filled" } },
|
|
118
|
+
MuiFormControl: { defaultProps: { variant: "filled" } },
|
|
119
|
+
},
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Bridges Designsystemet's colour tokens into a MUI theme, so MUI components
|
|
124
|
+
* (most notably the data grid) follow Designsystemet instead of MUI defaults.
|
|
125
|
+
*
|
|
126
|
+
* This lives in a separate entry point (`@olenbetong/synergi-react/mui`) so apps
|
|
127
|
+
* that have migrated to Designsystemet don't pull ~160 kB of MUI and Emotion
|
|
128
|
+
* into their bundle just by using `AppShell`. Wrap `AppShell` with it in apps
|
|
129
|
+
* that still render MUI components:
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```tsx
|
|
133
|
+
* import { AppShell } from "@olenbetong/synergi-react";
|
|
134
|
+
* import { MuiThemeProvider } from "@olenbetong/synergi-react/mui";
|
|
135
|
+
*
|
|
136
|
+
* <MuiThemeProvider>
|
|
137
|
+
* <AppShell>{children}</AppShell>
|
|
138
|
+
* </MuiThemeProvider>
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
141
|
+
export function MuiThemeProvider({ children }) {
|
|
142
|
+
const colorScheme = useColorScheme();
|
|
143
|
+
// Rebuilt whenever the color scheme changes so MUI components (notably the
|
|
144
|
+
// data grid) follow Designsystemet instead of staying stuck in light mode.
|
|
145
|
+
// Also re-read after mount, since the stylesheets are imported from JS and
|
|
146
|
+
// the CSS variables aren't necessarily resolved during the first render.
|
|
147
|
+
const [theme, setTheme] = useState(() => buildMuiTheme(colorScheme));
|
|
148
|
+
useEffect(() => {
|
|
149
|
+
setTheme(buildMuiTheme(colorScheme));
|
|
150
|
+
}, [colorScheme]);
|
|
151
|
+
return (_jsx(StyledEngineProvider, { injectFirst: true, children: _jsx(ThemeProvider, { theme: theme, children: children }) }));
|
|
152
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { MuiThemeProvider, type MuiThemeProviderProps } from "./MuiThemeProvider.js";
|
package/es/mui/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { MuiThemeProvider } 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,55 @@
|
|
|
1
|
+
import "./ReportLauncher.css";
|
|
2
|
+
import { type FieldMetadata } from "@olenbetong/appframe-core";
|
|
3
|
+
import type { FilterEditorSize, GetFieldOptions } from "../filter/types.js";
|
|
4
|
+
export type ReportLauncherTab = "parameters" | "filter";
|
|
5
|
+
export type ReportLauncherProps = {
|
|
6
|
+
/** The report to run, e.g. `arpt_Personnel_Persons`. */
|
|
7
|
+
reportId: string;
|
|
8
|
+
/**
|
|
9
|
+
* `"dialog"` wraps the launcher in a modal, `"inline"` renders it in place.
|
|
10
|
+
* @default "dialog"
|
|
11
|
+
*/
|
|
12
|
+
variant?: "dialog" | "inline";
|
|
13
|
+
/** Whether the dialog is open. Ignored when `variant` is `"inline"`. */
|
|
14
|
+
open?: boolean;
|
|
15
|
+
/** Called when the launcher is dismissed. */
|
|
16
|
+
onClose?: () => void;
|
|
17
|
+
/**
|
|
18
|
+
* Overrides the filter the report was designed with, as a criteria string.
|
|
19
|
+
* An empty string starts the launcher with no filter at all.
|
|
20
|
+
*/
|
|
21
|
+
initialFilter?: string | null;
|
|
22
|
+
/**
|
|
23
|
+
* The fields the filter can be built from. Loaded from the report's view
|
|
24
|
+
* when not supplied.
|
|
25
|
+
*/
|
|
26
|
+
fields?: FieldMetadata[];
|
|
27
|
+
/**
|
|
28
|
+
* The tab shown first.
|
|
29
|
+
* @default "parameters"
|
|
30
|
+
*/
|
|
31
|
+
defaultTab?: ReportLauncherTab;
|
|
32
|
+
getFieldOptions?: GetFieldOptions;
|
|
33
|
+
className?: string;
|
|
34
|
+
"data-size"?: FilterEditorSize;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* The web port of the Windows report launcher: the saved filters and criteria
|
|
38
|
+
* editor of the filter builder, the report's parameters, the report options,
|
|
39
|
+
* and the save/preview/print actions.
|
|
40
|
+
*
|
|
41
|
+
* Everything the launcher needs comes from the report itself, so a caller only
|
|
42
|
+
* has to name it. A report that does not resolve is one the current user has no
|
|
43
|
+
* access to — `sviw_WinClient_MyReports` is permission-resolved.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```jsx
|
|
47
|
+
* <ReportLauncher
|
|
48
|
+
* reportId="arpt_Production_ElementsDaily"
|
|
49
|
+
* open={open}
|
|
50
|
+
* initialFilter={`[ProjectID] = '${projectId}'`}
|
|
51
|
+
* onClose={() => setOpen(false)}
|
|
52
|
+
* />
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export declare function ReportLauncher({ reportId, variant, open, onClose, initialFilter: initialFilterOverride, fields: fieldsOverride, defaultTab, getFieldOptions, className, "data-size": size, }: ReportLauncherProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import "./ReportLauncher.css";
|
|
3
|
+
import { Button, Checkbox, Dialog, Dropdown, Heading, Tabs, Textfield } from "@digdir/designsystemet-react";
|
|
4
|
+
import { ChevronDownIcon, XMarkIcon } from "@navikt/aksel-icons";
|
|
5
|
+
import { convertFilter, createEmptyFilter, getLocalizedString, restoreParameterValues, serializeParameters, } from "@olenbetong/appframe-core";
|
|
6
|
+
import { useFilterFields, useReport, useReportRender } from "@olenbetong/appframe-react";
|
|
7
|
+
import clsx from "clsx";
|
|
8
|
+
import { useEffect, useId, useMemo, useState } from "react";
|
|
9
|
+
import { FilterBuilder } from "../filter/FilterBuilder.js";
|
|
10
|
+
import { ReportParameters } from "./ReportParameters.js";
|
|
11
|
+
/** The label shown on the save button for each format. */
|
|
12
|
+
const FORMAT_LABELS = {
|
|
13
|
+
CSV: "Save as CSV",
|
|
14
|
+
HTML: "Save as HTML",
|
|
15
|
+
IMAGE: "Save as image",
|
|
16
|
+
MHT: "Save as MHT",
|
|
17
|
+
PDF: "Save as PDF",
|
|
18
|
+
RTF: "Save as RTF",
|
|
19
|
+
TEXT: "Save as text",
|
|
20
|
+
XLS: "Save as XLS (Excel)",
|
|
21
|
+
XLSX: "Save as XLSX (Excel 2007)",
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* The web port of the Windows report launcher: the saved filters and criteria
|
|
25
|
+
* editor of the filter builder, the report's parameters, the report options,
|
|
26
|
+
* and the save/preview/print actions.
|
|
27
|
+
*
|
|
28
|
+
* Everything the launcher needs comes from the report itself, so a caller only
|
|
29
|
+
* has to name it. A report that does not resolve is one the current user has no
|
|
30
|
+
* access to — `sviw_WinClient_MyReports` is permission-resolved.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```jsx
|
|
34
|
+
* <ReportLauncher
|
|
35
|
+
* reportId="arpt_Production_ElementsDaily"
|
|
36
|
+
* open={open}
|
|
37
|
+
* initialFilter={`[ProjectID] = '${projectId}'`}
|
|
38
|
+
* onClose={() => setOpen(false)}
|
|
39
|
+
* />
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export function ReportLauncher({ reportId, variant = "dialog", open = true, onClose, initialFilter: initialFilterOverride, fields: fieldsOverride, defaultTab = "parameters", getFieldOptions, className, "data-size": size = "sm", }) {
|
|
43
|
+
let { report, parameters, initialFilter, defaultValues, loading, error } = useReport(reportId, {
|
|
44
|
+
initialFilter: initialFilterOverride,
|
|
45
|
+
});
|
|
46
|
+
let viewName = report?.viewName ?? undefined;
|
|
47
|
+
let { fields: loadedFields } = useFilterFields(fieldsOverride ? null : viewName);
|
|
48
|
+
let fields = fieldsOverride ?? loadedFields;
|
|
49
|
+
let { open: openReport, print, download, isRendering, progress, error: renderError } = useReportRender(reportId);
|
|
50
|
+
let [filter, setFilter] = useState(createEmptyFilter);
|
|
51
|
+
let [filterString, setFilterString] = useState("");
|
|
52
|
+
let [values, setValues] = useState({});
|
|
53
|
+
let [reportTitle, setReportTitle] = useState("");
|
|
54
|
+
let [headerText, setHeaderText] = useState("");
|
|
55
|
+
let [hideFilterString, setHideFilterString] = useState(false);
|
|
56
|
+
let [tab, setTab] = useState(defaultTab);
|
|
57
|
+
let panelId = useId();
|
|
58
|
+
// The report's own defaults arrive in two rounds — the literal ones first,
|
|
59
|
+
// then the ones a stored procedure produces — so they are copied into the
|
|
60
|
+
// form whenever they change rather than only once.
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
setValues(defaultValues);
|
|
63
|
+
}, [defaultValues]);
|
|
64
|
+
useEffect(() => {
|
|
65
|
+
setReportTitle(report?.title ?? "");
|
|
66
|
+
}, [report?.title]);
|
|
67
|
+
/*
|
|
68
|
+
* The initial filter is a criteria string, so it has to be parsed into a
|
|
69
|
+
* tree before the editor can show it.
|
|
70
|
+
*/
|
|
71
|
+
useEffect(() => {
|
|
72
|
+
if (!initialFilter) {
|
|
73
|
+
setFilter(createEmptyFilter());
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
let controller = new AbortController();
|
|
77
|
+
convertFilter({ filterString: initialFilter, viewName }, controller.signal)
|
|
78
|
+
.then((result) => {
|
|
79
|
+
if (!controller.signal.aborted)
|
|
80
|
+
setFilter(result.filterObject ?? createEmptyFilter());
|
|
81
|
+
})
|
|
82
|
+
.catch(() => {
|
|
83
|
+
// An initial filter the converter rejects is better dropped than
|
|
84
|
+
// blocking the launcher; the user can rebuild it.
|
|
85
|
+
});
|
|
86
|
+
return () => {
|
|
87
|
+
controller.abort();
|
|
88
|
+
};
|
|
89
|
+
}, [initialFilter, viewName]);
|
|
90
|
+
/** Selecting a saved filter restores the report options stored with it. */
|
|
91
|
+
function handleSelectFilter(saved) {
|
|
92
|
+
if (!saved) {
|
|
93
|
+
setValues(defaultValues);
|
|
94
|
+
setHeaderText("");
|
|
95
|
+
setHideFilterString(false);
|
|
96
|
+
setReportTitle(report?.title ?? "");
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
setValues(restoreParameterValues(parameters, saved.parameters));
|
|
100
|
+
setHeaderText(saved.headerText ?? "");
|
|
101
|
+
setHideFilterString(saved.hideCriteria);
|
|
102
|
+
setReportTitle(saved.reportTitle ?? report?.title ?? "");
|
|
103
|
+
}
|
|
104
|
+
let saveValues = useMemo(() => ({
|
|
105
|
+
headerText: headerText || null,
|
|
106
|
+
hideCriteria: hideFilterString,
|
|
107
|
+
parameters: parameters.length > 0 ? serializeParameters(parameters, values) : null,
|
|
108
|
+
}), [headerText, hideFilterString, parameters, values]);
|
|
109
|
+
let formats = report?.formats ?? [];
|
|
110
|
+
// PDF is the only format worth previewing or printing in place; the rest are
|
|
111
|
+
// downloads whatever the browser is asked to do with them.
|
|
112
|
+
let canPreview = formats.includes("PDF");
|
|
113
|
+
function getRenderOptions(format) {
|
|
114
|
+
return {
|
|
115
|
+
format,
|
|
116
|
+
fileName: reportTitle || report?.title || reportId,
|
|
117
|
+
filter: filterString,
|
|
118
|
+
parameters: values,
|
|
119
|
+
headerText: report?.hasHeader ? headerText : null,
|
|
120
|
+
hideFilterString,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
function run(action, format) {
|
|
124
|
+
void action(getRenderOptions(format));
|
|
125
|
+
}
|
|
126
|
+
/*
|
|
127
|
+
* The parameters and the criteria are too much to show at once, so they get
|
|
128
|
+
* a tab each. The report options stay below the tabs: they apply to the
|
|
129
|
+
* report whichever tab is open, and the hide-criteria flag in particular
|
|
130
|
+
* reads as belonging to both.
|
|
131
|
+
*/
|
|
132
|
+
let options = (_jsxs("div", { className: "ObReportLauncher-options", children: [report?.hasTitle && (_jsx(Textfield, { "data-size": size, label: getLocalizedString("Report name"), description: getLocalizedString("Used as the file name when the report is saved."), value: reportTitle, onChange: (event) => setReportTitle(event.target.value) })), report?.hasHeader && (_jsx(Textfield, { "data-size": size, multiline: true, rows: 2, label: getLocalizedString("Optional text (at the top of every page)"), value: headerText, onChange: (event) => setHeaderText(event.target.value) })), _jsx(Checkbox, { "data-size": size, label: getLocalizedString("Do not show the filter criteria at the top of the pages"), checked: hideFilterString, onChange: (event) => setHideFilterString(event.currentTarget.checked) })] }));
|
|
133
|
+
let actions = (_jsxs("div", { className: "ObReportLauncher-actions", children: [isRendering && (_jsx("span", { className: "ObReportLauncher-progress", children: progress?.bytesReceived
|
|
134
|
+
? `${Math.round(progress.bytesReceived / 1024)} kB`
|
|
135
|
+
: getLocalizedString("Rendering...") })), formats.length > 0 && (_jsxs("div", { className: "ObReportLauncher-saveGroup", children: [_jsx(Button, { type: "button", "data-size": size, disabled: isRendering, onClick: () => run(download, formats[0]), children: getLocalizedString(FORMAT_LABELS[formats[0]]) }), formats.length > 1 && (_jsxs(Dropdown.TriggerContext, { children: [_jsx(Dropdown.Trigger, { "data-size": size, icon: true, disabled: isRendering, "aria-label": getLocalizedString("More formats"), children: _jsx(ChevronDownIcon, { "aria-hidden": true }) }), _jsx(Dropdown, { children: _jsx(Dropdown.List, { children: formats.slice(1).map((format) => (_jsx(Dropdown.Item, { children: _jsx(Dropdown.Button, { onClick: () => run(download, format), children: getLocalizedString(FORMAT_LABELS[format]) }) }, format))) }) })] }))] })), _jsx(Button, { type: "button", variant: "secondary", "data-size": size, disabled: !canPreview || isRendering, onClick: () => run(openReport, "PDF"), children: getLocalizedString("Preview") }), _jsx(Button, { type: "button", variant: "secondary", "data-size": size, disabled: !canPreview || isRendering, onClick: () => run(print, "PDF"), children: getLocalizedString("Print") }), _jsx(Button, { type: "button", variant: "tertiary", "data-size": size, onClick: onClose, children: getLocalizedString("Close") })] }));
|
|
136
|
+
let content = (_jsxs("div", { className: clsx("ObReportLauncher-root", className), "data-size": size, children: [loading && _jsx("p", { className: "ObReportLauncher-status", children: getLocalizedString("Loading...") }), !loading && !report && (_jsx("p", { className: "ObReportLauncher-error", role: "alert", children: error
|
|
137
|
+
? error.message
|
|
138
|
+
: getLocalizedString("The report does not exist, or you do not have access to run it.") })), report && (_jsx(FilterBuilder, { fields: fields, viewName: viewName, reportId: reportId, getFieldOptions: getFieldOptions, variant: "inline", value: filter, "data-size": size, actions: actions, saveValues: saveValues, onChange: setFilter, onFilterStringChange: setFilterString, onSelect: handleSelectFilter, renderMain: (editor) => (_jsxs("div", { className: "ObReportLauncher-main", children: [_jsx(Tabs, { value: tab, "data-size": size, className: "ObReportLauncher-tabs", onChange: (value) => setTab(value), children: _jsxs(Tabs.List, { children: [_jsx(Tabs.Tab, { value: "parameters", "aria-controls": `${panelId}-parameters`, children: parameters.length > 0 ? getLocalizedString("Parameters") : getLocalizedString("Report") }), _jsx(Tabs.Tab, { value: "filter", "aria-controls": `${panelId}-filter`, children: getLocalizedString("Filter") })] }) }), tab === "parameters" ? (_jsx("div", { role: "tabpanel", id: `${panelId}-parameters`, className: "ObReportLauncher-panel ObReportLauncher-panel--scroll", children: parameters.length > 0 ? (_jsx(ReportParameters, { parameters: parameters, values: values, onChange: setValues, legend: null, "data-size": size })) : (_jsx("p", { className: "ObReportLauncher-status", children: getLocalizedString("The report has no parameters.") })) })) : (_jsx("div", { role: "tabpanel", id: `${panelId}-filter`, className: "ObReportLauncher-panel", children: editor })), options] })) })), renderError && (_jsx("p", { className: "ObReportLauncher-error", role: "alert", children: renderError.message }))] }));
|
|
139
|
+
if (variant === "inline")
|
|
140
|
+
return content;
|
|
141
|
+
return (_jsxs(Dialog, { open: open, closedby: "closerequest", closeButton: false, "data-size": size, className: "ObReportLauncher-dialog", onClose: onClose, children: [_jsxs(Dialog.Block, { className: "ObReportLauncher-dialogHeader", children: [_jsxs(Heading, { level: 2, "data-size": "xs", children: [getLocalizedString("Report"), ": ", report?.title ?? reportId, report?.shortId !== null && report?.shortId !== undefined && ` (ID: ${report.shortId})`] }), _jsx(Button, { type: "button", variant: "tertiary", "data-color": "neutral", "data-size": size, icon: true, "aria-label": getLocalizedString("Close"), onClick: onClose, children: _jsx(XMarkIcon, { "aria-hidden": true }) })] }), _jsx(Dialog.Block, { className: "ObReportLauncher-dialogBody", children: content })] }));
|
|
142
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|