Skip to content

Commit 8948d60

Browse files
committed
Restrict related pubs table by selected form
1 parent 0973b89 commit 8948d60

File tree

4 files changed

+62
-13
lines changed

4 files changed

+62
-13
lines changed

core/app/c/[communitySlug]/pubs/[pubId]/components/RelatedPubsTable.tsx

+40-9
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,17 @@
33
import type { ColumnDef } from "@tanstack/react-table";
44
import type { ReactNode } from "react";
55

6-
import React, { useMemo, useState } from "react";
6+
import { useMemo, useState } from "react";
77
import Link from "next/link";
88
import { usePathname } from "next/navigation";
99

10-
import type { ActionInstances, PubTypes, Stages } from "db/public";
10+
import type { ProcessedPubWithForm } from "contracts";
11+
import type { PubTypes, Stages } from "db/public";
1112
import { Badge } from "ui/badge";
1213
import { Button } from "ui/button";
1314
import { Checkbox } from "ui/checkbox";
1415
import { DataTableColumnHeader } from "ui/data-table";
1516

16-
import type { PageContext } from "~/app/components/ActionUI/PubsRunActionDropDownMenu";
17-
import type { FullProcessedPub } from "~/lib/server/pub";
18-
import { PubsRunActionDropDownMenu } from "~/app/components/ActionUI/PubsRunActionDropDownMenu";
1917
import { DataTable } from "~/app/components/DataTable/DataTable";
2018
import { dateFormatOptions } from "~/lib/dates";
2119
import { getPubTitle } from "~/lib/pubs";
@@ -95,14 +93,29 @@ const getRelatedPubsColumns = (relatedPubActionsDropdowns: Record<string, ReactN
9593
return relatedPubActionsDropdowns[row.original.id];
9694
},
9795
},
98-
] as const satisfies ColumnDef<FullProcessedPub, unknown>[];
96+
] as const satisfies ColumnDef<
97+
ProcessedPubWithForm<{
98+
withRelatedPubs: true;
99+
withStage: true;
100+
withPubType: true;
101+
withMembers: true;
102+
withStageActionInstances: true;
103+
}>,
104+
unknown
105+
>[];
99106
};
100107

101108
const Table = ({
102109
pubs,
103110
relatedPubActionsDropdowns,
104111
}: {
105-
pubs: FullProcessedPub[];
112+
pubs: ProcessedPubWithForm<{
113+
withRelatedPubs: true;
114+
withStage: true;
115+
withPubType: true;
116+
withMembers: true;
117+
withStageActionInstances: true;
118+
}>[];
106119
relatedPubActionsDropdowns: Record<string, ReactNode>;
107120
}) => {
108121
const columns = getRelatedPubsColumns(relatedPubActionsDropdowns);
@@ -114,11 +127,29 @@ export const RelatedPubsTable = ({
114127
pub,
115128
relatedPubActionsDropdowns,
116129
}: {
117-
pub: FullProcessedPub;
130+
pub: ProcessedPubWithForm<{
131+
withRelatedPubs: true;
132+
withStage: true;
133+
withPubType: true;
134+
withMembers: true;
135+
withStageActionInstances: true;
136+
}>;
118137
relatedPubActionsDropdowns: Record<string, ReactNode>;
119138
}) => {
120139
const groupedBySlug = useMemo(() => {
121-
const grouped: Record<string, { pub: FullProcessedPub; fieldName: string }[]> = {};
140+
const grouped: Record<
141+
string,
142+
{
143+
pub: ProcessedPubWithForm<{
144+
withRelatedPubs: true;
145+
withStage: true;
146+
withPubType: true;
147+
withMembers: true;
148+
withStageActionInstances: true;
149+
}>;
150+
fieldName: string;
151+
}[]
152+
> = {};
122153
for (const value of pub.values) {
123154
const { relatedPub, fieldSlug, fieldName } = value;
124155
if (relatedPub) {

core/app/c/[communitySlug]/pubs/[pubId]/components/RelatedPubsTableWrapper.tsx

+18-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
import type { ProcessedPubWithForm } from "contracts";
12
import { Info } from "ui/icon";
23
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "ui/tooltip";
34

45
import type { PageContext } from "~/app/components/ActionUI/PubsRunActionDropDownMenu";
5-
import type { FullProcessedPub } from "~/lib/server";
66
import { PubsRunActionDropDownMenu } from "~/app/components/ActionUI/PubsRunActionDropDownMenu";
77
import { RelatedPubsTable } from "./RelatedPubsTable";
88

@@ -24,7 +24,16 @@ const NoActions = () => {
2424
);
2525
};
2626

27-
const getRelatedPubRunActionsDropdowns = (row: FullProcessedPub, pageContext: PageContext) => {
27+
const getRelatedPubRunActionsDropdowns = (
28+
row: ProcessedPubWithForm<{
29+
withRelatedPubs: true;
30+
withStage: true;
31+
withPubType: true;
32+
withMembers: true;
33+
withStageActionInstances: true;
34+
}>,
35+
pageContext: PageContext
36+
) => {
2837
return row.stage && row.stage?.actionInstances.length > 0 ? (
2938
<PubsRunActionDropDownMenu
3039
actionInstances={row.stage.actionInstances}
@@ -38,7 +47,13 @@ const getRelatedPubRunActionsDropdowns = (row: FullProcessedPub, pageContext: Pa
3847
};
3948

4049
type Props = {
41-
pub: FullProcessedPub;
50+
pub: ProcessedPubWithForm<{
51+
withRelatedPubs: true;
52+
withStage: true;
53+
withPubType: true;
54+
withMembers: true;
55+
withStageActionInstances: true;
56+
}>;
4257
pageContext: PageContext;
4358
};
4459

core/app/c/[communitySlug]/pubs/[pubId]/page.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ export default async function Page(props: {
268268
relatedPub={{ pubId: pub.id, pubTypeId: pub.pubTypeId }}
269269
className="w-fit"
270270
/>
271-
<RelatedPubsTableWrapper pub={pub} pageContext={pageContext} />
271+
<RelatedPubsTableWrapper pub={pubByForm} pageContext={pageContext} />
272272
</div>
273273
)}
274274
</div>

core/lib/pubs.ts

+3
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ export const getPubByForm = ({
9696
withStage: true;
9797
withPubType: true;
9898
withMembers: true;
99+
withStageActionInstances: true;
99100
}> => {
100101
const { values } = pub;
101102
if (!values.length) {
@@ -120,6 +121,7 @@ export const getPubByForm = ({
120121
withStage: true;
121122
withPubType: true;
122123
withMembers: true;
124+
withStageActionInstances: true;
123125
}>["values"] = [];
124126
for (const formElement of pubFieldFormElements) {
125127
const values = valuesByFieldSlug[formElement.slug];
@@ -161,6 +163,7 @@ export const getPubByForm = ({
161163
withStage: true;
162164
withPubType: true;
163165
withMembers: true;
166+
withStageActionInstances: true;
164167
}>["values"] = [];
165168
for (const slug of slugsNotInForm) {
166169
for (const value of valuesByFieldSlug[slug]) {

0 commit comments

Comments
 (0)