Skip to content

Commit 44171e9

Browse files
committed
Fix query; cleanup
1 parent ab8162c commit 44171e9

File tree

11 files changed

+86
-79
lines changed

11 files changed

+86
-79
lines changed

core/actions/_lib/runActionInstance.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,6 @@ const _runActionInstance = async (
9797
stageId: actionInstance.stageId,
9898
});
9999

100-
revalidateTag(`community-stages_${pub.communityId}`);
101-
102100
return result;
103101
} catch (error) {
104102
captureException(error);
@@ -161,8 +159,6 @@ export async function runActionInstance(args: RunActionInstanceArgs) {
161159
})
162160
.execute();
163161

164-
revalidateTag(`action_runs_${pubResult.value.communityId}`);
165-
166162
return result;
167163
}
168164

core/actions/_lib/runActionInstanceServerAction.ts

Lines changed: 0 additions & 26 deletions
This file was deleted.

core/actions/api/server.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
export { runActionInstance, runInstancesForEvent } from "../_lib/runActionInstance";
2-
export { runActionInstanceServerAction } from "../_lib/runActionInstanceServerAction";

core/actions/api/serverAction.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
"use server";
2+
3+
import { revalidateTag } from "next/cache";
4+
5+
import { db } from "~/kysely/database";
6+
import { UsersId } from "~/kysely/types/public/Users";
7+
import { getLoginData } from "~/lib/auth/loginData";
8+
import {
9+
ActionInstanceRunResult,
10+
RunActionInstanceArgs,
11+
runActionInstance as runActionInstanceInner,
12+
} from "../_lib/runActionInstance";
13+
14+
export const runActionInstance = async function runActionInstance(
15+
args: Omit<RunActionInstanceArgs, "userId" | "event">
16+
): Promise<ActionInstanceRunResult> {
17+
const user = await getLoginData();
18+
19+
if (!user) {
20+
return {
21+
error: "Not logged in",
22+
};
23+
}
24+
25+
// Retrieve the pub's community id in order to revalidate the next server
26+
// cache after the action is run.
27+
const pub = await db
28+
.selectFrom("pubs")
29+
.select(["community_id as communityId"])
30+
.where("id", "=", args.pubId)
31+
.executeTakeFirst();
32+
33+
const result = await runActionInstanceInner({
34+
...args,
35+
userId: user.id as UsersId,
36+
});
37+
38+
if (pub !== undefined) {
39+
// Because an action can move a pub to a different stage, we need to
40+
// revalidate the community stage cache.
41+
revalidateTag(`community-stages_${pub.communityId}`);
42+
// Revalidate the community action runs cache for the action activity table.
43+
revalidateTag(`community-action-runs_${pub.communityId}`);
44+
}
45+
46+
return result;
47+
};

core/app/c/[communitySlug]/SideNav.tsx

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Button } from "ui/button";
2-
import { Menu } from "ui/icon";
2+
import { Activity, Menu } from "ui/icon";
33
import { Sheet, SheetContent, SheetTrigger } from "ui/sheet";
44

55
import type { CommunityData } from "./layout";
@@ -47,18 +47,13 @@ const Links = ({
4747
icon={<img src="/icons/members.svg" alt="" />}
4848
/>
4949
)}
50-
51-
{/* <NavLink
52-
href={`${prefix}/search`}
53-
text={"Search"}
54-
icon={<img src="/icons/search.svg" />}
55-
/>
56-
<NavLink
57-
href={`${prefix}/`}
58-
text={"Dashboard"}
59-
icon={<img src="/icons/dashboard.svg" />}
60-
count={8}
61-
/> */}
50+
{isAdmin && (
51+
<NavLink
52+
href={`${prefix}/activity/actions`}
53+
text="Activity"
54+
icon={<Activity className="w-4" />}
55+
/>
56+
)}
6257
</>
6358
);
6459
};

core/app/c/[communitySlug]/activity/actions/ActionRunsTable.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,5 @@ import { ActionRun, getActionRunsTableColumns } from "./getActionRunsTableColumn
77

88
export const ActionRunsTable = ({ actionRuns }: { actionRuns: ActionRun[] }) => {
99
const actionRunsColumns = getActionRunsTableColumns();
10-
return (
11-
<DataTable columns={actionRunsColumns} data={actionRuns} searchBy="actionInstance.name" />
12-
);
10+
return <DataTable columns={actionRunsColumns} data={actionRuns} />;
1311
};

core/app/c/[communitySlug]/activity/actions/page.tsx

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,10 @@ import { ActionRun } from "./getActionRunsTableColumns";
1313

1414
export default async function Page({
1515
params: { communitySlug },
16-
searchParams,
1716
}: {
1817
params: {
1918
communitySlug: string;
2019
};
21-
searchParams: {
22-
page?: string;
23-
};
2420
}) {
2521
const community = await findCommunityBySlug(communitySlug);
2622

@@ -37,16 +33,14 @@ export default async function Page({
3733
return null;
3834
}
3935

40-
const page = searchParams.page ? parseInt(searchParams.page, 10) : 1;
41-
const limit = 20;
4236
const actionRuns = (await unstable_cache(
4337
() =>
4438
db
4539
.selectFrom("stages")
4640
.where("stages.community_id", "=", community.id)
4741
.innerJoin("action_instances", "stages.id", "action_instances.stage_id")
4842
.innerJoin("action_runs", "action_instances.id", "action_runs.action_instance_id")
49-
.innerJoin("users", "action_runs.user_id", "users.id")
43+
.leftJoin("users", "action_runs.user_id", "users.id")
5044
.select((eb) => [
5145
"action_runs.id",
5246
"action_runs.config",
@@ -81,14 +75,17 @@ export default async function Page({
8175
).as("user"),
8276
])
8377
.orderBy("action_runs.created_at", "desc")
84-
.limit(limit)
85-
.offset(page * limit - limit)
8678
.execute(),
8779
[community.id],
88-
{ tags: [`action_runs_${community.id}`] }
80+
{ tags: [`community-action-runs_${community.id}`] }
8981
)()) as ActionRun[];
9082

91-
logger.info("Action runs", actionRuns);
92-
93-
return <ActionRunsTable actionRuns={actionRuns} />;
83+
return (
84+
<>
85+
<div className="mb-16 flex items-center justify-between">
86+
<h1 className="text-xl font-bold">Action Activity</h1>
87+
</div>
88+
<ActionRunsTable actionRuns={actionRuns} />
89+
</>
90+
);
9491
}

core/app/c/[communitySlug]/stages/manage/components/panel/StagePanelPubsRunActionButton.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { toast } from "ui/use-toast";
1414
import type { ActionInstances, ActionInstancesId } from "~/kysely/types/public/ActionInstances";
1515
import type { PubsId } from "~/kysely/types/public/Pubs";
1616
import { getActionByName } from "~/actions/api";
17-
import { runActionInstanceServerAction } from "~/actions/api/server";
17+
import { runActionInstance } from "~/actions/api/serverAction";
1818
import { useServerAction } from "~/lib/serverActions";
1919

2020
export const StagePanelPubsRunActionButton = ({
@@ -24,7 +24,7 @@ export const StagePanelPubsRunActionButton = ({
2424
actionInstance: ActionInstances;
2525
pub: Pub;
2626
}) => {
27-
const runAction = useServerAction(runActionInstanceServerAction);
27+
const runAction = useServerAction(runActionInstance);
2828

2929
const [isPending, startTransition] = useTransition();
3030

core/app/components/DataTable.tsx

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "u
2020
interface DataTableProps<TData, TValue> {
2121
columns: ColumnDef<TData, TValue>[];
2222
data: TData[];
23-
searchBy: string;
23+
searchBy?: string;
2424
}
2525

2626
export function DataTable<TData, TValue>({
@@ -51,20 +51,22 @@ export function DataTable<TData, TValue>({
5151

5252
return (
5353
<div>
54-
<div className="flex flex-col items-start gap-y-2 py-4">
55-
<Label htmlFor="email-filter" className="flex items-center gap-x-1">
56-
<Search className="h-4 w-4" /> Search by {searchBy}
57-
</Label>
58-
<Input
59-
name={`${searchBy}-filter`}
60-
placeholder={`Search table by ${searchBy}`}
61-
value={(table.getColumn(`${searchBy}`)?.getFilterValue() as string) ?? ""}
62-
onChange={(event) =>
63-
table.getColumn(`${searchBy}`)?.setFilterValue(event.target.value)
64-
}
65-
className="max-w-sm"
66-
/>
67-
</div>
54+
{searchBy && (
55+
<div className="flex flex-col items-start gap-y-2 py-4">
56+
<Label htmlFor="email-filter" className="flex items-center gap-x-1">
57+
<Search className="h-4 w-4" /> Search by {searchBy}
58+
</Label>
59+
<Input
60+
name={`${searchBy}-filter`}
61+
placeholder={`Search table by ${searchBy}`}
62+
value={(table.getColumn(`${searchBy}`)?.getFilterValue() as string) ?? ""}
63+
onChange={(event) =>
64+
table.getColumn(`${searchBy}`)?.setFilterValue(event.target.value)
65+
}
66+
className="max-w-sm"
67+
/>
68+
</div>
69+
)}
6870
<div className="mb-2 rounded-md border">
6971
<Table>
7072
<TableHeader>

core/pages/api/v0/[...ts-rest].ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,13 @@ import { compareAPIKeys, getBearerToken } from "~/lib/auth/api";
1111
import { env } from "~/lib/env/env.mjs";
1212
import {
1313
_getPubType,
14-
BadRequestError,
1514
createPub,
1615
deletePub,
1716
generateSignedAssetUploadUrl,
1817
getIntegrationInstanceConfig,
1918
getIntegrationInstanceState,
2019
getMembers,
2120
getPub,
22-
getPubType,
2321
getSuggestedMembers,
2422
setIntegrationInstanceConfig,
2523
setIntegrationInstanceState,

0 commit comments

Comments
 (0)