@orsetra/shared-ui 1.11.5 → 1.11.8

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.
@@ -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 max-w-[46vw] md:max-w-xs flex items-center 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"
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>
@@ -3,40 +3,27 @@
3
3
  import { useEffect, useRef } from "react"
4
4
  import { usePathname } from "next/navigation"
5
5
  import { useQuickAccess } from "../../../hooks/use-quick-access"
6
+ import { quickAccessHref } from "../../../lib/quick-access-href"
6
7
 
7
8
  interface QuickAccessTrackerProps {
8
- /** Human-readable label shown in the quick-access list */
9
9
  label: string
10
- /** Icon name (resolved via resolveIcon). Defaults to "Box". */
11
10
  icon?: string
12
- /** Set to false to skip tracking this page (e.g. list/index pages) */
13
11
  enabled?: boolean
14
- /**
15
- * Canonical href for this resource — overrides the current page URL.
16
- * Pass the resource root (e.g. "/my-app") so that visiting any tab of
17
- * the same resource tracks a single entry instead of one per tab.
18
- * Absolute URL or path relative to the current origin.
19
- */
20
12
  href?: string
21
13
  }
22
14
 
23
- /**
24
- * Drop this inside any page or layout to register that page in the
25
- * sidebar's quick-access list. Tracks on mount and whenever pathname changes.
26
- * Renders nothing.
27
- */
28
15
  export function QuickAccessTracker({ label, icon, enabled = true, href: hrefProp }: QuickAccessTrackerProps) {
29
16
  const pathname = usePathname()
30
17
  const { addItem } = useQuickAccess()
31
- // Stable ref so the effect doesn't re-run when addItem reference changes
32
18
  const addRef = useRef(addItem)
33
19
  addRef.current = addItem
34
20
 
35
21
  useEffect(() => {
36
22
  if (!enabled || !label || !pathname) return
37
- const href = hrefProp
38
- ? (hrefProp.startsWith("http") ? hrefProp : window.location.origin + hrefProp)
39
- : window.location.origin + window.location.pathname
23
+ const href = quickAccessHref(
24
+ { origin: window.location.origin, locationPath: window.location.pathname, routerPath: pathname },
25
+ hrefProp,
26
+ )
40
27
  addRef.current({ label, href, icon })
41
28
  // eslint-disable-next-line react-hooks/exhaustive-deps
42
29
  }, [pathname, label, icon, enabled, hrefProp])
@@ -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 118.55 32"
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 M57.95 23.68Q57.03 23.68 56.49 23.14Q55.95 22.6 55.82 21.7H55.68Q55.4 22.82 54.52 23.38Q53.64 23.94 52.34 23.94Q50.58 23.94 49.63 23.02Q48.69 22.09 48.69 20.55Q48.69 18.77 49.96 17.9Q51.24 17.03 53.59 17.03H55.55V16.2Q55.55 15.23 55.05 14.7Q54.54 14.17 53.42 14.17Q52.43 14.17 51.82 14.6Q51.22 15.03 50.8 15.63L49.13 14.13Q49.77 13.14 50.82 12.53Q51.88 11.93 53.62 11.93Q55.95 11.93 57.16 12.99Q58.37 14.04 58.37 16.02V21.43H59.51V23.68ZM53.29 21.9Q54.23 21.9 54.89 21.48Q55.55 21.06 55.55 20.25V18.73H53.75Q51.55 18.73 51.55 20.14V20.51Q51.55 21.21 52 21.55Q52.45 21.9 53.29 21.9Z M61.8 23.68V12.19H64.62V14.11H64.73Q65.06 13.21 65.78 12.57Q66.51 11.93 67.81 11.93Q68.99 11.93 69.85 12.5Q70.71 13.07 71.13 14.24H71.17Q71.48 13.27 72.39 12.6Q73.31 11.93 74.69 11.93Q76.39 11.93 77.3 13.1Q78.21 14.26 78.21 16.42V23.68H75.4V16.7Q75.4 14.24 73.55 14.24Q73.13 14.24 72.75 14.36Q72.36 14.48 72.06 14.71Q71.77 14.94 71.59 15.28Q71.41 15.63 71.41 16.09V23.68H68.6V16.7Q68.6 14.24 66.75 14.24Q66.35 14.24 65.97 14.36Q65.58 14.48 65.29 14.71Q64.99 14.94 64.8 15.28Q64.62 15.63 64.62 16.09V23.68Z M85.98 23.94Q84.7 23.94 83.7 23.51Q82.7 23.08 82.01 22.3Q81.31 21.52 80.94 20.41Q80.57 19.3 80.57 17.91Q80.57 16.55 80.93 15.45Q81.29 14.35 81.97 13.57Q82.66 12.79 83.65 12.36Q84.64 11.93 85.89 11.93Q87.23 11.93 88.22 12.39Q89.21 12.85 89.85 13.65Q90.49 14.44 90.81 15.48Q91.13 16.53 91.13 17.72V18.64H83.49V18.93Q83.49 20.18 84.2 20.94Q84.9 21.7 86.29 21.7Q87.34 21.7 88.01 21.26Q88.68 20.82 89.21 20.14L90.73 21.83Q90.03 22.82 88.81 23.38Q87.58 23.94 85.98 23.94ZM85.93 14.04Q84.81 14.04 84.15 14.79Q83.49 15.54 83.49 16.73V16.9H88.2V16.7Q88.2 15.52 87.62 14.78Q87.03 14.04 85.93 14.04Z M96.43 23.68Q94.98 23.68 94.29 22.95Q93.61 22.23 93.61 20.91V7.4H96.43V21.43H97.95V23.68Z" />
39
- <path fill="#0F62FE" d="M117.66 23.68H114.27L110.75 17.78H110.68L107.21 23.68H104.04L109.01 15.8L104.26 8.32H107.65L110.9 13.78H110.97L114.27 8.32H117.44L112.64 15.8Z" />
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
 
package/index.ts CHANGED
@@ -7,6 +7,7 @@ export * from './lib/config-selection'
7
7
  export * from './lib/environment-context'
8
8
  export * from './lib/environment-controller'
9
9
  export * from './lib/project-requirement'
10
+ export * from './lib/quick-access-href'
10
11
  export * from './lib/status-indicator'
11
12
  export { createPlatformConfigSource, templateFilter, configOfHit, environmentWithTargets, type ConfigSource } from './lib/config-source'
12
13
  export { default as HttpClient, useHttpClient, ApiError } from './lib/http-client'
@@ -0,0 +1,21 @@
1
+ export interface QuickAccessLocation {
2
+ origin: string
3
+ locationPath: string
4
+ routerPath: string
5
+ }
6
+
7
+ const withoutTrailingSlash = (path: string): string => path.replace(/\/+$/, "")
8
+
9
+ export function appBasePath({ locationPath, routerPath }: Pick<QuickAccessLocation, "locationPath" | "routerPath">): string {
10
+ const full = withoutTrailingSlash(locationPath)
11
+ const inner = withoutTrailingSlash(routerPath)
12
+ if (!inner) return full
13
+ return full.endsWith(inner) ? full.slice(0, full.length - inner.length) : ""
14
+ }
15
+
16
+ export function quickAccessHref(location: QuickAccessLocation, target?: string): string {
17
+ if (!target) return location.origin + location.locationPath
18
+ if (/^https?:\/\//i.test(target)) return target
19
+ const path = target.startsWith("/") ? target : `/${target}`
20
+ return location.origin + appBasePath(location) + path
21
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orsetra/shared-ui",
3
- "version": "1.11.5",
3
+ "version": "1.11.8",
4
4
  "description": "Shared UI components for Orsetra platform",
5
5
  "main": "./index.ts",
6
6
  "types": "./index.ts",