From 08ba9d3e335a088d27bde792bf90d90b9e83236e Mon Sep 17 00:00:00 2001 From: Andy Rae <1127507+AndyRae@users.noreply.github.com> Date: Tue, 30 Sep 2025 18:28:28 +0100 Subject: [PATCH] Make columns optional --- .../fields/[fieldId]/beta/columns.tsx | 295 +++++++++--------- 1 file changed, 152 insertions(+), 143 deletions(-) diff --git a/app/next-client-app/app/(protected)/scanreports/[id]/tables/[tableId]/fields/[fieldId]/beta/columns.tsx b/app/next-client-app/app/(protected)/scanreports/[id]/tables/[tableId]/fields/[fieldId]/beta/columns.tsx index 687f0be37..46f6183b6 100644 --- a/app/next-client-app/app/(protected)/scanreports/[id]/tables/[tableId]/fields/[fieldId]/beta/columns.tsx +++ b/app/next-client-app/app/(protected)/scanreports/[id]/tables/[tableId]/fields/[fieldId]/beta/columns.tsx @@ -8,167 +8,176 @@ import CopyButton from "@/components/core/CopyButton"; import AddConceptV3 from "@/components/concepts/AddConceptV3"; import { AISuggestionsButton } from "@/components/recommendations/ai-suggesions-button"; import { StoredRecommendationsButton } from "@/components/recommendations/stored-recommendations-button"; -import { enableAIRecommendation, enableStoredRecommendation } from "@/constants"; +import { + enableAIRecommendation, + enableStoredRecommendation, +} from "@/constants"; export const columns = ( tableId: string, canEdit: boolean, - scanReportId: string -): ColumnDef[] => [ - { - id: "Value", - accessorKey: "value", - header: ({ column }) => ( - - ), - enableHiding: true, - enableSorting: true, - cell: ({ row }) => { - const { value, id } = row.original; + scanReportId: string, +): ColumnDef[] => { + const baseColumns: ColumnDef[] = [ + { + id: "Value", + accessorKey: "value", + header: ({ column }) => ( + + ), + enableHiding: true, + enableSorting: true, + cell: ({ row }) => { + const { value, id } = row.original; - return ( - - ); - } - }, - { - id: "Stored Recommendations", - header: ({ column }) => ( - - ), - enableHiding: true, - enableSorting: false, - cell: ({ row }) => { - const { value, id, mapping_recommendations } = row.original; + return ( + + ); + }, + }, + { + id: "Value Description", + accessorKey: "value_description", + header: ({ column }) => ( + + ), + enableHiding: true, + enableSorting: true, + cell: ({ row }) => { + const { value_description } = row.original; + return ( + + {value_description} + + ); + }, + }, + { + id: "Frequency", + accessorKey: "frequency", + header: ({ column }) => ( + + ), + enableHiding: true, + enableSorting: true, + cell: ({ row }) => { + const { frequency } = row.original; + return {frequency}; + }, + }, + { + id: "Concepts", + header: ({ column }) => ( + + ), + enableHiding: true, + enableSorting: false, + cell: ({ row }) => { + const { concepts } = row.original; + return ( + }> + + + ); + }, + }, + { + id: "Add Concept", + header: "", + cell: ({ row }) => { + const { id } = row.original; - return ( - enableStoredRecommendation === "true" && ( -
- + ); + }, + }, + ]; + + // Stored Recommendations Column - insert at position 1 (2nd column) + if (enableStoredRecommendation === "true") { + baseColumns.splice(1, 0, { + id: "Stored Recommendations", + header: ({ column }) => ( + + ), + enableHiding: true, + enableSorting: false, + cell: ({ row }) => { + const { value, id, mapping_recommendations } = row.original; + + return ( +
+
- ) - ); - } - }, - { - id: "AI Suggestions", - header: ({ column }) => ( - - ), - enableHiding: true, - enableSorting: false, - cell: ({ row }) => { - const { value, id } = row.original; + ); + }, + }); + } - return ( -
- {enableAIRecommendation === "true" ? ( + // AI Suggestions Column - insert at position 2 (3rd column) + if (enableAIRecommendation === "true") { + baseColumns.splice(2, 0, { + id: "AI Suggestions", + header: ({ column }) => ( + + ), + enableHiding: true, + enableSorting: false, + cell: ({ row }) => { + const { value, id } = row.original; + + return ( +
- ) : ( - Disabled - )} -
- ); - } - }, - { - id: "Value Description", - accessorKey: "value_description", - header: ({ column }) => ( - - ), - enableHiding: true, - enableSorting: true, - cell: ({ row }) => { - const { value_description } = row.original; - return ( - - {value_description} - - ); - } - }, - { - id: "Frequency", - accessorKey: "frequency", - header: ({ column }) => ( - - ), - enableHiding: true, - enableSorting: true, - cell: ({ row }) => { - const { frequency } = row.original; - return {frequency}; - } - }, - { - id: "Concepts", - header: ({ column }) => ( - - ), - enableHiding: true, - enableSorting: false, - cell: ({ row }) => { - const { concepts } = row.original; - return ( - }> - - - ); - } - }, - { - id: "Add Concept", - header: "", - cell: ({ row }) => { - const { id } = row.original; - - return ( - - ); - } +
+ ); + }, + }); } -]; + + return baseColumns; +};