From 5cad08db7a1d676c58476cb665aa351f88c28fce Mon Sep 17 00:00:00 2001 From: Feroze Mohideen Date: Thu, 28 Sep 2023 18:25:36 -0400 Subject: [PATCH] support delete predeploy (#3683) Co-authored-by: David Townley --- api/server/handlers/porter_app/validate.go | 2 ++ dashboard/src/lib/hooks/useAppValidation.ts | 1 + dashboard/src/lib/porter-apps/index.ts | 21 ++++++++++++------- .../app-view/AppDataContainer.tsx | 14 +++++++------ .../app-dashboard/app-view/tabs/Overview.tsx | 2 +- .../app-dashboard/create-app/CreateApp.tsx | 1 + .../services-settings/ServiceList.tsx | 2 +- dashboard/src/shared/api.tsx | 1 + go.work.sum | 2 ++ 9 files changed, 30 insertions(+), 16 deletions(-) diff --git a/api/server/handlers/porter_app/validate.go b/api/server/handlers/porter_app/validate.go index bcfac2b1dd..4ccb67bca4 100644 --- a/api/server/handlers/porter_app/validate.go +++ b/api/server/handlers/porter_app/validate.go @@ -39,6 +39,7 @@ func NewValidatePorterAppHandler( // Deletions are the names of services and env variables to delete type Deletions struct { ServiceNames []string `json:"service_names"` + Predeploy []string `json:"predeploy"` EnvVariableNames []string `json:"env_variable_names"` EnvGroupNames []string `json:"env_group_names"` } @@ -150,6 +151,7 @@ func (c *ValidatePorterAppHandler) ServeHTTP(w http.ResponseWriter, r *http.Requ AppOverrides: overrides, Deletions: &porterv1.Deletions{ ServiceNames: request.Deletions.ServiceNames, + PredeployNames: request.Deletions.Predeploy, EnvVariableNames: request.Deletions.EnvVariableNames, EnvGroupNames: request.Deletions.EnvGroupNames, }, diff --git a/dashboard/src/lib/hooks/useAppValidation.ts b/dashboard/src/lib/hooks/useAppValidation.ts index 3ad2b8ab0c..e049061423 100644 --- a/dashboard/src/lib/hooks/useAppValidation.ts +++ b/dashboard/src/lib/hooks/useAppValidation.ts @@ -119,6 +119,7 @@ export const useAppValidation = ({ commit_sha, deletions: { service_names: data.deletions.serviceNames.map((s) => s.name), + predeploy: data.deletions.predeploy.map((s) => s.name), env_group_names: data.deletions.envGroupNames.map((eg) => eg.name), env_variable_names: [], }, diff --git a/dashboard/src/lib/porter-apps/index.ts b/dashboard/src/lib/porter-apps/index.ts index d0caa3b27f..bc273086f0 100644 --- a/dashboard/src/lib/porter-apps/index.ts +++ b/dashboard/src/lib/porter-apps/index.ts @@ -43,6 +43,11 @@ export const deletionValidator = z.object({ name: z.string(), }) .array(), + predeploy: z + .object({ + name: z.string(), + }) + .array(), envGroupNames: z .object({ name: z.string(), @@ -358,15 +363,15 @@ export function clientAppFromProto({ const predeployOverrides = serializeService(overrides.predeploy); const predeploy = proto.predeploy ? [ - deserializeService({ - service: serializedServiceFromProto({ - name: "pre-deploy", - service: proto.predeploy, - isPredeploy: true, - }), - override: predeployOverrides, + deserializeService({ + service: serializedServiceFromProto({ + name: "pre-deploy", + service: proto.predeploy, + isPredeploy: true, }), - ] + override: predeployOverrides, + }), + ] : undefined; return { diff --git a/dashboard/src/main/home/app-dashboard/app-view/AppDataContainer.tsx b/dashboard/src/main/home/app-dashboard/app-view/AppDataContainer.tsx index 36745b1f18..a7ce4ffaa5 100644 --- a/dashboard/src/main/home/app-dashboard/app-view/AppDataContainer.tsx +++ b/dashboard/src/main/home/app-dashboard/app-view/AppDataContainer.tsx @@ -121,6 +121,7 @@ const AppDataContainer: React.FC = ({ tabParam }) => { deletions: { serviceNames: [], envGroupNames: [], + predeploy: [], }, }, }); @@ -268,7 +269,7 @@ const AppDataContainer: React.FC = ({ tabParam }) => { // redirect to the default tab after save history.push(`/apps/${porterApp.name}/${DEFAULT_TAB}`); - } catch (err) {} + } catch (err) { } }); const cancelRedeploy = useCallback(() => { @@ -310,6 +311,7 @@ const AppDataContainer: React.FC = ({ tabParam }) => { deletions: { envGroupNames: [], serviceNames: [], + predeploy: [], }, redeployOnSave: false, }); @@ -372,11 +374,11 @@ const AppDataContainer: React.FC = ({ tabParam }) => { { label: "Environment", value: "environment" }, ...(latestProto.build ? [ - { - label: "Build Settings", - value: "build-settings", - }, - ] + { + label: "Build Settings", + value: "build-settings", + }, + ] : []), { label: "Settings", value: "settings" }, ]} diff --git a/dashboard/src/main/home/app-dashboard/app-view/tabs/Overview.tsx b/dashboard/src/main/home/app-dashboard/app-view/tabs/Overview.tsx index 9577292738..0d924b959e 100644 --- a/dashboard/src/main/home/app-dashboard/app-view/tabs/Overview.tsx +++ b/dashboard/src/main/home/app-dashboard/app-view/tabs/Overview.tsx @@ -59,7 +59,7 @@ const Overview: React.FC = () => { type: "predeploy", }), })} - existingServiceNames={Object.keys(latestProto.services)} + existingServiceNames={latestProto.predeploy ? ["pre-deploy"] : []} isPredeploy fieldArrayName={"app.predeploy"} /> diff --git a/dashboard/src/main/home/app-dashboard/create-app/CreateApp.tsx b/dashboard/src/main/home/app-dashboard/create-app/CreateApp.tsx index 1269e7921b..90abdcdbf6 100644 --- a/dashboard/src/main/home/app-dashboard/create-app/CreateApp.tsx +++ b/dashboard/src/main/home/app-dashboard/create-app/CreateApp.tsx @@ -159,6 +159,7 @@ const CreateApp: React.FC = ({ history }) => { deletions: { serviceNames: [], envGroupNames: [], + predeploy: [], }, }, }); diff --git a/dashboard/src/main/home/app-dashboard/validate-apply/services-settings/ServiceList.tsx b/dashboard/src/main/home/app-dashboard/validate-apply/services-settings/ServiceList.tsx index 2ef10cacbb..1d1bfb24c8 100644 --- a/dashboard/src/main/home/app-dashboard/validate-apply/services-settings/ServiceList.tsx +++ b/dashboard/src/main/home/app-dashboard/validate-apply/services-settings/ServiceList.tsx @@ -87,7 +87,7 @@ const ServiceList: React.FC = ({ fields: deletedServices, } = useFieldArray({ control: appControl, - name: "deletions.serviceNames", + name: fieldArrayName === "app.services" ? "deletions.serviceNames" : "deletions.predeploy", }); const serviceType = watch("type"); diff --git a/dashboard/src/shared/api.tsx b/dashboard/src/shared/api.tsx index 84c8a65592..11391053d9 100644 --- a/dashboard/src/shared/api.tsx +++ b/dashboard/src/shared/api.tsx @@ -898,6 +898,7 @@ const validatePorterApp = baseApi< commit_sha: string; deletions: { service_names: string[]; + predeploy: string[]; env_variable_names: string[]; env_group_names: string[]; }; diff --git a/go.work.sum b/go.work.sum index b7ada28281..3c115030fe 100644 --- a/go.work.sum +++ b/go.work.sum @@ -823,6 +823,8 @@ github.com/porter-dev/api-contracts v0.0.63/go.mod h1:qr2L58mJLr5DUGV5OPw3REiSrQ github.com/porter-dev/api-contracts v0.0.86/go.mod h1:fX6JmP5QuzxDLvqP3evFOTXjI4dHxsG0+VKNTjImZU8= github.com/porter-dev/api-contracts v0.1.7 h1:Mxua9qTur0HIhIS4gmK0a9sLcHrgJfFwSQI0CxZBkh4= github.com/porter-dev/api-contracts v0.1.7/go.mod h1:fX6JmP5QuzxDLvqP3evFOTXjI4dHxsG0+VKNTjImZU8= +github.com/porter-dev/api-contracts v0.2.3 h1:JDdi2QT6RkI37XiYRaKM3L5wvFSp070pWmnlexDsd4c= +github.com/porter-dev/api-contracts v0.2.3/go.mod h1:fX6JmP5QuzxDLvqP3evFOTXjI4dHxsG0+VKNTjImZU8= github.com/posener/complete v1.2.3 h1:NP0eAhjcjImqslEwo/1hq7gpajME0fTLTezBKDqfXqo= github.com/pquerna/cachecontrol v0.1.0 h1:yJMy84ti9h/+OEWa752kBTKv4XC30OtVVHYv/8cTqKc= github.com/pquerna/cachecontrol v0.1.0/go.mod h1:NrUG3Z7Rdu85UNR3vm7SOsl1nFIeSiQnrHV5K9mBcUI=