-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathautomations-list.tsx
More file actions
121 lines (115 loc) · 3.72 KB
/
Copy pathautomations-list.tsx
File metadata and controls
121 lines (115 loc) · 3.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import { useState, useTransition } from "react";
import { useNavigate } from "@tanstack/react-router";
import { Plus, Zap } from "@untitledui/icons";
import { Button } from "@deco/ui/components/button.tsx";
import { SearchInput } from "@deco/ui/components/search-input.tsx";
import { Page } from "@/web/components/page";
import { EmptyState } from "@/web/components/empty-state.tsx";
import {
buildDefaultAutomationInput,
useAutomationActions,
useAutomations,
} from "@/web/hooks/use-automations";
import { AutomationListRow } from "./automation-list-row";
export function AutomationsList({ virtualMcpId }: { virtualMcpId: string }) {
const navigate = useNavigate();
const [search, setSearch] = useState("");
const [serverSearch, setServerSearch] = useState("");
const [, startTransition] = useTransition();
const { data: automations = [] } = useAutomations(
virtualMcpId,
serverSearch || null,
);
const { create } = useAutomationActions();
const handleSearch = (value: string) => {
setSearch(value);
startTransition(() => {
setServerSearch(value);
});
};
const goToDetail = (id: string) =>
navigate({
to: ".",
search: (prev: Record<string, unknown>) => ({
...prev,
main: "automation:" + id,
}),
replace: true,
});
const handleNew = async () => {
if (create.isPending) return;
const created = await create.mutateAsync(
buildDefaultAutomationInput(virtualMcpId),
);
goToDetail(created.id);
};
return (
<Page>
<Page.Content>
<Page.Body>
<div className="flex flex-col gap-6">
<Page.Title
actions={
<Button
size="sm"
onClick={handleNew}
disabled={create.isPending}
>
<Plus size={14} />
New automation
</Button>
}
>
Automations
</Page.Title>
{automations.length > 0 && (
<SearchInput
value={search}
onChange={handleSearch}
placeholder="Search automations..."
className="w-full md:w-[375px]"
/>
)}
</div>
{automations.length === 0 ? (
<div className="flex items-center justify-center py-20">
<EmptyState
image={<Zap size={48} className="text-muted-foreground" />}
title="No automations yet"
description="Create your first automation to run this agent on a schedule or in response to events."
actions={
<Button
size="sm"
onClick={handleNew}
disabled={create.isPending}
>
<Plus size={14} />
New automation
</Button>
}
/>
</div>
) : automations.length === 0 && serverSearch ? (
<div className="flex items-center justify-center py-20">
<EmptyState
image={<Zap size={48} className="text-muted-foreground" />}
title="No automations found"
description={`No automations match "${search}"`}
/>
</div>
) : (
<div className="mt-6 rounded-xl border border-border overflow-hidden">
{automations.map((a) => (
<AutomationListRow
key={a.id}
automation={a}
onClick={() => goToDetail(a.id)}
/>
))}
</div>
)}
</Page.Body>
</Page.Content>
</Page>
);
}