From 72c4b830103f413da93b1268e17ae75f74358143 Mon Sep 17 00:00:00 2001 From: minnakt <47064971+minnakt@users.noreply.github.com> Date: Fri, 10 May 2024 13:26:13 -0400 Subject: [PATCH] DEVPROD-6883: Create input for image on distro settings page (#85) --- apps/spruce/src/gql/generated/types.ts | 1 + apps/spruce/src/gql/queries/distro.graphql | 1 + .../tabs/GeneralTab/getFormSchema.ts | 21 +++++++++++++++++-- .../tabs/GeneralTab/transformers.test.ts | 6 +++++- .../tabs/GeneralTab/transformers.ts | 11 +++++++--- .../distroSettings/tabs/GeneralTab/types.ts | 5 ++++- .../src/pages/distroSettings/tabs/testData.ts | 1 + 7 files changed, 39 insertions(+), 7 deletions(-) diff --git a/apps/spruce/src/gql/generated/types.ts b/apps/spruce/src/gql/generated/types.ts index 45d0396d3..bc925e61f 100644 --- a/apps/spruce/src/gql/generated/types.ts +++ b/apps/spruce/src/gql/generated/types.ts @@ -5774,6 +5774,7 @@ export type DistroQuery = { containerPool: string; disabled: boolean; disableShallowClone: boolean; + imageId?: string | null; isCluster: boolean; isVirtualWorkStation: boolean; mountpoints?: Array | null; diff --git a/apps/spruce/src/gql/queries/distro.graphql b/apps/spruce/src/gql/queries/distro.graphql index ea46c09eb..8236869d5 100644 --- a/apps/spruce/src/gql/queries/distro.graphql +++ b/apps/spruce/src/gql/queries/distro.graphql @@ -59,6 +59,7 @@ query Distro($distroId: String!) { configPath schedulerHost } + imageId isCluster isVirtualWorkStation mountpoints diff --git a/apps/spruce/src/pages/distroSettings/tabs/GeneralTab/getFormSchema.ts b/apps/spruce/src/pages/distroSettings/tabs/GeneralTab/getFormSchema.ts index f658e7f1d..126fd1859 100644 --- a/apps/spruce/src/pages/distroSettings/tabs/GeneralTab/getFormSchema.ts +++ b/apps/spruce/src/pages/distroSettings/tabs/GeneralTab/getFormSchema.ts @@ -13,13 +13,24 @@ export const getFormSchema = ( type: "object" as "object", title: "", properties: { - identifier: { + name: { type: "string" as "string", title: "Identifier", readOnly: true, }, }, }, + distroImage: { + type: "object" as "object", + title: "", + properties: { + image: { + type: "string" as "string", + title: "Image", + default: "", + }, + }, + }, distroAliases: { type: "object" as "object", title: "Aliases", @@ -76,7 +87,7 @@ export const getFormSchema = ( uiSchema: { distroName: { "ui:ObjectFieldTemplate": CardFieldTemplate, - identifier: { + name: { ...(isContainerDistro && { "ui:warnings": [ "Distro is a container pool, so it cannot be spawned for tasks.", @@ -84,6 +95,12 @@ export const getFormSchema = ( }), }, }, + distroImage: { + "ui:ObjectFieldTemplate": CardFieldTemplate, + image: { + "ui:description": "The image from which this distro inherits.", + }, + }, distroAliases: { "ui:rootFieldId": "aliases", "ui:ObjectFieldTemplate": CardFieldTemplate, diff --git a/apps/spruce/src/pages/distroSettings/tabs/GeneralTab/transformers.test.ts b/apps/spruce/src/pages/distroSettings/tabs/GeneralTab/transformers.test.ts index bc80f5034..48da16727 100644 --- a/apps/spruce/src/pages/distroSettings/tabs/GeneralTab/transformers.test.ts +++ b/apps/spruce/src/pages/distroSettings/tabs/GeneralTab/transformers.test.ts @@ -15,7 +15,10 @@ describe("general tab", () => { const generalForm: GeneralFormState = { distroName: { - identifier: "rhel71-power8-large", + name: "rhel71-power8-large", + }, + distroImage: { + image: "rhel71-power8", }, distroAliases: { aliases: ["rhel71-power8", "rhel71-power8-build"], @@ -33,6 +36,7 @@ const generalForm: GeneralFormState = { const generalGql: DistroInput = { ...distroData, name: "rhel71-power8-large", + imageId: "rhel71-power8", adminOnly: false, aliases: ["rhel71-power8", "rhel71-power8-build"], isCluster: false, diff --git a/apps/spruce/src/pages/distroSettings/tabs/GeneralTab/transformers.ts b/apps/spruce/src/pages/distroSettings/tabs/GeneralTab/transformers.ts index 0a97b0453..33f4ab717 100644 --- a/apps/spruce/src/pages/distroSettings/tabs/GeneralTab/transformers.ts +++ b/apps/spruce/src/pages/distroSettings/tabs/GeneralTab/transformers.ts @@ -11,6 +11,7 @@ export const gqlToForm = ((data) => { aliases, disableShallowClone, disabled, + imageId, isCluster, name, note, @@ -19,7 +20,10 @@ export const gqlToForm = ((data) => { return { distroName: { - identifier: name, + name, + }, + distroImage: { + image: imageId, }, distroAliases: { aliases, @@ -36,11 +40,12 @@ export const gqlToForm = ((data) => { }) satisfies GqlToFormFunction; export const formToGql = (( - { distroAliases, distroName, distroOptions }, + { distroAliases, distroImage, distroName, distroOptions }, distro, ) => ({ ...distro, - name: distroName.identifier, + name: distroName.name, + imageId: distroImage.image, adminOnly: distroOptions.adminOnly, aliases: distroAliases.aliases, note: distroOptions.note, diff --git a/apps/spruce/src/pages/distroSettings/tabs/GeneralTab/types.ts b/apps/spruce/src/pages/distroSettings/tabs/GeneralTab/types.ts index 3c75d67bb..50f126e71 100644 --- a/apps/spruce/src/pages/distroSettings/tabs/GeneralTab/types.ts +++ b/apps/spruce/src/pages/distroSettings/tabs/GeneralTab/types.ts @@ -1,6 +1,9 @@ export interface GeneralFormState { distroName: { - identifier: string; + name: string; + }; + distroImage: { + image: string; }; distroAliases: { aliases: string[]; diff --git a/apps/spruce/src/pages/distroSettings/tabs/testData.ts b/apps/spruce/src/pages/distroSettings/tabs/testData.ts index ae7bd52a6..fed701927 100644 --- a/apps/spruce/src/pages/distroSettings/tabs/testData.ts +++ b/apps/spruce/src/pages/distroSettings/tabs/testData.ts @@ -19,6 +19,7 @@ const distroData: DistroQuery["distro"] = { aliases: ["rhel71-power8", "rhel71-power8-build"], arch: Arch.Linux_64Bit, authorizedKeysFile: "", + imageId: "rhel71-power8", bootstrapSettings: { clientDir: "/home/evg/client", communication: CommunicationMethod.LegacySsh,