@orsetra/shared-ui 1.15.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.
@@ -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
+ }
@@ -6,6 +6,7 @@ export { Avatar, AvatarImage, AvatarFallback } from './avatar'
6
6
  export { DropdownMenu, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator } from './dropdown-menu'
7
7
  export { Separator } from './separator'
8
8
  export { Logo } from './logo'
9
+ export { ProductMark, PRODUCT_IDENTITIES, type ProductId, type ProductMarkProps, type ProductMarkVariant } from './product-mark'
9
10
  export { UserMenu, type UserMenuItem, type UserMenuConfig } from './user-menu'
10
11
  export { Input } from './input'
11
12
  export { Tooltip, TooltipTrigger, TooltipContent, TooltipProvider } from './tooltip'
@@ -0,0 +1,91 @@
1
+ /**
2
+ * The mark of a service of the platform: its pictogram on a square tile, and optionally its code.
3
+ * Drawn from graphic/product/svg; the rules are in graphic/BRAND-GUIDELINES.md, Product Identities.
4
+ */
5
+ import { cn } from "../../lib/utils"
6
+
7
+ export type ProductId = "cis" | "cms" | "apim"
8
+ export type ProductMarkVariant = "mark" | "tile" | "gray"
9
+
10
+ export const PRODUCT_IDENTITIES: Record<ProductId, { code: string; name: string; color: string; tint: string }> = {
11
+ cis: { code: "CIS", name: "Camel Integration Service", color: "#0F62FE", tint: "#EDF5FF" },
12
+ cms: { code: "CMS", name: "Camel Messaging Service", color: "#007D79", tint: "#D9FBFB" },
13
+ apim: { code: "APIM", name: "API Management", color: "#8A3FFC", tint: "#F6F2FF" },
14
+ }
15
+
16
+ function Pictogram({ product, ink }: { product: ProductId; ink: string }) {
17
+ const line = { fill: "none", stroke: ink, strokeWidth: 2, strokeLinecap: "square" as const, strokeLinejoin: "miter" as const }
18
+ if (product === "cis") {
19
+ return (
20
+ <g>
21
+ <rect x="6" y="19" width="8" height="10" {...line} />
22
+ <path d="M14 24h4" {...line} />
23
+ <path d="M24 17l7 7-7 7-7-7z" fill={ink} />
24
+ <path d="M31 24h6" {...line} />
25
+ <path d="M34 21l3 3-3 3" {...line} />
26
+ <rect x="38" y="19" width="4" height="10" {...line} />
27
+ </g>
28
+ )
29
+ }
30
+ if (product === "cms") {
31
+ return (
32
+ <g>
33
+ <rect x="7" y="9" width="8" height="8" {...line} />
34
+ <rect x="20" y="9" width="8" height="8" {...line} />
35
+ <rect x="33" y="9" width="8" height="8" {...line} />
36
+ <path d="M11 17v12M24 17v12M37 17v12" {...line} />
37
+ <rect x="7" y="29" width="34" height="10" fill={ink} />
38
+ </g>
39
+ )
40
+ }
41
+ return (
42
+ <g>
43
+ <path d="M17 40V8h14v32" {...line} />
44
+ <path d="M6 24h34" {...line} />
45
+ <path d="M37 21l3 3-3 3" {...line} />
46
+ <rect x="21" y="12" width="6" height="6" fill={ink} />
47
+ </g>
48
+ )
49
+ }
50
+
51
+ export interface ProductMarkProps {
52
+ product: ProductId
53
+ /** Side of the tile, in pixels. */
54
+ size?: number
55
+ variant?: ProductMarkVariant
56
+ /** Shows the code of the service next to the tile, from 32px. */
57
+ withCode?: boolean
58
+ /** Names the mark for assistive technologies; without it the mark is decorative. */
59
+ label?: string
60
+ className?: string
61
+ }
62
+
63
+ export function ProductMark({ product, size = 40, variant = "mark", withCode = false, label, className }: ProductMarkProps) {
64
+ const identity = PRODUCT_IDENTITIES[product]
65
+ const ground = variant === "tile" ? identity.color : variant === "gray" ? "#F4F4F4" : identity.tint
66
+ const ink = variant === "tile" ? "#FFFFFF" : variant === "gray" ? "#6F6F6F" : identity.color
67
+ return (
68
+ <span className={cn("inline-flex items-center gap-2.5 align-middle", className)}>
69
+ <svg
70
+ width={size}
71
+ height={size}
72
+ viewBox="0 0 48 48"
73
+ className="block flex-shrink-0"
74
+ role={label ? "img" : undefined}
75
+ aria-label={label}
76
+ aria-hidden={label ? undefined : true}
77
+ >
78
+ <rect width="48" height="48" fill={ground} />
79
+ <Pictogram product={product} ink={ink} />
80
+ </svg>
81
+ {withCode && size >= 32 && (
82
+ <span
83
+ className="font-mono text-[11px] font-semibold tracking-wider leading-tight px-1.5 py-0.5 border"
84
+ style={{ color: identity.color, borderColor: identity.color }}
85
+ >
86
+ {identity.code}
87
+ </span>
88
+ )}
89
+ </span>
90
+ )
91
+ }
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.15.0",
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",