@olenbetong/synergi-react 3.2.2 → 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.
Files changed (112) hide show
  1. package/es/chrome/AppShell/index.d.ts +10 -2
  2. package/es/chrome/AppShell/index.js +13 -97
  3. package/es/chrome/openReport.d.ts +22 -0
  4. package/es/chrome/openReport.js +21 -0
  5. package/es/colorScheme.d.ts +4 -4
  6. package/es/components/Toolbar/index.d.ts +20 -11
  7. package/es/components/Toolbar/index.js +47 -6
  8. package/es/elements/ElementLookup.d.ts +7 -2
  9. package/es/elements/ElementLookup.js +4 -6
  10. package/es/elements/ElementLookupDialog/BarcodeScanner/decoder.d.ts +32 -0
  11. package/es/elements/ElementLookupDialog/BarcodeScanner/decoders/dbr.d.ts +28 -0
  12. package/es/elements/ElementLookupDialog/BarcodeScanner/decoders/dbr.js +81 -0
  13. package/es/elements/ElementLookupDialog/BarcodeScanner/decoders/native.d.ts +26 -0
  14. package/es/elements/ElementLookupDialog/BarcodeScanner/decoders/native.js +70 -0
  15. package/es/elements/ElementLookupDialog/BarcodeScanner/decoders/zxing.d.ts +20 -0
  16. package/es/elements/ElementLookupDialog/BarcodeScanner/decoders/zxing.js +69 -0
  17. package/es/elements/ElementLookupDialog/BarcodeScanner/decoders.test.js +103 -0
  18. package/es/elements/ElementLookupDialog/BarcodeScanner/duplicateFilter.d.ts +6 -0
  19. package/es/elements/ElementLookupDialog/BarcodeScanner/duplicateFilter.js +19 -0
  20. package/es/elements/ElementLookupDialog/BarcodeScanner/index.d.ts +14 -7
  21. package/es/elements/ElementLookupDialog/BarcodeScanner/index.js +10 -6
  22. package/es/elements/ElementLookupDialog/BarcodeScanner/useScanner.d.ts +14 -12
  23. package/es/elements/ElementLookupDialog/BarcodeScanner/useScanner.js +222 -116
  24. package/es/elements/ElementLookupDialog/index.d.ts +6 -0
  25. package/es/elements/ElementLookupDialog/index.js +2 -2
  26. package/es/index.d.ts +3 -4
  27. package/es/index.js +5 -4
  28. package/package.json +9 -8
  29. package/src/chrome/AppShell/index.tsx +13 -134
  30. package/src/chrome/openReport.ts +34 -0
  31. package/src/colorScheme.ts +4 -4
  32. package/src/components/Toolbar/index.tsx +65 -14
  33. package/src/elements/ElementLookup.tsx +12 -5
  34. package/src/elements/ElementLookupDialog/BarcodeScanner/decoder.ts +32 -0
  35. package/src/elements/ElementLookupDialog/BarcodeScanner/decoders/dbr.ts +118 -0
  36. package/src/elements/ElementLookupDialog/BarcodeScanner/decoders/native.ts +103 -0
  37. package/src/elements/ElementLookupDialog/BarcodeScanner/decoders/zxing.ts +95 -0
  38. package/src/elements/ElementLookupDialog/BarcodeScanner/decoders.test.ts +118 -0
  39. package/src/elements/ElementLookupDialog/BarcodeScanner/duplicateFilter.ts +21 -0
  40. package/src/elements/ElementLookupDialog/BarcodeScanner/index.tsx +29 -14
  41. package/src/elements/ElementLookupDialog/BarcodeScanner/useScanner.ts +246 -136
  42. package/src/elements/ElementLookupDialog/index.tsx +12 -4
  43. package/src/index.ts +6 -37
  44. package/es/chrome/AppMenu/AppMenu.css +0 -648
  45. package/es/chrome/AppMenu/AppMenu.d.ts +0 -56
  46. package/es/chrome/AppMenu/AppMenu.js +0 -145
  47. package/es/chrome/AppMenu/AppMenuColorScheme.d.ts +0 -2
  48. package/es/chrome/AppMenu/AppMenuColorScheme.js +0 -18
  49. package/es/chrome/AppMenu/AppMenuFavoriteButton.d.ts +0 -18
  50. package/es/chrome/AppMenu/AppMenuFavoriteButton.js +0 -11
  51. package/es/chrome/AppMenu/AppMenuHeader.d.ts +0 -24
  52. package/es/chrome/AppMenu/AppMenuHeader.js +0 -18
  53. package/es/chrome/AppMenu/AppMenuList.d.ts +0 -18
  54. package/es/chrome/AppMenu/AppMenuList.js +0 -39
  55. package/es/chrome/AppMenu/AppMenuRail.d.ts +0 -26
  56. package/es/chrome/AppMenu/AppMenuRail.js +0 -30
  57. package/es/chrome/AppMenu/AppMenuToggle.d.ts +0 -15
  58. package/es/chrome/AppMenu/AppMenuToggle.js +0 -14
  59. package/es/chrome/AppMenu/AppMenuUserMenu.d.ts +0 -32
  60. package/es/chrome/AppMenu/AppMenuUserMenu.js +0 -110
  61. package/es/chrome/AppMenu/developerCategories.d.ts +0 -24
  62. package/es/chrome/AppMenu/developerCategories.js +0 -116
  63. package/es/chrome/AppMenu/icons.d.ts +0 -15
  64. package/es/chrome/AppMenu/icons.js +0 -13
  65. package/es/chrome/AppMenu/index.d.ts +0 -12
  66. package/es/chrome/AppMenu/index.js +0 -10
  67. package/es/chrome/AppMenu/menuEntries.d.ts +0 -51
  68. package/es/chrome/AppMenu/menuEntries.js +0 -93
  69. package/es/chrome/AppMenu/types.d.ts +0 -43
  70. package/es/chrome/AppMenu/useFavorites.d.ts +0 -13
  71. package/es/chrome/AppMenu/useFavorites.js +0 -28
  72. package/es/chrome/AppMenu/useRovingTabIndex.d.ts +0 -28
  73. package/es/chrome/AppMenu/useRovingTabIndex.js +0 -114
  74. package/es/chrome/AppMenu/useServiceWorkerUpdate.d.ts +0 -16
  75. package/es/chrome/AppMenu/useServiceWorkerUpdate.js +0 -62
  76. package/es/report/ReportLauncher.css +0 -147
  77. package/es/report/ReportLauncher.d.ts +0 -55
  78. package/es/report/ReportLauncher.js +0 -142
  79. package/es/report/ReportLauncher.test.js +0 -231
  80. package/es/report/ReportParameters.css +0 -29
  81. package/es/report/ReportParameters.d.ts +0 -46
  82. package/es/report/ReportParameters.js +0 -65
  83. package/es/report/ReportParameters.test.d.ts +0 -1
  84. package/es/report/ReportParameters.test.js +0 -84
  85. package/es/report/index.d.ts +0 -2
  86. package/es/report/index.js +0 -2
  87. package/src/chrome/AppMenu/AppMenu.css +0 -648
  88. package/src/chrome/AppMenu/AppMenu.tsx +0 -285
  89. package/src/chrome/AppMenu/AppMenuColorScheme.tsx +0 -41
  90. package/src/chrome/AppMenu/AppMenuFavoriteButton.tsx +0 -47
  91. package/src/chrome/AppMenu/AppMenuHeader.tsx +0 -79
  92. package/src/chrome/AppMenu/AppMenuList.tsx +0 -89
  93. package/src/chrome/AppMenu/AppMenuRail.tsx +0 -117
  94. package/src/chrome/AppMenu/AppMenuToggle.tsx +0 -51
  95. package/src/chrome/AppMenu/AppMenuUserMenu.tsx +0 -190
  96. package/src/chrome/AppMenu/developerCategories.ts +0 -142
  97. package/src/chrome/AppMenu/icons.tsx +0 -76
  98. package/src/chrome/AppMenu/index.ts +0 -17
  99. package/src/chrome/AppMenu/menuEntries.ts +0 -128
  100. package/src/chrome/AppMenu/types.ts +0 -45
  101. package/src/chrome/AppMenu/useFavorites.ts +0 -40
  102. package/src/chrome/AppMenu/useRovingTabIndex.ts +0 -130
  103. package/src/chrome/AppMenu/useServiceWorkerUpdate.ts +0 -68
  104. package/src/report/ReportLauncher.css +0 -147
  105. package/src/report/ReportLauncher.test.tsx +0 -281
  106. package/src/report/ReportLauncher.tsx +0 -420
  107. package/src/report/ReportParameters.css +0 -29
  108. package/src/report/ReportParameters.test.tsx +0 -133
  109. package/src/report/ReportParameters.tsx +0 -198
  110. package/src/report/index.ts +0 -2
  111. /package/es/{chrome/AppMenu/types.js → elements/ElementLookupDialog/BarcodeScanner/decoder.js} +0 -0
  112. /package/es/{report/ReportLauncher.test.d.ts → elements/ElementLookupDialog/BarcodeScanner/decoders.test.d.ts} +0 -0
@@ -1,130 +0,0 @@
1
- import { type KeyboardEvent, useEffect, useState } from "react";
2
-
3
- const NEXT_KEYS = ["ArrowDown", "ArrowRight"];
4
- const PREV_KEYS = ["ArrowUp", "ArrowLeft"];
5
- const HORIZONTAL_KEYS = ["ArrowLeft", "ArrowRight"];
6
- const ARROW_KEYS = [...HORIZONTAL_KEYS, "ArrowUp", "ArrowDown"];
7
-
8
- /**
9
- * Find the item closest to `from` in the neighbouring visual row or column.
10
- *
11
- * The app list is a grid whose column count depends on the available width, so
12
- * which row and column an item ends up in is only known after layout. Comparing
13
- * client rectangles is therefore the only reliable way to move in two
14
- * dimensions.
15
- */
16
- function findAdjacent(items: readonly HTMLElement[], from: number, axis: "x" | "y", direction: 1 | -1) {
17
- // `main` is the axis stepped along, `cross` the one used to pick the closest
18
- // candidate within the target row/column.
19
- let rects = items.map((item) => {
20
- let rect = item.getBoundingClientRect();
21
- return axis === "x" ? { main: rect.left, cross: rect.top } : { main: rect.top, cross: rect.left };
22
- });
23
-
24
- let origin = rects[from];
25
- if (!origin) return null;
26
-
27
- // The nearest row/column edge in the requested direction.
28
- let target: number | null = null;
29
- for (let rect of rects) {
30
- let delta = rect.main - origin.main;
31
- if (direction > 0 ? delta <= 1 : delta >= -1) continue;
32
- if (target === null || Math.abs(rect.main - origin.main) < Math.abs(target - origin.main)) {
33
- target = rect.main;
34
- }
35
- }
36
-
37
- if (target === null) return null;
38
-
39
- let best: number | null = null;
40
- let bestDistance = Number.POSITIVE_INFINITY;
41
- for (let index = 0; index < rects.length; index++) {
42
- let rect = rects[index];
43
- if (Math.abs(rect.main - target) > 1) continue;
44
-
45
- let distance = Math.abs(rect.cross - origin.cross);
46
- if (distance < bestDistance) {
47
- bestDistance = distance;
48
- best = index;
49
- }
50
- }
51
-
52
- return best;
53
- }
54
-
55
- export type RovingTabIndexOptions = {
56
- /**
57
- * When true, the arrow keys follow the visual layout of a wrapping grid
58
- * instead of the DOM order: left/right move between columns and up/down
59
- * between rows.
60
- */
61
- columns?: boolean;
62
- };
63
-
64
- /**
65
- * Roving tabindex: the container holds a single tab stop, and the arrow keys
66
- * (plus Home/End) move focus between the items inside it.
67
- *
68
- * Spread `getItemProps(index)` on every focusable item and put `onKeyDown` on
69
- * their common ancestor.
70
- */
71
- export function useRovingTabIndex(itemCount: number, { columns = false }: RovingTabIndexOptions = {}) {
72
- let [activeIndex, setActiveIndex] = useState(0);
73
-
74
- // Keep the tab stop within the list when it shrinks (e.g. while searching).
75
- useEffect(() => {
76
- setActiveIndex((index) => (index >= itemCount ? 0 : index));
77
- }, [itemCount]);
78
-
79
- function onKeyDown(event: KeyboardEvent<HTMLElement>) {
80
- if (itemCount === 0) return;
81
-
82
- let items = [...event.currentTarget.querySelectorAll<HTMLElement>("[data-roving-item]")];
83
- let next: number | null;
84
-
85
- if (columns && ARROW_KEYS.includes(event.key)) {
86
- event.preventDefault();
87
-
88
- let isHorizontal = HORIZONTAL_KEYS.includes(event.key);
89
- let direction: 1 | -1 = NEXT_KEYS.includes(event.key) ? 1 : -1;
90
- next = findAdjacent(items, activeIndex, isHorizontal ? "x" : "y", direction);
91
-
92
- if (next === null) {
93
- // Stay put at the first/last column, but let up/down continue into the
94
- // neighbouring item so the whole list stays reachable.
95
- if (isHorizontal) return;
96
- next = (activeIndex + direction + itemCount) % itemCount;
97
- }
98
- } else if (NEXT_KEYS.includes(event.key)) next = (activeIndex + 1) % itemCount;
99
- else if (PREV_KEYS.includes(event.key)) next = (activeIndex - 1 + itemCount) % itemCount;
100
- else if (event.key === "Home") next = 0;
101
- else if (event.key === "End") next = itemCount - 1;
102
- else return;
103
-
104
- event.preventDefault();
105
- setActiveIndex(next);
106
- items[next]?.focus();
107
- }
108
-
109
- function getItemProps(index: number) {
110
- return {
111
- "data-roving-item": "",
112
- tabIndex: index === activeIndex ? 0 : -1,
113
- onFocus: () => setActiveIndex(index),
114
- };
115
- }
116
-
117
- /**
118
- * Props for a secondary control belonging to item `index`, e.g. the favorite
119
- * toggle next to an app link. It shares the item's tab stop — so Tab reaches
120
- * it from the link — but the arrow keys skip it.
121
- */
122
- function getSecondaryProps(index: number) {
123
- return {
124
- tabIndex: index === activeIndex ? 0 : -1,
125
- onFocus: () => setActiveIndex(index),
126
- };
127
- }
128
-
129
- return { onKeyDown, getItemProps, getSecondaryProps };
130
- }
@@ -1,68 +0,0 @@
1
- import { useCallback, useEffect, useState } from "react";
2
-
3
- /**
4
- * Track whether a new version of the site has been downloaded by the service
5
- * worker and is waiting to take over.
6
- *
7
- * A waiting worker means every asset of the new version is already cached, so
8
- * installing it is just `skipWaiting` followed by a reload. The reload is
9
- * triggered from the worker's `activated` state change rather than immediately,
10
- * so the page never reloads into the old version.
11
- *
12
- * Replaces the DOM based `[data-update-worker]` wiring in the site bundle, which
13
- * only works for markup that exists when the page loads.
14
- */
15
- export function useServiceWorkerUpdate() {
16
- let [waitingWorker, setWaitingWorker] = useState<ServiceWorker | null>(null);
17
-
18
- useEffect(() => {
19
- if (!("serviceWorker" in navigator)) return;
20
-
21
- let isCancelled = false;
22
- let cleanups: (() => void)[] = [];
23
-
24
- function watch(worker: ServiceWorker) {
25
- if (isCancelled) return;
26
- setWaitingWorker(worker);
27
-
28
- function onStateChange() {
29
- // The new worker took over, so the page can safely reload into it.
30
- if (worker.state === "activated") window.location.reload();
31
- }
32
-
33
- worker.addEventListener("statechange", onStateChange);
34
- cleanups.push(() => worker.removeEventListener("statechange", onStateChange));
35
- }
36
-
37
- navigator.serviceWorker.ready.then((registration) => {
38
- if (isCancelled) return;
39
- if (registration.waiting) watch(registration.waiting);
40
-
41
- function onUpdateFound() {
42
- let installing = registration.installing;
43
- if (!installing) return;
44
-
45
- function onStateChange() {
46
- if (installing?.state === "installed") watch(installing);
47
- }
48
-
49
- installing.addEventListener("statechange", onStateChange);
50
- cleanups.push(() => installing.removeEventListener("statechange", onStateChange));
51
- }
52
-
53
- registration.addEventListener("updatefound", onUpdateFound);
54
- cleanups.push(() => registration.removeEventListener("updatefound", onUpdateFound));
55
- });
56
-
57
- return () => {
58
- isCancelled = true;
59
- for (let cleanup of cleanups) cleanup();
60
- };
61
- }, []);
62
-
63
- let installUpdate = useCallback(() => {
64
- waitingWorker?.postMessage({ action: "skipWaiting" });
65
- }, [waitingWorker]);
66
-
67
- return { isUpdateAvailable: waitingWorker !== null, installUpdate };
68
- }
@@ -1,147 +0,0 @@
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
- }
@@ -1,281 +0,0 @@
1
- import type { Report, ReportParameter, ReportParameterValues, SavedFilter } from "@olenbetong/appframe-core";
2
- import { render, screen, waitFor, within } from "@testing-library/react";
3
- import userEvent from "@testing-library/user-event";
4
- import { beforeEach, describe, expect, it, vi } from "vitest";
5
-
6
- const download = vi.fn(async () => undefined);
7
- const openRendered = vi.fn(async () => undefined);
8
- const print = vi.fn(async () => undefined);
9
- const save = vi.fn(async () => undefined);
10
- const convertFilter = vi.fn(async () => ({ filterObject: null, filterString: "", whereClause: "" }));
11
-
12
- let report: Report | null = null;
13
- let parameters: ReportParameter[] = [];
14
- let defaultValues: ReportParameterValues = {};
15
- let savedFilters: SavedFilter[] = [];
16
- let initialFilter: string | null = null;
17
-
18
- vi.mock("@olenbetong/appframe-core", async (importOriginal) => ({
19
- ...(await importOriginal<Record<string, unknown>>()),
20
- convertFilter: (...args: unknown[]) => convertFilter(...(args as [])),
21
- }));
22
-
23
- vi.mock("@olenbetong/appframe-react", async (importOriginal) => ({
24
- ...(await importOriginal<Record<string, unknown>>()),
25
- setNamedFilter: vi.fn(),
26
- useFilterFields: () => ({ fields: [], loading: false, error: null, refresh: vi.fn() }),
27
- useFilterConversion: () => ({
28
- filterString: "[ProjectID] = 1",
29
- isConverting: false,
30
- error: null,
31
- parseFilterString: vi.fn(async () => null),
32
- }),
33
- useReport: () => ({
34
- report,
35
- parameters,
36
- initialFilter,
37
- defaultValues,
38
- loading: false,
39
- error: null,
40
- refresh: vi.fn(),
41
- }),
42
- useReportRender: () => ({
43
- open: openRendered,
44
- print,
45
- download,
46
- render: vi.fn(),
47
- cancel: vi.fn(),
48
- isRendering: false,
49
- progress: null,
50
- error: null,
51
- }),
52
- useSavedFilters: () => ({
53
- filters: savedFilters,
54
- mine: savedFilters,
55
- shared: [],
56
- loading: false,
57
- error: null,
58
- refresh: vi.fn(),
59
- save,
60
- rename: vi.fn(),
61
- remove: vi.fn(),
62
- setCrossDomain: vi.fn(),
63
- }),
64
- }));
65
-
66
- const { ReportLauncher } = await import("./ReportLauncher.js");
67
-
68
- function makeReport(overrides: Partial<Report> = {}): Report {
69
- return {
70
- reportId: "arpt_Test_Report",
71
- shortId: 4711,
72
- title: "Test report",
73
- description: null,
74
- viewName: "aviw_Test_View",
75
- initialFilter: null,
76
- hasTitle: true,
77
- hasHeader: true,
78
- formats: ["PDF", "XLSX"],
79
- timeout: null,
80
- ...overrides,
81
- };
82
- }
83
-
84
- function savedFilter(overrides: Partial<SavedFilter> = {}): SavedFilter {
85
- return {
86
- filterId: 1,
87
- primKey: "pk-1",
88
- name: "Mitt filter",
89
- criteria: "[ProjectID] = 1",
90
- dbObjectId: "aviw_Test_View",
91
- accessLevel: "Manager",
92
- createdByUser: true,
93
- createdBy: "bvh",
94
- domain: "OB",
95
- crossDomain: false,
96
- isPersonallyShared: false,
97
- hideCriteria: true,
98
- headerText: "Lagret overskrift",
99
- comment: null,
100
- parameters: '<Parameters Version="1"><Parameter Name="Period" Type="Integer">202601</Parameter></Parameters>',
101
- reportTitle: null,
102
- created: null,
103
- updated: null,
104
- ...overrides,
105
- };
106
- }
107
-
108
- function numberParameter(overrides: Partial<ReportParameter> = {}): ReportParameter {
109
- return {
110
- name: "Period",
111
- label: "Periode",
112
- description: null,
113
- type: "Integer",
114
- editor: "number",
115
- defaultValue: null,
116
- items: [],
117
- recordSource: null,
118
- valueMember: null,
119
- displayMember: null,
120
- sortOrder: 0,
121
- lookupWidth: null,
122
- lookupHeight: null,
123
- ...overrides,
124
- };
125
- }
126
-
127
- function renderLauncher(props: Record<string, unknown> = {}) {
128
- return render(<ReportLauncher reportId="arpt_Test_Report" variant="inline" {...props} />);
129
- }
130
-
131
- describe("ReportLauncher", () => {
132
- beforeEach(() => {
133
- vi.clearAllMocks();
134
- report = makeReport();
135
- parameters = [];
136
- defaultValues = {};
137
- savedFilters = [];
138
- initialFilter = null;
139
- });
140
-
141
- it("tells the user when the report is not available to them", () => {
142
- report = null;
143
- renderLauncher();
144
-
145
- expect(screen.getByRole("alert").textContent).toContain("do not have access");
146
- });
147
-
148
- it("shows the report option fields the report has bands for", () => {
149
- renderLauncher();
150
-
151
- expect(screen.getByLabelText("Report name")).toHaveValue("Test report");
152
- expect(screen.getByLabelText("Optional text (at the top of every page)")).toBeInTheDocument();
153
- });
154
-
155
- it("puts the parameters and the criteria in a tab each, with the options below both", async () => {
156
- parameters = [numberParameter()];
157
- defaultValues = { Period: null };
158
- renderLauncher();
159
-
160
- expect(screen.getByLabelText("Periode")).toBeInTheDocument();
161
- expect(screen.queryByLabelText("Filter string")).toBeNull();
162
-
163
- await userEvent.click(screen.getByText("Filter"));
164
-
165
- expect(screen.queryByLabelText("Periode")).toBeNull();
166
- expect(screen.getByLabelText("Filter string")).toBeInTheDocument();
167
- // The options apply to the report whichever tab is open.
168
- expect(screen.getByLabelText("Report name")).toBeInTheDocument();
169
- });
170
-
171
- it("can start on the filter tab", () => {
172
- parameters = [numberParameter()];
173
- renderLauncher({ defaultTab: "filter" });
174
-
175
- expect(screen.getByLabelText("Filter string")).toBeInTheDocument();
176
- expect(screen.queryByLabelText("Periode")).toBeNull();
177
- });
178
-
179
- it("names the report and its number in the dialog heading", () => {
180
- render(<ReportLauncher reportId="arpt_Test_Report" />);
181
-
182
- expect(screen.getByRole("heading").textContent).toBe("Report: Test report (ID: 4711)");
183
- });
184
-
185
- it("hides the title and header fields when the report has no such bands", () => {
186
- report = makeReport({ hasTitle: false, hasHeader: false });
187
- renderLauncher();
188
-
189
- expect(screen.queryByLabelText("Report name")).toBeNull();
190
- expect(screen.queryByLabelText("Optional text (at the top of every page)")).toBeNull();
191
- });
192
-
193
- it("offers the report's first format on the save button and the rest in a menu", async () => {
194
- renderLauncher();
195
-
196
- await userEvent.click(screen.getByRole("button", { name: "Save as PDF" }));
197
-
198
- expect(download).toHaveBeenCalledWith(
199
- expect.objectContaining({ format: "PDF", fileName: "Test report", filter: "[ProjectID] = 1" }),
200
- );
201
- expect(screen.getByRole("button", { name: "More formats" })).toBeInTheDocument();
202
- });
203
-
204
- it("does not offer a format menu for a report with a single format", () => {
205
- report = makeReport({ formats: ["PDF"] });
206
- renderLauncher();
207
-
208
- expect(screen.queryByRole("button", { name: "More formats" })).toBeNull();
209
- });
210
-
211
- it("previews and prints as PDF", async () => {
212
- renderLauncher();
213
-
214
- await userEvent.click(screen.getByRole("button", { name: "Preview" }));
215
- await userEvent.click(screen.getByRole("button", { name: "Print" }));
216
-
217
- expect(openRendered).toHaveBeenCalledWith(expect.objectContaining({ format: "PDF" }));
218
- expect(print).toHaveBeenCalledWith(expect.objectContaining({ format: "PDF" }));
219
- });
220
-
221
- it("cannot preview or print a report that has no PDF format", () => {
222
- report = makeReport({ formats: ["CSV"] });
223
- renderLauncher();
224
-
225
- expect(screen.getByRole("button", { name: "Preview" }).hasAttribute("disabled")).toBe(true);
226
- expect(screen.getByRole("button", { name: "Print" }).hasAttribute("disabled")).toBe(true);
227
- });
228
-
229
- it("sends the header text and the hide-criteria flag with the render", async () => {
230
- renderLauncher();
231
-
232
- await userEvent.type(screen.getByLabelText("Optional text (at the top of every page)"), "Hei");
233
- await userEvent.click(screen.getByLabelText("Do not show the filter criteria at the top of the pages"));
234
- await userEvent.click(screen.getByRole("button", { name: "Save as PDF" }));
235
-
236
- expect(download).toHaveBeenCalledWith(expect.objectContaining({ headerText: "Hei", hideFilterString: true }));
237
- });
238
-
239
- it("restores the report options stored with a saved filter", async () => {
240
- parameters = [numberParameter()];
241
- defaultValues = { Period: null };
242
- savedFilters = [savedFilter()];
243
- renderLauncher();
244
-
245
- await userEvent.click(screen.getByRole("button", { name: "Mitt filter" }));
246
-
247
- await waitFor(() => expect(screen.getByLabelText("Periode")).toHaveValue(202601));
248
- expect(screen.getByLabelText("Optional text (at the top of every page)")).toHaveValue("Lagret overskrift");
249
- expect(
250
- (screen.getByLabelText("Do not show the filter criteria at the top of the pages") as HTMLInputElement).checked,
251
- ).toBe(true);
252
- });
253
-
254
- it("stores the report options on the filter when it is saved", async () => {
255
- parameters = [];
256
- // "Save as" is only offered for a filter with conditions, so the launcher
257
- // starts from the report's own filter.
258
- convertFilter.mockResolvedValue({
259
- filterObject: {
260
- type: "group",
261
- mode: "and",
262
- items: [{ type: "expression", column: "ProjectID", operator: "equals", value: 1, valueType: "number" }],
263
- },
264
- filterString: "[ProjectID] = 1",
265
- whereClause: "",
266
- } as never);
267
- initialFilter = "[ProjectID] = 1";
268
- renderLauncher();
269
-
270
- await userEvent.type(screen.getByLabelText("Optional text (at the top of every page)"), "Hei");
271
- await userEvent.click(screen.getByRole("button", { name: "Save as" }));
272
-
273
- let dialog = screen.getByRole("dialog");
274
- await userEvent.type(within(dialog).getByRole("textbox", { name: "Filter name" }), "Nytt filter");
275
- await userEvent.click(within(dialog).getByRole("button", { name: "Save" }));
276
-
277
- await waitFor(() =>
278
- expect(save).toHaveBeenCalledWith(expect.objectContaining({ headerText: "Hei", hideCriteria: false })),
279
- );
280
- });
281
- });