-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
171 additions
and
29 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 |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* 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 { useForm } from 'react-hook-form' | ||
import { useNavigate, type LoaderFunctionArgs } from 'react-router-dom' | ||
|
||
import { apiQueryClient, usePrefetchedApiQuery } from '@oxide/api' | ||
import { Key16Icon } from '@oxide/design-system/icons/react' | ||
|
||
import { DescriptionField } from '~/components/form/fields/DescriptionField' | ||
import { NameField } from '~/components/form/fields/NameField' | ||
import { TextField } from '~/components/form/fields/TextField' | ||
import { SideModalForm } from '~/components/form/SideModalForm' | ||
import { getSshKeySelector, useSshKeySelector } from '~/hooks/use-params' | ||
import { CopyToClipboard } from '~/ui/lib/CopyToClipboard' | ||
import { DateTime } from '~/ui/lib/DateTime' | ||
import { PropertiesTable } from '~/ui/lib/PropertiesTable' | ||
import { ResourceLabel } from '~/ui/lib/SideModal' | ||
import { Truncate } from '~/ui/lib/Truncate' | ||
import { pb } from '~/util/path-builder' | ||
|
||
EditSSHKeySideModalForm.loader = async ({ params }: LoaderFunctionArgs) => { | ||
const { sshKey } = getSshKeySelector(params) | ||
await apiQueryClient.prefetchQuery('currentUserSshKeyView', { path: { sshKey } }) | ||
return null | ||
} | ||
|
||
export function EditSSHKeySideModalForm() { | ||
const navigate = useNavigate() | ||
const { sshKey } = useSshKeySelector() | ||
|
||
const { data } = usePrefetchedApiQuery('currentUserSshKeyView', { | ||
path: { sshKey }, | ||
}) | ||
|
||
const form = useForm({ defaultValues: data }) | ||
|
||
return ( | ||
<SideModalForm | ||
form={form} | ||
formType="edit" | ||
resourceName="SSH key" | ||
title="View SSH key" | ||
onDismiss={() => navigate(pb.sshKeys())} | ||
subtitle={ | ||
<ResourceLabel> | ||
<Key16Icon /> {data.name} | ||
</ResourceLabel> | ||
} | ||
// TODO: pass actual error when this form is hooked up | ||
loading={false} | ||
submitError={null} | ||
> | ||
<PropertiesTable> | ||
<PropertiesTable.Row label="ID"> | ||
<Truncate text={data.id} maxLength={32} hasCopyButton /> | ||
</PropertiesTable.Row> | ||
<PropertiesTable.Row label="Created"> | ||
<DateTime date={data.timeCreated} /> | ||
</PropertiesTable.Row> | ||
<PropertiesTable.Row label="Updated"> | ||
<DateTime date={data.timeModified} /> | ||
</PropertiesTable.Row> | ||
</PropertiesTable> | ||
<NameField name="name" control={form.control} disabled /> | ||
<DescriptionField name="description" control={form.control} disabled /> | ||
<div className="relative"> | ||
<CopyToClipboard className="!absolute right-0 top-0" text={data.publicKey} /> | ||
<TextField | ||
as="textarea" | ||
name="publicKey" | ||
label="Public key" | ||
required | ||
rows={8} | ||
control={form.control} | ||
disabled | ||
/> | ||
</div> | ||
</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
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
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 |
---|---|---|
|
@@ -17,7 +17,8 @@ export const sshKeys: Json<SshKey>[] = [ | |
description: 'For use on personal projects', | ||
time_created: new Date().toISOString(), | ||
time_modified: new Date().toISOString(), | ||
public_key: 'aslsddlfkjsdlfkjsdlfkjsdlfkjsdflkjsdlfkjsdlfkjsd', | ||
public_key: | ||
'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDU3w4FaSj/tEZYaoBtzijAFZanW9MakaPhSERtdC75opT6F/bs4ZXE8sjWgqDM1azoZbUKa42b4RWPPtCgqGQkbyYDZTzdssrml3/T1Avcy5GKlfTjACRHSI6PhC6r6bM1jxPUUstH7fBbw+DTHywUpdkvz7SHxTEOyZuP2sn38V9vBakYVsLFOu7C1W0+Jm4TYCRJlcsuC5LHVMVc4WbWzBcAZZlAznWx0XajMxmkyCB5tsyhTpykabfHbih4F3bwHYKXO613JZ6DurGcPz6CPkAVS5BWG6GrdBCkd+YK8Lw8k1oAAZLYIKQZbMnPJSNxirJ8+vr+iyIwP1DjBMnJ [email protected]', | ||
silo_user_id: user1.id, | ||
}, | ||
{ | ||
|
@@ -26,7 +27,8 @@ export const sshKeys: Json<SshKey>[] = [ | |
description: '', | ||
time_created: new Date().toISOString(), | ||
time_modified: new Date().toISOString(), | ||
public_key: 'aslsddlfkjsdlfkjsdlfkjsdlfkjsdflkjsdlfkjsdlfkjsd', | ||
public_key: | ||
'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDVav/u9wm2ALv4ks18twWQB0LHlJ1Q1y7HTi91SUuv4H95EEwqj6tVDSOtHQi08PG7xp6/8gaMVC9rs1jKl7o0cy32kuWp/rXtryn3d1bEaY9wOGwR6iokx0zjocHILhrjHpAmWnXP8oWvzx8TWOg3VPhBkZsyNdqzcdxYP2UsqccaNyz5kcuNhOYbGjIskNPAk1drsHnyKvqoEVix8UzVkLHC6vVbcVjQGTaeUif29xvUN3W5QMGb/E1L66RPN3ovaDyDylgA8az8q56vrn4jSY5Mx3ANQEvjxl//Hnq31dpoDFiEvHyB4bbq8bSpypa2TyvheobmLnsnIaXEMHFT [email protected]', | ||
silo_user_id: user1.id, | ||
}, | ||
] |
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