deployment actions show build if attached

This commit is contained in:
mbecker20
2024-04-21 02:45:04 -07:00
parent 528b74d156
commit c583a5dc62
3 changed files with 65 additions and 11 deletions

View File

@@ -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 (
<ConfirmButton
@@ -48,4 +61,4 @@ export const RunBuild = ({id}: {id: string}) => {
/>
);
}
}
};

View File

@@ -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 <RunBuild id={build_id} />;
},
DeployContainer,
StartOrStopContainer,
RemoveContainer,
},
Page: { DeploymentLogs },

View File

@@ -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 (
<Section
@@ -78,10 +77,42 @@ export const ResourceUpdates = ({ type, id }: Types.ResourceTarget) => {
}
>
<div className="grid md:grid-cols-2 lg:grid-cols-3 gap-4">
{data?.updates.slice(0, 3).map((update) => (
{updates?.updates.slice(0, 3).map((update) => (
<UpdateCard update={update} key={update.id} />
))}
</div>
</Section>
);
};
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,
};
}
};