add updates page basic

This commit is contained in:
mbecker20
2024-03-25 08:04:30 -07:00
parent 478a046074
commit f4b77598c3
5 changed files with 91 additions and 3 deletions

View File

@@ -124,6 +124,8 @@ export const TagsWithBadge = ({
};
export const AddTags = ({ target }: { target: TargetExcludingSystem }) => {
const { toast } = useToast();
const { type, id } = target;
const resource = useRead(`List${type}s`, {}).data?.find((d) => d.id === id);
@@ -137,6 +139,7 @@ export const AddTags = ({ target }: { target: TargetExcludingSystem }) => {
const { mutate: update } = useWrite("UpdateTagsOnResource", {
onSuccess: () => {
inv([`List${type}s`]);
toast({ title: `Added tag ${input}` });
setOpen(false);
},
});
@@ -157,7 +160,6 @@ export const AddTags = ({ target }: { target: TargetExcludingSystem }) => {
if (open) setInput("");
}, [open]);
const { toast } = useToast();
const create_tag = async () => {
if (!input) return toast({ title: "Must provide tag name in input" });
const tag = await create({ name: input });
@@ -180,10 +182,19 @@ export const AddTags = ({ target }: { target: TargetExcludingSystem }) => {
<PopoverContent className="w-[200px] p-0" sideOffset={12}>
<Command>
<CommandInput
placeholder="Search Tags"
placeholder="Search / Create"
className="h-9"
value={input}
onValueChange={setInput}
onKeyDown={(e) => {
if (
e.key === "Enter" &&
// check that no tags still match
all_tags?.every((tag) => !tag.name.includes(input))
) {
create_tag();
}
}}
/>
<CommandEmpty
className="justify-between cursor-pointer hover:bg-accent m-1"

View File

@@ -129,7 +129,7 @@ export const ResourceUpdates = ({ type, id }: Types.ResourceTarget) => {
title="Updates"
icon={<Bell className="w-4 h-4" />}
actions={
<Link to={`/deployments/${id}/updates`}>
<Link to={`/${type.toLowerCase()}s/${id}/updates`}>
<Button variant="secondary">
<ExternalLink className="w-4 h-4" />
</Button>

View File

@@ -0,0 +1,44 @@
import { fmt_date_with_minutes } from "@lib/utils";
import { Types } from "@monitor/client";
import { DataTable } from "@ui/data-table";
export const UpdatesTable = ({
updates,
showTarget,
}: {
updates: Types.UpdateListItem[];
showTarget?: boolean;
}) => {
return (
<DataTable
data={updates}
columns={[
// showTarget ? {
// header: "Target",
// accessorKey: "target.id",
// } : undefined,
{
header: "Operation",
accessorKey: "operation",
},
{
header: "Status",
accessorKey: "status",
},
{
header: "Success",
accessorFn: ({ success }) => success ? "Ok" : "Fail",
},
{
header: "Start Time",
accessorFn: ({ start_ts }) =>
fmt_date_with_minutes(new Date(start_ts)),
},
{
header: "Operator",
accessorKey: "username",
},
]}
/>
);
};

View File

@@ -0,0 +1,31 @@
import { Page } from "@components/layouts";
import { ResourceComponents } from "@components/resources";
import { AddTags, ResourceTags } from "@components/tags";
import { UpdatesTable } from "@components/updates/table";
import { useRead, useResourceParamType } from "@lib/hooks";
import { useParams } from "react-router-dom";
export const ResourceUpdates = () => {
const type = useResourceParamType();
const id = useParams().id as string;
const updates = useRead("ListUpdates", {
query: {
"target.type": type,
"target.id": id,
},
}).data;
const Components = ResourceComponents[type];
return (
<Page
title={<Components.Name id={id} />}
titleRight={
<div className="flex gap-2">
<ResourceTags target={{ id, type }} click_to_delete />
<AddTags target={{ id, type }} />
</div>
}
>
<UpdatesTable updates={updates?.updates ?? []} />
</Page>
);
};

View File

@@ -8,6 +8,7 @@ import { Keys } from "@pages/keys";
import { RouterProvider, createBrowserRouter } from "react-router-dom";
import { Tree } from "@pages/tree";
import { Tags } from "@pages/tags";
import { ResourceUpdates } from "@pages/resource_update";
const router = createBrowserRouter([
{
@@ -23,6 +24,7 @@ const router = createBrowserRouter([
children: [
{ path: "", element: <Resources /> },
{ path: ":id", element: <Resource /> },
{ path: ":id/updates", element: <ResourceUpdates /> }
],
},
],