@orsetra/shared-ui 1.16.0 → 1.17.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/auth/session-controller.ts +3 -0
- package/components/layout/index.ts +2 -0
- package/components/layout/layout-container.tsx +2 -0
- package/components/layout/shell-skeleton.tsx +29 -0
- package/components/layout/speculation-rules.tsx +35 -0
- package/index.ts +1 -0
- package/lib/session-cache.ts +56 -0
- package/package.json +5 -1
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { clearSessionCache } from '../lib/session-cache';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* The state of the user's session, for every application of the console.
|
|
3
5
|
*
|
|
@@ -218,6 +220,7 @@ export class SessionController {
|
|
|
218
220
|
|
|
219
221
|
async signOut(): Promise<void> {
|
|
220
222
|
this.update({ status: 'signing-out', pending: false, error: null });
|
|
223
|
+
clearSessionCache();
|
|
221
224
|
try {
|
|
222
225
|
await this.userManager.signoutRedirect();
|
|
223
226
|
} catch (error) {
|
|
@@ -38,3 +38,5 @@ export { EnvironmentSwitcher, type EnvironmentSwitcherProps } from './environmen
|
|
|
38
38
|
export { EnvironmentGate, type EnvironmentGateProps } from './environment-gate'
|
|
39
39
|
export { ProjectGate, useStoreHydrated, type ProjectGateProps } from './project-gate'
|
|
40
40
|
export { PageWithSidePanel } from './page-with-side-panel'
|
|
41
|
+
export { ShellSkeleton } from './shell-skeleton'
|
|
42
|
+
export { SpeculationRules } from './speculation-rules'
|
|
@@ -16,6 +16,7 @@ import { EnvironmentGate } from "./environment-gate"
|
|
|
16
16
|
import { ProjectGate } from "./project-gate"
|
|
17
17
|
import type { ProjectSelection } from "../../lib/project-requirement"
|
|
18
18
|
import { useMenuContext } from "../../context/menu-context"
|
|
19
|
+
import { SpeculationRules } from "./speculation-rules"
|
|
19
20
|
|
|
20
21
|
// ─── Layout ──────────────────────────────────────────────────────────────────
|
|
21
22
|
|
|
@@ -130,6 +131,7 @@ function LayoutContent({
|
|
|
130
131
|
|
|
131
132
|
return (
|
|
132
133
|
<div className="flex flex-col h-screen w-full bg-white overflow-hidden">
|
|
134
|
+
<SpeculationRules />
|
|
133
135
|
<header className="h-14 bg-gray-50 border-b border-ui-border flex-shrink-0">
|
|
134
136
|
<div className="h-full flex items-center justify-between">
|
|
135
137
|
<div
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import { Skeleton } from "./skeleton"
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The frame of LayoutContainer (header, menu, page) drawn while the session is checked, in place of
|
|
7
|
+
* a spinner on a blank page: the page keeps its place and its proportions from the first paint.
|
|
8
|
+
*/
|
|
9
|
+
export function ShellSkeleton({ label }: { label?: string }) {
|
|
10
|
+
return (
|
|
11
|
+
<div className="flex flex-col h-screen w-full bg-white overflow-hidden" aria-busy="true" aria-label={label}>
|
|
12
|
+
<header className="h-14 bg-gray-50 border-b border-ui-border flex-shrink-0 flex items-center justify-between px-4 md:px-6">
|
|
13
|
+
<Skeleton className="h-6 w-28" />
|
|
14
|
+
<Skeleton className="h-8 w-8 rounded-full" />
|
|
15
|
+
</header>
|
|
16
|
+
<div className="flex flex-1 min-h-0">
|
|
17
|
+
<aside className="hidden md:flex flex-col gap-3 w-56 lg:w-60 xl:w-64 border-r border-ui-border p-4">
|
|
18
|
+
{Array.from({ length: 7 }, (_, i) => <Skeleton key={i} className="h-5 w-full" />)}
|
|
19
|
+
</aside>
|
|
20
|
+
<main className="flex-1 bg-ibm-gray-10 p-6 space-y-4">
|
|
21
|
+
<Skeleton className="h-8 w-64" />
|
|
22
|
+
<Skeleton className="h-4 w-96 max-w-full" />
|
|
23
|
+
<Skeleton className="h-48 w-full" />
|
|
24
|
+
</main>
|
|
25
|
+
</div>
|
|
26
|
+
{label && <span className="sr-only">{label}</span>}
|
|
27
|
+
</div>
|
|
28
|
+
)
|
|
29
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Each section of the console is an application of its own: going from one to another loads a new
|
|
5
|
+
* document. These rules ask the browser (Chromium) to prerender the application a link leads to once
|
|
6
|
+
* the pointer rests on it (eagerness "moderate"), so that the click shows a page already built. The
|
|
7
|
+
* links of the current application are left out: Next navigates between them itself.
|
|
8
|
+
*
|
|
9
|
+
* Browsers without speculation rules ignore the script.
|
|
10
|
+
*/
|
|
11
|
+
const BASE_PATH = (process.env.NEXT_PUBLIC_BASE_PATH || '').replace(/\/+$/, '')
|
|
12
|
+
|
|
13
|
+
const own = BASE_PATH
|
|
14
|
+
? [{ not: { href_matches: BASE_PATH } }, { not: { href_matches: `${BASE_PATH}/*` } }]
|
|
15
|
+
: []
|
|
16
|
+
|
|
17
|
+
const RULES = JSON.stringify({
|
|
18
|
+
prerender: [
|
|
19
|
+
{
|
|
20
|
+
where: {
|
|
21
|
+
and: [
|
|
22
|
+
{ href_matches: '/*' },
|
|
23
|
+
...own,
|
|
24
|
+
{ not: { href_matches: '/callback*' } },
|
|
25
|
+
{ not: { selector_matches: '[target=_blank], [download], [data-no-prerender]' } },
|
|
26
|
+
],
|
|
27
|
+
},
|
|
28
|
+
eagerness: 'moderate',
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
export function SpeculationRules() {
|
|
34
|
+
return <script type="speculationrules" dangerouslySetInnerHTML={{ __html: RULES }} />
|
|
35
|
+
}
|
package/index.ts
CHANGED
|
@@ -11,6 +11,7 @@ export * from './lib/env-services'
|
|
|
11
11
|
export * from './lib/quick-access-href'
|
|
12
12
|
export * from './lib/status-indicator'
|
|
13
13
|
export * from './lib/field-description'
|
|
14
|
+
export * from './lib/session-cache'
|
|
14
15
|
export { createPlatformConfigSource, templateFilter, configOfHit, environmentWithTargets, type ConfigSource } from './lib/config-source'
|
|
15
16
|
export { default as HttpClient, useHttpClient, ApiError } from './lib/http-client'
|
|
16
17
|
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a page loads for the whole session (the organisation, the business units), kept in
|
|
3
|
+
* sessionStorage: the applications of the console share an origin, so the next application shows
|
|
4
|
+
* at once what the previous one loaded, then refreshes it.
|
|
5
|
+
*
|
|
6
|
+
* The key carries the user: the cache of a tab never serves another account.
|
|
7
|
+
*/
|
|
8
|
+
const PREFIX = 'orsetra:session-cache:'
|
|
9
|
+
|
|
10
|
+
function storage(): Storage | null {
|
|
11
|
+
try {
|
|
12
|
+
return typeof window === 'undefined' ? null : window.sessionStorage
|
|
13
|
+
} catch {
|
|
14
|
+
return null
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function readSessionCache<T>(key: string): T | undefined {
|
|
19
|
+
const raw = storage()?.getItem(PREFIX + key)
|
|
20
|
+
if (raw == null) return undefined
|
|
21
|
+
try {
|
|
22
|
+
return JSON.parse(raw) as T
|
|
23
|
+
} catch {
|
|
24
|
+
return undefined
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function writeSessionCache<T>(key: string, value: T): void {
|
|
29
|
+
try {
|
|
30
|
+
storage()?.setItem(PREFIX + key, JSON.stringify(value))
|
|
31
|
+
} catch {
|
|
32
|
+
// Full or refused storage: the page works without the cache.
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function clearSessionCache(): void {
|
|
37
|
+
const s = storage()
|
|
38
|
+
if (!s) return
|
|
39
|
+
for (let i = s.length - 1; i >= 0; i--) {
|
|
40
|
+
const k = s.key(i)
|
|
41
|
+
if (k?.startsWith(PREFIX)) s.removeItem(k)
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Applies the cached value at once if there is one, then loads the current one, applies and keeps
|
|
47
|
+
* it. A failed load leaves the cached value applied and rejects, as the load alone would.
|
|
48
|
+
*/
|
|
49
|
+
export async function withSessionCache<T>(key: string, load: () => Promise<T>, apply: (value: T) => void): Promise<T> {
|
|
50
|
+
const cached = readSessionCache<T>(key)
|
|
51
|
+
if (cached !== undefined) apply(cached)
|
|
52
|
+
const fresh = await load()
|
|
53
|
+
apply(fresh)
|
|
54
|
+
writeSessionCache(key, fresh)
|
|
55
|
+
return fresh
|
|
56
|
+
}
|
package/package.json
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orsetra/shared-ui",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.17.0",
|
|
4
4
|
"description": "Shared UI components for Orsetra platform",
|
|
5
5
|
"main": "./index.ts",
|
|
6
6
|
"types": "./index.ts",
|
|
7
|
+
"sideEffects": [
|
|
8
|
+
"./i18n.tsx",
|
|
9
|
+
"./utils/locale.tsx"
|
|
10
|
+
],
|
|
7
11
|
"exports": {
|
|
8
12
|
".": "./index.ts",
|
|
9
13
|
"./components/ui": "./components/ui/index.ts",
|