@igstack/app-catalog-frontend-core 6.12.3 → 6.13.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/dist/esm/__tests__/modules/appCatalog/utils/searchServiceDesks.test.d.ts +1 -0
- package/dist/esm/api/infra/trpc.d.ts +45 -0
- package/dist/esm/modules/appCatalog/ui/pages/ServiceDesksPage.d.ts +7 -3
- package/dist/esm/modules/appCatalog/ui/pages/ServiceDesksPage.js +288 -73
- package/dist/esm/modules/appCatalog/ui/pages/ServiceDesksPage.js.map +1 -1
- package/dist/esm/modules/appCatalog/ui/serviceDesks/Marked.d.ts +11 -0
- package/dist/esm/modules/appCatalog/ui/serviceDesks/Marked.js +23 -0
- package/dist/esm/modules/appCatalog/ui/serviceDesks/Marked.js.map +1 -0
- package/dist/esm/modules/appCatalog/ui/serviceDesks/ServiceDeskCard.d.ts +25 -0
- package/dist/esm/modules/appCatalog/ui/serviceDesks/ServiceDeskCard.js +161 -0
- package/dist/esm/modules/appCatalog/ui/serviceDesks/ServiceDeskCard.js.map +1 -0
- package/dist/esm/modules/appCatalog/ui/serviceDesks/ServiceDeskDetail.d.ts +17 -0
- package/dist/esm/modules/appCatalog/ui/serviceDesks/ServiceDeskDetail.js +267 -0
- package/dist/esm/modules/appCatalog/ui/serviceDesks/ServiceDeskDetail.js.map +1 -0
- package/dist/esm/modules/appCatalog/ui/serviceDesks/searchServiceDesks.d.ts +37 -0
- package/dist/esm/modules/appCatalog/ui/serviceDesks/searchServiceDesks.js +111 -0
- package/dist/esm/modules/appCatalog/ui/serviceDesks/searchServiceDesks.js.map +1 -0
- package/dist/esm/node_modules/.pnpm/zod@4.3.5/node_modules/zod/v4/classic/schemas.js +43 -3
- package/dist/esm/node_modules/.pnpm/zod@4.3.5/node_modules/zod/v4/classic/schemas.js.map +1 -1
- package/dist/esm/node_modules/.pnpm/zod@4.3.5/node_modules/zod/v4/core/api.js +72 -1
- package/dist/esm/node_modules/.pnpm/zod@4.3.5/node_modules/zod/v4/core/api.js.map +1 -1
- package/dist/esm/node_modules/.pnpm/zod@4.3.5/node_modules/zod/v4/core/checks.js +169 -2
- package/dist/esm/node_modules/.pnpm/zod@4.3.5/node_modules/zod/v4/core/checks.js.map +1 -1
- package/dist/esm/node_modules/.pnpm/zod@4.3.5/node_modules/zod/v4/core/json-schema-processors.js +45 -0
- package/dist/esm/node_modules/.pnpm/zod@4.3.5/node_modules/zod/v4/core/json-schema-processors.js.map +1 -1
- package/dist/esm/node_modules/.pnpm/zod@4.3.5/node_modules/zod/v4/core/regexes.js +4 -0
- package/dist/esm/node_modules/.pnpm/zod@4.3.5/node_modules/zod/v4/core/regexes.js.map +1 -1
- package/dist/esm/node_modules/.pnpm/zod@4.3.5/node_modules/zod/v4/core/schemas.js +33 -3
- package/dist/esm/node_modules/.pnpm/zod@4.3.5/node_modules/zod/v4/core/schemas.js.map +1 -1
- package/dist/esm/node_modules/.pnpm/zod@4.3.5/node_modules/zod/v4/core/util.js +24 -0
- package/dist/esm/node_modules/.pnpm/zod@4.3.5/node_modules/zod/v4/core/util.js.map +1 -1
- package/dist/esm/routeTree.gen.d.ts +3 -0
- package/dist/esm/routes/_layout/service-desks.d.ts +3 -0
- package/dist/esm/routes/_layout/service-desks.js +12 -2
- package/dist/esm/routes/_layout/service-desks.js.map +1 -1
- package/dist/esm/ui/item.d.ts +1 -1
- package/package.json +4 -4
- package/src/__tests__/modules/appCatalog/utils/searchServiceDesks.test.ts +117 -0
- package/src/modules/appCatalog/ui/pages/ServiceDesksPage.tsx +385 -113
- package/src/modules/appCatalog/ui/serviceDesks/Marked.tsx +31 -0
- package/src/modules/appCatalog/ui/serviceDesks/ServiceDeskCard.tsx +221 -0
- package/src/modules/appCatalog/ui/serviceDesks/ServiceDeskDetail.tsx +349 -0
- package/src/modules/appCatalog/ui/serviceDesks/searchServiceDesks.ts +173 -0
- package/src/routes/_layout/service-desks.tsx +10 -0
- package/dist/esm/ui/input-group.js +0 -82
- package/dist/esm/ui/input-group.js.map +0 -1
|
@@ -1,130 +1,402 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { useQuery } from '@tanstack/react-query'
|
|
2
|
+
import { useNavigate, useSearch } from '@tanstack/react-router'
|
|
3
|
+
import { Search, X } from 'lucide-react'
|
|
4
4
|
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
} from '
|
|
5
|
+
useCallback,
|
|
6
|
+
useDeferredValue,
|
|
7
|
+
useEffect,
|
|
8
|
+
useMemo,
|
|
9
|
+
useRef,
|
|
10
|
+
useState,
|
|
11
|
+
} from 'react'
|
|
12
|
+
import { useTRPC } from '~/api/infra/trpc'
|
|
13
|
+
import { cn } from '~/lib/utils'
|
|
12
14
|
import { useAppCatalogContext } from '../../context/AppCatalogContext'
|
|
13
|
-
import {
|
|
15
|
+
import { DeskCard, ServiceDeskCard } from '../serviceDesks/ServiceDeskCard'
|
|
16
|
+
import { ServiceDeskDetail } from '../serviceDesks/ServiceDeskDetail'
|
|
17
|
+
import {
|
|
18
|
+
effectiveQuery,
|
|
19
|
+
hasPortal,
|
|
20
|
+
searchServiceDesks,
|
|
21
|
+
} from '../serviceDesks/searchServiceDesks'
|
|
22
|
+
import type { ServiceDesk } from '../serviceDesks/searchServiceDesks'
|
|
23
|
+
|
|
24
|
+
/** Results rendered before "Show more": a one-letter query matches hundreds. */
|
|
25
|
+
const FIRST_PAGE = 50
|
|
26
|
+
|
|
27
|
+
/** Where desks with no area, or no portal at all, are listed. */
|
|
28
|
+
const OTHER_AREA = 'Other ways to ask'
|
|
14
29
|
|
|
15
30
|
/**
|
|
16
|
-
* Service Desks view (#9):
|
|
17
|
-
*
|
|
18
|
-
*
|
|
31
|
+
* Service Desks view (#9, #273): one search over every service desk — its key,
|
|
32
|
+
* name, description, request forms and their dropdown options. A result is a
|
|
33
|
+
* form; the card opens the desk's details, the form's address opens the portal.
|
|
34
|
+
* With no search, every desk is listed by area, like the catalog's own home.
|
|
35
|
+
*
|
|
36
|
+
* The desks' portals come from `getServiceDesks`, kept out of the main catalog
|
|
37
|
+
* payload. Until it answers, the catalog's own (portal-less) desks are listed.
|
|
19
38
|
*/
|
|
20
39
|
export function ServiceDesksPage() {
|
|
40
|
+
const trpc = useTRPC()
|
|
21
41
|
const { approvalMethods } = useAppCatalogContext()
|
|
42
|
+
const fetched = useQuery(trpc.appCatalog.getServiceDesks.queryOptions())
|
|
22
43
|
const [search, setSearch] = useState('')
|
|
44
|
+
const [shown, setShown] = useState(FIRST_PAGE)
|
|
45
|
+
// The open card lives in the URL, so Back closes it and a link reopens it.
|
|
46
|
+
const { desk: openSlug, form: openFormId } = useSearch({ strict: false })
|
|
47
|
+
const navigate = useNavigate()
|
|
48
|
+
const inputRef = useRef<HTMLInputElement>(null)
|
|
49
|
+
const scrollRef = useRef<HTMLDivElement>(null)
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Same split as the catalog search: the box commits each character at once,
|
|
53
|
+
* and everything below re-renders from this value at low priority, abandoned
|
|
54
|
+
* when the next key arrives. The cards are memoized, so a pass that does run
|
|
55
|
+
* only touches the cards that changed.
|
|
56
|
+
*/
|
|
57
|
+
const deferredSearch = useDeferredValue(search)
|
|
58
|
+
const isPending = search !== deferredSearch
|
|
59
|
+
const isSearching = deferredSearch.trim() !== ''
|
|
60
|
+
|
|
61
|
+
const desks: ServiceDesk[] = useMemo(
|
|
62
|
+
() =>
|
|
63
|
+
[
|
|
64
|
+
...(fetched.data ??
|
|
65
|
+
approvalMethods.filter(
|
|
66
|
+
(m): m is ServiceDesk => m.type === 'service',
|
|
67
|
+
)),
|
|
68
|
+
].sort((a, b) => a.displayName.localeCompare(b.displayName)),
|
|
69
|
+
[fetched.data, approvalMethods],
|
|
70
|
+
)
|
|
71
|
+
const portalDesks = useMemo(() => desks.filter(hasPortal), [desks])
|
|
72
|
+
|
|
73
|
+
const { query, results } = useMemo(() => {
|
|
74
|
+
// The query as typed is searched once; a reread runs only when it finds nothing.
|
|
75
|
+
const asTyped = searchServiceDesks(portalDesks, deferredSearch)
|
|
76
|
+
if (asTyped.length) return { query: deferredSearch, results: asTyped }
|
|
77
|
+
const reread = effectiveQuery(
|
|
78
|
+
deferredSearch,
|
|
79
|
+
(alt) => searchServiceDesks(portalDesks, alt).length > 0,
|
|
80
|
+
)
|
|
81
|
+
return {
|
|
82
|
+
query: reread,
|
|
83
|
+
results:
|
|
84
|
+
reread === deferredSearch
|
|
85
|
+
? asTyped
|
|
86
|
+
: searchServiceDesks(portalDesks, reread),
|
|
87
|
+
}
|
|
88
|
+
}, [portalDesks, deferredSearch])
|
|
23
89
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
90
|
+
// Desks found by name or description that publish no forms: links only.
|
|
91
|
+
const plainHits = useMemo(() => {
|
|
92
|
+
if (!isSearching) return []
|
|
93
|
+
const q = query.trim().toLowerCase()
|
|
94
|
+
return desks.filter(
|
|
95
|
+
(d) =>
|
|
96
|
+
!hasPortal(d) &&
|
|
97
|
+
`${d.displayName} ${d.config.description ?? ''}`
|
|
98
|
+
.toLowerCase()
|
|
99
|
+
.includes(q),
|
|
32
100
|
)
|
|
33
|
-
}, [
|
|
101
|
+
}, [desks, isSearching, query])
|
|
102
|
+
|
|
103
|
+
const areas = useMemo(() => groupByArea(desks), [desks])
|
|
104
|
+
|
|
105
|
+
const onOpen = useCallback(
|
|
106
|
+
(slug: string, formId?: string) =>
|
|
107
|
+
void navigate({
|
|
108
|
+
to: '/service-desks',
|
|
109
|
+
search: (prev) => ({
|
|
110
|
+
...prev,
|
|
111
|
+
desk: slug,
|
|
112
|
+
form: formId && /^\d+$/.test(formId) ? Number(formId) : formId,
|
|
113
|
+
tab: undefined,
|
|
114
|
+
}),
|
|
115
|
+
}),
|
|
116
|
+
[navigate],
|
|
117
|
+
)
|
|
118
|
+
const onClose = () =>
|
|
119
|
+
void navigate({
|
|
120
|
+
to: '/service-desks',
|
|
121
|
+
search: (prev) => ({
|
|
122
|
+
...prev,
|
|
123
|
+
desk: undefined,
|
|
124
|
+
form: undefined,
|
|
125
|
+
tab: undefined,
|
|
126
|
+
}),
|
|
127
|
+
})
|
|
128
|
+
const openDesk = openSlug
|
|
129
|
+
? portalDesks.find((d) => d.slug === openSlug)
|
|
130
|
+
: undefined
|
|
131
|
+
const openForm = openDesk?.config.portal.requestTypes.find(
|
|
132
|
+
(f) => openFormId !== undefined && f.id === String(openFormId),
|
|
133
|
+
)
|
|
134
|
+
const deskCount = new Set(results.map((r) => r.desk.slug)).size
|
|
135
|
+
|
|
136
|
+
const updateSearch = (value: string) => {
|
|
137
|
+
setSearch(value)
|
|
138
|
+
setShown(FIRST_PAGE)
|
|
139
|
+
}
|
|
140
|
+
const clear = () => {
|
|
141
|
+
updateSearch('')
|
|
142
|
+
inputRef.current?.focus()
|
|
143
|
+
}
|
|
34
144
|
|
|
35
145
|
return (
|
|
36
|
-
<div
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
<div className="flex-1 min-h-0 overflow-y-auto">
|
|
49
|
-
{desks.length === 0 ? (
|
|
50
|
-
<p className="text-sm text-muted-foreground">
|
|
51
|
-
No service desks found{search && ` for "${search}"`}.
|
|
146
|
+
<div
|
|
147
|
+
ref={scrollRef}
|
|
148
|
+
className="flex-1 min-h-0 overflow-y-auto [scrollbar-gutter:stable] pb-24"
|
|
149
|
+
>
|
|
150
|
+
<div className="mx-auto w-full max-w-[1000px]">
|
|
151
|
+
<div className="pb-1.5 pt-10 text-center">
|
|
152
|
+
<h1 className="m-0 mb-1.5 font-serif text-[30px] font-semibold tracking-tight">
|
|
153
|
+
Where do I file this?
|
|
154
|
+
</h1>
|
|
155
|
+
<p className="m-0 mb-6 text-[15px] text-muted-foreground">
|
|
156
|
+
Search every service desk by its name, key, forms and the options
|
|
157
|
+
those forms offer.
|
|
52
158
|
</p>
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
<
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
159
|
+
<div className="mx-auto max-w-[620px]">
|
|
160
|
+
<div className="flex h-14 items-center gap-3 rounded-full border-[1.5px] border-input bg-card px-5 shadow-sm transition-colors focus-within:border-primary focus-within:ring-4 focus-within:ring-primary/15">
|
|
161
|
+
<Search className="size-5 shrink-0 text-muted-foreground" />
|
|
162
|
+
<input
|
|
163
|
+
ref={inputRef}
|
|
164
|
+
autoFocus
|
|
165
|
+
value={search}
|
|
166
|
+
onChange={(e) => updateSearch(e.target.value)}
|
|
167
|
+
onFocus={(e) => e.target.select()}
|
|
168
|
+
onKeyDown={(e) => {
|
|
169
|
+
if (e.key === 'Escape' && search) {
|
|
170
|
+
e.preventDefault()
|
|
171
|
+
clear()
|
|
172
|
+
}
|
|
173
|
+
}}
|
|
174
|
+
placeholder="Database access, a broken laptop, or a desk key"
|
|
175
|
+
aria-label="Search service desks"
|
|
176
|
+
className="flex-1 border-0 bg-transparent text-[16px] text-foreground outline-none placeholder:text-muted-foreground"
|
|
177
|
+
/>
|
|
178
|
+
{search && (
|
|
179
|
+
<button
|
|
180
|
+
type="button"
|
|
181
|
+
onClick={clear}
|
|
182
|
+
aria-label="Clear search"
|
|
183
|
+
title="Clear search (Esc)"
|
|
184
|
+
className="shrink-0 rounded-full p-1 text-muted-foreground transition-colors hover:bg-accent hover:text-foreground"
|
|
185
|
+
>
|
|
186
|
+
<X className="size-4" />
|
|
187
|
+
</button>
|
|
188
|
+
)}
|
|
189
|
+
</div>
|
|
190
|
+
</div>
|
|
191
|
+
</div>
|
|
192
|
+
|
|
193
|
+
<div
|
|
194
|
+
className={cn(
|
|
195
|
+
'mt-8 transition-opacity',
|
|
196
|
+
// A render behind the box: dimmed so stale rows read as stale.
|
|
197
|
+
isPending && 'opacity-60',
|
|
198
|
+
)}
|
|
199
|
+
>
|
|
200
|
+
{isSearching ? (
|
|
201
|
+
<div className="mx-auto max-w-[820px]">
|
|
202
|
+
<p
|
|
203
|
+
className="mb-3 px-1 text-[14px] text-muted-foreground"
|
|
204
|
+
aria-live="polite"
|
|
205
|
+
>
|
|
206
|
+
{query !== deferredSearch && (
|
|
207
|
+
<>
|
|
208
|
+
Showing results for{' '}
|
|
209
|
+
<b className="text-foreground">{query}</b>.{' '}
|
|
210
|
+
</>
|
|
211
|
+
)}
|
|
212
|
+
{results.length
|
|
213
|
+
? `${results.length} form${results.length === 1 ? '' : 's'} at ${deskCount} desk${deskCount === 1 ? '' : 's'}`
|
|
214
|
+
: plainHits.length
|
|
215
|
+
? ''
|
|
216
|
+
: `No desk or form mentions “${deferredSearch}”. Try one word.`}
|
|
217
|
+
</p>
|
|
218
|
+
<ol className="flex flex-col gap-3">
|
|
219
|
+
{results.slice(0, shown).map((r) => (
|
|
220
|
+
<ServiceDeskCard
|
|
221
|
+
key={`${r.desk.slug}:${r.form.id}`}
|
|
222
|
+
result={r}
|
|
223
|
+
query={query}
|
|
224
|
+
onOpen={onOpen}
|
|
225
|
+
/>
|
|
226
|
+
))}
|
|
227
|
+
</ol>
|
|
228
|
+
{results.length > shown && (
|
|
229
|
+
<button
|
|
230
|
+
type="button"
|
|
231
|
+
onClick={() => setShown(shown + FIRST_PAGE)}
|
|
232
|
+
className="mx-auto mt-4 block rounded-full border border-border bg-card px-4 py-2 text-[14px] font-semibold transition-colors hover:border-ring"
|
|
233
|
+
>
|
|
234
|
+
Show {Math.min(FIRST_PAGE, results.length - shown)} more of{' '}
|
|
235
|
+
{results.length - shown}
|
|
236
|
+
</button>
|
|
237
|
+
)}
|
|
238
|
+
{plainHits.length > 0 && (
|
|
239
|
+
<section className="mt-8">
|
|
240
|
+
<h2 className="m-0 mb-3 px-1 font-serif text-[15px] font-semibold tracking-tight">
|
|
241
|
+
Other desks
|
|
242
|
+
</h2>
|
|
243
|
+
<ul className="grid grid-cols-1 gap-3 md:grid-cols-2">
|
|
244
|
+
{plainHits.map((d) => (
|
|
245
|
+
<DeskCard key={d.slug} desk={d} onOpen={onOpen} />
|
|
246
|
+
))}
|
|
247
|
+
</ul>
|
|
248
|
+
</section>
|
|
249
|
+
)}
|
|
250
|
+
</div>
|
|
251
|
+
) : (
|
|
252
|
+
<AreaBrowse areas={areas} onOpen={onOpen} scrollRef={scrollRef} />
|
|
253
|
+
)}
|
|
254
|
+
</div>
|
|
255
|
+
</div>
|
|
256
|
+
|
|
257
|
+
{openDesk && (
|
|
258
|
+
<ServiceDeskDetail desk={openDesk} form={openForm} onClose={onClose} />
|
|
259
|
+
)}
|
|
260
|
+
</div>
|
|
261
|
+
)
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
const areaId = (area: string) =>
|
|
265
|
+
`area-${area.toLowerCase().replace(/[^a-z0-9]+/g, '-')}`
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Every desk by area, with a contents list beside it on wide screens. The list
|
|
269
|
+
* scrolls the page to an area and marks the one being read.
|
|
270
|
+
*/
|
|
271
|
+
function AreaBrowse({
|
|
272
|
+
areas,
|
|
273
|
+
onOpen,
|
|
274
|
+
scrollRef,
|
|
275
|
+
}: {
|
|
276
|
+
areas: [string, ServiceDesk[]][]
|
|
277
|
+
onOpen: (slug: string) => void
|
|
278
|
+
scrollRef: React.RefObject<HTMLDivElement | null>
|
|
279
|
+
}) {
|
|
280
|
+
const [current, setCurrent] = useState(areas[0]?.[0])
|
|
281
|
+
useEffect(() => {
|
|
282
|
+
const root = scrollRef.current
|
|
283
|
+
if (!root) return
|
|
284
|
+
// The current area is the last one whose heading has scrolled past the
|
|
285
|
+
// top: a rule that never depends on how tall the section above it is.
|
|
286
|
+
let frame = 0
|
|
287
|
+
const update = () => {
|
|
288
|
+
frame = 0
|
|
289
|
+
const line = root.getBoundingClientRect().top + 120
|
|
290
|
+
let last = areas[0]?.[0]
|
|
291
|
+
for (const el of root.querySelectorAll<HTMLElement>('[data-area]')) {
|
|
292
|
+
if (el.getBoundingClientRect().top <= line) last = el.dataset.area
|
|
293
|
+
}
|
|
294
|
+
// At the bottom nothing below can reach the line: the last area wins.
|
|
295
|
+
if (root.scrollTop + root.clientHeight >= root.scrollHeight - 4) {
|
|
296
|
+
last = areas[areas.length - 1]?.[0]
|
|
297
|
+
}
|
|
298
|
+
setCurrent(last)
|
|
299
|
+
}
|
|
300
|
+
const onScroll = () => {
|
|
301
|
+
if (!frame) frame = requestAnimationFrame(update)
|
|
302
|
+
}
|
|
303
|
+
update()
|
|
304
|
+
root.addEventListener('scroll', onScroll, { passive: true })
|
|
305
|
+
return () => {
|
|
306
|
+
root.removeEventListener('scroll', onScroll)
|
|
307
|
+
cancelAnimationFrame(frame)
|
|
308
|
+
}
|
|
309
|
+
}, [areas, scrollRef])
|
|
310
|
+
|
|
311
|
+
return (
|
|
312
|
+
<div className="xl:grid xl:grid-cols-[minmax(0,1fr)_200px] xl:gap-10">
|
|
313
|
+
<div>
|
|
314
|
+
{areas.map(([area, list]) => (
|
|
315
|
+
<section
|
|
316
|
+
key={area}
|
|
317
|
+
id={areaId(area)}
|
|
318
|
+
data-area={area}
|
|
319
|
+
className="mt-11 first:mt-2"
|
|
320
|
+
>
|
|
321
|
+
<div className="mb-4 flex items-center gap-2.5">
|
|
322
|
+
<div className="h-[3px] w-11 rounded-full bg-primary" />
|
|
323
|
+
<h2 className="m-0 font-serif text-[27px] font-semibold leading-tight tracking-tight">
|
|
324
|
+
{area}
|
|
325
|
+
</h2>
|
|
326
|
+
<span className="text-[13px] text-muted-foreground">
|
|
327
|
+
{list.length} {list.length === 1 ? 'desk' : 'desks'}
|
|
328
|
+
</span>
|
|
329
|
+
</div>
|
|
330
|
+
<ul className="grid grid-cols-1 gap-3 md:grid-cols-2">
|
|
331
|
+
{list.map((d) => (
|
|
332
|
+
<DeskCard
|
|
333
|
+
key={d.slug}
|
|
334
|
+
desk={d}
|
|
335
|
+
onOpen={onOpen}
|
|
336
|
+
showArea={false}
|
|
337
|
+
/>
|
|
338
|
+
))}
|
|
339
|
+
</ul>
|
|
340
|
+
</section>
|
|
341
|
+
))}
|
|
127
342
|
</div>
|
|
343
|
+
<nav aria-label="Areas" className="hidden xl:block">
|
|
344
|
+
<ol className="sticky top-4 mt-2 flex flex-col border-l border-border">
|
|
345
|
+
{areas.map(([area, list]) => {
|
|
346
|
+
const active = area === current
|
|
347
|
+
return (
|
|
348
|
+
<li key={area}>
|
|
349
|
+
<a
|
|
350
|
+
href={`#${areaId(area)}`}
|
|
351
|
+
aria-current={active ? 'true' : undefined}
|
|
352
|
+
onClick={(e) => {
|
|
353
|
+
e.preventDefault()
|
|
354
|
+
// Scrolls this view only: scrollIntoView would also move
|
|
355
|
+
// the document and push the header band off screen.
|
|
356
|
+
const root = scrollRef.current
|
|
357
|
+
const el = document.getElementById(areaId(area))
|
|
358
|
+
if (!root || !el) return
|
|
359
|
+
root.scrollTo({
|
|
360
|
+
top:
|
|
361
|
+
root.scrollTop +
|
|
362
|
+
el.getBoundingClientRect().top -
|
|
363
|
+
root.getBoundingClientRect().top -
|
|
364
|
+
16,
|
|
365
|
+
behavior: 'smooth',
|
|
366
|
+
})
|
|
367
|
+
}}
|
|
368
|
+
className={cn(
|
|
369
|
+
'-ml-px flex items-baseline justify-between gap-2 border-l-2 py-1.5 pl-3 text-[13px] leading-snug transition-colors',
|
|
370
|
+
active
|
|
371
|
+
? 'border-primary font-semibold text-foreground'
|
|
372
|
+
: 'border-transparent text-muted-foreground hover:text-foreground',
|
|
373
|
+
)}
|
|
374
|
+
>
|
|
375
|
+
<span>{area}</span>
|
|
376
|
+
<span className="tabular-nums text-[12px] text-muted-foreground">
|
|
377
|
+
{list.length}
|
|
378
|
+
</span>
|
|
379
|
+
</a>
|
|
380
|
+
</li>
|
|
381
|
+
)
|
|
382
|
+
})}
|
|
383
|
+
</ol>
|
|
384
|
+
</nav>
|
|
128
385
|
</div>
|
|
129
386
|
)
|
|
130
387
|
}
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* Desks by their portal's area, areas A to Z, desks A to Z inside one. Desks
|
|
391
|
+
* with no area — chat bots, web forms, portals nobody has placed yet — go last.
|
|
392
|
+
*/
|
|
393
|
+
function groupByArea(desks: ServiceDesk[]): [string, ServiceDesk[]][] {
|
|
394
|
+
const byArea = new Map<string, ServiceDesk[]>()
|
|
395
|
+
for (const d of desks) {
|
|
396
|
+
const area = (hasPortal(d) && d.config.portal.area) || OTHER_AREA
|
|
397
|
+
byArea.set(area, [...(byArea.get(area) ?? []), d])
|
|
398
|
+
}
|
|
399
|
+
return [...byArea.entries()].sort(([a], [b]) =>
|
|
400
|
+
a === OTHER_AREA ? 1 : b === OTHER_AREA ? -1 : a.localeCompare(b),
|
|
401
|
+
)
|
|
402
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Marks every search term in `text`. Terms match independently, so a query of
|
|
3
|
+
* two words lights up both wherever they occur.
|
|
4
|
+
*
|
|
5
|
+
* Plain marker on ink, no weight change: on a card that already carries a title,
|
|
6
|
+
* a muted line and a link, the match is the one accent.
|
|
7
|
+
*/
|
|
8
|
+
export function Marked({ text, query }: { text: string; query: string }) {
|
|
9
|
+
const terms = query.trim().split(/\s+/).filter(Boolean)
|
|
10
|
+
if (!terms.length) return <>{text}</>
|
|
11
|
+
const pattern = new RegExp(
|
|
12
|
+
`(${terms.map((t) => t.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')).join('|')})`,
|
|
13
|
+
'gi',
|
|
14
|
+
)
|
|
15
|
+
return (
|
|
16
|
+
<>
|
|
17
|
+
{text.split(pattern).map((part, i) =>
|
|
18
|
+
i % 2 === 1 ? (
|
|
19
|
+
<mark
|
|
20
|
+
key={i}
|
|
21
|
+
className="rounded-[3px] bg-highlight px-0.5 text-foreground"
|
|
22
|
+
>
|
|
23
|
+
{part}
|
|
24
|
+
</mark>
|
|
25
|
+
) : (
|
|
26
|
+
part
|
|
27
|
+
),
|
|
28
|
+
)}
|
|
29
|
+
</>
|
|
30
|
+
)
|
|
31
|
+
}
|