@olenbetong/synergi-react 3.2.1 → 4.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 +10 -2
- package/es/chrome/AppShell/index.js +13 -97
- package/es/chrome/openReport.d.ts +22 -0
- package/es/chrome/openReport.js +21 -0
- package/es/colorScheme.d.ts +4 -4
- package/es/components/Toolbar/index.d.ts +20 -11
- package/es/components/Toolbar/index.js +47 -6
- package/es/elements/ElementLookup.d.ts +7 -2
- package/es/elements/ElementLookup.js +4 -6
- package/es/elements/ElementLookupDialog/BarcodeScanner/decoder.d.ts +32 -0
- package/es/elements/ElementLookupDialog/BarcodeScanner/decoders/dbr.d.ts +28 -0
- package/es/elements/ElementLookupDialog/BarcodeScanner/decoders/dbr.js +81 -0
- package/es/elements/ElementLookupDialog/BarcodeScanner/decoders/native.d.ts +26 -0
- package/es/elements/ElementLookupDialog/BarcodeScanner/decoders/native.js +70 -0
- package/es/elements/ElementLookupDialog/BarcodeScanner/decoders/zxing.d.ts +20 -0
- package/es/elements/ElementLookupDialog/BarcodeScanner/decoders/zxing.js +69 -0
- package/es/elements/ElementLookupDialog/BarcodeScanner/decoders.test.js +103 -0
- package/es/elements/ElementLookupDialog/BarcodeScanner/duplicateFilter.d.ts +6 -0
- package/es/elements/ElementLookupDialog/BarcodeScanner/duplicateFilter.js +19 -0
- package/es/elements/ElementLookupDialog/BarcodeScanner/index.d.ts +14 -7
- package/es/elements/ElementLookupDialog/BarcodeScanner/index.js +10 -6
- package/es/elements/ElementLookupDialog/BarcodeScanner/useScanner.d.ts +14 -12
- package/es/elements/ElementLookupDialog/BarcodeScanner/useScanner.js +222 -116
- package/es/elements/ElementLookupDialog/index.d.ts +6 -0
- package/es/elements/ElementLookupDialog/index.js +2 -2
- package/es/index.d.ts +3 -4
- package/es/index.js +5 -4
- package/package.json +11 -10
- package/src/chrome/AppShell/index.tsx +13 -134
- package/src/chrome/openReport.ts +34 -0
- package/src/colorScheme.ts +4 -4
- package/src/components/Toolbar/index.tsx +65 -14
- package/src/elements/ElementLookup.tsx +12 -5
- package/src/elements/ElementLookupDialog/BarcodeScanner/decoder.ts +32 -0
- package/src/elements/ElementLookupDialog/BarcodeScanner/decoders/dbr.ts +118 -0
- package/src/elements/ElementLookupDialog/BarcodeScanner/decoders/native.ts +103 -0
- package/src/elements/ElementLookupDialog/BarcodeScanner/decoders/zxing.ts +95 -0
- package/src/elements/ElementLookupDialog/BarcodeScanner/decoders.test.ts +118 -0
- package/src/elements/ElementLookupDialog/BarcodeScanner/duplicateFilter.ts +21 -0
- package/src/elements/ElementLookupDialog/BarcodeScanner/index.tsx +29 -14
- package/src/elements/ElementLookupDialog/BarcodeScanner/useScanner.ts +246 -136
- package/src/elements/ElementLookupDialog/index.tsx +12 -4
- package/src/index.ts +6 -37
- package/es/chrome/AppMenu/AppMenu.css +0 -648
- package/es/chrome/AppMenu/AppMenu.d.ts +0 -56
- package/es/chrome/AppMenu/AppMenu.js +0 -145
- package/es/chrome/AppMenu/AppMenuColorScheme.d.ts +0 -2
- package/es/chrome/AppMenu/AppMenuColorScheme.js +0 -18
- package/es/chrome/AppMenu/AppMenuFavoriteButton.d.ts +0 -18
- package/es/chrome/AppMenu/AppMenuFavoriteButton.js +0 -11
- package/es/chrome/AppMenu/AppMenuHeader.d.ts +0 -24
- package/es/chrome/AppMenu/AppMenuHeader.js +0 -18
- package/es/chrome/AppMenu/AppMenuList.d.ts +0 -18
- package/es/chrome/AppMenu/AppMenuList.js +0 -39
- package/es/chrome/AppMenu/AppMenuRail.d.ts +0 -26
- package/es/chrome/AppMenu/AppMenuRail.js +0 -30
- package/es/chrome/AppMenu/AppMenuToggle.d.ts +0 -15
- package/es/chrome/AppMenu/AppMenuToggle.js +0 -14
- package/es/chrome/AppMenu/AppMenuUserMenu.d.ts +0 -32
- package/es/chrome/AppMenu/AppMenuUserMenu.js +0 -110
- package/es/chrome/AppMenu/developerCategories.d.ts +0 -24
- package/es/chrome/AppMenu/developerCategories.js +0 -116
- package/es/chrome/AppMenu/icons.d.ts +0 -15
- package/es/chrome/AppMenu/icons.js +0 -13
- package/es/chrome/AppMenu/index.d.ts +0 -12
- package/es/chrome/AppMenu/index.js +0 -10
- package/es/chrome/AppMenu/menuEntries.d.ts +0 -51
- package/es/chrome/AppMenu/menuEntries.js +0 -93
- package/es/chrome/AppMenu/types.d.ts +0 -43
- package/es/chrome/AppMenu/useFavorites.d.ts +0 -13
- package/es/chrome/AppMenu/useFavorites.js +0 -28
- package/es/chrome/AppMenu/useRovingTabIndex.d.ts +0 -28
- package/es/chrome/AppMenu/useRovingTabIndex.js +0 -114
- package/es/chrome/AppMenu/useServiceWorkerUpdate.d.ts +0 -16
- package/es/chrome/AppMenu/useServiceWorkerUpdate.js +0 -62
- package/es/report/ReportLauncher.css +0 -147
- package/es/report/ReportLauncher.d.ts +0 -55
- package/es/report/ReportLauncher.js +0 -142
- package/es/report/ReportLauncher.test.js +0 -231
- package/es/report/ReportParameters.css +0 -29
- package/es/report/ReportParameters.d.ts +0 -46
- package/es/report/ReportParameters.js +0 -65
- package/es/report/ReportParameters.test.d.ts +0 -1
- package/es/report/ReportParameters.test.js +0 -84
- package/es/report/index.d.ts +0 -2
- package/es/report/index.js +0 -2
- package/src/chrome/AppMenu/AppMenu.css +0 -648
- package/src/chrome/AppMenu/AppMenu.tsx +0 -285
- package/src/chrome/AppMenu/AppMenuColorScheme.tsx +0 -41
- package/src/chrome/AppMenu/AppMenuFavoriteButton.tsx +0 -47
- package/src/chrome/AppMenu/AppMenuHeader.tsx +0 -79
- package/src/chrome/AppMenu/AppMenuList.tsx +0 -89
- package/src/chrome/AppMenu/AppMenuRail.tsx +0 -117
- package/src/chrome/AppMenu/AppMenuToggle.tsx +0 -51
- package/src/chrome/AppMenu/AppMenuUserMenu.tsx +0 -190
- package/src/chrome/AppMenu/developerCategories.ts +0 -142
- package/src/chrome/AppMenu/icons.tsx +0 -76
- package/src/chrome/AppMenu/index.ts +0 -17
- package/src/chrome/AppMenu/menuEntries.ts +0 -128
- package/src/chrome/AppMenu/types.ts +0 -45
- package/src/chrome/AppMenu/useFavorites.ts +0 -40
- package/src/chrome/AppMenu/useRovingTabIndex.ts +0 -130
- package/src/chrome/AppMenu/useServiceWorkerUpdate.ts +0 -68
- package/src/report/ReportLauncher.css +0 -147
- package/src/report/ReportLauncher.test.tsx +0 -281
- package/src/report/ReportLauncher.tsx +0 -420
- package/src/report/ReportParameters.css +0 -29
- package/src/report/ReportParameters.test.tsx +0 -133
- package/src/report/ReportParameters.tsx +0 -198
- package/src/report/index.ts +0 -2
- /package/es/{chrome/AppMenu/types.js → elements/ElementLookupDialog/BarcodeScanner/decoder.js} +0 -0
- /package/es/{report/ReportLauncher.test.d.ts → elements/ElementLookupDialog/BarcodeScanner/decoders.test.d.ts} +0 -0
|
@@ -1,420 +0,0 @@
|
|
|
1
|
-
import "./ReportLauncher.css";
|
|
2
|
-
|
|
3
|
-
import { Button, Checkbox, Dialog, Dropdown, Heading, Tabs, Textfield } from "@digdir/designsystemet-react";
|
|
4
|
-
import { ChevronDownIcon, XMarkIcon } from "@navikt/aksel-icons";
|
|
5
|
-
import {
|
|
6
|
-
convertFilter,
|
|
7
|
-
createEmptyFilter,
|
|
8
|
-
type FieldMetadata,
|
|
9
|
-
type FilterTree,
|
|
10
|
-
getLocalizedString,
|
|
11
|
-
type ReportFormat,
|
|
12
|
-
type ReportParameterValues,
|
|
13
|
-
restoreParameterValues,
|
|
14
|
-
type SavedFilter,
|
|
15
|
-
serializeParameters,
|
|
16
|
-
} from "@olenbetong/appframe-core";
|
|
17
|
-
import { useFilterFields, useReport, useReportRender } from "@olenbetong/appframe-react";
|
|
18
|
-
import clsx from "clsx";
|
|
19
|
-
import { useEffect, useId, useMemo, useState } from "react";
|
|
20
|
-
|
|
21
|
-
import { FilterBuilder, type FilterEditorSize, type GetFieldOptions } from "@olenbetong/appframe-ds";
|
|
22
|
-
import { ReportParameters } from "./ReportParameters.js";
|
|
23
|
-
|
|
24
|
-
/** The label shown on the save button for each format. */
|
|
25
|
-
const FORMAT_LABELS: Record<ReportFormat, string> = {
|
|
26
|
-
CSV: "Save as CSV",
|
|
27
|
-
HTML: "Save as HTML",
|
|
28
|
-
IMAGE: "Save as image",
|
|
29
|
-
MHT: "Save as MHT",
|
|
30
|
-
PDF: "Save as PDF",
|
|
31
|
-
RTF: "Save as RTF",
|
|
32
|
-
TEXT: "Save as text",
|
|
33
|
-
XLS: "Save as XLS (Excel)",
|
|
34
|
-
XLSX: "Save as XLSX (Excel 2007)",
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
export type ReportLauncherTab = "parameters" | "filter";
|
|
38
|
-
|
|
39
|
-
export type ReportLauncherProps = {
|
|
40
|
-
/** The report to run, e.g. `arpt_Personnel_Persons`. */
|
|
41
|
-
reportId: string;
|
|
42
|
-
/**
|
|
43
|
-
* `"dialog"` wraps the launcher in a modal, `"inline"` renders it in place.
|
|
44
|
-
* @default "dialog"
|
|
45
|
-
*/
|
|
46
|
-
variant?: "dialog" | "inline";
|
|
47
|
-
/** Whether the dialog is open. Ignored when `variant` is `"inline"`. */
|
|
48
|
-
open?: boolean;
|
|
49
|
-
/** Called when the launcher is dismissed. */
|
|
50
|
-
onClose?: () => void;
|
|
51
|
-
/**
|
|
52
|
-
* Overrides the filter the report was designed with, as a criteria string.
|
|
53
|
-
* An empty string starts the launcher with no filter at all.
|
|
54
|
-
*/
|
|
55
|
-
initialFilter?: string | null;
|
|
56
|
-
/**
|
|
57
|
-
* The fields the filter can be built from. Loaded from the report's view
|
|
58
|
-
* when not supplied.
|
|
59
|
-
*/
|
|
60
|
-
fields?: FieldMetadata[];
|
|
61
|
-
/**
|
|
62
|
-
* The tab shown first.
|
|
63
|
-
* @default "parameters"
|
|
64
|
-
*/
|
|
65
|
-
defaultTab?: ReportLauncherTab;
|
|
66
|
-
getFieldOptions?: GetFieldOptions;
|
|
67
|
-
className?: string;
|
|
68
|
-
"data-size"?: FilterEditorSize;
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* The web port of the Windows report launcher: the saved filters and criteria
|
|
73
|
-
* editor of the filter builder, the report's parameters, the report options,
|
|
74
|
-
* and the save/preview/print actions.
|
|
75
|
-
*
|
|
76
|
-
* Everything the launcher needs comes from the report itself, so a caller only
|
|
77
|
-
* has to name it. A report that does not resolve is one the current user has no
|
|
78
|
-
* access to — `sviw_WinClient_MyReports` is permission-resolved.
|
|
79
|
-
*
|
|
80
|
-
* @example
|
|
81
|
-
* ```jsx
|
|
82
|
-
* <ReportLauncher
|
|
83
|
-
* reportId="arpt_Production_ElementsDaily"
|
|
84
|
-
* open={open}
|
|
85
|
-
* initialFilter={`[ProjectID] = '${projectId}'`}
|
|
86
|
-
* onClose={() => setOpen(false)}
|
|
87
|
-
* />
|
|
88
|
-
* ```
|
|
89
|
-
*/
|
|
90
|
-
export function ReportLauncher({
|
|
91
|
-
reportId,
|
|
92
|
-
variant = "dialog",
|
|
93
|
-
open = true,
|
|
94
|
-
onClose,
|
|
95
|
-
initialFilter: initialFilterOverride,
|
|
96
|
-
fields: fieldsOverride,
|
|
97
|
-
defaultTab = "parameters",
|
|
98
|
-
getFieldOptions,
|
|
99
|
-
className,
|
|
100
|
-
"data-size": size = "sm",
|
|
101
|
-
}: ReportLauncherProps) {
|
|
102
|
-
let { report, parameters, initialFilter, defaultValues, loading, error } = useReport(reportId, {
|
|
103
|
-
initialFilter: initialFilterOverride,
|
|
104
|
-
});
|
|
105
|
-
let viewName = report?.viewName ?? undefined;
|
|
106
|
-
let { fields: loadedFields } = useFilterFields(fieldsOverride ? null : viewName);
|
|
107
|
-
let fields = fieldsOverride ?? loadedFields;
|
|
108
|
-
let { open: openReport, print, download, isRendering, progress, error: renderError } = useReportRender(reportId);
|
|
109
|
-
|
|
110
|
-
let [filter, setFilter] = useState<FilterTree>(createEmptyFilter);
|
|
111
|
-
let [filterString, setFilterString] = useState("");
|
|
112
|
-
let [values, setValues] = useState<ReportParameterValues>({});
|
|
113
|
-
let [reportTitle, setReportTitle] = useState("");
|
|
114
|
-
let [headerText, setHeaderText] = useState("");
|
|
115
|
-
let [hideFilterString, setHideFilterString] = useState(false);
|
|
116
|
-
let [tab, setTab] = useState<ReportLauncherTab>(defaultTab);
|
|
117
|
-
let panelId = useId();
|
|
118
|
-
|
|
119
|
-
// The report's own defaults arrive in two rounds — the literal ones first,
|
|
120
|
-
// then the ones a stored procedure produces — so they are copied into the
|
|
121
|
-
// form whenever they change rather than only once.
|
|
122
|
-
useEffect(() => {
|
|
123
|
-
setValues(defaultValues);
|
|
124
|
-
}, [defaultValues]);
|
|
125
|
-
|
|
126
|
-
useEffect(() => {
|
|
127
|
-
setReportTitle(report?.title ?? "");
|
|
128
|
-
}, [report?.title]);
|
|
129
|
-
|
|
130
|
-
/*
|
|
131
|
-
* The initial filter is a criteria string, so it has to be parsed into a
|
|
132
|
-
* tree before the editor can show it.
|
|
133
|
-
*/
|
|
134
|
-
useEffect(() => {
|
|
135
|
-
if (!initialFilter) {
|
|
136
|
-
setFilter(createEmptyFilter());
|
|
137
|
-
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
let controller = new AbortController();
|
|
142
|
-
|
|
143
|
-
convertFilter({ filterString: initialFilter, viewName }, controller.signal)
|
|
144
|
-
.then((result) => {
|
|
145
|
-
if (!controller.signal.aborted) setFilter(result.filterObject ?? createEmptyFilter());
|
|
146
|
-
})
|
|
147
|
-
.catch(() => {
|
|
148
|
-
// An initial filter the converter rejects is better dropped than
|
|
149
|
-
// blocking the launcher; the user can rebuild it.
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
return () => {
|
|
153
|
-
controller.abort();
|
|
154
|
-
};
|
|
155
|
-
}, [initialFilter, viewName]);
|
|
156
|
-
|
|
157
|
-
/** Selecting a saved filter restores the report options stored with it. */
|
|
158
|
-
function handleSelectFilter(saved: SavedFilter | null) {
|
|
159
|
-
if (!saved) {
|
|
160
|
-
setValues(defaultValues);
|
|
161
|
-
setHeaderText("");
|
|
162
|
-
setHideFilterString(false);
|
|
163
|
-
setReportTitle(report?.title ?? "");
|
|
164
|
-
|
|
165
|
-
return;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
setValues(restoreParameterValues(parameters, saved.parameters));
|
|
169
|
-
setHeaderText(saved.headerText ?? "");
|
|
170
|
-
setHideFilterString(saved.hideCriteria);
|
|
171
|
-
setReportTitle(saved.reportTitle ?? report?.title ?? "");
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
let saveValues = useMemo(
|
|
175
|
-
() => ({
|
|
176
|
-
headerText: headerText || null,
|
|
177
|
-
hideCriteria: hideFilterString,
|
|
178
|
-
parameters: parameters.length > 0 ? serializeParameters(parameters, values) : null,
|
|
179
|
-
}),
|
|
180
|
-
[headerText, hideFilterString, parameters, values],
|
|
181
|
-
);
|
|
182
|
-
|
|
183
|
-
let formats = report?.formats ?? [];
|
|
184
|
-
// PDF is the only format worth previewing or printing in place; the rest are
|
|
185
|
-
// downloads whatever the browser is asked to do with them.
|
|
186
|
-
let canPreview = formats.includes("PDF");
|
|
187
|
-
|
|
188
|
-
function getRenderOptions(format: ReportFormat) {
|
|
189
|
-
return {
|
|
190
|
-
format,
|
|
191
|
-
fileName: reportTitle || report?.title || reportId,
|
|
192
|
-
filter: filterString,
|
|
193
|
-
parameters: values,
|
|
194
|
-
headerText: report?.hasHeader ? headerText : null,
|
|
195
|
-
hideFilterString,
|
|
196
|
-
};
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
function run(action: (options: ReturnType<typeof getRenderOptions>) => Promise<void>, format: ReportFormat) {
|
|
200
|
-
void action(getRenderOptions(format));
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
/*
|
|
204
|
-
* The parameters and the criteria are too much to show at once, so they get
|
|
205
|
-
* a tab each. The report options stay below the tabs: they apply to the
|
|
206
|
-
* report whichever tab is open, and the hide-criteria flag in particular
|
|
207
|
-
* reads as belonging to both.
|
|
208
|
-
*/
|
|
209
|
-
let options = (
|
|
210
|
-
<div className="ObReportLauncher-options">
|
|
211
|
-
{report?.hasTitle && (
|
|
212
|
-
<Textfield
|
|
213
|
-
data-size={size}
|
|
214
|
-
label={getLocalizedString("Report name")}
|
|
215
|
-
description={getLocalizedString("Used as the file name when the report is saved.")}
|
|
216
|
-
value={reportTitle}
|
|
217
|
-
onChange={(event) => setReportTitle(event.target.value)}
|
|
218
|
-
/>
|
|
219
|
-
)}
|
|
220
|
-
{report?.hasHeader && (
|
|
221
|
-
<Textfield
|
|
222
|
-
data-size={size}
|
|
223
|
-
multiline
|
|
224
|
-
rows={2}
|
|
225
|
-
label={getLocalizedString("Optional text (at the top of every page)")}
|
|
226
|
-
value={headerText}
|
|
227
|
-
onChange={(event) => setHeaderText(event.target.value)}
|
|
228
|
-
/>
|
|
229
|
-
)}
|
|
230
|
-
<Checkbox
|
|
231
|
-
data-size={size}
|
|
232
|
-
label={getLocalizedString("Do not show the filter criteria at the top of the pages")}
|
|
233
|
-
checked={hideFilterString}
|
|
234
|
-
onChange={(event) => setHideFilterString(event.currentTarget.checked)}
|
|
235
|
-
/>
|
|
236
|
-
</div>
|
|
237
|
-
);
|
|
238
|
-
|
|
239
|
-
let actions = (
|
|
240
|
-
<div className="ObReportLauncher-actions">
|
|
241
|
-
{isRendering && (
|
|
242
|
-
<span className="ObReportLauncher-progress">
|
|
243
|
-
{progress?.bytesReceived
|
|
244
|
-
? `${Math.round(progress.bytesReceived / 1024)} kB`
|
|
245
|
-
: getLocalizedString("Rendering...")}
|
|
246
|
-
</span>
|
|
247
|
-
)}
|
|
248
|
-
{formats.length > 0 && (
|
|
249
|
-
<div className="ObReportLauncher-saveGroup">
|
|
250
|
-
<Button type="button" data-size={size} disabled={isRendering} onClick={() => run(download, formats[0])}>
|
|
251
|
-
{getLocalizedString(FORMAT_LABELS[formats[0]])}
|
|
252
|
-
</Button>
|
|
253
|
-
{formats.length > 1 && (
|
|
254
|
-
<Dropdown.TriggerContext>
|
|
255
|
-
<Dropdown.Trigger
|
|
256
|
-
data-size={size}
|
|
257
|
-
icon
|
|
258
|
-
disabled={isRendering}
|
|
259
|
-
aria-label={getLocalizedString("More formats")}
|
|
260
|
-
>
|
|
261
|
-
<ChevronDownIcon aria-hidden />
|
|
262
|
-
</Dropdown.Trigger>
|
|
263
|
-
<Dropdown>
|
|
264
|
-
<Dropdown.List>
|
|
265
|
-
{formats.slice(1).map((format) => (
|
|
266
|
-
<Dropdown.Item key={format}>
|
|
267
|
-
<Dropdown.Button onClick={() => run(download, format)}>
|
|
268
|
-
{getLocalizedString(FORMAT_LABELS[format])}
|
|
269
|
-
</Dropdown.Button>
|
|
270
|
-
</Dropdown.Item>
|
|
271
|
-
))}
|
|
272
|
-
</Dropdown.List>
|
|
273
|
-
</Dropdown>
|
|
274
|
-
</Dropdown.TriggerContext>
|
|
275
|
-
)}
|
|
276
|
-
</div>
|
|
277
|
-
)}
|
|
278
|
-
<Button
|
|
279
|
-
type="button"
|
|
280
|
-
variant="secondary"
|
|
281
|
-
data-size={size}
|
|
282
|
-
disabled={!canPreview || isRendering}
|
|
283
|
-
onClick={() => run(openReport, "PDF")}
|
|
284
|
-
>
|
|
285
|
-
{getLocalizedString("Preview")}
|
|
286
|
-
</Button>
|
|
287
|
-
<Button
|
|
288
|
-
type="button"
|
|
289
|
-
variant="secondary"
|
|
290
|
-
data-size={size}
|
|
291
|
-
disabled={!canPreview || isRendering}
|
|
292
|
-
onClick={() => run(print, "PDF")}
|
|
293
|
-
>
|
|
294
|
-
{getLocalizedString("Print")}
|
|
295
|
-
</Button>
|
|
296
|
-
<Button type="button" variant="tertiary" data-size={size} onClick={onClose}>
|
|
297
|
-
{getLocalizedString("Close")}
|
|
298
|
-
</Button>
|
|
299
|
-
</div>
|
|
300
|
-
);
|
|
301
|
-
|
|
302
|
-
let content = (
|
|
303
|
-
<div className={clsx("ObReportLauncher-root", className)} data-size={size}>
|
|
304
|
-
{loading && <p className="ObReportLauncher-status">{getLocalizedString("Loading...")}</p>}
|
|
305
|
-
{!loading && !report && (
|
|
306
|
-
<p className="ObReportLauncher-error" role="alert">
|
|
307
|
-
{error
|
|
308
|
-
? error.message
|
|
309
|
-
: getLocalizedString("The report does not exist, or you do not have access to run it.")}
|
|
310
|
-
</p>
|
|
311
|
-
)}
|
|
312
|
-
{report && (
|
|
313
|
-
<FilterBuilder
|
|
314
|
-
fields={fields}
|
|
315
|
-
viewName={viewName}
|
|
316
|
-
reportId={reportId}
|
|
317
|
-
getFieldOptions={getFieldOptions}
|
|
318
|
-
variant="inline"
|
|
319
|
-
value={filter}
|
|
320
|
-
data-size={size}
|
|
321
|
-
actions={actions}
|
|
322
|
-
saveValues={saveValues}
|
|
323
|
-
onChange={setFilter}
|
|
324
|
-
onFilterStringChange={setFilterString}
|
|
325
|
-
onSelect={handleSelectFilter}
|
|
326
|
-
renderMain={(editor) => (
|
|
327
|
-
<div className="ObReportLauncher-main">
|
|
328
|
-
<Tabs
|
|
329
|
-
value={tab}
|
|
330
|
-
data-size={size}
|
|
331
|
-
className="ObReportLauncher-tabs"
|
|
332
|
-
onChange={(value) => setTab(value as ReportLauncherTab)}
|
|
333
|
-
>
|
|
334
|
-
<Tabs.List>
|
|
335
|
-
<Tabs.Tab value="parameters" aria-controls={`${panelId}-parameters`}>
|
|
336
|
-
{parameters.length > 0 ? getLocalizedString("Parameters") : getLocalizedString("Report")}
|
|
337
|
-
</Tabs.Tab>
|
|
338
|
-
<Tabs.Tab value="filter" aria-controls={`${panelId}-filter`}>
|
|
339
|
-
{getLocalizedString("Filter")}
|
|
340
|
-
</Tabs.Tab>
|
|
341
|
-
</Tabs.List>
|
|
342
|
-
</Tabs>
|
|
343
|
-
{/*
|
|
344
|
-
* The panels are rendered outside `Tabs` rather than as
|
|
345
|
-
* `Tabs.Panel`, so the criteria editor gets a flex parent
|
|
346
|
-
* it can fill and scroll inside of.
|
|
347
|
-
*/}
|
|
348
|
-
{tab === "parameters" ? (
|
|
349
|
-
<div
|
|
350
|
-
role="tabpanel"
|
|
351
|
-
id={`${panelId}-parameters`}
|
|
352
|
-
className="ObReportLauncher-panel ObReportLauncher-panel--scroll"
|
|
353
|
-
>
|
|
354
|
-
{parameters.length > 0 ? (
|
|
355
|
-
// No legend: the tab is labelled "Parameters" already.
|
|
356
|
-
<ReportParameters
|
|
357
|
-
parameters={parameters}
|
|
358
|
-
values={values}
|
|
359
|
-
onChange={setValues}
|
|
360
|
-
legend={null}
|
|
361
|
-
data-size={size}
|
|
362
|
-
/>
|
|
363
|
-
) : (
|
|
364
|
-
<p className="ObReportLauncher-status">{getLocalizedString("The report has no parameters.")}</p>
|
|
365
|
-
)}
|
|
366
|
-
</div>
|
|
367
|
-
) : (
|
|
368
|
-
<div role="tabpanel" id={`${panelId}-filter`} className="ObReportLauncher-panel">
|
|
369
|
-
{editor}
|
|
370
|
-
</div>
|
|
371
|
-
)}
|
|
372
|
-
{options}
|
|
373
|
-
</div>
|
|
374
|
-
)}
|
|
375
|
-
/>
|
|
376
|
-
)}
|
|
377
|
-
{renderError && (
|
|
378
|
-
<p className="ObReportLauncher-error" role="alert">
|
|
379
|
-
{renderError.message}
|
|
380
|
-
</p>
|
|
381
|
-
)}
|
|
382
|
-
</div>
|
|
383
|
-
);
|
|
384
|
-
|
|
385
|
-
if (variant === "inline") return content;
|
|
386
|
-
|
|
387
|
-
return (
|
|
388
|
-
<Dialog
|
|
389
|
-
open={open}
|
|
390
|
-
closedby="closerequest"
|
|
391
|
-
closeButton={false}
|
|
392
|
-
data-size={size}
|
|
393
|
-
className="ObReportLauncher-dialog"
|
|
394
|
-
onClose={onClose}
|
|
395
|
-
>
|
|
396
|
-
{/* As in the filter builder, `Dialog`'s floated close button does not
|
|
397
|
-
survive a flex layout, so the header renders its own. */}
|
|
398
|
-
<Dialog.Block className="ObReportLauncher-dialogHeader">
|
|
399
|
-
<Heading level={2} data-size="xs">
|
|
400
|
-
{getLocalizedString("Report")}: {report?.title ?? reportId}
|
|
401
|
-
{/* The report number is what users refer to a report by — it is
|
|
402
|
-
printed in the footer of every report. */}
|
|
403
|
-
{report?.shortId !== null && report?.shortId !== undefined && ` (ID: ${report.shortId})`}
|
|
404
|
-
</Heading>
|
|
405
|
-
<Button
|
|
406
|
-
type="button"
|
|
407
|
-
variant="tertiary"
|
|
408
|
-
data-color="neutral"
|
|
409
|
-
data-size={size}
|
|
410
|
-
icon
|
|
411
|
-
aria-label={getLocalizedString("Close")}
|
|
412
|
-
onClick={onClose}
|
|
413
|
-
>
|
|
414
|
-
<XMarkIcon aria-hidden />
|
|
415
|
-
</Button>
|
|
416
|
-
</Dialog.Block>
|
|
417
|
-
<Dialog.Block className="ObReportLauncher-dialogBody">{content}</Dialog.Block>
|
|
418
|
-
</Dialog>
|
|
419
|
-
);
|
|
420
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
import type { ReportParameter } from "@olenbetong/appframe-core";
|
|
2
|
-
import { render, screen } from "@testing-library/react";
|
|
3
|
-
import userEvent from "@testing-library/user-event";
|
|
4
|
-
import { describe, expect, it, vi } from "vitest";
|
|
5
|
-
|
|
6
|
-
let parameterOptions: { value: string; label: string }[] = [];
|
|
7
|
-
|
|
8
|
-
vi.mock("@olenbetong/appframe-react", async (importOriginal) => ({
|
|
9
|
-
...(await importOriginal<Record<string, unknown>>()),
|
|
10
|
-
useParameterOptions: () => ({ options: parameterOptions, loading: false, error: null }),
|
|
11
|
-
}));
|
|
12
|
-
|
|
13
|
-
const { ReportParameters } = await import("./ReportParameters.js");
|
|
14
|
-
|
|
15
|
-
function parameter(overrides: Partial<ReportParameter> & Pick<ReportParameter, "name">): ReportParameter {
|
|
16
|
-
return {
|
|
17
|
-
label: overrides.name,
|
|
18
|
-
description: null,
|
|
19
|
-
type: "String",
|
|
20
|
-
editor: "text",
|
|
21
|
-
defaultValue: null,
|
|
22
|
-
items: [],
|
|
23
|
-
recordSource: null,
|
|
24
|
-
valueMember: null,
|
|
25
|
-
displayMember: null,
|
|
26
|
-
sortOrder: 0,
|
|
27
|
-
lookupWidth: null,
|
|
28
|
-
lookupHeight: null,
|
|
29
|
-
...overrides,
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
describe("ReportParameters", () => {
|
|
34
|
-
it("renders nothing when the report has no parameters", () => {
|
|
35
|
-
let { container } = render(<ReportParameters parameters={[]} values={{}} onChange={vi.fn()} />);
|
|
36
|
-
|
|
37
|
-
expect(container).toBeEmptyDOMElement();
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it("renders a labelled editor per parameter with the description as help text", () => {
|
|
41
|
-
render(
|
|
42
|
-
<ReportParameters
|
|
43
|
-
parameters={[
|
|
44
|
-
parameter({ name: "Period", label: "Periode", type: "Integer", editor: "number" }),
|
|
45
|
-
parameter({ name: "Comment", label: "Kommentar", description: "Vises på forsiden" }),
|
|
46
|
-
]}
|
|
47
|
-
values={{ Period: 202601, Comment: "" }}
|
|
48
|
-
onChange={vi.fn()}
|
|
49
|
-
/>,
|
|
50
|
-
);
|
|
51
|
-
|
|
52
|
-
expect(screen.getByLabelText("Periode")).toHaveValue(202601);
|
|
53
|
-
expect(screen.getByLabelText("Kommentar")).toBeInTheDocument();
|
|
54
|
-
expect(screen.getByText("Vises på forsiden")).toBeInTheDocument();
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it("coerces numeric input to a number", async () => {
|
|
58
|
-
let onChange = vi.fn();
|
|
59
|
-
let user = userEvent.setup();
|
|
60
|
-
render(
|
|
61
|
-
<ReportParameters
|
|
62
|
-
parameters={[parameter({ name: "Period", type: "Integer", editor: "number" })]}
|
|
63
|
-
values={{ Period: null }}
|
|
64
|
-
onChange={onChange}
|
|
65
|
-
/>,
|
|
66
|
-
);
|
|
67
|
-
|
|
68
|
-
await user.type(screen.getByLabelText("Period"), "7");
|
|
69
|
-
|
|
70
|
-
expect(onChange).toHaveBeenCalledWith({ Period: 7 });
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it("renders a checkbox for boolean parameters", async () => {
|
|
74
|
-
let onChange = vi.fn();
|
|
75
|
-
let user = userEvent.setup();
|
|
76
|
-
render(
|
|
77
|
-
<ReportParameters
|
|
78
|
-
parameters={[parameter({ name: "IncludeClosed", type: "Boolean", editor: "boolean" })]}
|
|
79
|
-
values={{ IncludeClosed: false }}
|
|
80
|
-
onChange={onChange}
|
|
81
|
-
/>,
|
|
82
|
-
);
|
|
83
|
-
|
|
84
|
-
await user.click(screen.getByLabelText("IncludeClosed"));
|
|
85
|
-
|
|
86
|
-
expect(onChange).toHaveBeenCalledWith({ IncludeClosed: true });
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
it("renders a select for parameters with a fixed item list", async () => {
|
|
90
|
-
let onChange = vi.fn();
|
|
91
|
-
let user = userEvent.setup();
|
|
92
|
-
render(
|
|
93
|
-
<ReportParameters
|
|
94
|
-
parameters={[parameter({ name: "Type", editor: "select", items: ["Alle", "Åpne"] })]}
|
|
95
|
-
values={{ Type: "Alle" }}
|
|
96
|
-
onChange={onChange}
|
|
97
|
-
/>,
|
|
98
|
-
);
|
|
99
|
-
|
|
100
|
-
await user.selectOptions(screen.getByLabelText("Type"), "Åpne");
|
|
101
|
-
|
|
102
|
-
expect(onChange).toHaveBeenCalledWith({ Type: "Åpne" });
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
it("renders lookup options from the record source", () => {
|
|
106
|
-
parameterOptions = [
|
|
107
|
-
{ value: "1", label: "1 - Første" },
|
|
108
|
-
{ value: "2", label: "2 - Andre" },
|
|
109
|
-
];
|
|
110
|
-
render(
|
|
111
|
-
<ReportParameters
|
|
112
|
-
parameters={[
|
|
113
|
-
parameter({
|
|
114
|
-
name: "Type",
|
|
115
|
-
editor: "lookup",
|
|
116
|
-
valueMember: "ID",
|
|
117
|
-
recordSource: {
|
|
118
|
-
viewName: "aviw_Test_Types",
|
|
119
|
-
columns: [{ name: "ID", type: "number" }],
|
|
120
|
-
whereClause: null,
|
|
121
|
-
filterString: null,
|
|
122
|
-
maxRecords: null,
|
|
123
|
-
},
|
|
124
|
-
}),
|
|
125
|
-
]}
|
|
126
|
-
values={{ Type: "2" }}
|
|
127
|
-
onChange={vi.fn()}
|
|
128
|
-
/>,
|
|
129
|
-
);
|
|
130
|
-
|
|
131
|
-
expect(screen.getByLabelText("Type")).toHaveValue("2 - Andre");
|
|
132
|
-
});
|
|
133
|
-
});
|