forked from github-starred/komodo
deployment actions show build if attached
This commit is contained in:
@@ -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}) => {
|
||||
/>
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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 },
|
||||
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user