@gsa-tts/graymatter-ui 0.3.18 → 0.3.20

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gsa-tts/graymatter-ui",
3
- "version": "0.3.18",
3
+ "version": "0.3.20",
4
4
  "type": "module",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -19,7 +19,6 @@
19
19
  import ApiIcon from './icons/ApiIcon.svelte';
20
20
  import MenuIcon from './icons/MenuIcon.svelte';
21
21
  import ProfileMenu from './ProfileMenu.svelte';
22
- import { getAppUrls } from '../utils/getAppUrls';
23
22
  // import HelpIcon from './icons/HelpIcon.svelte';
24
23
 
25
24
  const {
@@ -35,12 +34,6 @@
35
34
  discoverUrl,
36
35
  } = $props();
37
36
 
38
- // Only call getAppUrls if not all URLs are provided via props
39
- const urls =
40
- apiUrl && chatUrl && consoleUrl && discoverUrl
41
- ? { api: '#', chat: '#', console: '#', discover: '#' }
42
- : getAppUrls();
43
-
44
37
  let hydrated = false;
45
38
  let navContainer: HTMLDivElement;
46
39
  let hoveredItem = $state<string | null>(null);
@@ -332,7 +325,7 @@
332
325
  <div class="nav-items" part="nav-items">
333
326
  {#if !hideDiscover}
334
327
  <a
335
- href={discoverUrl || urls.discover}
328
+ href={discoverUrl || '#'}
336
329
  class="nav-item discover-item"
337
330
  class:selected={isNavSelected('discover')}
338
331
  class:hovered={isNavHovered('discover')}
@@ -356,7 +349,7 @@
356
349
  </a>
357
350
  {/if}
358
351
  <a
359
- href={chatUrl || urls.chat}
352
+ href={chatUrl || '#'}
360
353
  class="nav-item chat-item"
361
354
  class:selected={isNavSelected('chat')}
362
355
  class:hovered={isNavHovered('chat')}
@@ -380,7 +373,7 @@
380
373
  </a>
381
374
 
382
375
  <a
383
- href={consoleUrl || urls.console}
376
+ href={consoleUrl || '#'}
384
377
  class="nav-item console-item"
385
378
  class:selected={isNavSelected('console')}
386
379
  class:hovered={isNavHovered('console')}
@@ -404,7 +397,7 @@
404
397
  </a>
405
398
 
406
399
  <a
407
- href={apiUrl || urls.api}
400
+ href={apiUrl || '#'}
408
401
  class="nav-item api-item"
409
402
  class:selected={isNavSelected('api')}
410
403
  class:hovered={isNavHovered('api')}
@@ -5,7 +5,6 @@
5
5
  import ChatIcon from './icons/ChatIcon.svelte';
6
6
  import ConsoleIcon from './icons/ConsoleIcon.svelte';
7
7
  import ApiIcon from './icons/ApiIcon.svelte';
8
- import { getAppUrls } from '../utils/getAppUrls';
9
8
  import slugify from 'slugify';
10
9
 
11
10
  let {
@@ -29,27 +28,21 @@
29
28
  discoverUrl?: string;
30
29
  } = $props();
31
30
 
32
- // Only call getAppUrls if not all URLs are provided via props
33
- const urls =
34
- apiUrl && chatUrl && consoleUrl && discoverUrl
35
- ? { api: '#', chat: '#', console: '#', discover: '#' }
36
- : getAppUrls();
37
-
38
31
  const allNavItems = [
39
32
  {
40
33
  id: 'discover',
41
34
  label: 'Discover',
42
35
  icon: DiscoverIcon,
43
- href: discoverUrl || urls.discover,
36
+ href: discoverUrl || '#',
44
37
  },
45
- { id: 'chat', label: 'Chat', icon: ChatIcon, href: chatUrl || urls.chat },
38
+ { id: 'chat', label: 'Chat', icon: ChatIcon, href: chatUrl || '#' },
46
39
  {
47
40
  id: 'console',
48
41
  label: 'Console',
49
42
  icon: ConsoleIcon,
50
- href: consoleUrl || urls.console,
43
+ href: consoleUrl || '#',
51
44
  },
52
- { id: 'api', label: 'API', icon: ApiIcon, href: apiUrl || urls.api },
45
+ { id: 'api', label: 'API', icon: ApiIcon, href: apiUrl || '#' },
53
46
  ] as const;
54
47
 
55
48
  // Filter out discover item if hideDiscover is true
@@ -15,6 +15,7 @@ const {
15
15
  disableCodeCopyButtons = false,
16
16
  postItems = null,
17
17
  profileMenuData = null,
18
+ hideDiscover = true,
18
19
  } = Astro.props;
19
20
  ---
20
21
 
@@ -28,6 +29,7 @@ const {
28
29
  title={title}
29
30
  {description}
30
31
  {openGraphImage}
32
+ {hideDiscover}
31
33
  >
32
34
  <!-- Initialize navigation state and auto-expand submenu for section pages -->
33
35
  <NavigationInitializer
@@ -8,6 +8,7 @@ import MobileBottomNav from '../components/MobileBottomNav.svelte';
8
8
  import MobileSideMenu from '../components/MobileSideMenu.svelte';
9
9
  import Logo from '../components/Logo.svelte';
10
10
  import { siteName } from '../constants';
11
+ import { getAppUrls } from '../utils/getAppUrls';
11
12
 
12
13
  const {
13
14
  componentOptions = {},
@@ -20,7 +21,10 @@ const {
20
21
  title: pageTitle,
21
22
  description,
22
23
  openGraphImage,
24
+ hideDiscover = true,
23
25
  } = Astro.props;
26
+
27
+ const { api, chat, console, discover } = getAppUrls();
24
28
  ---
25
29
 
26
30
  <BaseLayout title={pageTitle} {gtmID} {description} {openGraphImage}>
@@ -31,8 +35,13 @@ const {
31
35
  <DesktopSideNav
32
36
  client:load
33
37
  ssrSelectedItem={ssrSelectedItem}
34
- {showAppIcons}
35
- {profileMenuData}
38
+ showAppIcons={showAppIcons}
39
+ hideDiscover={hideDiscover}
40
+ profileMenuData={profileMenuData}
41
+ apiUrl={api}
42
+ chatUrl={chat}
43
+ consoleUrl={console}
44
+ discoverUrl={discover}
36
45
  >
37
46
  <slot name="sub-nav" />
38
47
  </DesktopSideNav>
@@ -51,14 +60,26 @@ const {
51
60
  <nav aria-label="Mobile navigation">
52
61
  <MobileTopNav
53
62
  client:load
54
- {profileMenuData}
55
- {logoLinkUrl}
56
- {logoLinkLabel}
63
+ profileMenuData={profileMenuData}
64
+ logoLinkUrl={logoLinkUrl}
65
+ logoLinkLabel={logoLinkLabel}
66
+ apiUrl={api}
67
+ chatUrl={chat}
68
+ consoleUrl={console}
69
+ discoverUrl={discover}
57
70
  />
58
71
  <MobileSideMenu client:load {logoLinkUrl} {logoLinkLabel}>
59
72
  <slot name="sub-nav" />
60
73
  </MobileSideMenu>
61
- <MobileBottomNav client:load {showAppIcons} />
74
+ <MobileBottomNav
75
+ client:load
76
+ showAppIcons={showAppIcons}
77
+ hideDiscover={hideDiscover}
78
+ apiUrl={api}
79
+ chatUrl={chat}
80
+ consoleUrl={console}
81
+ discoverUrl={discover}
82
+ />
62
83
  </nav>
63
84
 
64
85
  <!-- Fixed Logo (Desktop only) -->
@@ -1,11 +1,23 @@
1
1
  import { getUrlFromBase } from '@gsa-tts/graymatter-ui/helpers/url.js';
2
2
 
3
+ /**
4
+ * Logs a warning message when an environment variable is missing.
5
+ *
6
+ * @param name - The name of the missing environment variable
7
+ * @param value - The value of the environment variable (should be undefined)
8
+ */
3
9
  function warnIfMissing(name: string, value: string | undefined) {
4
10
  if (!value) {
5
11
  console.warn(`[getAppUrls] Environment variable for ${name} is missing!`);
6
12
  }
7
13
  }
8
14
 
15
+ /**
16
+ * Checks if a URL is absolute (starts with protocol like http:// or https://).
17
+ *
18
+ * @param url - The URL string to check
19
+ * @returns True if the URL is absolute, false otherwise
20
+ */
9
21
  function isAbsoluteUrl(url: string): boolean {
10
22
  try {
11
23
  new URL(url);
@@ -15,6 +27,24 @@ function isAbsoluteUrl(url: string): boolean {
15
27
  }
16
28
  }
17
29
 
30
+ /**
31
+ * Processes a URL string, handling both absolute and relative URLs.
32
+ *
33
+ * If the URL is undefined, returns the fallback. If it's absolute (starts with protocol),
34
+ * returns it as-is. If it's relative, processes it through `getUrlFromBase()` to create
35
+ * a full URL.
36
+ *
37
+ * @param url - The URL string to process (can be undefined)
38
+ * @param fallback - The fallback URL to use if the input URL is undefined
39
+ * @returns The processed URL string (can be absolute URL or relative path)
40
+ *
41
+ * @example
42
+ * ```typescript
43
+ * processUrl('https://example.com', '/fallback'); // "https://example.com"
44
+ * processUrl('/api/docs', '/fallback'); // "/api/docs" (processed by getUrlFromBase)
45
+ * processUrl(undefined, '/fallback'); // "/fallback"
46
+ * ```
47
+ */
18
48
  function processUrl(url: string | undefined, fallback: string): string {
19
49
  if (!url) {
20
50
  return fallback;
@@ -27,6 +57,60 @@ function processUrl(url: string | undefined, fallback: string): string {
27
57
  return getUrlFromBase(url);
28
58
  }
29
59
 
60
+ /**
61
+ * Retrieves application URLs/paths from environment variables with fallback support.
62
+ *
63
+ * This utility function processes environment variables to provide URLs or paths for different
64
+ * application sections (chat, console, API, discover). It supports both absolute URLs
65
+ * and relative paths, with intelligent fallback handling.
66
+ *
67
+ * @param envArg - Optional environment object to use instead of `import.meta.env`.
68
+ * Useful for testing or when you want to override environment variables.
69
+ * If not provided, uses Vite's `import.meta.env`.
70
+ *
71
+ * @returns An object containing processed URLs/paths for each application section:
72
+ * - `chat`: Chat application URL or path
73
+ * - `console`: Console application URL or path
74
+ * - `api`: API documentation URL or path
75
+ * - `discover`: Discover page URL or path
76
+ *
77
+ * @example
78
+ * ```typescript
79
+ * // Using default environment variables
80
+ * const urls = getAppUrls();
81
+ * console.log(urls.chat); // "#" (fallback) or "https://chat.example.com" (URL)
82
+ *
83
+ * // Using custom environment object (useful for testing)
84
+ * const urls = getAppUrls({
85
+ * PUBLIC_CHAT_URL: 'https://chat.dev/',
86
+ * PUBLIC_CONSOLE_URL: 'https://console.dev/',
87
+ * PUBLIC_API_URL: 'https://api.dev/docs',
88
+ * PUBLIC_DISCOVER_URL: 'https://discover.dev/'
89
+ * });
90
+ * ```
91
+ *
92
+ * @example
93
+ * ```typescript
94
+ * // Environment variables (.env file)
95
+ * PUBLIC_CHAT_URL=https://chat.example.com
96
+ * PUBLIC_CONSOLE_URL=https://console.example.com
97
+ * PUBLIC_API_URL=/api/documentation
98
+ * PUBLIC_DISCOVER_URL=https://discover.example.com
99
+ *
100
+ * // Usage in code
101
+ * const { chat, console, api, discover } = getAppUrls();
102
+ * ```
103
+ *
104
+ * @remarks
105
+ * - URLs are processed through `processUrl()` which handles both absolute and relative URLs
106
+ * - Relative URLs are processed through `getUrlFromBase()` to create full URLs
107
+ * - Missing environment variables result in fallback values (`#` for most, `/api/documentation` for API)
108
+ * - Warnings are logged in development when environment variables are missing
109
+ * - The function is designed to work with Vite's `import.meta.env` system
110
+ *
111
+ * @see {@link processUrl} - URL processing logic
112
+ * @see {@link getUrlFromBase} - Base URL resolution
113
+ */
30
114
  export function getAppUrls(envArg?: Record<string, string | undefined>) {
31
115
  const env = envArg || import.meta.env;
32
116
  const fallback = '#';