@olenbetong/synergi-react 2.7.1 → 2.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/styles/styles.css.map +1 -1
- package/es/{components → chrome}/AppMenu/AppMenu.css +648 -648
- package/es/{components → chrome}/AppMenu/index.d.ts +1 -1
- package/es/components/ImageEditor/ImageEditor.d.ts +12 -0
- package/es/components/ImageEditor/ImageEditor.js +27 -6
- package/es/components/ImageEditor/index.d.ts +2 -0
- package/es/components/ImageEditor/index.js +2 -0
- package/es/components/ImageEditor/plugins/zoomPlugin/ZoomControls.js +1 -1
- package/es/components/ImageEditor/useImageHistory.d.ts +6 -1
- package/es/components/ImageEditor/useImageHistory.js +21 -23
- package/es/components/PageBanner/index.d.ts +1 -1
- package/es/elements/ElementDamage/DamageFormButtons.d.ts +2 -3
- package/es/elements/ElementDamage/DamageFormButtons.js +1 -1
- package/es/elements/ElementDamage/TransportElementSelect.d.ts +1 -2
- package/es/elements/index.d.ts +5 -0
- package/es/elements/index.js +5 -0
- package/es/index.d.ts +2 -2
- package/es/index.js +2 -2
- package/package.json +4 -4
- package/src/{components → chrome}/AppMenu/AppMenu.css +648 -648
- package/src/{components → chrome}/AppMenu/AppMenu.tsx +285 -285
- package/src/{components → chrome}/AppMenu/AppMenuFavoriteButton.tsx +47 -47
- package/src/{components → chrome}/AppMenu/AppMenuHeader.tsx +79 -79
- package/src/{components → chrome}/AppMenu/AppMenuList.tsx +89 -89
- package/src/{components → chrome}/AppMenu/AppMenuRail.tsx +117 -117
- package/src/{components → chrome}/AppMenu/icons.tsx +76 -76
- package/src/{components → chrome}/AppMenu/index.ts +17 -17
- package/src/{components → chrome}/AppMenu/menuEntries.ts +128 -128
- package/src/{components → chrome}/AppMenu/types.ts +45 -45
- package/src/{components → chrome}/AppMenu/useFavorites.ts +40 -40
- package/src/{components → chrome}/AppMenu/useRovingTabIndex.ts +130 -130
- package/src/{components → chrome}/AppShell/index.tsx +287 -287
- package/src/colorScheme.ts +81 -81
- package/src/components/ImageEditor/ImageEditor.tsx +41 -6
- package/src/components/ImageEditor/index.ts +2 -0
- package/src/components/ImageEditor/plugins/zoomPlugin/ZoomControls.tsx +7 -8
- package/src/components/ImageEditor/useImageHistory.ts +27 -19
- package/src/components/LinkedCardList/index.scss +95 -93
- package/src/components/PageBanner/index.tsx +5 -4
- package/src/components/ProgressBar/index.scss +96 -94
- package/src/elements/ElementDamage/DamageFormButtons.tsx +2 -2
- package/src/elements/ElementDamage/TransportElementSelect.tsx +1 -1
- package/src/elements/index.ts +5 -0
- package/src/index.ts +70 -61
- /package/es/{components → chrome}/AppMenu/AppMenu.d.ts +0 -0
- /package/es/{components → chrome}/AppMenu/AppMenu.js +0 -0
- /package/es/{components → chrome}/AppMenu/AppMenuColorScheme.d.ts +0 -0
- /package/es/{components → chrome}/AppMenu/AppMenuColorScheme.js +0 -0
- /package/es/{components → chrome}/AppMenu/AppMenuFavoriteButton.d.ts +0 -0
- /package/es/{components → chrome}/AppMenu/AppMenuFavoriteButton.js +0 -0
- /package/es/{components → chrome}/AppMenu/AppMenuHeader.d.ts +0 -0
- /package/es/{components → chrome}/AppMenu/AppMenuHeader.js +0 -0
- /package/es/{components → chrome}/AppMenu/AppMenuList.d.ts +0 -0
- /package/es/{components → chrome}/AppMenu/AppMenuList.js +0 -0
- /package/es/{components → chrome}/AppMenu/AppMenuRail.d.ts +0 -0
- /package/es/{components → chrome}/AppMenu/AppMenuRail.js +0 -0
- /package/es/{components → chrome}/AppMenu/AppMenuToggle.d.ts +0 -0
- /package/es/{components → chrome}/AppMenu/AppMenuToggle.js +0 -0
- /package/es/{components → chrome}/AppMenu/AppMenuUserMenu.d.ts +0 -0
- /package/es/{components → chrome}/AppMenu/AppMenuUserMenu.js +0 -0
- /package/es/{components → chrome}/AppMenu/developerCategories.d.ts +0 -0
- /package/es/{components → chrome}/AppMenu/developerCategories.js +0 -0
- /package/es/{components → chrome}/AppMenu/icons.d.ts +0 -0
- /package/es/{components → chrome}/AppMenu/icons.js +0 -0
- /package/es/{components → chrome}/AppMenu/index.js +0 -0
- /package/es/{components → chrome}/AppMenu/menuEntries.d.ts +0 -0
- /package/es/{components → chrome}/AppMenu/menuEntries.js +0 -0
- /package/es/{components → chrome}/AppMenu/types.d.ts +0 -0
- /package/es/{components → chrome}/AppMenu/types.js +0 -0
- /package/es/{components → chrome}/AppMenu/useFavorites.d.ts +0 -0
- /package/es/{components → chrome}/AppMenu/useFavorites.js +0 -0
- /package/es/{components → chrome}/AppMenu/useRovingTabIndex.d.ts +0 -0
- /package/es/{components → chrome}/AppMenu/useRovingTabIndex.js +0 -0
- /package/es/{components → chrome}/AppMenu/useServiceWorkerUpdate.d.ts +0 -0
- /package/es/{components → chrome}/AppMenu/useServiceWorkerUpdate.js +0 -0
- /package/es/{components → chrome}/AppShell/index.d.ts +0 -0
- /package/es/{components → chrome}/AppShell/index.js +0 -0
- /package/src/{components → chrome}/AppMenu/AppMenuColorScheme.tsx +0 -0
- /package/src/{components → chrome}/AppMenu/AppMenuToggle.tsx +0 -0
- /package/src/{components → chrome}/AppMenu/AppMenuUserMenu.tsx +0 -0
- /package/src/{components → chrome}/AppMenu/developerCategories.ts +0 -0
- /package/src/{components → chrome}/AppMenu/useServiceWorkerUpdate.ts +0 -0
|
@@ -1,287 +1,287 @@
|
|
|
1
|
-
import { StyledEngineProvider, ThemeProvider } from "@mui/material";
|
|
2
|
-
import { createTheme as muiCreateTheme } from "@mui/material/styles";
|
|
3
|
-
import { getLocalizedString } from "@olenbetong/appframe-core";
|
|
4
|
-
import { AppErrorBoundary } from "@olenbetong/appframe-mui";
|
|
5
|
-
import { type ReactNode, useCallback, useEffect, useMemo, useState } from "react";
|
|
6
|
-
import { createPortal } from "react-dom";
|
|
7
|
-
|
|
8
|
-
import { AppMenu, type AppMenuArticle } from "../AppMenu/AppMenu.js";
|
|
9
|
-
import { AppMenuToggle } from "../AppMenu/AppMenuToggle.js";
|
|
10
|
-
import type { AppMenuUser } from "../AppMenu/AppMenuUserMenu.js";
|
|
11
|
-
import { createDeveloperCategories } from "../AppMenu/developerCategories.js";
|
|
12
|
-
import { useServiceWorkerUpdate } from "../AppMenu/useServiceWorkerUpdate.js";
|
|
13
|
-
|
|
14
|
-
const hostName = globalThis.af?.article?.hostName ?? globalThis.location?.hostname ?? "";
|
|
15
|
-
|
|
16
|
-
/*
|
|
17
|
-
* `aviw_WebShared_Articles` stores every published version of an article as its
|
|
18
|
-
* own row, and rows for all sites share the view. Without the host name filter
|
|
19
|
-
* and `ArticleVersion IS NULL` (which keeps only the development row, i.e. the
|
|
20
|
-
* canonical article) every app shows up once per published version.
|
|
21
|
-
*/
|
|
22
|
-
const menuArticlesWhereClause = [
|
|
23
|
-
`HostName = '${hostName.replace(/'/g, "''")}'`,
|
|
24
|
-
"ArticleVersion IS NULL",
|
|
25
|
-
"LastPublished IS NOT NULL",
|
|
26
|
-
"Authenticated = 1",
|
|
27
|
-
"ListOnFrontPage = 1",
|
|
28
|
-
"SysApp = 0",
|
|
29
|
-
"HideFromNav = 0",
|
|
30
|
-
"Hidden = 0",
|
|
31
|
-
"ISNULL(ParentArticleId, '') <> 'news'",
|
|
32
|
-
].join(" AND ");
|
|
33
|
-
|
|
34
|
-
// Created once — shared across all AppShell instances on a page.
|
|
35
|
-
const dsMenuArticles = af.data.generateApiDataObject<AppMenuArticle>({
|
|
36
|
-
resource: "aviw_WebShared_Articles",
|
|
37
|
-
id: "dsMenuArticles",
|
|
38
|
-
allowUpdate: false,
|
|
39
|
-
allowInsert: false,
|
|
40
|
-
allowDelete: false,
|
|
41
|
-
dynamicLoading: false,
|
|
42
|
-
fields: [
|
|
43
|
-
{ name: "ArticleId", type: "string", nullable: false },
|
|
44
|
-
{ name: "Title", type: "string", nullable: true },
|
|
45
|
-
{ name: "MenuGroup", type: "string", nullable: true },
|
|
46
|
-
{ name: "Path", type: "string", nullable: true },
|
|
47
|
-
{ name: "IsFavorite", type: "boolean", nullable: true },
|
|
48
|
-
],
|
|
49
|
-
parameters: {
|
|
50
|
-
maxRecords: -1,
|
|
51
|
-
whereClause: menuArticlesWhereClause,
|
|
52
|
-
sortOrder: [{ MenuGroup: af.data.SortOrder.Asc }, { Title: af.data.SortOrder.Asc }],
|
|
53
|
-
},
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
// Toggles the current user's favorite state for an article.
|
|
57
|
-
const procSetArticleFavorite = new af.ProcedureAPI<{ HostName: string; ArticleID: string; Favorite: boolean }, unknown>(
|
|
58
|
-
{
|
|
59
|
-
procedureId: "astp_WebShared_SetArticleFavorite",
|
|
60
|
-
parameters: [
|
|
61
|
-
{ name: "HostName", type: "string", required: true, hasDefault: false },
|
|
62
|
-
{ name: "ArticleID", type: "string", required: true, hasDefault: false },
|
|
63
|
-
{ name: "Favorite", type: "boolean", required: false, hasDefault: true },
|
|
64
|
-
],
|
|
65
|
-
timeout: 30000,
|
|
66
|
-
},
|
|
67
|
-
);
|
|
68
|
-
|
|
69
|
-
// The current user's employee record, used for the photo and full name.
|
|
70
|
-
const dsAppMenuUser = af.data.generateApiDataObject<AppMenuUser>({
|
|
71
|
-
resource: "aviw_Personnel_Employees_Lookup",
|
|
72
|
-
id: "dsAppMenuUser",
|
|
73
|
-
allowUpdate: false,
|
|
74
|
-
allowInsert: false,
|
|
75
|
-
allowDelete: false,
|
|
76
|
-
dynamicLoading: false,
|
|
77
|
-
fields: [
|
|
78
|
-
{ name: "PrimKey", type: "string", nullable: false },
|
|
79
|
-
{ name: "PersonID", type: "string", nullable: false },
|
|
80
|
-
{ name: "FirstName", type: "string", nullable: true },
|
|
81
|
-
{ name: "LastName", type: "string", nullable: true },
|
|
82
|
-
{ name: "Fullname", type: "string", nullable: true },
|
|
83
|
-
{ name: "ImageHash", type: "number", nullable: true },
|
|
84
|
-
],
|
|
85
|
-
parameters: {
|
|
86
|
-
maxRecords: 1,
|
|
87
|
-
// Resolved server side so it doesn't depend on the session being hydrated.
|
|
88
|
-
whereClause: "PersonID = SUSER_SNAME()",
|
|
89
|
-
},
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
function getColorScheme(): "light" | "dark" {
|
|
93
|
-
let scheme = document.body?.dataset.colorScheme ?? document.documentElement?.dataset.colorScheme ?? "light";
|
|
94
|
-
|
|
95
|
-
if (scheme === "auto") {
|
|
96
|
-
return globalThis.matchMedia?.("(prefers-color-scheme: dark)").matches ? "dark" : "light";
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
return scheme === "dark" ? "dark" : "light";
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Tracks the color scheme Designsystemet is rendering with. The article template
|
|
104
|
-
* sets `data-color-scheme` on `<body>`, so watch that attribute as well as the
|
|
105
|
-
* OS preference (used when the scheme is `auto`).
|
|
106
|
-
*/
|
|
107
|
-
function useColorScheme() {
|
|
108
|
-
let [scheme, setScheme] = useState<"light" | "dark">(() => getColorScheme());
|
|
109
|
-
|
|
110
|
-
useEffect(() => {
|
|
111
|
-
function update() {
|
|
112
|
-
setScheme(getColorScheme());
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
update();
|
|
116
|
-
|
|
117
|
-
let observer = new MutationObserver(update);
|
|
118
|
-
observer.observe(document.body, { attributes: true, attributeFilter: ["data-color-scheme"] });
|
|
119
|
-
observer.observe(document.documentElement, { attributes: true, attributeFilter: ["data-color-scheme"] });
|
|
120
|
-
|
|
121
|
-
let media = globalThis.matchMedia?.("(prefers-color-scheme: dark)");
|
|
122
|
-
media?.addEventListener("change", update);
|
|
123
|
-
|
|
124
|
-
return () => {
|
|
125
|
-
observer.disconnect();
|
|
126
|
-
media?.removeEventListener("change", update);
|
|
127
|
-
};
|
|
128
|
-
}, []);
|
|
129
|
-
|
|
130
|
-
return scheme;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
function buildMuiTheme(mode: "light" | "dark") {
|
|
134
|
-
const s = getComputedStyle(document.body);
|
|
135
|
-
const get = (v: string) => s.getPropertyValue(v).trim();
|
|
136
|
-
const isDark = mode === "dark";
|
|
137
|
-
|
|
138
|
-
return muiCreateTheme({
|
|
139
|
-
palette: {
|
|
140
|
-
mode,
|
|
141
|
-
primary: {
|
|
142
|
-
main: get("--ds-color-brand-base-default") || "#116069",
|
|
143
|
-
dark: get("--ds-color-brand-base-hover") || "#0d4b52",
|
|
144
|
-
contrastText: get("--ds-color-brand-base-contrast-default") || "#ffffff",
|
|
145
|
-
},
|
|
146
|
-
secondary: {
|
|
147
|
-
main: get("--ds-color-brand-light-base-default") || "#1a95a2",
|
|
148
|
-
},
|
|
149
|
-
background: {
|
|
150
|
-
default: get("--ds-color-neutral-background-default") || (isDark ? "#17181a" : "#ffffff"),
|
|
151
|
-
paper: get("--ds-color-neutral-background-default") || (isDark ? "#17181a" : "#ffffff"),
|
|
152
|
-
},
|
|
153
|
-
text: {
|
|
154
|
-
primary: get("--ds-color-neutral-text-default") || (isDark ? "#e5e6e7" : "#292c30"),
|
|
155
|
-
secondary: get("--ds-color-neutral-text-subtle") || (isDark ? "#b3b5b7" : "#5b5f64"),
|
|
156
|
-
},
|
|
157
|
-
divider: get("--ds-color-neutral-border-subtle") || (isDark ? "#4e5052" : "#bbbcbd"),
|
|
158
|
-
},
|
|
159
|
-
typography: {
|
|
160
|
-
fontFamily: [
|
|
161
|
-
"-apple-system",
|
|
162
|
-
"BlinkMacSystemFont",
|
|
163
|
-
'"Segoe UI"',
|
|
164
|
-
"Roboto",
|
|
165
|
-
'"Helvetica Neue"',
|
|
166
|
-
"Arial",
|
|
167
|
-
"sans-serif",
|
|
168
|
-
'"Apple Color Emoji"',
|
|
169
|
-
'"Segoe UI Emoji"',
|
|
170
|
-
'"Segoe UI Symbol"',
|
|
171
|
-
].join(","),
|
|
172
|
-
},
|
|
173
|
-
components: {
|
|
174
|
-
MuiTypography: {
|
|
175
|
-
styleOverrides: {
|
|
176
|
-
h1: { fontSize: "2.488rem" },
|
|
177
|
-
h2: { fontSize: "2.074rem" },
|
|
178
|
-
h3: { fontSize: "1.728rem" },
|
|
179
|
-
h4: { fontSize: "1.44rem" },
|
|
180
|
-
h5: { fontSize: "1.2rem" },
|
|
181
|
-
h6: { fontSize: "1rem" },
|
|
182
|
-
},
|
|
183
|
-
},
|
|
184
|
-
MuiAppBar: {
|
|
185
|
-
styleOverrides: {
|
|
186
|
-
root: {
|
|
187
|
-
"& .MuiTypography-h1": {
|
|
188
|
-
fontSize: "1.25rem",
|
|
189
|
-
fontWeight: "500",
|
|
190
|
-
},
|
|
191
|
-
},
|
|
192
|
-
},
|
|
193
|
-
},
|
|
194
|
-
MuiButton: {
|
|
195
|
-
styleOverrides: {
|
|
196
|
-
root: { borderRadius: 2 },
|
|
197
|
-
},
|
|
198
|
-
},
|
|
199
|
-
MuiDialogTitle: {
|
|
200
|
-
styleOverrides: {
|
|
201
|
-
root: {
|
|
202
|
-
fontSize: "1.2rem",
|
|
203
|
-
fontWeight: 500,
|
|
204
|
-
paddingLeft: 16,
|
|
205
|
-
paddingRight: 16,
|
|
206
|
-
},
|
|
207
|
-
},
|
|
208
|
-
},
|
|
209
|
-
MuiFormLabel: {
|
|
210
|
-
styleOverrides: {
|
|
211
|
-
root: { color: get("--ds-color-neutral-text-subtle") || "rgba(0, 0, 0, 0.72)" },
|
|
212
|
-
},
|
|
213
|
-
},
|
|
214
|
-
MuiTextField: { defaultProps: { variant: "filled" } },
|
|
215
|
-
MuiSelect: { defaultProps: { variant: "filled" } },
|
|
216
|
-
MuiFormControl: { defaultProps: { variant: "filled" } },
|
|
217
|
-
},
|
|
218
|
-
});
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
export type AppShellProps = {
|
|
222
|
-
children: ReactNode;
|
|
223
|
-
};
|
|
224
|
-
|
|
225
|
-
export function AppShell({ children }: AppShellProps) {
|
|
226
|
-
const colorScheme = useColorScheme();
|
|
227
|
-
const [isAppMenuOpen, setIsAppMenuOpen] = useState(false);
|
|
228
|
-
const { isUpdateAvailable, installUpdate } = useServiceWorkerUpdate();
|
|
229
|
-
|
|
230
|
-
// The developer tools are only reachable for developers, so hide them for
|
|
231
|
-
// everyone else instead of showing links that all return 403.
|
|
232
|
-
const categories = useMemo(() => (globalThis.af?.userSession?.isDeveloper ? createDeveloperCategories() : []), []);
|
|
233
|
-
|
|
234
|
-
// The portal isn't listed with the apps, so link to it from the menu itself
|
|
235
|
-
// unless that's the article we're already on.
|
|
236
|
-
const homeLink = useMemo(() => {
|
|
237
|
-
const articleId = (globalThis.af?.article?.id ?? "").replace(/\.\d+$/, "");
|
|
238
|
-
return articleId === "portal" ? undefined : { label: getLocalizedString("Front page"), href: "/portal" };
|
|
239
|
-
}, []);
|
|
240
|
-
|
|
241
|
-
const toggleFavorite = useCallback(async (articleId: string, favorite: boolean) => {
|
|
242
|
-
await procSetArticleFavorite.execute({ HostName: hostName, ArticleID: articleId, Favorite: favorite });
|
|
243
|
-
}, []);
|
|
244
|
-
|
|
245
|
-
// Rebuilt whenever the color scheme changes so MUI components (notably the
|
|
246
|
-
// data grid) follow Designsystemet instead of staying stuck in light mode.
|
|
247
|
-
// Also re-read after mount, since the stylesheets are imported from JS and
|
|
248
|
-
// the CSS variables aren't necessarily resolved during the first render.
|
|
249
|
-
const [theme, setTheme] = useState(() => buildMuiTheme(colorScheme));
|
|
250
|
-
useEffect(() => {
|
|
251
|
-
setTheme(buildMuiTheme(colorScheme));
|
|
252
|
-
}, [colorScheme]);
|
|
253
|
-
|
|
254
|
-
const appMenuSlot = document.getElementById("ob-toolbar-app-menu");
|
|
255
|
-
|
|
256
|
-
return (
|
|
257
|
-
<StyledEngineProvider injectFirst>
|
|
258
|
-
<ThemeProvider theme={theme}>
|
|
259
|
-
<AppErrorBoundary>
|
|
260
|
-
{appMenuSlot &&
|
|
261
|
-
createPortal(
|
|
262
|
-
<AppMenuToggle
|
|
263
|
-
open={isAppMenuOpen}
|
|
264
|
-
hasUpdate={isUpdateAvailable}
|
|
265
|
-
aria-controls="ob-app-menu"
|
|
266
|
-
onClick={() => setIsAppMenuOpen((open) => !open)}
|
|
267
|
-
/>,
|
|
268
|
-
appMenuSlot,
|
|
269
|
-
)}
|
|
270
|
-
<AppMenu
|
|
271
|
-
id="ob-app-menu"
|
|
272
|
-
dataObject={dsMenuArticles}
|
|
273
|
-
userDataObject={dsAppMenuUser}
|
|
274
|
-
categories={categories}
|
|
275
|
-
homeLink={homeLink}
|
|
276
|
-
onToggleFavorite={toggleFavorite}
|
|
277
|
-
hasUpdate={isUpdateAvailable}
|
|
278
|
-
onInstallUpdate={installUpdate}
|
|
279
|
-
open={isAppMenuOpen}
|
|
280
|
-
onClose={() => setIsAppMenuOpen(false)}
|
|
281
|
-
/>
|
|
282
|
-
{children}
|
|
283
|
-
</AppErrorBoundary>
|
|
284
|
-
</ThemeProvider>
|
|
285
|
-
</StyledEngineProvider>
|
|
286
|
-
);
|
|
287
|
-
}
|
|
1
|
+
import { StyledEngineProvider, ThemeProvider } from "@mui/material";
|
|
2
|
+
import { createTheme as muiCreateTheme } from "@mui/material/styles";
|
|
3
|
+
import { getLocalizedString } from "@olenbetong/appframe-core";
|
|
4
|
+
import { AppErrorBoundary } from "@olenbetong/appframe-mui";
|
|
5
|
+
import { type ReactNode, useCallback, useEffect, useMemo, useState } from "react";
|
|
6
|
+
import { createPortal } from "react-dom";
|
|
7
|
+
|
|
8
|
+
import { AppMenu, type AppMenuArticle } from "../AppMenu/AppMenu.js";
|
|
9
|
+
import { AppMenuToggle } from "../AppMenu/AppMenuToggle.js";
|
|
10
|
+
import type { AppMenuUser } from "../AppMenu/AppMenuUserMenu.js";
|
|
11
|
+
import { createDeveloperCategories } from "../AppMenu/developerCategories.js";
|
|
12
|
+
import { useServiceWorkerUpdate } from "../AppMenu/useServiceWorkerUpdate.js";
|
|
13
|
+
|
|
14
|
+
const hostName = globalThis.af?.article?.hostName ?? globalThis.location?.hostname ?? "";
|
|
15
|
+
|
|
16
|
+
/*
|
|
17
|
+
* `aviw_WebShared_Articles` stores every published version of an article as its
|
|
18
|
+
* own row, and rows for all sites share the view. Without the host name filter
|
|
19
|
+
* and `ArticleVersion IS NULL` (which keeps only the development row, i.e. the
|
|
20
|
+
* canonical article) every app shows up once per published version.
|
|
21
|
+
*/
|
|
22
|
+
const menuArticlesWhereClause = [
|
|
23
|
+
`HostName = '${hostName.replace(/'/g, "''")}'`,
|
|
24
|
+
"ArticleVersion IS NULL",
|
|
25
|
+
"LastPublished IS NOT NULL",
|
|
26
|
+
"Authenticated = 1",
|
|
27
|
+
"ListOnFrontPage = 1",
|
|
28
|
+
"SysApp = 0",
|
|
29
|
+
"HideFromNav = 0",
|
|
30
|
+
"Hidden = 0",
|
|
31
|
+
"ISNULL(ParentArticleId, '') <> 'news'",
|
|
32
|
+
].join(" AND ");
|
|
33
|
+
|
|
34
|
+
// Created once — shared across all AppShell instances on a page.
|
|
35
|
+
const dsMenuArticles = af.data.generateApiDataObject<AppMenuArticle>({
|
|
36
|
+
resource: "aviw_WebShared_Articles",
|
|
37
|
+
id: "dsMenuArticles",
|
|
38
|
+
allowUpdate: false,
|
|
39
|
+
allowInsert: false,
|
|
40
|
+
allowDelete: false,
|
|
41
|
+
dynamicLoading: false,
|
|
42
|
+
fields: [
|
|
43
|
+
{ name: "ArticleId", type: "string", nullable: false },
|
|
44
|
+
{ name: "Title", type: "string", nullable: true },
|
|
45
|
+
{ name: "MenuGroup", type: "string", nullable: true },
|
|
46
|
+
{ name: "Path", type: "string", nullable: true },
|
|
47
|
+
{ name: "IsFavorite", type: "boolean", nullable: true },
|
|
48
|
+
],
|
|
49
|
+
parameters: {
|
|
50
|
+
maxRecords: -1,
|
|
51
|
+
whereClause: menuArticlesWhereClause,
|
|
52
|
+
sortOrder: [{ MenuGroup: af.data.SortOrder.Asc }, { Title: af.data.SortOrder.Asc }],
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
// Toggles the current user's favorite state for an article.
|
|
57
|
+
const procSetArticleFavorite = new af.ProcedureAPI<{ HostName: string; ArticleID: string; Favorite: boolean }, unknown>(
|
|
58
|
+
{
|
|
59
|
+
procedureId: "astp_WebShared_SetArticleFavorite",
|
|
60
|
+
parameters: [
|
|
61
|
+
{ name: "HostName", type: "string", required: true, hasDefault: false },
|
|
62
|
+
{ name: "ArticleID", type: "string", required: true, hasDefault: false },
|
|
63
|
+
{ name: "Favorite", type: "boolean", required: false, hasDefault: true },
|
|
64
|
+
],
|
|
65
|
+
timeout: 30000,
|
|
66
|
+
},
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
// The current user's employee record, used for the photo and full name.
|
|
70
|
+
const dsAppMenuUser = af.data.generateApiDataObject<AppMenuUser>({
|
|
71
|
+
resource: "aviw_Personnel_Employees_Lookup",
|
|
72
|
+
id: "dsAppMenuUser",
|
|
73
|
+
allowUpdate: false,
|
|
74
|
+
allowInsert: false,
|
|
75
|
+
allowDelete: false,
|
|
76
|
+
dynamicLoading: false,
|
|
77
|
+
fields: [
|
|
78
|
+
{ name: "PrimKey", type: "string", nullable: false },
|
|
79
|
+
{ name: "PersonID", type: "string", nullable: false },
|
|
80
|
+
{ name: "FirstName", type: "string", nullable: true },
|
|
81
|
+
{ name: "LastName", type: "string", nullable: true },
|
|
82
|
+
{ name: "Fullname", type: "string", nullable: true },
|
|
83
|
+
{ name: "ImageHash", type: "number", nullable: true },
|
|
84
|
+
],
|
|
85
|
+
parameters: {
|
|
86
|
+
maxRecords: 1,
|
|
87
|
+
// Resolved server side so it doesn't depend on the session being hydrated.
|
|
88
|
+
whereClause: "PersonID = SUSER_SNAME()",
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
function getColorScheme(): "light" | "dark" {
|
|
93
|
+
let scheme = document.body?.dataset.colorScheme ?? document.documentElement?.dataset.colorScheme ?? "light";
|
|
94
|
+
|
|
95
|
+
if (scheme === "auto") {
|
|
96
|
+
return globalThis.matchMedia?.("(prefers-color-scheme: dark)").matches ? "dark" : "light";
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return scheme === "dark" ? "dark" : "light";
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Tracks the color scheme Designsystemet is rendering with. The article template
|
|
104
|
+
* sets `data-color-scheme` on `<body>`, so watch that attribute as well as the
|
|
105
|
+
* OS preference (used when the scheme is `auto`).
|
|
106
|
+
*/
|
|
107
|
+
function useColorScheme() {
|
|
108
|
+
let [scheme, setScheme] = useState<"light" | "dark">(() => getColorScheme());
|
|
109
|
+
|
|
110
|
+
useEffect(() => {
|
|
111
|
+
function update() {
|
|
112
|
+
setScheme(getColorScheme());
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
update();
|
|
116
|
+
|
|
117
|
+
let observer = new MutationObserver(update);
|
|
118
|
+
observer.observe(document.body, { attributes: true, attributeFilter: ["data-color-scheme"] });
|
|
119
|
+
observer.observe(document.documentElement, { attributes: true, attributeFilter: ["data-color-scheme"] });
|
|
120
|
+
|
|
121
|
+
let media = globalThis.matchMedia?.("(prefers-color-scheme: dark)");
|
|
122
|
+
media?.addEventListener("change", update);
|
|
123
|
+
|
|
124
|
+
return () => {
|
|
125
|
+
observer.disconnect();
|
|
126
|
+
media?.removeEventListener("change", update);
|
|
127
|
+
};
|
|
128
|
+
}, []);
|
|
129
|
+
|
|
130
|
+
return scheme;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function buildMuiTheme(mode: "light" | "dark") {
|
|
134
|
+
const s = getComputedStyle(document.body);
|
|
135
|
+
const get = (v: string) => s.getPropertyValue(v).trim();
|
|
136
|
+
const isDark = mode === "dark";
|
|
137
|
+
|
|
138
|
+
return muiCreateTheme({
|
|
139
|
+
palette: {
|
|
140
|
+
mode,
|
|
141
|
+
primary: {
|
|
142
|
+
main: get("--ds-color-brand-base-default") || "#116069",
|
|
143
|
+
dark: get("--ds-color-brand-base-hover") || "#0d4b52",
|
|
144
|
+
contrastText: get("--ds-color-brand-base-contrast-default") || "#ffffff",
|
|
145
|
+
},
|
|
146
|
+
secondary: {
|
|
147
|
+
main: get("--ds-color-brand-light-base-default") || "#1a95a2",
|
|
148
|
+
},
|
|
149
|
+
background: {
|
|
150
|
+
default: get("--ds-color-neutral-background-default") || (isDark ? "#17181a" : "#ffffff"),
|
|
151
|
+
paper: get("--ds-color-neutral-background-default") || (isDark ? "#17181a" : "#ffffff"),
|
|
152
|
+
},
|
|
153
|
+
text: {
|
|
154
|
+
primary: get("--ds-color-neutral-text-default") || (isDark ? "#e5e6e7" : "#292c30"),
|
|
155
|
+
secondary: get("--ds-color-neutral-text-subtle") || (isDark ? "#b3b5b7" : "#5b5f64"),
|
|
156
|
+
},
|
|
157
|
+
divider: get("--ds-color-neutral-border-subtle") || (isDark ? "#4e5052" : "#bbbcbd"),
|
|
158
|
+
},
|
|
159
|
+
typography: {
|
|
160
|
+
fontFamily: [
|
|
161
|
+
"-apple-system",
|
|
162
|
+
"BlinkMacSystemFont",
|
|
163
|
+
'"Segoe UI"',
|
|
164
|
+
"Roboto",
|
|
165
|
+
'"Helvetica Neue"',
|
|
166
|
+
"Arial",
|
|
167
|
+
"sans-serif",
|
|
168
|
+
'"Apple Color Emoji"',
|
|
169
|
+
'"Segoe UI Emoji"',
|
|
170
|
+
'"Segoe UI Symbol"',
|
|
171
|
+
].join(","),
|
|
172
|
+
},
|
|
173
|
+
components: {
|
|
174
|
+
MuiTypography: {
|
|
175
|
+
styleOverrides: {
|
|
176
|
+
h1: { fontSize: "2.488rem" },
|
|
177
|
+
h2: { fontSize: "2.074rem" },
|
|
178
|
+
h3: { fontSize: "1.728rem" },
|
|
179
|
+
h4: { fontSize: "1.44rem" },
|
|
180
|
+
h5: { fontSize: "1.2rem" },
|
|
181
|
+
h6: { fontSize: "1rem" },
|
|
182
|
+
},
|
|
183
|
+
},
|
|
184
|
+
MuiAppBar: {
|
|
185
|
+
styleOverrides: {
|
|
186
|
+
root: {
|
|
187
|
+
"& .MuiTypography-h1": {
|
|
188
|
+
fontSize: "1.25rem",
|
|
189
|
+
fontWeight: "500",
|
|
190
|
+
},
|
|
191
|
+
},
|
|
192
|
+
},
|
|
193
|
+
},
|
|
194
|
+
MuiButton: {
|
|
195
|
+
styleOverrides: {
|
|
196
|
+
root: { borderRadius: 2 },
|
|
197
|
+
},
|
|
198
|
+
},
|
|
199
|
+
MuiDialogTitle: {
|
|
200
|
+
styleOverrides: {
|
|
201
|
+
root: {
|
|
202
|
+
fontSize: "1.2rem",
|
|
203
|
+
fontWeight: 500,
|
|
204
|
+
paddingLeft: 16,
|
|
205
|
+
paddingRight: 16,
|
|
206
|
+
},
|
|
207
|
+
},
|
|
208
|
+
},
|
|
209
|
+
MuiFormLabel: {
|
|
210
|
+
styleOverrides: {
|
|
211
|
+
root: { color: get("--ds-color-neutral-text-subtle") || "rgba(0, 0, 0, 0.72)" },
|
|
212
|
+
},
|
|
213
|
+
},
|
|
214
|
+
MuiTextField: { defaultProps: { variant: "filled" } },
|
|
215
|
+
MuiSelect: { defaultProps: { variant: "filled" } },
|
|
216
|
+
MuiFormControl: { defaultProps: { variant: "filled" } },
|
|
217
|
+
},
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
export type AppShellProps = {
|
|
222
|
+
children: ReactNode;
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
export function AppShell({ children }: AppShellProps) {
|
|
226
|
+
const colorScheme = useColorScheme();
|
|
227
|
+
const [isAppMenuOpen, setIsAppMenuOpen] = useState(false);
|
|
228
|
+
const { isUpdateAvailable, installUpdate } = useServiceWorkerUpdate();
|
|
229
|
+
|
|
230
|
+
// The developer tools are only reachable for developers, so hide them for
|
|
231
|
+
// everyone else instead of showing links that all return 403.
|
|
232
|
+
const categories = useMemo(() => (globalThis.af?.userSession?.isDeveloper ? createDeveloperCategories() : []), []);
|
|
233
|
+
|
|
234
|
+
// The portal isn't listed with the apps, so link to it from the menu itself
|
|
235
|
+
// unless that's the article we're already on.
|
|
236
|
+
const homeLink = useMemo(() => {
|
|
237
|
+
const articleId = (globalThis.af?.article?.id ?? "").replace(/\.\d+$/, "");
|
|
238
|
+
return articleId === "portal" ? undefined : { label: getLocalizedString("Front page"), href: "/portal" };
|
|
239
|
+
}, []);
|
|
240
|
+
|
|
241
|
+
const toggleFavorite = useCallback(async (articleId: string, favorite: boolean) => {
|
|
242
|
+
await procSetArticleFavorite.execute({ HostName: hostName, ArticleID: articleId, Favorite: favorite });
|
|
243
|
+
}, []);
|
|
244
|
+
|
|
245
|
+
// Rebuilt whenever the color scheme changes so MUI components (notably the
|
|
246
|
+
// data grid) follow Designsystemet instead of staying stuck in light mode.
|
|
247
|
+
// Also re-read after mount, since the stylesheets are imported from JS and
|
|
248
|
+
// the CSS variables aren't necessarily resolved during the first render.
|
|
249
|
+
const [theme, setTheme] = useState(() => buildMuiTheme(colorScheme));
|
|
250
|
+
useEffect(() => {
|
|
251
|
+
setTheme(buildMuiTheme(colorScheme));
|
|
252
|
+
}, [colorScheme]);
|
|
253
|
+
|
|
254
|
+
const appMenuSlot = document.getElementById("ob-toolbar-app-menu");
|
|
255
|
+
|
|
256
|
+
return (
|
|
257
|
+
<StyledEngineProvider injectFirst>
|
|
258
|
+
<ThemeProvider theme={theme}>
|
|
259
|
+
<AppErrorBoundary>
|
|
260
|
+
{appMenuSlot &&
|
|
261
|
+
createPortal(
|
|
262
|
+
<AppMenuToggle
|
|
263
|
+
open={isAppMenuOpen}
|
|
264
|
+
hasUpdate={isUpdateAvailable}
|
|
265
|
+
aria-controls="ob-app-menu"
|
|
266
|
+
onClick={() => setIsAppMenuOpen((open) => !open)}
|
|
267
|
+
/>,
|
|
268
|
+
appMenuSlot,
|
|
269
|
+
)}
|
|
270
|
+
<AppMenu
|
|
271
|
+
id="ob-app-menu"
|
|
272
|
+
dataObject={dsMenuArticles}
|
|
273
|
+
userDataObject={dsAppMenuUser}
|
|
274
|
+
categories={categories}
|
|
275
|
+
homeLink={homeLink}
|
|
276
|
+
onToggleFavorite={toggleFavorite}
|
|
277
|
+
hasUpdate={isUpdateAvailable}
|
|
278
|
+
onInstallUpdate={installUpdate}
|
|
279
|
+
open={isAppMenuOpen}
|
|
280
|
+
onClose={() => setIsAppMenuOpen(false)}
|
|
281
|
+
/>
|
|
282
|
+
{children}
|
|
283
|
+
</AppErrorBoundary>
|
|
284
|
+
</ThemeProvider>
|
|
285
|
+
</StyledEngineProvider>
|
|
286
|
+
);
|
|
287
|
+
}
|