|
1 | | -'use client' |
2 | | - |
3 | | -import { useState } from 'react' |
4 | 1 | import styles from '@/platform/app/(shell)/integrations/_components/connection-access/connection-access.module.css' |
5 | 2 | import { |
6 | 3 | SCOPE_GROUPS, |
7 | 4 | scopeGroup, |
8 | 5 | } from '@/platform/app/(shell)/integrations/_components/connection-access/scope-groups' |
9 | | -import { Button, Disclosure } from '@/platform/design-system/components' |
| 6 | +import { CountedLabel } from '@/platform/design-system/components/overflow-text/counted-label' |
10 | 7 | import type { OrganizationIntegration } from '@/platform/lib/integrations/model' |
11 | 8 |
|
| 9 | +interface AccessGroupProps { |
| 10 | + title: string |
| 11 | + items: readonly { id: string; label: string }[] |
| 12 | +} |
| 13 | + |
| 14 | +function AccessGroup({ title, items }: AccessGroupProps) { |
| 15 | + if (!items.length) return null |
| 16 | + return ( |
| 17 | + <div className={styles.group}> |
| 18 | + <h3 data-type='T059'> |
| 19 | + <CountedLabel label={title} count={items.length} /> |
| 20 | + </h3> |
| 21 | + <ul className={styles.items} aria-label={title}> |
| 22 | + {items.map(({ id, label }) => ( |
| 23 | + <li data-type='T060' key={id}> |
| 24 | + {label} |
| 25 | + </li> |
| 26 | + ))} |
| 27 | + </ul> |
| 28 | + </div> |
| 29 | + ) |
| 30 | +} |
| 31 | + |
12 | 32 | interface ConnectionAccessProps { |
13 | 33 | integration: OrganizationIntegration |
14 | 34 | } |
15 | 35 |
|
16 | 36 | export function ConnectionAccess({ integration }: ConnectionAccessProps) { |
17 | | - const [showIds, setShowIds] = useState(false) |
18 | | - const scopes = integration.requestedScopes |
19 | | - if (!scopes?.length) return null |
| 37 | + const { searchReads, searchResource, requestedScopes, availability, accessDescription } = |
| 38 | + integration |
20 | 39 | return ( |
21 | | - <section className={styles.section} aria-label='Requested permissions'> |
22 | | - <header className={styles.header}> |
23 | | - <h2 data-type='T093'>Requested permissions</h2> |
24 | | - <Button |
25 | | - size='compact' |
26 | | - variant='quiet' |
27 | | - render={<button type='button' aria-expanded={showIds} />} |
28 | | - onClick={() => setShowIds(!showIds)} |
29 | | - > |
30 | | - {showIds ? 'Hide scope IDs' : 'Show scope IDs'} |
31 | | - </Button> |
32 | | - </header> |
33 | | - {SCOPE_GROUPS.map((group) => { |
34 | | - const entries = scopes.filter(({ id }) => scopeGroup(id) === group) |
35 | | - if (!entries.length) return null |
36 | | - return ( |
37 | | - <Disclosure key={group} label={group} initiallyOpen> |
38 | | - <ul className={styles.scopes} aria-label={group}> |
39 | | - {entries.map(({ id, label }) => ( |
40 | | - <li key={id} className={styles.scope}> |
41 | | - <span data-type='T060'>{label}</span> |
42 | | - {showIds && label !== id && <span data-type='T050'>{id}</span>} |
43 | | - </li> |
44 | | - ))} |
45 | | - </ul> |
46 | | - </Disclosure> |
47 | | - ) |
48 | | - })} |
49 | | - </section> |
| 40 | + <> |
| 41 | + {searchResource && |
| 42 | + availability === 'ready' && |
| 43 | + (searchReads.length > 0 || !requestedScopes?.length) && ( |
| 44 | + <section className={styles.section} aria-label='Search access'> |
| 45 | + <header className={styles.heading}> |
| 46 | + <h2 data-type='T093'>Search access</h2> |
| 47 | + <p data-type='T060'>{accessDescription}</p> |
| 48 | + </header> |
| 49 | + <AccessGroup title='Read-only tools' items={searchReads} /> |
| 50 | + </section> |
| 51 | + )} |
| 52 | + {requestedScopes && requestedScopes.length > 0 && ( |
| 53 | + <section className={styles.section} aria-label='Requested permissions'> |
| 54 | + <h2 data-type='T093'>Requested permissions</h2> |
| 55 | + {SCOPE_GROUPS.map((group) => ( |
| 56 | + <AccessGroup |
| 57 | + key={group} |
| 58 | + title={group} |
| 59 | + items={requestedScopes.filter(({ id }) => scopeGroup(id) === group)} |
| 60 | + /> |
| 61 | + ))} |
| 62 | + </section> |
| 63 | + )} |
| 64 | + </> |
50 | 65 | ) |
51 | 66 | } |
0 commit comments