@orsetra/shared-ui 1.11.4 → 1.11.7
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/components/layout/environment-switcher.tsx +1 -1
- package/components/layout/index.ts +1 -0
- package/components/layout/layout-container.tsx +11 -3
- package/components/layout/project-gate.tsx +47 -0
- package/components/ui/index.ts +1 -0
- package/components/ui/logo.tsx +3 -3
- package/components/ui/status-indicator.tsx +88 -0
- package/index.ts +2 -0
- package/lib/project-requirement.ts +24 -0
- package/lib/status-indicator.ts +28 -0
- package/package.json +1 -1
|
@@ -28,7 +28,7 @@ export function EnvironmentSwitcher({ createHref }: EnvironmentSwitcherProps) {
|
|
|
28
28
|
disabled={status === "loading"}
|
|
29
29
|
title="Change environment"
|
|
30
30
|
aria-haspopup="dialog"
|
|
31
|
-
className="h-8
|
|
31
|
+
className="h-8 w-40 flex-shrink-0 ml-2 flex items-center justify-between gap-1.5 px-2.5 bg-gray-200/70 text-gray-600 hover:bg-gray-200 hover:text-gray-900 transition-colors disabled:cursor-default"
|
|
32
32
|
>
|
|
33
33
|
{label ? (
|
|
34
34
|
<span className="truncate text-xs font-medium uppercase tracking-wider">{label}</span>
|
|
@@ -35,4 +35,5 @@ export { RootLayoutWrapper, ibmPlexSans, ibmPlexMono } from './root-layout-wrapp
|
|
|
35
35
|
export { LayoutContainer, type LayoutContainerProps } from './layout-container'
|
|
36
36
|
export { EnvironmentSwitcher, type EnvironmentSwitcherProps } from './environment-switcher'
|
|
37
37
|
export { EnvironmentGate, type EnvironmentGateProps } from './environment-gate'
|
|
38
|
+
export { ProjectGate, useStoreHydrated, type ProjectGateProps } from './project-gate'
|
|
38
39
|
export { PageWithSidePanel } from './page-with-side-panel'
|
|
@@ -13,6 +13,8 @@ import { Menu } from "lucide-react"
|
|
|
13
13
|
import { UserPanel } from "./user-panel"
|
|
14
14
|
import { EnvironmentSwitcher } from "./environment-switcher"
|
|
15
15
|
import { EnvironmentGate } from "./environment-gate"
|
|
16
|
+
import { ProjectGate } from "./project-gate"
|
|
17
|
+
import type { ProjectSelection } from "../../lib/project-requirement"
|
|
16
18
|
import { useMenuContext } from "../../context/menu-context"
|
|
17
19
|
|
|
18
20
|
// ─── Layout ──────────────────────────────────────────────────────────────────
|
|
@@ -26,6 +28,8 @@ export interface LayoutContainerProps {
|
|
|
26
28
|
getCurrentMenu?: (pathname: string, searchParams: URLSearchParams) => string
|
|
27
29
|
getCurrentMenuItem?: (pathname: string, searchParams: URLSearchParams) => string
|
|
28
30
|
isEnvironmentRequired?: (pathname: string) => boolean
|
|
31
|
+
projectSelection?: ProjectSelection
|
|
32
|
+
isProjectRequired?: boolean
|
|
29
33
|
}
|
|
30
34
|
|
|
31
35
|
function LayoutContent({
|
|
@@ -37,6 +41,8 @@ function LayoutContent({
|
|
|
37
41
|
getCurrentMenu,
|
|
38
42
|
getCurrentMenuItem,
|
|
39
43
|
isEnvironmentRequired,
|
|
44
|
+
projectSelection,
|
|
45
|
+
isProjectRequired,
|
|
40
46
|
}: LayoutContainerProps) {
|
|
41
47
|
const { fetchMenus } = useMenuContext()
|
|
42
48
|
const pathname = usePathname()
|
|
@@ -175,9 +181,11 @@ function LayoutContent({
|
|
|
175
181
|
/>
|
|
176
182
|
|
|
177
183
|
<main className="flex-1 bg-ibm-gray-10 min-h-0 overflow-auto">
|
|
178
|
-
<
|
|
179
|
-
{
|
|
180
|
-
|
|
184
|
+
<ProjectGate selection={projectSelection} required={isProjectRequired} mainBaseUrl={main_base_url}>
|
|
185
|
+
<EnvironmentGate required={environmentRequired} createHref={createEnvironmentHref}>
|
|
186
|
+
{children}
|
|
187
|
+
</EnvironmentGate>
|
|
188
|
+
</ProjectGate>
|
|
181
189
|
</main>
|
|
182
190
|
</div>
|
|
183
191
|
</div>
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import React, { useEffect } from "react"
|
|
4
|
+
import { Spinner } from "../ui/spinner"
|
|
5
|
+
import { mainAppHomeUrl, mustLeaveForMainApp, type ProjectSelection } from "../../lib/project-requirement"
|
|
6
|
+
|
|
7
|
+
export interface ProjectGateProps {
|
|
8
|
+
selection?: ProjectSelection
|
|
9
|
+
required?: boolean
|
|
10
|
+
mainBaseUrl: string
|
|
11
|
+
children: React.ReactNode
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function ProjectGate({ selection, required, mainBaseUrl, children }: ProjectGateProps) {
|
|
15
|
+
const leaving = mustLeaveForMainApp(selection, required)
|
|
16
|
+
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
if (leaving) window.location.replace(mainAppHomeUrl(mainBaseUrl))
|
|
19
|
+
}, [leaving, mainBaseUrl])
|
|
20
|
+
|
|
21
|
+
if (!leaving) return <>{children}</>
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<div className="flex items-center justify-center min-h-[60vh]">
|
|
25
|
+
<Spinner size="lg" label="Opening the home page" />
|
|
26
|
+
</div>
|
|
27
|
+
)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
interface PersistedStore {
|
|
31
|
+
persist?: {
|
|
32
|
+
hasHydrated: () => boolean
|
|
33
|
+
onFinishHydration: (listener: () => void) => () => void
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function useStoreHydrated(store: PersistedStore): boolean {
|
|
38
|
+
const [hydrated, setHydrated] = React.useState(() => store.persist?.hasHydrated() ?? true)
|
|
39
|
+
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
if (!store.persist) return
|
|
42
|
+
if (store.persist.hasHydrated()) setHydrated(true)
|
|
43
|
+
return store.persist.onFinishHydration(() => setHydrated(true))
|
|
44
|
+
}, [store])
|
|
45
|
+
|
|
46
|
+
return hydrated
|
|
47
|
+
}
|
package/components/ui/index.ts
CHANGED
|
@@ -41,6 +41,7 @@ export { ProjectSelectorModal, type Project as ProjectSelectorItem, type Project
|
|
|
41
41
|
export { Drawer, DrawerTrigger, DrawerContent, DrawerHeader, DrawerFooter, DrawerTitle, DrawerDescription } from './drawer'
|
|
42
42
|
export { Form, FormItem, FormLabel, FormControl, FormDescription, FormMessage, FormField } from './form'
|
|
43
43
|
export { HoverCard, HoverCardTrigger, HoverCardContent } from './hover-card'
|
|
44
|
+
export { StatusIndicator, type StatusIndicatorProps } from './status-indicator'
|
|
44
45
|
export { InputOTP, InputOTPGroup, InputOTPSlot, InputOTPSeparator } from './input-otp'
|
|
45
46
|
export { Label } from './label'
|
|
46
47
|
export { Menubar, MenubarMenu, MenubarTrigger, MenubarContent, MenubarItem, MenubarSeparator, MenubarLabel, MenubarCheckboxItem, MenubarRadioGroup, MenubarRadioItem, MenubarPortal, MenubarSubContent, MenubarSubTrigger, MenubarGroup, MenubarSub, MenubarShortcut } from './menubar'
|
package/components/ui/logo.tsx
CHANGED
|
@@ -26,7 +26,7 @@ const MonogramIcon = ({ className }: { className?: string }) => (
|
|
|
26
26
|
const Wordmark = ({ className }: { className?: string }) => (
|
|
27
27
|
<svg
|
|
28
28
|
xmlns="http://www.w3.org/2000/svg"
|
|
29
|
-
viewBox="0 0
|
|
29
|
+
viewBox="0 0 125.37 32"
|
|
30
30
|
className={cn("inline-block flex-shrink-0", className)}
|
|
31
31
|
style={{ height: "1.15em", width: "auto" }}
|
|
32
32
|
role="img"
|
|
@@ -35,8 +35,8 @@ const Wordmark = ({ className }: { className?: string }) => (
|
|
|
35
35
|
<polygon fill="#161616" points="0,5 3.67,5 9.17,16 3.67,27 0,27 5.5,16" />
|
|
36
36
|
<polygon fill="#161616" points="24.75,5 21.08,5 15.58,16 21.08,27 24.75,27 19.25,16" />
|
|
37
37
|
<rect fill="#0F62FE" x="10.08" y="13.71" width="4.58" height="4.58" />
|
|
38
|
-
<path fill="#161616" d="M41.52 23.94Q40 23.94 38.78 23.45Q37.56 22.95 36.69 21.96Q35.82 20.97 35.36 19.51Q34.89 18.05 34.89 16.11Q34.89 14.17 35.36 12.67Q35.82 11.16 36.69 10.14Q37.56 9.11 38.78 8.59Q40 8.06 41.52 8.06Q43.58 8.06 44.95 8.94Q46.31 9.82 47.13 11.6L44.64 12.92Q44.31 11.89 43.56 11.26Q42.81 10.63 41.52 10.63Q39.89 10.63 38.93 11.73Q37.97 12.83 37.97 14.81V17.23Q37.97 19.23 38.93 20.3Q39.89 21.37 41.52 21.37Q42.81 21.37 43.64 20.66Q44.46 19.96 44.84 18.93L47.19 20.31Q46.36 22.03 44.97 22.98Q43.58 23.94 41.52 23.94Z
|
|
39
|
-
<path fill="#0F62FE" d="
|
|
38
|
+
<path fill="#161616" d="M41.52 23.94Q40 23.94 38.78 23.45Q37.56 22.95 36.69 21.96Q35.82 20.97 35.36 19.51Q34.89 18.05 34.89 16.11Q34.89 14.17 35.36 12.67Q35.82 11.16 36.69 10.14Q37.56 9.11 38.78 8.59Q40 8.06 41.52 8.06Q43.58 8.06 44.95 8.94Q46.31 9.82 47.13 11.6L44.64 12.92Q44.31 11.89 43.56 11.26Q42.81 10.63 41.52 10.63Q39.89 10.63 38.93 11.73Q37.97 12.83 37.97 14.81V17.23Q37.97 19.23 38.93 20.3Q39.89 21.37 41.52 21.37Q42.81 21.37 43.64 20.66Q44.46 19.96 44.84 18.93L47.19 20.31Q46.36 22.03 44.97 22.98Q43.58 23.94 41.52 23.94Z M59.18 23.68 57.95 19.76H52.49L51.28 23.68H48.34L53.48 8.32H57.09L62.2 23.68ZM55.27 10.96H55.16L53.2 17.28H57.25Z M76.06 12.66H75.97L74.78 15.1L71.63 20.91L68.49 15.1L67.3 12.66H67.21V23.68H64.46V8.32H67.74L71.68 15.82H71.77L75.66 8.32H78.81V23.68H76.06Z M82.41 23.68V8.32H92.53V10.9H85.32V14.61H91.7V17.19H85.32V21.1H92.53V23.68Z M95.61 23.68V8.32H98.52V21.1H104.57V23.68Z" />
|
|
39
|
+
<path fill="#0F62FE" d="M124.48 23.68H121.09L117.57 17.78H117.5L114.03 23.68H110.86L115.83 15.8L111.08 8.32H114.47L117.72 13.78H117.79L121.09 8.32H124.26L119.46 15.8Z" />
|
|
40
40
|
</svg>
|
|
41
41
|
)
|
|
42
42
|
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
import { cn } from "../../lib/utils"
|
|
5
|
+
import { HoverCard, HoverCardContent, HoverCardTrigger } from "./hover-card"
|
|
6
|
+
import {
|
|
7
|
+
STATUS_IDLE_COLOR, STATUS_WAVE_COLOR, STATUS_WAVE_PERIOD_MS, STATUS_WAVE_SQUARES,
|
|
8
|
+
statusLabel, statusToneColor, waveDelayMs,
|
|
9
|
+
type StatusTone,
|
|
10
|
+
} from "../../lib/status-indicator"
|
|
11
|
+
|
|
12
|
+
const SQUARE = 6
|
|
13
|
+
const GAP = 2
|
|
14
|
+
|
|
15
|
+
export interface StatusIndicatorProps {
|
|
16
|
+
loading?: boolean
|
|
17
|
+
tone?: StatusTone | null
|
|
18
|
+
label?: string
|
|
19
|
+
details?: React.ReactNode
|
|
20
|
+
detailsClassName?: string
|
|
21
|
+
side?: "top" | "right" | "bottom" | "left"
|
|
22
|
+
align?: "start" | "center" | "end"
|
|
23
|
+
openDelay?: number
|
|
24
|
+
closeDelay?: number
|
|
25
|
+
className?: string
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function Wave() {
|
|
29
|
+
const width = STATUS_WAVE_SQUARES * SQUARE + (STATUS_WAVE_SQUARES - 1) * GAP
|
|
30
|
+
return (
|
|
31
|
+
<svg width={width} height={SQUARE} viewBox={`0 0 ${width} ${SQUARE}`} aria-hidden="true" focusable="false">
|
|
32
|
+
{Array.from({ length: STATUS_WAVE_SQUARES }, (_, index) => (
|
|
33
|
+
<rect key={index} x={index * (SQUARE + GAP)} y={0} width={SQUARE} height={SQUARE} fill={STATUS_IDLE_COLOR}>
|
|
34
|
+
<animate
|
|
35
|
+
attributeName="fill"
|
|
36
|
+
values={`${STATUS_IDLE_COLOR};${STATUS_WAVE_COLOR};${STATUS_IDLE_COLOR};${STATUS_IDLE_COLOR}`}
|
|
37
|
+
keyTimes="0;0.25;0.5;1"
|
|
38
|
+
dur={`${STATUS_WAVE_PERIOD_MS}ms`}
|
|
39
|
+
begin={`${waveDelayMs(index)}ms`}
|
|
40
|
+
repeatCount="indefinite"
|
|
41
|
+
/>
|
|
42
|
+
</rect>
|
|
43
|
+
))}
|
|
44
|
+
</svg>
|
|
45
|
+
)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function Settled({ tone }: { tone: StatusTone | null | undefined }) {
|
|
49
|
+
return (
|
|
50
|
+
<svg width={SQUARE} height={SQUARE} viewBox={`0 0 ${SQUARE} ${SQUARE}`} aria-hidden="true" focusable="false">
|
|
51
|
+
<rect x={0} y={0} width={SQUARE} height={SQUARE} fill={statusToneColor(tone)} />
|
|
52
|
+
</svg>
|
|
53
|
+
)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function StatusIndicator({
|
|
57
|
+
loading = false, tone, label, details, detailsClassName,
|
|
58
|
+
side = "bottom", align = "start", openDelay = 150, closeDelay = 120, className,
|
|
59
|
+
}: StatusIndicatorProps) {
|
|
60
|
+
const spoken = statusLabel(loading, tone, label)
|
|
61
|
+
const mark = (
|
|
62
|
+
<span role="status" aria-label={spoken} className={cn("inline-flex items-center align-middle", className)}>
|
|
63
|
+
{loading ? <Wave /> : <Settled tone={tone} />}
|
|
64
|
+
</span>
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
if (!details) return mark
|
|
68
|
+
|
|
69
|
+
return (
|
|
70
|
+
<HoverCard openDelay={openDelay} closeDelay={closeDelay}>
|
|
71
|
+
<HoverCardTrigger asChild>
|
|
72
|
+
<button
|
|
73
|
+
type="button"
|
|
74
|
+
aria-label={spoken}
|
|
75
|
+
className={cn(
|
|
76
|
+
"inline-flex items-center align-middle p-1 -m-1 cursor-default focus:outline-none focus-visible:ring-2 focus-visible:ring-ibm-blue-60",
|
|
77
|
+
className,
|
|
78
|
+
)}
|
|
79
|
+
>
|
|
80
|
+
{loading ? <Wave /> : <Settled tone={tone} />}
|
|
81
|
+
</button>
|
|
82
|
+
</HoverCardTrigger>
|
|
83
|
+
<HoverCardContent side={side} align={align} className={cn("w-80 rounded-none p-4 text-sm", detailsClassName)}>
|
|
84
|
+
{details}
|
|
85
|
+
</HoverCardContent>
|
|
86
|
+
</HoverCard>
|
|
87
|
+
)
|
|
88
|
+
}
|
package/index.ts
CHANGED
|
@@ -6,6 +6,8 @@ export { BaseService } from './lib/base-service'
|
|
|
6
6
|
export * from './lib/config-selection'
|
|
7
7
|
export * from './lib/environment-context'
|
|
8
8
|
export * from './lib/environment-controller'
|
|
9
|
+
export * from './lib/project-requirement'
|
|
10
|
+
export * from './lib/status-indicator'
|
|
9
11
|
export { createPlatformConfigSource, templateFilter, configOfHit, environmentWithTargets, type ConfigSource } from './lib/config-source'
|
|
10
12
|
export { default as HttpClient, useHttpClient, ApiError } from './lib/http-client'
|
|
11
13
|
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export type ProjectSelection = "pending" | "none" | "selected"
|
|
2
|
+
|
|
3
|
+
export interface ProjectSelectionInput {
|
|
4
|
+
hydrated: boolean
|
|
5
|
+
projectId: string | null | undefined
|
|
6
|
+
projectsLoaded: boolean
|
|
7
|
+
isKnown: boolean
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function projectSelectionOf({ hydrated, projectId, projectsLoaded, isKnown }: ProjectSelectionInput): ProjectSelection {
|
|
11
|
+
if (!hydrated) return "pending"
|
|
12
|
+
if (!projectId) return "none"
|
|
13
|
+
if (!projectsLoaded) return "selected"
|
|
14
|
+
return isKnown ? "selected" : "none"
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function mustLeaveForMainApp(selection: ProjectSelection | undefined, required: boolean | undefined): boolean {
|
|
18
|
+
return required === true && selection === "none"
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function mainAppHomeUrl(mainBaseUrl: string | null | undefined): string {
|
|
22
|
+
const base = (mainBaseUrl ?? "").trim().replace(/\/+$/, "")
|
|
23
|
+
return `${base}/`
|
|
24
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export type StatusTone = "success" | "warning" | "error"
|
|
2
|
+
|
|
3
|
+
export const STATUS_TONE_COLOR: Readonly<Record<StatusTone, string>> = {
|
|
4
|
+
success: "#24a148",
|
|
5
|
+
warning: "#ff832b",
|
|
6
|
+
error: "#da1e28",
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const STATUS_IDLE_COLOR = "#c6c6c6"
|
|
10
|
+
export const STATUS_WAVE_COLOR = "#0f62fe"
|
|
11
|
+
export const STATUS_WAVE_SQUARES = 3
|
|
12
|
+
export const STATUS_WAVE_PERIOD_MS = 1_200
|
|
13
|
+
|
|
14
|
+
export function statusToneColor(tone: StatusTone | null | undefined): string {
|
|
15
|
+
return (tone && STATUS_TONE_COLOR[tone]) || STATUS_IDLE_COLOR
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function waveDelayMs(index: number, squares: number = STATUS_WAVE_SQUARES, periodMs: number = STATUS_WAVE_PERIOD_MS): number {
|
|
19
|
+
if (squares <= 0) return 0
|
|
20
|
+
const position = ((index % squares) + squares) % squares
|
|
21
|
+
return Math.round((periodMs / (squares + 1)) * position)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function statusLabel(loading: boolean, tone: StatusTone | null | undefined, label?: string): string {
|
|
25
|
+
if (label) return label
|
|
26
|
+
if (loading) return "In progress"
|
|
27
|
+
return tone === "success" ? "Healthy" : tone === "warning" ? "Needs attention" : tone === "error" ? "Failed" : "Unknown"
|
|
28
|
+
}
|