diff --git a/apps/spruce/src/components/Spawn/editHostModal/utils.ts b/apps/spruce/src/components/Spawn/editHostModal/utils.ts index eb371a855..c09a5c85a 100644 --- a/apps/spruce/src/components/Spawn/editHostModal/utils.ts +++ b/apps/spruce/src/components/Spawn/editHostModal/utils.ts @@ -26,6 +26,10 @@ export const computeDiff = ( ); } + if (mutationParams.publicKey) { + mutationParams.publicKey = currEditState.publicKey; + } + // Always overwrite the whole sleep schedule, no need to update on a per-field basis. if (mutationParams.sleepSchedule) { mutationParams.sleepSchedule = currEditState.sleepSchedule; diff --git a/apps/spruce/src/components/Spawn/utils/hostUptime.ts b/apps/spruce/src/components/Spawn/utils/hostUptime.ts index b8e2323bd..8c842f6d1 100644 --- a/apps/spruce/src/components/Spawn/utils/hostUptime.ts +++ b/apps/spruce/src/components/Spawn/utils/hostUptime.ts @@ -90,7 +90,7 @@ export const getHostUptimeWarnings = ({ * @returns - object with enabledHoursCount indicating total hours per week and enabledWeekdaysCount indicating number of days per week */ export const getEnabledHoursCount = ( - hostUptime: HostUptime, + hostUptime?: HostUptime, ): { enabledHoursCount: number; enabledWeekdaysCount: number } => { if (!hostUptime) { return { diff --git a/apps/spruce/src/pages/spawn/spawnHost/EditSpawnHostModal.tsx b/apps/spruce/src/pages/spawn/spawnHost/EditSpawnHostModal.tsx index e2cb8130e..897f036e7 100644 --- a/apps/spruce/src/pages/spawn/spawnHost/EditSpawnHostModal.tsx +++ b/apps/spruce/src/pages/spawn/spawnHost/EditSpawnHostModal.tsx @@ -46,16 +46,16 @@ export const EditSpawnHostModal: React.FC = ({ const { disableExpirationCheckbox, instanceTypesData, - noExpirationCheckboxTooltip, + noExpirationCheckboxTooltip = "", publicKeysData, volumesData, } = useLoadFormData(host); let instanceTypes = instanceTypesData?.instanceTypes ?? []; - // The list of instance types provided by Evergreen can be out-of-date, so make sure the instance type in use is considered valid by RJSF - // @ts-expect-error: FIXME. This comment was added by an automated script. - if (!instanceTypes.includes(host.instanceType)) { - // @ts-expect-error: FIXME. This comment was added by an automated script. + + // The list of instance types provided by Evergreen can be out-of-date, + // so make sure the instance type in use is considered valid by RJSF. + if (host.instanceType && !instanceTypes.includes(host.instanceType)) { instanceTypes = [...instanceTypes, host.instanceType]; } @@ -76,7 +76,7 @@ export const EditSpawnHostModal: React.FC = ({ rdpPassword: "", userTags, expirationDetails: { - expiration: host.expiration ? host.expiration.toString() : null, + expiration: host.expiration ? host.expiration.toString() : undefined, noExpiration: host.noExpiration, hostUptime: host?.sleepSchedule && !isNullSleepSchedule(host?.sleepSchedule) @@ -86,38 +86,32 @@ export const EditSpawnHostModal: React.FC = ({ publicKeySection: { useExisting: true, publicKeyNameDropdown: "" }, }; - // @ts-expect-error: FIXME. This comment was added by an automated script. const [formState, setFormState] = useState(initialFormState); const [hasError, setHasError] = useState(false); const hostUptimeWarnings = useMemo(() => { const { enabledHoursCount, enabledWeekdaysCount } = getEnabledHoursCount( - // @ts-expect-error: FIXME. This comment was added by an automated script. formState?.expirationDetails?.hostUptime, ); const warnings = getHostUptimeWarnings({ enabledHoursCount, enabledWeekdaysCount, - // @ts-expect-error: FIXME. This comment was added by an automated script. runContinuously: formState?.expirationDetails?.hostUptime?.sleepSchedule?.timeSelection - ?.runContinuously, + ?.runContinuously ?? false, }); return { enabledHoursCount, warnings }; }, [formState?.expirationDetails?.hostUptime]); const { schema, uiSchema } = getFormSchema({ canEditInstanceType: host.status === HostStatus.Stopped, - // @ts-expect-error: FIXME. This comment was added by an automated script. canEditRdpPassword: - // @ts-expect-error: FIXME. This comment was added by an automated script. - host.distro.isWindows && host.status === HostStatus.Running, + (host?.distro?.isWindows && host.status === HostStatus.Running) ?? false, canEditSshKeys: host.status === HostStatus.Running, disableExpirationCheckbox, hostUptimeWarnings, instanceTypes: instanceTypes ?? [], myPublicKeys: publicKeys ?? [], - // @ts-expect-error: FIXME. This comment was added by an automated script. noExpirationCheckboxTooltip, permanentlyExempt: !!host.sleepSchedule?.permanentlyExempt, timeZone: @@ -125,17 +119,16 @@ export const EditSpawnHostModal: React.FC = ({ volumes, }); - // EDIT HOST MUTATION const [editSpawnHostMutation, { loading: loadingSpawnHost }] = useMutation< EditSpawnHostMutation, EditSpawnHostMutationVariables >(EDIT_SPAWN_HOST, { - onCompleted(mutationResult) { + onCompleted: (mutationResult) => { const { id } = mutationResult?.editSpawnHost ?? {}; dispatchToast.success(`Successfully modified spawned host ${id}`); onCancel(); }, - onError(err) { + onError: (err) => { dispatchToast.error( `There was an error while modifying your host: ${err.message}`, ); @@ -145,12 +138,10 @@ export const EditSpawnHostModal: React.FC = ({ }); const initialEditState = formToGql({ - // @ts-expect-error: FIXME. This comment was added by an automated script. formData: initialFormState, hostId: host.id, myPublicKeys: publicKeys, oldUserTags: userTags, - timeZone, }); const currEditState = formToGql({ @@ -171,25 +162,27 @@ export const EditSpawnHostModal: React.FC = ({ }); editSpawnHostMutation({ variables: { - // @ts-expect-error: FIXME. This comment was added by an automated script. - hostId: host.id, ...mutationParams, + hostId: host.id, }, }); }; return ( { - onCancel(); - // @ts-expect-error: FIXME. This comment was added by an automated script. - setFormState(initialFormState); + cancelButtonProps={{ + onClick: () => { + onCancel(); + setFormState(initialFormState); + }, + }} + confirmButtonProps={{ + onClick: onSubmit, + children: loadingSpawnHost ? "Saving" : "Save", + disabled: !hasChanges || hasError || loadingSpawnHost, }} - onConfirm={onSubmit} + data-cy="edit-spawn-host-modal" open={visible} - submitDisabled={!hasChanges || hasError || loadingSpawnHost} title="Edit Host Details" > = ({ SpawnHostMutation, SpawnHostMutationVariables >(SPAWN_HOST, { - onCompleted(hostMutation) { + onCompleted: (hostMutation) => { const { id } = hostMutation?.spawnHost ?? {}; dispatchToast.success(`Successfully spawned host ${id}`); setOpen(false); }, - onError(err) { + onError: (err) => { dispatchToast.error( `There was an error while spawning your host: ${err.message}`, ); @@ -86,8 +86,7 @@ export const SpawnHostModal: React.FC = ({ ); useVirtualWorkstationDefaultExpiration({ - // @ts-expect-error: FIXME. This comment was added by an automated script. - isVirtualWorkstation: selectedDistro?.isVirtualWorkStation, + isVirtualWorkstation: selectedDistro?.isVirtualWorkStation ?? false, setFormState, formState, disableExpirationCheckbox: formSchemaInput.disableExpirationCheckbox, @@ -95,16 +94,14 @@ export const SpawnHostModal: React.FC = ({ const hostUptimeWarnings = useMemo(() => { const { enabledHoursCount, enabledWeekdaysCount } = getEnabledHoursCount( - // @ts-expect-error: FIXME. This comment was added by an automated script. formState?.expirationDetails?.hostUptime, ); const warnings = getHostUptimeWarnings({ enabledHoursCount, enabledWeekdaysCount, - // @ts-expect-error: FIXME. This comment was added by an automated script. runContinuously: formState?.expirationDetails?.hostUptime?.sleepSchedule?.timeSelection - ?.runContinuously, + ?.runContinuously ?? false, }); return { enabledHoursCount, warnings }; }, [formState?.expirationDetails?.hostUptime]); @@ -129,13 +126,10 @@ export const SpawnHostModal: React.FC = ({ const spawnHost = () => { const mutationInput = formToGql({ - // @ts-expect-error: FIXME. This comment was added by an automated script. - isVirtualWorkStation: selectedDistro?.isVirtualWorkStation, + isVirtualWorkStation: selectedDistro?.isVirtualWorkStation ?? false, formData: formState, - // @ts-expect-error: FIXME. This comment was added by an automated script. - myPublicKeys: formSchemaInput.myPublicKeys, + myPublicKeys: formSchemaInput.myPublicKeys ?? [], spawnTaskData: spawnTaskData?.task, - timeZone, }); spawnAnalytics.sendEvent({ name: "Created a spawn host", @@ -151,14 +145,16 @@ export const SpawnHostModal: React.FC = ({ return ( { - setOpen(false); + cancelButtonProps={{ + onClick: () => setOpen(false), + }} + confirmButtonProps={{ + children: loadingSpawnHost ? "Spawning" : "Spawn a host", + onClick: spawnHost, + disabled: hasError || loadingSpawnHost, }} - onConfirm={spawnHost} + data-cy="spawn-host-modal" open={open} - submitDisabled={hasError || loadingSpawnHost} title="Spawn New Host" >