@coffre/ui 0.5.1 → 0.6.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.
Files changed (120) hide show
  1. package/dist/chunks/{affordances-Bqdevf7w.js → affordances-D0GyCT-I.js} +3 -3
  2. package/dist/chunks/affordances-D0GyCT-I.js.map +1 -0
  3. package/dist/chunks/{audit-sentence-Cm5nby5k.js → audit-sentence-CUUMshIp.js} +22 -6
  4. package/dist/chunks/audit-sentence-CUUMshIp.js.map +1 -0
  5. package/dist/chunks/{connected-apps-DTNS7YmY.js → connected-apps-IP0KfUjo.js} +5 -5
  6. package/dist/chunks/{connected-apps-DTNS7YmY.js.map → connected-apps-IP0KfUjo.js.map} +1 -1
  7. package/dist/chunks/{delete-place-CIaOq0mt.js → delete-place-CVv6CN5y.js} +5 -5
  8. package/dist/chunks/{delete-place-CIaOq0mt.js.map → delete-place-CVv6CN5y.js.map} +1 -1
  9. package/dist/chunks/{directory-DSVt5Tya.js → directory-pMVS1m-c.js} +62 -43
  10. package/dist/chunks/directory-pMVS1m-c.js.map +1 -0
  11. package/dist/chunks/{folders-CoGK9oqg.js → folders-hR2Lnk0k.js} +3 -3
  12. package/dist/chunks/{folders-CoGK9oqg.js.map → folders-hR2Lnk0k.js.map} +1 -1
  13. package/dist/chunks/{grants-CRU7yZhL.js → grants-CgC8Ybhu.js} +6 -6
  14. package/dist/chunks/{grants-CRU7yZhL.js.map → grants-CgC8Ybhu.js.map} +1 -1
  15. package/dist/chunks/{offboarding-DVBSiJRZ.js → offboarding-3fzRjKla.js} +5 -5
  16. package/dist/chunks/{offboarding-DVBSiJRZ.js.map → offboarding-3fzRjKla.js.map} +1 -1
  17. package/dist/chunks/{page-DvsgZ2Hd.js → page-JTORvh-N.js} +7 -3
  18. package/dist/chunks/page-JTORvh-N.js.map +1 -0
  19. package/dist/chunks/{principal-BIN-xwZw.js → principal-DFBswTBr.js} +2 -2
  20. package/dist/chunks/{principal-BIN-xwZw.js.map → principal-DFBswTBr.js.map} +1 -1
  21. package/dist/chunks/{principal-page-BEBr_zW7.js → principal-page-CYJIJAdp.js} +17 -19
  22. package/dist/chunks/principal-page-CYJIJAdp.js.map +1 -0
  23. package/dist/chunks/{project-page-B3TZ5_ig.js → project-page-lO5P6iCb.js} +3 -3
  24. package/dist/chunks/{project-page-B3TZ5_ig.js.map → project-page-lO5P6iCb.js.map} +1 -1
  25. package/dist/chunks/{queries-DE5nK2y4.js → queries-gigcQOO_.js} +26 -12
  26. package/dist/chunks/queries-gigcQOO_.js.map +1 -0
  27. package/dist/chunks/{references-uv4Mli9z.js → references-DZ179hTJ.js} +5 -5
  28. package/dist/chunks/{references-uv4Mli9z.js.map → references-DZ179hTJ.js.map} +1 -1
  29. package/dist/chunks/{role-field-DWhkRY6n.js → role-field-DiqiFwm_.js} +14 -7
  30. package/dist/chunks/role-field-DiqiFwm_.js.map +1 -0
  31. package/dist/chunks/{row-state-DOPUsjQK.js → row-state-Zf3kZVhd.js} +13 -5
  32. package/dist/chunks/row-state-Zf3kZVhd.js.map +1 -0
  33. package/dist/chunks/{signin-errors--ykMFuqN.js → signin-errors-TlQmQe0t.js} +2 -2
  34. package/dist/chunks/signin-errors-TlQmQe0t.js.map +1 -0
  35. package/dist/chunks/{theme-DJuz-xLM.js → theme-B6-V9JvY.js} +3 -3
  36. package/dist/chunks/{theme-DJuz-xLM.js.map → theme-B6-V9JvY.js.map} +1 -1
  37. package/dist/chunks/{ui-DJje3gST.js → ui-Br-dNUTc.js} +2 -2
  38. package/dist/chunks/{ui-DJje3gST.js.map → ui-Br-dNUTc.js.map} +1 -1
  39. package/dist/chunks/{use-action-BRgvbUWt.js → use-action-CQGGNqWb.js} +3 -3
  40. package/dist/chunks/{use-action-BRgvbUWt.js.map → use-action-CQGGNqWb.js.map} +1 -1
  41. package/dist/chunks/{use-change-BJ3dCFHb.js → use-change-BdS1gzyo.js} +31 -19
  42. package/dist/chunks/use-change-BdS1gzyo.js.map +1 -0
  43. package/dist/chunks/{use-shell-BO4ZTr1y.js → use-shell-BCU505bx.js} +3 -3
  44. package/dist/chunks/{use-shell-BO4ZTr1y.js.map → use-shell-BCU505bx.js.map} +1 -1
  45. package/dist/index.d.ts +6 -7
  46. package/dist/index.js +8 -9
  47. package/dist/index.js.map +1 -1
  48. package/dist/pages/account.js +12 -13
  49. package/dist/pages/account.js.map +1 -1
  50. package/dist/pages/approval.js +2 -2
  51. package/dist/pages/audit.js +5 -5
  52. package/dist/pages/audit.js.map +1 -1
  53. package/dist/pages/device-login.js +2 -2
  54. package/dist/pages/environment.js +829 -155
  55. package/dist/pages/environment.js.map +1 -1
  56. package/dist/pages/login.js +4 -4
  57. package/dist/pages/oauth-authorize.js +2 -2
  58. package/dist/pages/project-access.js +160 -80
  59. package/dist/pages/project-access.js.map +1 -1
  60. package/dist/pages/project-environments.js +10 -10
  61. package/dist/pages/project-settings.js +8 -8
  62. package/dist/pages/project.js +3 -3
  63. package/dist/pages/projects.js +10 -10
  64. package/dist/pages/projects.js.map +1 -1
  65. package/dist/pages/service-account.js +537 -109
  66. package/dist/pages/service-account.js.map +1 -1
  67. package/dist/pages/service-accounts.js +5 -5
  68. package/dist/pages/settings.js +8 -18
  69. package/dist/pages/settings.js.map +1 -1
  70. package/dist/pages/unregistered.js +3 -3
  71. package/dist/pages/unregistered.js.map +1 -1
  72. package/dist/pages/user.js +6 -6
  73. package/dist/pages/users.js +5 -5
  74. package/package.json +3 -3
  75. package/src/components/affordances.ts +1 -1
  76. package/src/components/directory.tsx +40 -34
  77. package/src/components/generate-value.tsx +362 -0
  78. package/src/components/github-picker.tsx +83 -0
  79. package/src/components/icons.tsx +4 -0
  80. package/src/components/masked.tsx +60 -0
  81. package/src/components/missing.tsx +3 -3
  82. package/src/components/multi-combobox.tsx +94 -0
  83. package/src/components/principal-page.tsx +8 -12
  84. package/src/components/principal-picker.tsx +68 -18
  85. package/src/components/role-field.tsx +7 -5
  86. package/src/components/row-state.tsx +7 -3
  87. package/src/components/shell.tsx +0 -1
  88. package/src/components/trusted-workloads.tsx +157 -62
  89. package/src/lib/audit-sentences.ts +25 -3
  90. package/src/lib/bindings.ts +125 -14
  91. package/src/lib/capabilities.ts +15 -9
  92. package/src/lib/changes.ts +15 -9
  93. package/src/lib/coffre.ts +2 -0
  94. package/src/lib/generate.ts +160 -0
  95. package/src/lib/queries.ts +18 -5
  96. package/src/lib/secret-edit-batch.ts +38 -5
  97. package/src/lib/secret-order.ts +23 -0
  98. package/src/lib/shortcuts.ts +9 -0
  99. package/src/lib/signin-errors.ts +1 -1
  100. package/src/lib/use-github-lookup.ts +70 -0
  101. package/src/pages/account.tsx +1 -2
  102. package/src/pages/audit.tsx +1 -1
  103. package/src/pages/environment.tsx +228 -119
  104. package/src/pages/project-access.tsx +19 -8
  105. package/src/pages/projects.tsx +3 -3
  106. package/src/pages/settings.tsx +0 -10
  107. package/src/pages/unregistered.tsx +1 -1
  108. package/src/parity.ts +3 -1
  109. package/src/shared/models.ts +2 -2
  110. package/src/styles/globals.css +303 -19
  111. package/dist/chunks/affordances-Bqdevf7w.js.map +0 -1
  112. package/dist/chunks/audit-sentence-Cm5nby5k.js.map +0 -1
  113. package/dist/chunks/directory-DSVt5Tya.js.map +0 -1
  114. package/dist/chunks/page-DvsgZ2Hd.js.map +0 -1
  115. package/dist/chunks/principal-page-BEBr_zW7.js.map +0 -1
  116. package/dist/chunks/queries-DE5nK2y4.js.map +0 -1
  117. package/dist/chunks/role-field-DWhkRY6n.js.map +0 -1
  118. package/dist/chunks/row-state-DOPUsjQK.js.map +0 -1
  119. package/dist/chunks/signin-errors--ykMFuqN.js.map +0 -1
  120. package/dist/chunks/use-change-BJ3dCFHb.js.map +0 -1
@@ -0,0 +1,60 @@
1
+ import { useEffect, useState, type ComponentProps, type InputHTMLAttributes } from 'react';
2
+
3
+ /**
4
+ * A text field whose contents are masked until asked, for secret values.
5
+ *
6
+ * Where the browser supports it, the mask is CSS on a text input rather than
7
+ * `type="password"`: password fields invite password managers to offer to
8
+ * save or fill them, and a secret being typed into coffre is neither.
9
+ */
10
+ export function MaskedInput({
11
+ masked,
12
+ className = '',
13
+ ...props
14
+ }: Omit<InputHTMLAttributes<HTMLInputElement>, 'type'> & { masked: boolean }) {
15
+ const cssMask = useCssMask();
16
+ return (
17
+ <input
18
+ {...props}
19
+ type={masked && !cssMask ? 'password' : 'text'}
20
+ className={`${className}${masked && cssMask ? ' is-masked' : ''}`}
21
+ autoComplete="off"
22
+ spellCheck={false}
23
+ data-1p-ignore
24
+ data-lpignore="true"
25
+ data-bwignore
26
+ />
27
+ );
28
+ }
29
+
30
+ function useCssMask(): boolean {
31
+ const [cssMask, setCssMask] = useState(false);
32
+ useEffect(() => {
33
+ setCssMask(typeof CSS !== 'undefined' && CSS.supports('-webkit-text-security', 'disc'));
34
+ }, []);
35
+ return cssMask;
36
+ }
37
+
38
+ /**
39
+ * MaskedInput for a value with line breaks, which a text input would drop.
40
+ * Without the CSS mask there is no password textarea, so masked text is
41
+ * drawn transparent instead.
42
+ */
43
+ export function MaskedTextarea({
44
+ masked,
45
+ className = '',
46
+ ...props
47
+ }: ComponentProps<'textarea'> & { masked: boolean }) {
48
+ const cssMask = useCssMask();
49
+ return (
50
+ <textarea
51
+ {...props}
52
+ className={`${className}${masked ? (cssMask ? ' is-masked' : ' is-masked-fallback') : ''}`}
53
+ autoComplete="off"
54
+ spellCheck={false}
55
+ data-1p-ignore
56
+ data-lpignore="true"
57
+ data-bwignore
58
+ />
59
+ );
60
+ }
@@ -8,8 +8,8 @@ import { Card } from './page';
8
8
  import { ErrorLine, Timestamp } from './ui';
9
9
 
10
10
  /**
11
- * Keys the environment's siblings have and it lacks, of those you read
12
- * (docs/design/environments.md): each with Add, which opens a new row with
11
+ * Keys the environment's siblings have and it lacks, by name, whether you
12
+ * read them or not (docs/design/environments.md): each with Add, which opens a new row with
13
13
  * its name, and Dismiss, which the whole team then sees, and below them
14
14
  * Dismiss all and what was dismissed, each with Restore. Nothing shows when
15
15
  * nothing is missing or dismissed.
@@ -42,7 +42,7 @@ export function MissingKeys({
42
42
  wide
43
43
  labelledBy="missing-keys"
44
44
  title={missing.length === 0 ? 'Nothing missing' : `${missing.length} ${missing.length === 1 ? 'key' : 'keys'} from other environments ${missing.length === 1 ? "isn't" : "aren't"} here`}
45
- description="Compared with the environments you can read."
45
+ description="Compared with every other environment of the project, by key name."
46
46
  >
47
47
  <div className="dt-wrap">
48
48
  <table className="dt stacks missing-keys">
@@ -0,0 +1,94 @@
1
+ import { Combobox } from '@base-ui/react/combobox';
2
+ import { useId, type ReactNode } from 'react';
3
+ import { usePreferences } from '../lib/preferences';
4
+ import { Check, X } from './icons';
5
+
6
+ /**
7
+ * Several of a fixed list, chosen by typing: each chosen one a chip in the
8
+ * field, the rest offered below as the text filters them. Base UI's
9
+ * combobox does the keyboard and ARIA: arrows move through the options,
10
+ * Enter takes one, Backspace in an empty field removes the last chip, and
11
+ * Left Arrow from the start of the field walks the chips.
12
+ *
13
+ * The value keeps the options' order, whatever order they were chosen in.
14
+ */
15
+ export function MultiCombobox({
16
+ label,
17
+ options,
18
+ value,
19
+ onChange,
20
+ placeholder,
21
+ hint,
22
+ note,
23
+ mono = false,
24
+ }: {
25
+ label: ReactNode;
26
+ options: readonly string[];
27
+ value: string[];
28
+ onChange: (value: string[]) => void;
29
+ placeholder?: string;
30
+ hint?: ReactNode;
31
+ /** A word beside an option in the list, such as what choosing it exposes. */
32
+ note?: (option: string) => ReactNode;
33
+ mono?: boolean;
34
+ }) {
35
+ const { portal } = usePreferences();
36
+ const id = useId();
37
+ const labelId = useId();
38
+ const hintId = useId();
39
+ return (
40
+ <Combobox.Root items={options} multiple value={value} onValueChange={(next) => onChange(options.filter((option) => next.includes(option)))}>
41
+ <div className="field">
42
+ <label className="label" htmlFor={id} id={labelId}>
43
+ {label}
44
+ </label>
45
+ <Combobox.InputGroup className={`combo${mono ? ' combo-mono' : ''}`}>
46
+ <Combobox.Chips className="combo-chips" aria-label={value.length > 0 ? 'Chosen' : undefined}>
47
+ {value.map((option) => (
48
+ <Combobox.Chip key={option} className="combo-chip" aria-label={option} aria-description="Press Backspace or Delete to remove">
49
+ {option}
50
+ <Combobox.ChipRemove className="combo-chip-remove" aria-label={`Remove ${option}`}>
51
+ <X size={12} />
52
+ </Combobox.ChipRemove>
53
+ </Combobox.Chip>
54
+ ))}
55
+ <Combobox.Input
56
+ id={id}
57
+ // Named by reference too: while the list is open, Base UI hides what lies outside it, the label included.
58
+ aria-labelledby={labelId}
59
+ className="combo-input"
60
+ placeholder={value.length > 0 ? undefined : placeholder}
61
+ aria-describedby={hint === undefined ? undefined : hintId}
62
+ aria-description={value.length > 0 ? `${value.length} chosen. From the start of the field, press Left Arrow to reach them` : undefined}
63
+ />
64
+ </Combobox.Chips>
65
+ </Combobox.InputGroup>
66
+ {hint !== undefined && (
67
+ <span className="hint" id={hintId}>
68
+ {hint}
69
+ </span>
70
+ )}
71
+ </div>
72
+ <Combobox.Portal container={portal}>
73
+ <Combobox.Positioner className="menu-positioner" sideOffset={4} align="start">
74
+ <Combobox.Popup className="menu combo-popup">
75
+ <Combobox.Empty className="combo-empty">Nothing matches.</Combobox.Empty>
76
+ <Combobox.List>
77
+ {(option: string) => (
78
+ <Combobox.Item key={option} value={option} className={`menu-item${mono ? ' mono' : ''}`}>
79
+ <span className="combo-check">
80
+ <Combobox.ItemIndicator>
81
+ <Check size={14} />
82
+ </Combobox.ItemIndicator>
83
+ </span>
84
+ <span className="combo-option">{option}</span>
85
+ {note?.(option)}
86
+ </Combobox.Item>
87
+ )}
88
+ </Combobox.List>
89
+ </Combobox.Popup>
90
+ </Combobox.Positioner>
91
+ </Combobox.Portal>
92
+ </Combobox.Root>
93
+ );
94
+ }
@@ -117,12 +117,12 @@ export function PrincipalLayout({ principalType, principalId }: { principalType:
117
117
  principalId,
118
118
  instanceRole: found.instanceRole,
119
119
  scope: found.scope,
120
- isRootAdmin: found.isRootAdmin,
121
120
  tampered: found.status === 'tampered',
122
121
  managed: principalType === 'service',
122
+ declared: found.declared,
123
123
  }
124
124
  : yours
125
- ? { principalType, principalId, instanceRole: 'member' as const, scope: null, isRootAdmin: false, tampered: false, managed: true }
125
+ ? { principalType, principalId, instanceRole: 'member' as const, scope: null, tampered: false, managed: true }
126
126
  : undefined;
127
127
 
128
128
  // Owners get a report about anyone ever registered, removed or not, so a
@@ -240,7 +240,6 @@ export function PrincipalLayout({ principalType, principalId }: { principalType:
240
240
  * its offboarding did instead.
241
241
  */
242
242
  export function PrincipalAccess({ principalType, principalId }: { principalType: PrincipalType; principalId: string }) {
243
- const { instanceRole } = useShell();
244
243
  const report = useReport(principalType, principalId);
245
244
  const { access: held, error, projects: access, offers } = useMemberAccess(principalType, principalId);
246
245
  const kind = KIND[principalType];
@@ -316,14 +315,11 @@ export function PrincipalAccess({ principalType, principalId }: { principalType:
316
315
  </div>
317
316
  )}
318
317
 
319
- {/* A root admin manages every project, so nothing is out of view. */}
320
- {instanceRole !== 'root-admin' && (
321
- <p className="hint section-foot">
322
- {held?.managed === true && principalType === 'service'
323
- ? 'Only projects where you may give it access are listed: what you hold there, where the instance lets you.'
324
- : 'Only projects where you manage access are listed.'}
325
- </p>
326
- )}
318
+ <p className="hint section-foot">
319
+ {held?.managed === true && principalType === 'service'
320
+ ? 'Only projects where you may give it access are listed: what you hold there, where the instance lets you.'
321
+ : 'Only projects where you manage access are listed.'}
322
+ </p>
327
323
 
328
324
  </>
329
325
  )}
@@ -335,7 +331,7 @@ export function PrincipalAccess({ principalType, principalId }: { principalType:
335
331
 
336
332
  /** What a person's instance role gives them, above the grants that add to it: nothing for a Member. */
337
333
  function InstanceRoleNote({ access }: { access: MemberAccess }) {
338
- if (access.instanceRole === 'member' || access.instanceRole === 'root-admin') return null;
334
+ if (access.instanceRole === 'member') return null;
339
335
  const { name } = INSTANCE_ROLES[access.instanceRole];
340
336
  return (
341
337
  <div className="report-notice">
@@ -8,18 +8,23 @@ import type { DirectoryPrincipal, GrantRow } from '../shared/models';
8
8
  import { KIND } from './directory';
9
9
  import { PrincipalAvatar } from './principal';
10
10
  import { Spinner } from './ui';
11
- import { Check, Search } from './icons';
11
+ import { Check, Plus, Search } from './icons';
12
12
 
13
13
  type PrincipalType = DirectoryPrincipal['principalType'];
14
14
 
15
+ /** A name the vault takes for a new service account: no spaces, and no colon first. */
16
+ const SERVICE_NAME = /^[^\s:]\S*$/;
17
+
15
18
  /**
16
19
  * Who a grant is for: picked from the registered users or service accounts, each shown
17
20
  * with what it already holds on this project, or typed when the list is not
18
- * yours to read.
21
+ * yours to read. Whoever sets up service accounts may name a new one instead,
22
+ * the last option, which the grant then makes (`admit`).
19
23
  *
20
- * Only instance owners may list the directory. Asking on anyone else's behalf
21
- * would write a refusal to the audit log in their name, so they get a text
22
- * field and the server's answer instead. The list is asked for when the
24
+ * Admins and owners list the directory, and whoever sets up service accounts
25
+ * lists those they manage, and those on their projects. Asking on anyone
26
+ * else's behalf would write a refusal to the audit log in their name, so they
27
+ * get a text field and the server's answer instead. The list is asked for when the
23
28
  * dialog opens rather than with the page, since most visits never open it,
24
29
  * and shared with the Users and Service accounts pages through the cache.
25
30
  */
@@ -27,23 +32,29 @@ export function PrincipalPicker({
27
32
  principalType,
28
33
  canList,
29
34
  grants,
35
+ canCreate = false,
30
36
  value,
37
+ admit = false,
31
38
  onChange,
32
39
  }: {
33
40
  principalType: PrincipalType;
34
- /** Whether you may list the directory: instance owners only. */
41
+ /** Whether you may list the directory: admins and owners, and for service accounts, whoever sets one up. */
35
42
  canList: boolean;
36
43
  /** The project's grants, to show what each entry already holds. */
37
44
  grants: GrantRow[];
45
+ /** Whether a new service account may be named: whoever sets one up. */
46
+ canCreate?: boolean;
38
47
  value: string;
39
- onChange: (principalId: string) => void;
48
+ /** Whether `value` is a new service account, to be made with the grant. */
49
+ admit?: boolean;
50
+ onChange: (principalId: string, admit: boolean) => void;
40
51
  }) {
41
52
  const coffre = useCoffre();
42
53
  const directory = useQuery(queries.directory(coffre, canList)).data ?? null;
43
54
  const [query, setQuery] = useState('');
44
55
  const name = useId();
45
56
  const kind = KIND[principalType];
46
- const label = principalType === 'user' ? 'User' : 'Token';
57
+ const label = principalType === 'user' ? 'User' : 'Service account';
47
58
 
48
59
  if (!canList || directory?.ok === false) {
49
60
  return (
@@ -58,7 +69,7 @@ export function PrincipalPicker({
58
69
  autoComplete="off"
59
70
  placeholder={principalType === 'user' ? 'someone@acme.example' : 'ci-deploy'}
60
71
  value={value}
61
- onChange={(event) => onChange(event.target.value)}
72
+ onChange={(event) => onChange(event.target.value, false)}
62
73
  />
63
74
  <span className="hint">
64
75
  The {kind} must already be registered under {principalType === 'user' ? 'Users' : 'Service accounts'}.
@@ -73,6 +84,10 @@ export function PrincipalPicker({
73
84
  const matches = registered.filter((principal) =>
74
85
  principal.principalId.toLowerCase().includes(needle),
75
86
  );
87
+ // A name no account has: offered as a new one, which follows the filter as it is typed.
88
+ const creatable = (text: string) =>
89
+ canCreate && SERVICE_NAME.test(text.trim()) && !registered.some((principal) => principal.principalId === text.trim());
90
+ const typed = query.trim();
76
91
 
77
92
  return (
78
93
  <fieldset className="field picker">
@@ -87,14 +102,21 @@ export function PrincipalPicker({
87
102
  autoFocus
88
103
  spellCheck={false}
89
104
  autoComplete="off"
90
- placeholder={principalType === 'user' ? 'Filter by email…' : 'Filter by name…'}
105
+ placeholder={principalType === 'user' ? 'Filter by email…' : canCreate ? 'Filter by name, or name a new one…' : 'Filter by name…'}
91
106
  value={query}
92
- onChange={(event) => setQuery(event.target.value)}
107
+ onChange={(event) => {
108
+ setQuery(event.target.value);
109
+ if (admit) onChange(creatable(event.target.value) ? event.target.value.trim() : '', creatable(event.target.value));
110
+ }}
93
111
  onKeyDown={(event) => {
94
- // Narrowed to one, Enter picks it rather than sending the form.
95
- if (event.key === 'Enter' && matches.length === 1) {
112
+ // Narrowed to one, Enter picks it rather than sending the form; to none, the new one.
113
+ if (event.key !== 'Enter') return;
114
+ if (matches.length === 1) {
115
+ event.preventDefault();
116
+ onChange(matches[0].principalId, false);
117
+ } else if (matches.length === 0 && creatable(query)) {
96
118
  event.preventDefault();
97
- onChange(matches[0].principalId);
119
+ onChange(typed, true);
98
120
  }
99
121
  }}
100
122
  />
@@ -106,13 +128,15 @@ export function PrincipalPicker({
106
128
  <Spinner size={13} />
107
129
  Loading {kind}s…
108
130
  </p>
131
+ ) : registered.length === 0 && canCreate ? (
132
+ typed === '' && <p className="picker-empty">No {kind}s yet: type a name to make one.</p>
109
133
  ) : registered.length === 0 ? (
110
134
  <p className="picker-empty">
111
135
  No {kind}s are registered yet.{' '}
112
136
  <Link to={principalType === 'user' ? '/users' : '/service-accounts'}>Add one</Link> first.
113
137
  </p>
114
- ) : matches.length === 0 ? (
115
- <p className="picker-empty">No registered {kind} matches “{query.trim()}”.</p>
138
+ ) : matches.length === 0 && canCreate ? null : matches.length === 0 ? (
139
+ <p className="picker-empty">No registered {kind} matches “{typed}”.</p>
116
140
  ) : (
117
141
  matches.map((principal) => {
118
142
  const held = grants
@@ -122,7 +146,7 @@ export function PrincipalPicker({
122
146
  grant.principalId === principal.principalId,
123
147
  )
124
148
  .map(projectAccessLabel);
125
- const chosen = principal.principalId === value;
149
+ const chosen = !admit && principal.principalId === value;
126
150
  return (
127
151
  <label
128
152
  key={principal.principalId}
@@ -134,7 +158,7 @@ export function PrincipalPicker({
134
158
  name={name}
135
159
  value={principal.principalId}
136
160
  checked={chosen}
137
- onChange={() => onChange(principal.principalId)}
161
+ onChange={() => onChange(principal.principalId, false)}
138
162
  />
139
163
  <PrincipalAvatar type={principalType} id={principal.principalId} />
140
164
  <span className="picker-name">{principal.principalId}</span>
@@ -153,6 +177,32 @@ export function PrincipalPicker({
153
177
  );
154
178
  })
155
179
  )}
180
+ {creatable(query) && (
181
+ <label className={`picker-option${admit ? ' is-chosen' : ''}`}>
182
+ <input
183
+ type="radio"
184
+ className="visually-hidden"
185
+ name={name}
186
+ value={typed}
187
+ checked={admit}
188
+ onChange={() => onChange(typed, true)}
189
+ />
190
+ <span className="avatar avatar-new" aria-hidden>
191
+ <Plus size={13} />
192
+ </span>
193
+ <span className="picker-name">{typed}</span>
194
+ <span className="picker-held">
195
+ <span className="visually-hidden">a new {kind}, made with this access</span>
196
+ <span className="tag" aria-hidden>
197
+ New
198
+ </span>
199
+ </span>
200
+ <Check size={14} className="picker-check" />
201
+ </label>
202
+ )}
203
+ {canCreate && typed !== '' && !SERVICE_NAME.test(typed) && (
204
+ <p className="picker-empty">A {kind}'s name has no spaces, and does not start with a colon.</p>
205
+ )}
156
206
  </div>
157
207
  </fieldset>
158
208
  );
@@ -9,28 +9,30 @@ import { X } from './icons';
9
9
  * A person's instance role, one dropdown, and under it, for every role but
10
10
  * Member, where it applies: projects and environments, each All, Only or
11
11
  * All except. Projects are picked from those there are; environments are
12
- * names, so any slug goes, the ones made later too.
12
+ * names, so any slug goes, the ones made later too. Owner is offered only
13
+ * to an Owner of the whole instance, who alone makes one.
13
14
  */
14
15
  export function RoleField({ value, onChange }: { value: RoleVars; onChange: (value: RoleVars) => void }) {
15
16
  const { role, scope } = value;
17
+ const owners = useShell().capabilities.ownsInstance;
16
18
  return (
17
19
  <>
18
20
  <label className="field">
19
- <span className="label">Instance role</span>
21
+ <span className="label">Role</span>
20
22
  <select
21
23
  className="select"
22
24
  value={role}
23
25
  onChange={(event) => onChange({ role: event.target.value as InstanceRole, scope })}
24
26
  >
25
- {INSTANCE_ROLE_NAMES.map((name) => (
27
+ {INSTANCE_ROLE_NAMES.filter((name) => owners || name !== 'owner').map((name) => (
26
28
  <option key={name} value={name}>
27
29
  {INSTANCE_ROLES[name].name}
28
30
  </option>
29
31
  ))}
30
32
  </select>
31
33
  <span className="hint">
32
- {INSTANCE_ROLES[role].description}
33
- {role === 'member' ? '' : ' Project grants add to it.'}
34
+ Default permissions: {INSTANCE_ROLES[role].description} Project grants add more.
35
+ {!owners && ' Only an Owner makes someone an Owner.'}
34
36
  </span>
35
37
  </label>
36
38
  {role !== 'member' && <ScopeField scope={scope} onChange={(next) => onChange({ role, scope: next })} />}
@@ -17,13 +17,17 @@ export function rowClass(status: ItemStatus): string {
17
17
  return '';
18
18
  }
19
19
 
20
- /** In place of a row's actions while its change is on its way. */
20
+ /**
21
+ * In place of a row's actions while its change is on its way. Where the
22
+ * actions column fits only a button, the words go from sight, not from the
23
+ * page: they stay for a screen reader and the spinner's tooltip.
24
+ */
21
25
  export function RowPending({ status }: { status: ItemStatus }) {
22
26
  if (status.state !== 'pending') return null;
23
27
  return (
24
- <span className="row-pending">
28
+ <span className="row-pending" title={status.words.pending}>
25
29
  <Spinner size={13} />
26
- {status.words.pending}
30
+ <span className="row-pending-words">{status.words.pending}</span>
27
31
  </span>
28
32
  );
29
33
  }
@@ -65,7 +65,6 @@ const CURRENT = { 'aria-current': 'page' } as const;
65
65
 
66
66
  function roleLabel(principal: Principal, instanceRole: InstanceRole): string {
67
67
  if (principal?.type === 'service') return 'Token';
68
- if (instanceRole === 'root-admin') return 'Root admin';
69
68
  return INSTANCE_ROLES[instanceRole ?? 'member'].name;
70
69
  }
71
70