Skip to content

Commit 167cf44

Browse files
authored
Make AI columns optional (#1218)
1 parent 48329ab commit 167cf44

1 file changed

Lines changed: 152 additions & 143 deletions

File tree

  • app/next-client-app/app/(protected)/scanreports/[id]/tables/[tableId]/fields/[fieldId]/beta

app/next-client-app/app/(protected)/scanreports/[id]/tables/[tableId]/fields/[fieldId]/beta/columns.tsx

Lines changed: 152 additions & 143 deletions
Original file line numberDiff line numberDiff line change
@@ -8,167 +8,176 @@ import CopyButton from "@/components/core/CopyButton";
88
import AddConceptV3 from "@/components/concepts/AddConceptV3";
99
import { AISuggestionsButton } from "@/components/recommendations/ai-suggesions-button";
1010
import { StoredRecommendationsButton } from "@/components/recommendations/stored-recommendations-button";
11-
import { enableAIRecommendation, enableStoredRecommendation } from "@/constants";
11+
import {
12+
enableAIRecommendation,
13+
enableStoredRecommendation,
14+
} from "@/constants";
1215

1316
export const columns = (
1417
tableId: string,
1518
canEdit: boolean,
16-
scanReportId: string
17-
): ColumnDef<ScanReportValueV3>[] => [
18-
{
19-
id: "Value",
20-
accessorKey: "value",
21-
header: ({ column }) => (
22-
<DataTableColumnHeader column={column} title="Value" sortName="value" />
23-
),
24-
enableHiding: true,
25-
enableSorting: true,
26-
cell: ({ row }) => {
27-
const { value, id } = row.original;
19+
scanReportId: string,
20+
): ColumnDef<ScanReportValueV3>[] => {
21+
const baseColumns: ColumnDef<ScanReportValueV3>[] = [
22+
{
23+
id: "Value",
24+
accessorKey: "value",
25+
header: ({ column }) => (
26+
<DataTableColumnHeader column={column} title="Value" sortName="value" />
27+
),
28+
enableHiding: true,
29+
enableSorting: true,
30+
cell: ({ row }) => {
31+
const { value, id } = row.original;
2832

29-
return (
30-
<div className="flex items-center gap-2">
31-
<a
32-
className="font-bold underline underline-offset-2"
33-
href={`https://athena.ohdsi.org/search-terms/terms?query=${value}`}
34-
target="_blank"
35-
>
36-
{value}
37-
</a>
38-
<CopyButton textToCopy={value} />
39-
</div>
40-
);
41-
}
42-
},
43-
{
44-
id: "Stored Recommendations",
45-
header: ({ column }) => (
46-
<DataTableColumnHeader column={column} title="Stored Recommendations" />
47-
),
48-
enableHiding: true,
49-
enableSorting: false,
50-
cell: ({ row }) => {
51-
const { value, id, mapping_recommendations } = row.original;
33+
return (
34+
<div className="flex items-center gap-2">
35+
<a
36+
className="font-bold underline underline-offset-2"
37+
href={`https://athena.ohdsi.org/search-terms/terms?query=${value}`}
38+
target="_blank"
39+
>
40+
{value}
41+
</a>
42+
<CopyButton textToCopy={value} />
43+
</div>
44+
);
45+
},
46+
},
47+
{
48+
id: "Value Description",
49+
accessorKey: "value_description",
50+
header: ({ column }) => (
51+
<DataTableColumnHeader
52+
column={column}
53+
title="Value Description"
54+
sortName="value_description"
55+
/>
56+
),
57+
enableHiding: true,
58+
enableSorting: true,
59+
cell: ({ row }) => {
60+
const { value_description } = row.original;
61+
return (
62+
<span className="max-w-[200px] whitespace-pre-wrap text-pretty">
63+
{value_description}
64+
</span>
65+
);
66+
},
67+
},
68+
{
69+
id: "Frequency",
70+
accessorKey: "frequency",
71+
header: ({ column }) => (
72+
<DataTableColumnHeader
73+
column={column}
74+
title="Frequency"
75+
sortName="frequency"
76+
/>
77+
),
78+
enableHiding: true,
79+
enableSorting: true,
80+
cell: ({ row }) => {
81+
const { frequency } = row.original;
82+
return <span className="tabular-nums">{frequency}</span>;
83+
},
84+
},
85+
{
86+
id: "Concepts",
87+
header: ({ column }) => (
88+
<DataTableColumnHeader column={column} title="Concepts" />
89+
),
90+
enableHiding: true,
91+
enableSorting: false,
92+
cell: ({ row }) => {
93+
const { concepts } = row.original;
94+
return (
95+
<Suspense fallback={<Skeleton className="h-5 w-[250px]" />}>
96+
<ConceptTagsV3
97+
concepts={concepts}
98+
scanReportId={scanReportId}
99+
tableId={tableId}
100+
fieldId={row.original.scan_report_field}
101+
valueId={row.original.id}
102+
/>
103+
</Suspense>
104+
);
105+
},
106+
},
107+
{
108+
id: "Add Concept",
109+
header: "",
110+
cell: ({ row }) => {
111+
const { id } = row.original;
52112

53-
return (
54-
enableStoredRecommendation === "true" && (
55-
<div className="flex justify-start w-full">
56-
<StoredRecommendationsButton
57-
value={value}
58-
tableId={tableId}
113+
return (
114+
<AddConceptV3
59115
rowId={id}
116+
tableId={tableId}
60117
contentType="scanreportvalue"
118+
disabled={!canEdit}
61119
scanReportId={scanReportId}
62120
fieldId={row.original.scan_report_field}
121+
/>
122+
);
123+
},
124+
},
125+
];
126+
127+
// Stored Recommendations Column - insert at position 1 (2nd column)
128+
if (enableStoredRecommendation === "true") {
129+
baseColumns.splice(1, 0, {
130+
id: "Stored Recommendations",
131+
header: ({ column }) => (
132+
<DataTableColumnHeader column={column} title="Stored Recommendations" />
133+
),
134+
enableHiding: true,
135+
enableSorting: false,
136+
cell: ({ row }) => {
137+
const { value, id, mapping_recommendations } = row.original;
138+
139+
return (
140+
<div className="flex justify-start w-full">
141+
<StoredRecommendationsButton
142+
value={value}
143+
tableId={tableId}
144+
rowId={id}
145+
contentType="scanreportvalue"
146+
scanReportId={scanReportId}
147+
fieldId={row.original.scan_report_field}
63148
mappingRecommendations={mapping_recommendations}
64149
/>
65150
</div>
66-
)
67-
);
68-
}
69-
},
70-
{
71-
id: "AI Suggestions",
72-
header: ({ column }) => (
73-
<DataTableColumnHeader column={column} title="AI Suggestions" />
74-
),
75-
enableHiding: true,
76-
enableSorting: false,
77-
cell: ({ row }) => {
78-
const { value, id } = row.original;
151+
);
152+
},
153+
});
154+
}
79155

80-
return (
81-
<div className="flex justify-start w-full">
82-
{enableAIRecommendation === "true" ? (
156+
// AI Suggestions Column - insert at position 2 (3rd column)
157+
if (enableAIRecommendation === "true") {
158+
baseColumns.splice(2, 0, {
159+
id: "AI Suggestions",
160+
header: ({ column }) => (
161+
<DataTableColumnHeader column={column} title="AI Suggestions" />
162+
),
163+
enableHiding: true,
164+
enableSorting: false,
165+
cell: ({ row }) => {
166+
const { value, id } = row.original;
167+
168+
return (
169+
<div className="flex justify-start w-full">
83170
<AISuggestionsButton
84171
value={value}
85172
tableId={tableId}
86173
rowId={id}
87174
contentType="scanreportvalue"
88175
/>
89-
) : (
90-
<span className="text-gray-400 text-sm">Disabled</span>
91-
)}
92-
</div>
93-
);
94-
}
95-
},
96-
{
97-
id: "Value Description",
98-
accessorKey: "value_description",
99-
header: ({ column }) => (
100-
<DataTableColumnHeader
101-
column={column}
102-
title="Value Description"
103-
sortName="value_description"
104-
/>
105-
),
106-
enableHiding: true,
107-
enableSorting: true,
108-
cell: ({ row }) => {
109-
const { value_description } = row.original;
110-
return (
111-
<span className="max-w-[200px] whitespace-pre-wrap text-pretty">
112-
{value_description}
113-
</span>
114-
);
115-
}
116-
},
117-
{
118-
id: "Frequency",
119-
accessorKey: "frequency",
120-
header: ({ column }) => (
121-
<DataTableColumnHeader
122-
column={column}
123-
title="Frequency"
124-
sortName="frequency"
125-
/>
126-
),
127-
enableHiding: true,
128-
enableSorting: true,
129-
cell: ({ row }) => {
130-
const { frequency } = row.original;
131-
return <span className="tabular-nums">{frequency}</span>;
132-
}
133-
},
134-
{
135-
id: "Concepts",
136-
header: ({ column }) => (
137-
<DataTableColumnHeader column={column} title="Concepts" />
138-
),
139-
enableHiding: true,
140-
enableSorting: false,
141-
cell: ({ row }) => {
142-
const { concepts } = row.original;
143-
return (
144-
<Suspense fallback={<Skeleton className="h-5 w-[250px]" />}>
145-
<ConceptTagsV3
146-
concepts={concepts}
147-
scanReportId={scanReportId}
148-
tableId={tableId}
149-
fieldId={row.original.scan_report_field}
150-
valueId={row.original.id}
151-
/>
152-
</Suspense>
153-
);
154-
}
155-
},
156-
{
157-
id: "Add Concept",
158-
header: "",
159-
cell: ({ row }) => {
160-
const { id } = row.original;
161-
162-
return (
163-
<AddConceptV3
164-
rowId={id}
165-
tableId={tableId}
166-
contentType="scanreportvalue"
167-
disabled={!canEdit}
168-
scanReportId={scanReportId}
169-
fieldId={row.original.scan_report_field}
170-
/>
171-
);
172-
}
176+
</div>
177+
);
178+
},
179+
});
173180
}
174-
];
181+
182+
return baseColumns;
183+
};

0 commit comments

Comments
 (0)