Skip to content

Commit 12f6fc5

Browse files
committed
Share the People loading status and drop callbacks nothing observes
1 parent f0d2039 commit 12f6fc5

10 files changed

Lines changed: 57 additions & 61 deletions

File tree

‎apps/sim/platform/app/(shell)/people/_components/directory/directory.module.css‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,3 @@
2020
inline-size: var(--spacing-224);
2121
max-inline-size: 100%;
2222
}
23-
24-
.status {
25-
color: var(--ui-secondary);
26-
padding-block: var(--spacing-48);
27-
text-align: center;
28-
}

‎apps/sim/platform/app/(shell)/people/_components/directory/directory.tsx‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import { useMemo, useState } from 'react'
44
import { useRouter } from 'next/navigation'
55
import styles from '@/platform/app/(shell)/people/_components/directory/directory.module.css'
6+
import { PeopleStatus } from '@/platform/app/(shell)/people/_components/people-page/people-status'
67
import {
78
Button,
89
DataTable,
@@ -99,9 +100,7 @@ export function PeopleDirectory({ organizationId }: PeopleDirectoryProps) {
99100
</div>
100101
)}
101102
{directory.loading ? (
102-
<p className={styles.status} role='status' data-type='T060'>
103-
Loading people…
104-
</p>
103+
<PeopleStatus>Loading people…</PeopleStatus>
105104
) : directory.error ? (
106105
<InlineNotice
107106
intent='danger'

‎apps/sim/platform/app/(shell)/people/_components/org-chart/chart-empty-state.tsx‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { MouseEvent } from 'react'
1+
import type { MouseEvent, RefCallback } from 'react'
22
import Link from 'next/link'
33
import styles from '@/platform/app/(shell)/people/_components/org-chart/org-chart.module.css'
44
import { Button, EmptyState } from '@/platform/design-system/components'
@@ -20,6 +20,7 @@ interface ChartEmptyStateProps {
2020
person: PersonSummary
2121
profileQuery: string
2222
onFocus: (memberId: string, event: MouseEvent<HTMLButtonElement>) => void
23+
currentPersonRef: RefCallback<HTMLElement>
2324
onImport?: () => void
2425
onSync?: () => void
2526
}
@@ -29,6 +30,7 @@ export function ChartEmptyState({
2930
person,
3031
profileQuery,
3132
onFocus,
33+
currentPersonRef,
3234
onImport,
3335
onSync,
3436
}: ChartEmptyStateProps) {
@@ -59,7 +61,11 @@ export function ChartEmptyState({
5961
)
6062
)}
6163
{emptyOrganization && onImport && <Button onClick={onImport}>Import people</Button>}
62-
<Button render={<Link href={personHref(person.memberId, profileQuery)} />}>
64+
<Button
65+
render={
66+
<Link ref={currentPersonRef} href={personHref(person.memberId, profileQuery)} />
67+
}
68+
>
6369
View profile
6470
</Button>
6571
</div>

‎apps/sim/platform/app/(shell)/people/_components/org-chart/org-chart.module.css‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,6 @@
4343
font-variant-numeric: tabular-nums;
4444
}
4545

46-
.status {
47-
color: var(--ui-secondary);
48-
padding-block: var(--spacing-48);
49-
text-align: center;
50-
}
51-
5246
.canvas {
5347
display: grid;
5448
justify-items: center;

‎apps/sim/platform/app/(shell)/people/_components/org-chart/org-chart.tsx‎

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Fragment, type MouseEvent, useCallback, useLayoutEffect, useRef } from
44
import { ChartCanvas } from '@/platform/app/(shell)/people/_components/org-chart/chart-canvas'
55
import { ChartEmptyState } from '@/platform/app/(shell)/people/_components/org-chart/chart-empty-state'
66
import styles from '@/platform/app/(shell)/people/_components/org-chart/org-chart.module.css'
7+
import { PeopleStatus } from '@/platform/app/(shell)/people/_components/people-page/people-status'
78
import {
89
Button,
910
EmptyState,
@@ -62,17 +63,14 @@ export function OrgChart({ organization, onImport, onSync }: OrgChartProps) {
6263
trigger: HTMLElement
6364
target: FocusTarget
6465
} | null>(null)
65-
const focusPerson = useCallback(
66-
(id: string, event?: MouseEvent<HTMLButtonElement>) => {
67-
// `detail === 0` is a keyboard click: focus follows the navigation instead of being lost.
68-
pendingFocus.current =
69-
event?.detail === 0
70-
? { focus: id, page: 1, trigger: event.currentTarget, target: 'person' }
71-
: null
72-
void setView({ focus: id, page: 1, view: 'chart' }, { history: 'push' })
73-
},
74-
[setView]
75-
)
66+
const focusPerson = (id: string, event?: MouseEvent<HTMLButtonElement>) => {
67+
// `detail === 0` is a keyboard click: focus follows the navigation instead of being lost.
68+
pendingFocus.current =
69+
event?.detail === 0
70+
? { focus: id, page: 1, trigger: event.currentTarget, target: 'person' }
71+
: null
72+
void setView({ focus: id, page: 1, view: 'chart' }, { history: 'push' })
73+
}
7674
const changePage = (
7775
value: number,
7876
target: 'previous' | 'next',
@@ -118,6 +116,7 @@ export function OrgChart({ organization, onImport, onSync }: OrgChartProps) {
118116
person={branch.person}
119117
profileQuery={profileQuery}
120118
onFocus={focusPerson}
119+
currentPersonRef={setCurrentPerson}
121120
onImport={onImport}
122121
onSync={onSync}
123122
/>
@@ -218,9 +217,7 @@ export function OrgChart({ organization, onImport, onSync }: OrgChartProps) {
218217
/>
219218
)
220219
) : (
221-
<p className={styles.status} role='status' data-type='T060'>
222-
Loading org chart…
223-
</p>
220+
<PeopleStatus>Loading org chart…</PeopleStatus>
224221
)}
225222
</section>
226223
)

‎apps/sim/platform/app/(shell)/people/_components/people-page/people-frame.tsx‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { ReactNode } from 'react'
22
import styles from '@/platform/app/(shell)/people/_components/people-page/people-page.module.css'
3+
import { PeopleStatus } from '@/platform/app/(shell)/people/_components/people-page/people-status'
34

45
interface PeopleFrameProps {
56
title?: string
@@ -16,13 +17,7 @@ export function PeopleFrame({ title = 'People', actions, loading, children }: Pe
1617
<h1 data-type='T076'>{title}</h1>
1718
{actions && <div className={styles.actions}>{actions}</div>}
1819
</header>
19-
{loading ? (
20-
<p className={styles.status} role='status' data-type='T060'>
21-
{loading}
22-
</p>
23-
) : (
24-
children
25-
)}
20+
{loading ? <PeopleStatus>{loading}</PeopleStatus> : children}
2621
</main>
2722
)
2823
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import styles from '@/platform/app/(shell)/people/_components/people-page/people-page.module.css'
2+
3+
interface PeopleStatusProps {
4+
children: string
5+
}
6+
7+
/** The body of a People view while its first read is pending, the same size in every view. */
8+
export function PeopleStatus({ children }: PeopleStatusProps) {
9+
return (
10+
<p className={styles.status} role='status' data-type='T060'>
11+
{children}
12+
</p>
13+
)
14+
}

‎apps/sim/platform/checks/live/members.spec.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect, type Page, test } from '@playwright/test'
2-
import { requireEnv, signIn } from './session'
2+
import { requireEnv, signIn } from '@/platform/checks/live/session'
33

44
/**
55
* Mutates the seeded organization. `PLATFORM_LIVE_EMAIL` is an administrator,

‎apps/sim/platform/checks/live/people.spec.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect, test } from '@playwright/test'
2-
import { requireEnv, signIn } from './session'
2+
import { requireEnv, signIn } from '@/platform/checks/live/session'
33

44
/**
55
* `PLATFORM_LIVE_EMAIL` is an administrator in an organization with the `people` flag on.

‎apps/sim/platform/lib/data/people.ts‎

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use client'
22

3-
import { useCallback, useMemo, useState } from 'react'
3+
import { useMemo, useState } from 'react'
44
import { useQueryStates } from 'nuqs'
55
import { isApiClientError } from '@/lib/api/client/errors'
66
import type {
@@ -353,26 +353,23 @@ export function useDirectorySync(organizationId: string) {
353353
const query = usePeopleSyncStatus(organizationId)
354354
const actions = usePeopleSyncActions(organizationId)
355355
const status = isDirectorySyncAccessError(query.error) ? undefined : query.data
356-
const connect = useCallback(
357-
(draft: SyncDraft, onConnected: () => void): SyncFieldErrors | null => {
358-
const parsed = peopleSyncConfigSchema.safeParse(
359-
draft.source === 'okta'
360-
? { source: 'okta', domain: draft.domain, token: draft.token }
361-
: draft.source === 'entra'
362-
? {
363-
source: 'entra',
364-
tenantId: draft.tenantId.trim(),
365-
clientId: draft.clientId.trim(),
366-
clientSecret: draft.clientSecret,
367-
}
368-
: { source: 'scim' }
369-
)
370-
if (!parsed.success) return flattenFieldErrors(parsed.error)
371-
actions.configure(parsed.data, onConnected)
372-
return null
373-
},
374-
[actions]
375-
)
356+
const connect = (draft: SyncDraft, onConnected: () => void): SyncFieldErrors | null => {
357+
const parsed = peopleSyncConfigSchema.safeParse(
358+
draft.source === 'okta'
359+
? { source: 'okta', domain: draft.domain, token: draft.token }
360+
: draft.source === 'entra'
361+
? {
362+
source: 'entra',
363+
tenantId: draft.tenantId.trim(),
364+
clientId: draft.clientId.trim(),
365+
clientSecret: draft.clientSecret,
366+
}
367+
: { source: 'scim' }
368+
)
369+
if (!parsed.success) return flattenFieldErrors(parsed.error)
370+
actions.configure(parsed.data, onConnected)
371+
return null
372+
}
376373
return {
377374
loading: query.isPending,
378375
loaded: Boolean(status),

0 commit comments

Comments
 (0)