Skip to content

Commit

Permalink
Working on getting it to work with an updated API; these API changes …
Browse files Browse the repository at this point in the history
…will have to be reverted.
  • Loading branch information
charliepark committed Aug 21, 2024
1 parent 827342e commit d515ba3
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 6 deletions.
9 changes: 6 additions & 3 deletions app/api/__generated__/Api.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions app/components/form/fields/ListboxField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ export type ListboxFieldProps<
onChange?: (value: string | null | undefined) => void
isLoading?: boolean
noItemsPlaceholder?: string
isClearable?: boolean
onClear?: () => void
}

export function ListboxField<
Expand All @@ -54,6 +56,8 @@ export function ListboxField<
onChange,
isLoading,
noItemsPlaceholder,
isClearable,
onClear,
}: ListboxFieldProps<TFieldValues, TName>) {
// TODO: recreate this logic
// validate: (v) => (required && !v ? `${name} is required` : undefined),
Expand Down Expand Up @@ -82,6 +86,11 @@ export function ListboxField<
buttonRef={field.ref}
/>
<ErrorMessage error={fieldState.error} label={label} />
{isClearable && (
<button type="button" onClick={onClear}>
clear
</button>
)}
</div>
)
}
2 changes: 1 addition & 1 deletion app/forms/subnet-create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { pb } from '~/util/path-builder'

const defaultValues: VpcSubnetCreate = {
name: '',
customRouter: '',
customRouter: undefined,
description: '',
ipv4Block: '',
}
Expand Down
16 changes: 15 additions & 1 deletion app/forms/subnet-edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ export function EditSubnetForm() {

const form = useForm({ defaultValues })
const { isLoading, items } = useCustomRouterItems()
const customRouterValue = form.watch('customRouter')
const clearCustomRouter = () => {
// Because this is `undefined`, the dropdown isn't behaving correctly; it should revert to the placeholder
// It works when the value is '', but that's not a valid value for this field and it trips zod's validator
form.setValue('customRouter', undefined)
}

return (
<SideModalForm
Expand All @@ -71,7 +77,13 @@ export function EditSubnetForm() {
updateSubnet.mutate({
path: { subnet: subnet.name },
query: { project, vpc },
body,
body: {
name: body.name,
description: body.description,
// this is currently failing because the API does not accept null for customRouter, but it should
// once that is fixed, this should allow clearing the customRouter
customRouter: body.customRouter,
},
})
}}
loading={updateSubnet.isPending}
Expand All @@ -87,6 +99,8 @@ export function EditSubnetForm() {
isLoading={isLoading}
items={items}
control={form.control}
isClearable={!!customRouterValue}
onClear={clearCustomRouter}
/>
</SideModalForm>
)
Expand Down
4 changes: 3 additions & 1 deletion mock-api/msw/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1180,8 +1180,10 @@ export const handlers = makeHandlers({
if (body.name) {
subnet.name = body.name
}
if (body.custom_router) {
if (body.custom_router !== undefined) {
subnet.custom_router_id = body.custom_router
} else {
subnet.custom_router_id = null
}
updateDesc(subnet, body)

Expand Down

0 comments on commit d515ba3

Please sign in to comment.