@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.
Files changed (128) hide show
  1. package/dist/styles/styles.css.map +1 -1
  2. package/es/chrome/AppShell/index.d.ts +8 -0
  3. package/es/chrome/AppShell/index.js +10 -130
  4. package/es/components/ImageEditor/ImageEditor.css +10 -0
  5. package/es/components/ImageEditor/ImageEditor.d.ts +12 -0
  6. package/es/components/ImageEditor/ImageEditor.js +27 -6
  7. package/es/components/ImageEditor/index.d.ts +3 -0
  8. package/es/components/ImageEditor/index.js +3 -0
  9. package/es/components/ImageEditor/plugins/cropPlugin/CropOverlay.js +27 -5
  10. package/es/components/ImageEditor/plugins/cropPlugin/CropToolbar.js +4 -3
  11. package/es/components/ImageEditor/plugins/cropPlugin/useCropTool.d.ts +20 -3
  12. package/es/components/ImageEditor/plugins/cropPlugin/useCropTool.js +216 -33
  13. package/es/components/ImageEditor/plugins/zoomPlugin/ZoomContext.d.ts +5 -0
  14. package/es/components/ImageEditor/plugins/zoomPlugin/ZoomContext.js +7 -0
  15. package/es/components/ImageEditor/plugins/zoomPlugin/ZoomControls.js +1 -1
  16. package/es/components/ImageEditor/useEdgeDetection.d.ts +0 -2
  17. package/es/components/ImageEditor/useEdgeDetection.js +11 -30
  18. package/es/components/ImageEditor/useImageHistory.d.ts +6 -1
  19. package/es/components/ImageEditor/useImageHistory.js +21 -23
  20. package/es/components/ImageEditor/useOpenCV.d.ts +26 -1
  21. package/es/components/ImageEditor/useOpenCV.js +108 -42
  22. package/es/components/SplitContainer/index.js +2 -4
  23. package/es/elements/ElementDamage/DamageFormButtons.d.ts +2 -3
  24. package/es/elements/ElementDamage/DamageFormButtons.js +1 -1
  25. package/es/elements/ElementDamage/TransportElementSelect.d.ts +1 -2
  26. package/es/elements/index.d.ts +5 -0
  27. package/es/elements/index.js +5 -0
  28. package/es/filter/ChipListInput.d.ts +13 -0
  29. package/es/filter/ChipListInput.js +34 -0
  30. package/es/filter/FilterBuilder.css +152 -0
  31. package/es/filter/FilterBuilder.d.ts +115 -0
  32. package/es/filter/FilterBuilder.js +146 -0
  33. package/es/filter/FilterBuilder.test.d.ts +1 -0
  34. package/es/filter/FilterBuilder.test.js +120 -0
  35. package/es/filter/FilterEditor.css +231 -0
  36. package/es/filter/FilterEditor.d.ts +17 -0
  37. package/es/filter/FilterEditor.js +38 -0
  38. package/es/filter/FilterEditor.test.d.ts +1 -0
  39. package/es/filter/FilterEditor.test.js +183 -0
  40. package/es/filter/FilterGroupEditor.d.ts +22 -0
  41. package/es/filter/FilterGroupEditor.js +34 -0
  42. package/es/filter/FilterNameDialog.css +22 -0
  43. package/es/filter/FilterNameDialog.d.ts +18 -0
  44. package/es/filter/FilterNameDialog.js +32 -0
  45. package/es/filter/FilterRow.d.ts +14 -0
  46. package/es/filter/FilterRow.js +32 -0
  47. package/es/filter/FilterShareDialog.css +28 -0
  48. package/es/filter/FilterShareDialog.d.ts +23 -0
  49. package/es/filter/FilterShareDialog.js +63 -0
  50. package/es/filter/FilterStringField.d.ts +15 -0
  51. package/es/filter/FilterStringField.js +37 -0
  52. package/es/filter/FilterValueEditor.d.ts +16 -0
  53. package/es/filter/FilterValueEditor.js +85 -0
  54. package/es/filter/SavedFilterTree.css +107 -0
  55. package/es/filter/SavedFilterTree.d.ts +45 -0
  56. package/es/filter/SavedFilterTree.js +44 -0
  57. package/es/filter/SavedFilterTree.test.d.ts +1 -0
  58. package/es/filter/SavedFilterTree.test.js +75 -0
  59. package/es/filter/index.d.ts +11 -0
  60. package/es/filter/index.js +10 -0
  61. package/es/filter/types.d.ts +34 -0
  62. package/es/filter/types.js +1 -0
  63. package/es/index.d.ts +2 -1
  64. package/es/index.js +6 -1
  65. package/es/mui/MuiThemeProvider.d.ts +24 -0
  66. package/es/mui/MuiThemeProvider.js +152 -0
  67. package/es/mui/index.d.ts +1 -0
  68. package/es/mui/index.js +1 -0
  69. package/es/report/ReportLauncher.css +147 -0
  70. package/es/report/ReportLauncher.d.ts +55 -0
  71. package/es/report/ReportLauncher.js +142 -0
  72. package/es/report/ReportLauncher.test.d.ts +1 -0
  73. package/es/report/ReportLauncher.test.js +231 -0
  74. package/es/report/ReportParameters.css +29 -0
  75. package/es/report/ReportParameters.d.ts +46 -0
  76. package/es/report/ReportParameters.js +65 -0
  77. package/es/report/ReportParameters.test.d.ts +1 -0
  78. package/es/report/ReportParameters.test.js +84 -0
  79. package/es/report/index.d.ts +2 -0
  80. package/es/report/index.js +2 -0
  81. package/es/test/setup.d.ts +1 -0
  82. package/es/test/setup.js +6 -0
  83. package/package.json +22 -7
  84. package/src/chrome/AppShell/index.tsx +34 -171
  85. package/src/components/ImageEditor/ImageEditor.css +10 -0
  86. package/src/components/ImageEditor/ImageEditor.tsx +40 -5
  87. package/src/components/ImageEditor/index.ts +1 -0
  88. package/src/components/ImageEditor/plugins/cropPlugin/CropOverlay.tsx +66 -20
  89. package/src/components/ImageEditor/plugins/cropPlugin/CropToolbar.tsx +19 -3
  90. package/src/components/ImageEditor/plugins/cropPlugin/useCropTool.ts +266 -39
  91. package/src/components/ImageEditor/plugins/zoomPlugin/ZoomContext.tsx +8 -0
  92. package/src/components/ImageEditor/useEdgeDetection.ts +11 -51
  93. package/src/components/ImageEditor/useImageHistory.ts +27 -19
  94. package/src/components/ImageEditor/useOpenCV.ts +112 -62
  95. package/src/components/LinkedCardList/index.scss +4 -2
  96. package/src/components/ProgressBar/index.scss +4 -2
  97. package/src/components/SplitContainer/index.tsx +3 -4
  98. package/src/filter/ChipListInput.tsx +79 -0
  99. package/src/filter/FilterBuilder.css +152 -0
  100. package/src/filter/FilterBuilder.test.tsx +153 -0
  101. package/src/filter/FilterBuilder.tsx +435 -0
  102. package/src/filter/FilterEditor.css +231 -0
  103. package/src/filter/FilterEditor.test.tsx +259 -0
  104. package/src/filter/FilterEditor.tsx +74 -0
  105. package/src/filter/FilterGroupEditor.tsx +160 -0
  106. package/src/filter/FilterNameDialog.css +22 -0
  107. package/src/filter/FilterNameDialog.tsx +81 -0
  108. package/src/filter/FilterRow.tsx +117 -0
  109. package/src/filter/FilterShareDialog.css +28 -0
  110. package/src/filter/FilterShareDialog.tsx +201 -0
  111. package/src/filter/FilterStringField.tsx +77 -0
  112. package/src/filter/FilterValueEditor.tsx +220 -0
  113. package/src/filter/SavedFilterTree.css +107 -0
  114. package/src/filter/SavedFilterTree.test.tsx +94 -0
  115. package/src/filter/SavedFilterTree.tsx +222 -0
  116. package/src/filter/index.ts +11 -0
  117. package/src/filter/types.ts +38 -0
  118. package/src/index.ts +39 -1
  119. package/src/mui/MuiThemeProvider.tsx +174 -0
  120. package/src/mui/index.ts +1 -0
  121. package/src/report/ReportLauncher.css +147 -0
  122. package/src/report/ReportLauncher.test.tsx +281 -0
  123. package/src/report/ReportLauncher.tsx +421 -0
  124. package/src/report/ReportParameters.css +29 -0
  125. package/src/report/ReportParameters.test.tsx +133 -0
  126. package/src/report/ReportParameters.tsx +198 -0
  127. package/src/report/index.ts +2 -0
  128. package/src/test/setup.ts +8 -0
@@ -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 {};
@@ -0,0 +1,231 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
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
+ const download = vi.fn(async () => undefined);
6
+ const openRendered = vi.fn(async () => undefined);
7
+ const print = vi.fn(async () => undefined);
8
+ const save = vi.fn(async () => undefined);
9
+ const convertFilter = vi.fn(async () => ({ filterObject: null, filterString: "", whereClause: "" }));
10
+ let report = null;
11
+ let parameters = [];
12
+ let defaultValues = {};
13
+ let savedFilters = [];
14
+ let initialFilter = null;
15
+ vi.mock("@olenbetong/appframe-core", async (importOriginal) => ({
16
+ ...(await importOriginal()),
17
+ convertFilter: (...args) => convertFilter(...args),
18
+ }));
19
+ vi.mock("@olenbetong/appframe-react", async (importOriginal) => ({
20
+ ...(await importOriginal()),
21
+ setNamedFilter: vi.fn(),
22
+ useFilterFields: () => ({ fields: [], loading: false, error: null, refresh: vi.fn() }),
23
+ useFilterConversion: () => ({
24
+ filterString: "[ProjectID] = 1",
25
+ isConverting: false,
26
+ error: null,
27
+ parseFilterString: vi.fn(async () => null),
28
+ }),
29
+ useReport: () => ({
30
+ report,
31
+ parameters,
32
+ initialFilter,
33
+ defaultValues,
34
+ loading: false,
35
+ error: null,
36
+ refresh: vi.fn(),
37
+ }),
38
+ useReportRender: () => ({
39
+ open: openRendered,
40
+ print,
41
+ download,
42
+ render: vi.fn(),
43
+ cancel: vi.fn(),
44
+ isRendering: false,
45
+ progress: null,
46
+ error: null,
47
+ }),
48
+ useSavedFilters: () => ({
49
+ filters: savedFilters,
50
+ mine: savedFilters,
51
+ shared: [],
52
+ loading: false,
53
+ error: null,
54
+ refresh: vi.fn(),
55
+ save,
56
+ rename: vi.fn(),
57
+ remove: vi.fn(),
58
+ setCrossDomain: vi.fn(),
59
+ }),
60
+ }));
61
+ const { ReportLauncher } = await import("./ReportLauncher.js");
62
+ function makeReport(overrides = {}) {
63
+ return {
64
+ reportId: "arpt_Test_Report",
65
+ shortId: 4711,
66
+ title: "Test report",
67
+ description: null,
68
+ viewName: "aviw_Test_View",
69
+ initialFilter: null,
70
+ hasTitle: true,
71
+ hasHeader: true,
72
+ formats: ["PDF", "XLSX"],
73
+ timeout: null,
74
+ ...overrides,
75
+ };
76
+ }
77
+ function savedFilter(overrides = {}) {
78
+ return {
79
+ filterId: 1,
80
+ primKey: "pk-1",
81
+ name: "Mitt filter",
82
+ criteria: "[ProjectID] = 1",
83
+ dbObjectId: "aviw_Test_View",
84
+ accessLevel: "Manager",
85
+ createdByUser: true,
86
+ createdBy: "bvh",
87
+ domain: "OB",
88
+ crossDomain: false,
89
+ isPersonallyShared: false,
90
+ hideCriteria: true,
91
+ headerText: "Lagret overskrift",
92
+ comment: null,
93
+ parameters: '<Parameters Version="1"><Parameter Name="Period" Type="Integer">202601</Parameter></Parameters>',
94
+ reportTitle: null,
95
+ created: null,
96
+ updated: null,
97
+ ...overrides,
98
+ };
99
+ }
100
+ function numberParameter(overrides = {}) {
101
+ return {
102
+ name: "Period",
103
+ label: "Periode",
104
+ description: null,
105
+ type: "Integer",
106
+ editor: "number",
107
+ defaultValue: null,
108
+ items: [],
109
+ recordSource: null,
110
+ valueMember: null,
111
+ displayMember: null,
112
+ sortOrder: 0,
113
+ lookupWidth: null,
114
+ lookupHeight: null,
115
+ ...overrides,
116
+ };
117
+ }
118
+ function renderLauncher(props = {}) {
119
+ return render(_jsx(ReportLauncher, { reportId: "arpt_Test_Report", variant: "inline", ...props }));
120
+ }
121
+ describe("ReportLauncher", () => {
122
+ beforeEach(() => {
123
+ vi.clearAllMocks();
124
+ report = makeReport();
125
+ parameters = [];
126
+ defaultValues = {};
127
+ savedFilters = [];
128
+ initialFilter = null;
129
+ });
130
+ it("tells the user when the report is not available to them", () => {
131
+ report = null;
132
+ renderLauncher();
133
+ expect(screen.getByRole("alert").textContent).toContain("do not have access");
134
+ });
135
+ it("shows the report option fields the report has bands for", () => {
136
+ renderLauncher();
137
+ expect(screen.getByLabelText("Report name")).toHaveValue("Test report");
138
+ expect(screen.getByLabelText("Optional text (at the top of every page)")).toBeInTheDocument();
139
+ });
140
+ it("puts the parameters and the criteria in a tab each, with the options below both", async () => {
141
+ parameters = [numberParameter()];
142
+ defaultValues = { Period: null };
143
+ renderLauncher();
144
+ expect(screen.getByLabelText("Periode")).toBeInTheDocument();
145
+ expect(screen.queryByLabelText("Filter string")).toBeNull();
146
+ await userEvent.click(screen.getByText("Filter"));
147
+ expect(screen.queryByLabelText("Periode")).toBeNull();
148
+ expect(screen.getByLabelText("Filter string")).toBeInTheDocument();
149
+ // The options apply to the report whichever tab is open.
150
+ expect(screen.getByLabelText("Report name")).toBeInTheDocument();
151
+ });
152
+ it("can start on the filter tab", () => {
153
+ parameters = [numberParameter()];
154
+ renderLauncher({ defaultTab: "filter" });
155
+ expect(screen.getByLabelText("Filter string")).toBeInTheDocument();
156
+ expect(screen.queryByLabelText("Periode")).toBeNull();
157
+ });
158
+ it("names the report and its number in the dialog heading", () => {
159
+ render(_jsx(ReportLauncher, { reportId: "arpt_Test_Report" }));
160
+ expect(screen.getByRole("heading").textContent).toBe("Report: Test report (ID: 4711)");
161
+ });
162
+ it("hides the title and header fields when the report has no such bands", () => {
163
+ report = makeReport({ hasTitle: false, hasHeader: false });
164
+ renderLauncher();
165
+ expect(screen.queryByLabelText("Report name")).toBeNull();
166
+ expect(screen.queryByLabelText("Optional text (at the top of every page)")).toBeNull();
167
+ });
168
+ it("offers the report's first format on the save button and the rest in a menu", async () => {
169
+ renderLauncher();
170
+ await userEvent.click(screen.getByRole("button", { name: "Save as PDF" }));
171
+ expect(download).toHaveBeenCalledWith(expect.objectContaining({ format: "PDF", fileName: "Test report", filter: "[ProjectID] = 1" }));
172
+ expect(screen.getByRole("button", { name: "More formats" })).toBeInTheDocument();
173
+ });
174
+ it("does not offer a format menu for a report with a single format", () => {
175
+ report = makeReport({ formats: ["PDF"] });
176
+ renderLauncher();
177
+ expect(screen.queryByRole("button", { name: "More formats" })).toBeNull();
178
+ });
179
+ it("previews and prints as PDF", async () => {
180
+ renderLauncher();
181
+ await userEvent.click(screen.getByRole("button", { name: "Preview" }));
182
+ await userEvent.click(screen.getByRole("button", { name: "Print" }));
183
+ expect(openRendered).toHaveBeenCalledWith(expect.objectContaining({ format: "PDF" }));
184
+ expect(print).toHaveBeenCalledWith(expect.objectContaining({ format: "PDF" }));
185
+ });
186
+ it("cannot preview or print a report that has no PDF format", () => {
187
+ report = makeReport({ formats: ["CSV"] });
188
+ renderLauncher();
189
+ expect(screen.getByRole("button", { name: "Preview" }).hasAttribute("disabled")).toBe(true);
190
+ expect(screen.getByRole("button", { name: "Print" }).hasAttribute("disabled")).toBe(true);
191
+ });
192
+ it("sends the header text and the hide-criteria flag with the render", async () => {
193
+ renderLauncher();
194
+ await userEvent.type(screen.getByLabelText("Optional text (at the top of every page)"), "Hei");
195
+ await userEvent.click(screen.getByLabelText("Do not show the filter criteria at the top of the pages"));
196
+ await userEvent.click(screen.getByRole("button", { name: "Save as PDF" }));
197
+ expect(download).toHaveBeenCalledWith(expect.objectContaining({ headerText: "Hei", hideFilterString: true }));
198
+ });
199
+ it("restores the report options stored with a saved filter", async () => {
200
+ parameters = [numberParameter()];
201
+ defaultValues = { Period: null };
202
+ savedFilters = [savedFilter()];
203
+ renderLauncher();
204
+ await userEvent.click(screen.getByRole("button", { name: "Mitt filter" }));
205
+ await waitFor(() => expect(screen.getByLabelText("Periode")).toHaveValue(202601));
206
+ expect(screen.getByLabelText("Optional text (at the top of every page)")).toHaveValue("Lagret overskrift");
207
+ expect(screen.getByLabelText("Do not show the filter criteria at the top of the pages").checked).toBe(true);
208
+ });
209
+ it("stores the report options on the filter when it is saved", async () => {
210
+ parameters = [];
211
+ // "Save as" is only offered for a filter with conditions, so the launcher
212
+ // starts from the report's own filter.
213
+ convertFilter.mockResolvedValue({
214
+ filterObject: {
215
+ type: "group",
216
+ mode: "and",
217
+ items: [{ type: "expression", column: "ProjectID", operator: "equals", value: 1, valueType: "number" }],
218
+ },
219
+ filterString: "[ProjectID] = 1",
220
+ whereClause: "",
221
+ });
222
+ initialFilter = "[ProjectID] = 1";
223
+ renderLauncher();
224
+ await userEvent.type(screen.getByLabelText("Optional text (at the top of every page)"), "Hei");
225
+ await userEvent.click(screen.getByRole("button", { name: "Save as" }));
226
+ let dialog = screen.getByRole("dialog");
227
+ await userEvent.type(within(dialog).getByRole("textbox", { name: "Filter name" }), "Nytt filter");
228
+ await userEvent.click(within(dialog).getByRole("button", { name: "Save" }));
229
+ await waitFor(() => expect(save).toHaveBeenCalledWith(expect.objectContaining({ headerText: "Hei", hideCriteria: false })));
230
+ });
231
+ });
@@ -0,0 +1,29 @@
1
+ .ObReportParameters-root {
2
+ margin: 0;
3
+ padding: 0;
4
+ border: none;
5
+ min-inline-size: 0;
6
+ }
7
+
8
+ .ObReportParameters-legend {
9
+ padding: 0;
10
+ margin-block-end: var(--ds-size-2);
11
+ font-size: var(--ds-font-size-3);
12
+ font-weight: var(--ds-font-weight-medium);
13
+ }
14
+
15
+ /*
16
+ * The parameters are stacked rather than laid out in columns: a report has a
17
+ * handful at most, and a single column keeps them readable next to the report
18
+ * options below them.
19
+ */
20
+ .ObReportParameters-grid {
21
+ display: flex;
22
+ flex-direction: column;
23
+ gap: var(--ds-size-3);
24
+ align-items: stretch;
25
+ }
26
+
27
+ .ObReportParameters-field {
28
+ min-inline-size: 0;
29
+ }
@@ -0,0 +1,46 @@
1
+ import "./ReportParameters.css";
2
+ import { type ReportParameter, type ReportParameterValue, type ReportParameterValues } from "@olenbetong/appframe-core";
3
+ import type { FilterEditorSize } from "../filter/types.js";
4
+ export type ReportParametersProps = {
5
+ /** The report's parameters, from `useReport`. */
6
+ parameters: ReportParameter[];
7
+ /** Current values, by parameter name. */
8
+ values: ReportParameterValues;
9
+ onChange: (values: ReportParameterValues) => void;
10
+ readOnly?: boolean;
11
+ /** Heading above the parameters. Pass `null` to render none. */
12
+ legend?: string | null;
13
+ className?: string;
14
+ "data-size"?: FilterEditorSize;
15
+ };
16
+ /**
17
+ * The parameter form of the report launcher.
18
+ *
19
+ * Reports rarely have parameters, so this renders nothing at all when the list
20
+ * is empty and the launcher can include it unconditionally.
21
+ *
22
+ * Each parameter gets the editor its metadata asks for: a lookup combobox when
23
+ * it is backed by a record source, a select when it has a fixed item list, and
24
+ * otherwise an editor for its data type. Values are coerced to the parameter's
25
+ * type as they are entered, so what the caller holds is what gets sent to the
26
+ * report.
27
+ *
28
+ * @example
29
+ * ```jsx
30
+ * let { parameters, defaultValues } = useReport(reportId);
31
+ * let [values, setValues] = useState(defaultValues);
32
+ *
33
+ * <ReportParameters parameters={parameters} values={values} onChange={setValues} />
34
+ * ```
35
+ */
36
+ export declare function ReportParameters({ parameters, values, onChange, readOnly, legend, className, "data-size": size, }: ReportParametersProps): import("react").JSX.Element | null;
37
+ type ReportParameterFieldProps = {
38
+ parameter: ReportParameter;
39
+ value: ReportParameterValue;
40
+ onChange: (value: ReportParameterValue) => void;
41
+ readOnly?: boolean;
42
+ size: FilterEditorSize;
43
+ };
44
+ /** The editor for a single parameter. */
45
+ export declare function ReportParameterField({ parameter, value, onChange, readOnly, size }: ReportParameterFieldProps): import("react").JSX.Element;
46
+ export {};