-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into silo-quotas
- Loading branch information
Showing
35 changed files
with
1,321 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
9b595e985721f8ab83d13c4dc4f257cbf8ac525c | ||
eeb723c6a0d727f016ca947541ac85c029801c06 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, you can obtain one at https://mozilla.org/MPL/2.0/. | ||
* | ||
* Copyright Oxide Computer Company | ||
*/ | ||
import { useNavigate } from 'react-router-dom' | ||
|
||
import { useApiMutation, useApiQueryClient, type VpcRouterCreate } from '@oxide/api' | ||
|
||
import { DescriptionField } from '~/components/form/fields/DescriptionField' | ||
import { NameField } from '~/components/form/fields/NameField' | ||
import { SideModalForm } from '~/components/form/SideModalForm' | ||
import { useForm, useVpcSelector } from '~/hooks' | ||
import { addToast } from '~/stores/toast' | ||
import { pb } from '~/util/path-builder' | ||
|
||
const defaultValues: VpcRouterCreate = { | ||
name: '', | ||
description: '', | ||
} | ||
|
||
export function CreateRouterSideModalForm() { | ||
const queryClient = useApiQueryClient() | ||
const vpcSelector = useVpcSelector() | ||
const navigate = useNavigate() | ||
|
||
const onDismiss = () => navigate(pb.vpcRouters(vpcSelector)) | ||
|
||
const createRouter = useApiMutation('vpcRouterCreate', { | ||
onSuccess() { | ||
queryClient.invalidateQueries('vpcRouterList') | ||
addToast({ content: 'Your router has been created' }) | ||
onDismiss() | ||
}, | ||
}) | ||
|
||
const form = useForm({ defaultValues }) | ||
|
||
return ( | ||
<SideModalForm | ||
form={form} | ||
formType="create" | ||
resourceName="router" | ||
onDismiss={onDismiss} | ||
onSubmit={(body) => createRouter.mutate({ query: vpcSelector, body })} | ||
loading={createRouter.isPending} | ||
submitError={createRouter.error} | ||
> | ||
<NameField name="name" control={form.control} /> | ||
<DescriptionField name="description" control={form.control} /> | ||
</SideModalForm> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, you can obtain one at https://mozilla.org/MPL/2.0/. | ||
* | ||
* Copyright Oxide Computer Company | ||
*/ | ||
import { | ||
useNavigate, | ||
type LoaderFunctionArgs, | ||
type NavigateFunction, | ||
} from 'react-router-dom' | ||
|
||
import { | ||
apiQueryClient, | ||
useApiMutation, | ||
useApiQueryClient, | ||
usePrefetchedApiQuery, | ||
type VpcRouterUpdate, | ||
} from '@oxide/api' | ||
|
||
import { DescriptionField } from '~/components/form/fields/DescriptionField' | ||
import { NameField } from '~/components/form/fields/NameField' | ||
import { SideModalForm } from '~/components/form/SideModalForm' | ||
import { getVpcRouterSelector, useForm, useVpcRouterSelector } from '~/hooks' | ||
import { addToast } from '~/stores/toast' | ||
import { pb } from '~/util/path-builder' | ||
|
||
EditRouterSideModalForm.loader = async ({ params }: LoaderFunctionArgs) => { | ||
const { router, project, vpc } = getVpcRouterSelector(params) | ||
await apiQueryClient.prefetchQuery('vpcRouterView', { | ||
path: { router }, | ||
query: { project, vpc }, | ||
}) | ||
return null | ||
} | ||
|
||
export function EditRouterSideModalForm() { | ||
const queryClient = useApiQueryClient() | ||
const routerSelector = useVpcRouterSelector() | ||
const { project, vpc, router } = routerSelector | ||
const { data: routerData } = usePrefetchedApiQuery('vpcRouterView', { | ||
path: { router }, | ||
query: { project, vpc }, | ||
}) | ||
const navigate = useNavigate() | ||
|
||
const onDismiss = (navigate: NavigateFunction) => { | ||
navigate(pb.vpcRouters({ project, vpc })) | ||
} | ||
|
||
const editRouter = useApiMutation('vpcRouterUpdate', { | ||
onSuccess() { | ||
queryClient.invalidateQueries('vpcRouterList') | ||
addToast({ content: 'Your router has been updated' }) | ||
navigate(pb.vpcRouters({ project, vpc })) | ||
}, | ||
}) | ||
|
||
const defaultValues: VpcRouterUpdate = { | ||
name: router, | ||
description: routerData.description, | ||
} | ||
|
||
const form = useForm({ defaultValues }) | ||
|
||
return ( | ||
<SideModalForm | ||
form={form} | ||
formType="edit" | ||
resourceName="router" | ||
onDismiss={() => onDismiss(navigate)} | ||
onSubmit={(body) => | ||
editRouter.mutate({ | ||
path: { router }, | ||
query: { project, vpc }, | ||
body, | ||
}) | ||
} | ||
loading={editRouter.isPending} | ||
submitError={editRouter.error} | ||
> | ||
<NameField name="name" control={form.control} /> | ||
<DescriptionField name="description" control={form.control} /> | ||
</SideModalForm> | ||
) | ||
} |
Oops, something went wrong.