Skip to content

Commit f278a74

Browse files
Conditionally render silo creation fields, depending on identity mode (#2332)
* Tie rendering logic for admin group name to identity mode * Put more of form behind conditional render; update test * Copy adjustment * add test assertions to match writeup in PR description * Move checkboxes back out of hidey-block * Remove unneeded classNames * Break up sections * small spacing below 'Role mapping' label * tweak spacing slightly --------- Co-authored-by: David Crespo <david.crespo@oxidecomputer.com>
1 parent 016ad1b commit f278a74

File tree

2 files changed

+41
-17
lines changed

2 files changed

+41
-17
lines changed

app/forms/silo-create.tsx

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*
66
* Copyright Oxide Computer Company
77
*/
8+
import { useEffect } from 'react'
89
import { useNavigate } from 'react-router-dom'
910

1011
import { useApiMutation, useApiQueryClient, type SiloCreate } from '@oxide/api'
@@ -20,6 +21,7 @@ import { SideModalForm } from '~/components/form/SideModalForm'
2021
import { useForm } from '~/hooks'
2122
import { addToast } from '~/stores/toast'
2223
import { FormDivider } from '~/ui/lib/Divider'
24+
import { FieldLabel } from '~/ui/lib/FieldLabel'
2325
import { Message } from '~/ui/lib/Message'
2426
import { pb } from '~/util/path-builder'
2527
import { GiB } from '~/util/units'
@@ -65,7 +67,13 @@ export function CreateSiloSideModalForm() {
6567
})
6668

6769
const form = useForm({ defaultValues })
68-
70+
const identityMode = form.watch('identityMode')
71+
// Clear the adminGroupName if the user selects the "local only" identity mode
72+
useEffect(() => {
73+
if (identityMode === 'local_only') {
74+
form.setValue('adminGroupName', '')
75+
}
76+
}, [identityMode, form])
6977
return (
7078
<SideModalForm
7179
form={form}
@@ -145,21 +153,27 @@ export function CreateSiloSideModalForm() {
145153
{ value: 'local_only', label: 'Local only' },
146154
]}
147155
/>
148-
<TextField
149-
name="adminGroupName"
150-
label="Admin group name"
151-
description="This group will be created and granted the Silo Admin role"
152-
control={form.control}
153-
/>
156+
{identityMode === 'saml_jit' && (
157+
<TextField
158+
name="adminGroupName"
159+
label="Admin group name"
160+
description="This group will be created and granted the Silo Admin role."
161+
control={form.control}
162+
/>
163+
)}
164+
<FormDivider />
154165
<div>
155-
<CheckboxField name="siloAdminGetsFleetAdmin" control={form.control}>
156-
Grant fleet admin role to silo admins
157-
</CheckboxField>
158-
</div>
159-
<div className="!mt-2">
160-
<CheckboxField name="siloViewerGetsFleetViewer" control={form.control}>
161-
Grant fleet viewer role to silo viewers
162-
</CheckboxField>
166+
<FieldLabel as="h3" id="role-mapping-label" className="mb-3">
167+
Role mapping
168+
</FieldLabel>
169+
<div className="space-y-1">
170+
<CheckboxField name="siloAdminGetsFleetAdmin" control={form.control}>
171+
Grant fleet admin role to silo admins
172+
</CheckboxField>
173+
<CheckboxField name="siloViewerGetsFleetViewer" control={form.control}>
174+
Grant fleet viewer role to silo viewers
175+
</CheckboxField>
176+
</div>
163177
</div>
164178
<FormDivider />
165179
<TlsCertsField control={form.control} />

test/e2e/silos.e2e.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,19 @@ test('Create silo', async ({ page }) => {
3838
const discoverable = page.getByRole('checkbox', { name: 'Discoverable' })
3939
await expect(discoverable).toBeChecked()
4040
await discoverable.click()
41-
await page.getByRole('radio', { name: 'Local only' }).click()
41+
await expect(page.getByRole('textbox', { name: 'Admin group name' })).toBeVisible()
4242
await page.getByRole('textbox', { name: 'Admin group name' }).fill('admins')
4343
await page.getByRole('checkbox', { name: 'Grant fleet admin' }).click()
44+
await expect(page.getByRole('textbox', { name: 'Admin group name' })).toHaveValue(
45+
'admins'
46+
)
47+
await expect(page.getByRole('checkbox', { name: 'Grant fleet admin' })).toBeChecked()
48+
await page.getByRole('radio', { name: 'Local only' }).click()
49+
await expect(page.getByRole('textbox', { name: 'Admin group name' })).toBeHidden()
50+
await page.getByRole('radio', { name: 'SAML' }).click()
51+
await expect(page.getByRole('textbox', { name: 'Admin group name' })).toHaveValue('')
52+
await expect(page.getByRole('checkbox', { name: 'Grant fleet admin' })).toBeChecked()
53+
await page.getByRole('textbox', { name: 'Admin group name' }).fill('admins')
4454
await page.getByRole('textbox', { name: 'CPU quota' }).fill('30')
4555
await page.getByRole('textbox', { name: 'Memory quota' }).fill('58')
4656
await page.getByRole('textbox', { name: 'Storage quota' }).fill('735')
@@ -99,7 +109,7 @@ test('Create silo', async ({ page }) => {
99109
await expectRowVisible(table, {
100110
name: 'other-silo',
101111
description: 'definitely a silo',
102-
'Identity mode': 'local only',
112+
'Identity mode': 'saml jit',
103113
// discoverable: 'false',
104114
})
105115
const otherSiloCell = page.getByRole('cell', { name: 'other-silo' })

0 commit comments

Comments
 (0)