From c583a5dc62ba5dd64aad4487017b6e02db947c8e Mon Sep 17 00:00:00 2001 From: mbecker20 Date: Sun, 21 Apr 2024 02:45:04 -0700 Subject: [PATCH] deployment actions show build if attached --- .../components/resources/build/actions.tsx | 19 ++++++-- .../components/resources/deployment/index.tsx | 12 ++++- frontend/src/components/updates/resource.tsx | 45 ++++++++++++++++--- 3 files changed, 65 insertions(+), 11 deletions(-) diff --git a/frontend/src/components/resources/build/actions.tsx b/frontend/src/components/resources/build/actions.tsx index 4212b704b..bd6e45970 100644 --- a/frontend/src/components/resources/build/actions.tsx +++ b/frontend/src/components/resources/build/actions.tsx @@ -1,10 +1,14 @@ import { ConfirmButton } from "@components/util"; import { useExecute, useRead } from "@lib/hooks"; +import { Types } from "@monitor/client"; import { useToast } from "@ui/use-toast"; import { Ban, Hammer, Loader2 } from "lucide-react"; -export const RunBuild = ({id}: {id: string}) => { - const { toast } = useToast(); +export const RunBuild = ({ id }: { id: string }) => { + const { toast } = useToast(); + const perms = useRead("GetPermissionLevel", { + target: { type: "Build", id }, + }).data; const building = useRead("GetBuildActionState", { build: id }).data?.building; const { mutate: run_mutate, isPending: runPending } = useExecute("RunBuild", { onMutate: () => { @@ -22,6 +26,15 @@ export const RunBuild = ({id}: {id: string}) => { }, } ); + + // make sure hidden without perms. + // not usually necessary, but this button also used in deployment actions. + if ( + perms !== Types.PermissionLevel.Execute && + perms !== Types.PermissionLevel.Write + ) + return null; + if (building) { return ( { /> ); } -} \ No newline at end of file +}; diff --git a/frontend/src/components/resources/deployment/index.tsx b/frontend/src/components/resources/deployment/index.tsx index 2e69929b4..44188fd11 100644 --- a/frontend/src/components/resources/deployment/index.tsx +++ b/frontend/src/components/resources/deployment/index.tsx @@ -23,6 +23,7 @@ import { DeploymentTable } from "./table"; import { DeploymentsChart } from "./dashboard"; import { NewResource, ResourceLink } from "../common"; import { Card, CardHeader } from "@ui/card"; +import { RunBuild } from "../build/actions"; export const useDeployment = (id?: string) => useRead("ListDeployments", {}, { refetchInterval: 5000 }).data?.find( @@ -94,7 +95,16 @@ export const DeploymentComponents: RequiredResourceComponents = { }, }, - Actions: { DeployContainer, StartOrStopContainer, RemoveContainer }, + Actions: { + RunBuild: ({ id }) => { + const build_id = useDeployment(id)?.info.build_id; + if (!build_id) return null; + return ; + }, + DeployContainer, + StartOrStopContainer, + RemoveContainer, + }, Page: { DeploymentLogs }, diff --git a/frontend/src/components/updates/resource.tsx b/frontend/src/components/updates/resource.tsx index 544497f2e..8d5be91af 100644 --- a/frontend/src/components/updates/resource.tsx +++ b/frontend/src/components/updates/resource.tsx @@ -58,12 +58,11 @@ const UpdateCard = ({ update }: { update: Types.UpdateListItem }) => { }; export const ResourceUpdates = ({ type, id }: Types.ResourceTarget) => { - const { data } = useRead("ListUpdates", { - query: { - "target.type": type, - "target.id": id, - }, - }); + const deployments = useRead("ListDeployments", {}).data; + + const updates = useRead("ListUpdates", { + query: getUpdateQuery({ type, id }, deployments), + }).data; return (
{ } >
- {data?.updates.slice(0, 3).map((update) => ( + {updates?.updates.slice(0, 3).map((update) => ( ))}
); }; + +const getUpdateQuery = ( + target: Types.ResourceTarget, + deployments: Types.DeploymentListItem[] | undefined +) => { + const build_id = + target.type === "Deployment" + ? deployments?.find((d) => d.id === target.id)?.info.build_id + : undefined; + if (build_id) { + return { + $or: [ + { + "target.type": target.type, + "target.id": target.id, + }, + { + "target.type": "Build", + "target.id": build_id, + operation: { + $in: [Types.Operation.RunBuild, Types.Operation.CancelBuild], + }, + }, + ], + }; + } else { + return { + "target.type": target.type, + "target.id": target.id, + }; + } +};