Skip to content

Commit

Permalink
support delete predeploy (#3683)
Browse files Browse the repository at this point in the history
Co-authored-by: David Townley <[email protected]>
  • Loading branch information
Feroze Mohideen and David Townley authored Sep 28, 2023
1 parent 88ce84a commit 5cad08d
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 16 deletions.
2 changes: 2 additions & 0 deletions api/server/handlers/porter_app/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
Expand Down Expand Up @@ -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,
},
Expand Down
1 change: 1 addition & 0 deletions dashboard/src/lib/hooks/useAppValidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [],
},
Expand Down
21 changes: 13 additions & 8 deletions dashboard/src/lib/porter-apps/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ const AppDataContainer: React.FC<AppDataContainerProps> = ({ tabParam }) => {
deletions: {
serviceNames: [],
envGroupNames: [],
predeploy: [],
},
},
});
Expand Down Expand Up @@ -268,7 +269,7 @@ const AppDataContainer: React.FC<AppDataContainerProps> = ({ tabParam }) => {

// redirect to the default tab after save
history.push(`/apps/${porterApp.name}/${DEFAULT_TAB}`);
} catch (err) {}
} catch (err) { }
});

const cancelRedeploy = useCallback(() => {
Expand Down Expand Up @@ -310,6 +311,7 @@ const AppDataContainer: React.FC<AppDataContainerProps> = ({ tabParam }) => {
deletions: {
envGroupNames: [],
serviceNames: [],
predeploy: [],
},
redeployOnSave: false,
});
Expand Down Expand Up @@ -372,11 +374,11 @@ const AppDataContainer: React.FC<AppDataContainerProps> = ({ tabParam }) => {
{ label: "Environment", value: "environment" },
...(latestProto.build
? [
{
label: "Build Settings",
value: "build-settings",
},
]
{
label: "Build Settings",
value: "build-settings",
},
]
: []),
{ label: "Settings", value: "settings" },
]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const Overview: React.FC = () => {
type: "predeploy",
}),
})}
existingServiceNames={Object.keys(latestProto.services)}
existingServiceNames={latestProto.predeploy ? ["pre-deploy"] : []}
isPredeploy
fieldArrayName={"app.predeploy"}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ const CreateApp: React.FC<CreateAppProps> = ({ history }) => {
deletions: {
serviceNames: [],
envGroupNames: [],
predeploy: [],
},
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ const ServiceList: React.FC<ServiceListProps> = ({
fields: deletedServices,
} = useFieldArray({
control: appControl,
name: "deletions.serviceNames",
name: fieldArrayName === "app.services" ? "deletions.serviceNames" : "deletions.predeploy",
});

const serviceType = watch("type");
Expand Down
1 change: 1 addition & 0 deletions dashboard/src/shared/api.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,7 @@ const validatePorterApp = baseApi<
commit_sha: string;
deletions: {
service_names: string[];
predeploy: string[];
env_variable_names: string[];
env_group_names: string[];
};
Expand Down
2 changes: 2 additions & 0 deletions go.work.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down

0 comments on commit 5cad08d

Please sign in to comment.