From b4ea1ab69bf641c0d225dad3121e839ce4c84256 Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Thu, 27 Jul 2023 11:38:25 +0100 Subject: [PATCH] Working on recommendations ui --- package-lock.json | 31 ++++ package.json | 1 + .../building-passport/RecommendationCard.tsx | 160 +++++++++++++++++- .../building-passport/RecommendationTable.tsx | 84 +++++++++ src/app/shadcn_components/ui/checkbox.tsx | 30 ++++ 5 files changed, 301 insertions(+), 5 deletions(-) create mode 100644 src/app/components/building-passport/RecommendationTable.tsx create mode 100644 src/app/shadcn_components/ui/checkbox.tsx diff --git a/package-lock.json b/package-lock.json index 2f02a4d..e04c0da 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,6 +11,7 @@ "@headlessui-float/react": "^0.11.2", "@headlessui/react": "^1.7.14", "@heroicons/react": "^2.0.18", + "@radix-ui/react-checkbox": "^1.0.4", "@radix-ui/react-dialog": "^1.0.4", "@radix-ui/react-dropdown-menu": "^2.0.5", "@radix-ui/react-hover-card": "^1.0.6", @@ -1533,6 +1534,36 @@ } } }, + "node_modules/@radix-ui/react-checkbox": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/@radix-ui/react-checkbox/-/react-checkbox-1.0.4.tgz", + "integrity": "sha512-CBuGQa52aAYnADZVt/KBQzXrwx6TqnlwtcIPGtVt5JkkzQwMOLJjPukimhfKEr4GQNd43C+djUh5Ikopj8pSLg==", + "dependencies": { + "@babel/runtime": "^7.13.10", + "@radix-ui/primitive": "1.0.1", + "@radix-ui/react-compose-refs": "1.0.1", + "@radix-ui/react-context": "1.0.1", + "@radix-ui/react-presence": "1.0.1", + "@radix-ui/react-primitive": "1.0.3", + "@radix-ui/react-use-controllable-state": "1.0.1", + "@radix-ui/react-use-previous": "1.0.1", + "@radix-ui/react-use-size": "1.0.1" + }, + "peerDependencies": { + "@types/react": "*", + "@types/react-dom": "*", + "react": "^16.8 || ^17.0 || ^18.0", + "react-dom": "^16.8 || ^17.0 || ^18.0" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "@types/react-dom": { + "optional": true + } + } + }, "node_modules/@radix-ui/react-collection": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/@radix-ui/react-collection/-/react-collection-1.0.3.tgz", diff --git a/package.json b/package.json index e5d54a7..46d6a75 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "@headlessui-float/react": "^0.11.2", "@headlessui/react": "^1.7.14", "@heroicons/react": "^2.0.18", + "@radix-ui/react-checkbox": "^1.0.4", "@radix-ui/react-dialog": "^1.0.4", "@radix-ui/react-dropdown-menu": "^2.0.5", "@radix-ui/react-hover-card": "^1.0.6", diff --git a/src/app/components/building-passport/RecommendationCard.tsx b/src/app/components/building-passport/RecommendationCard.tsx index 71d9b2d..60e865d 100644 --- a/src/app/components/building-passport/RecommendationCard.tsx +++ b/src/app/components/building-passport/RecommendationCard.tsx @@ -1,7 +1,150 @@ "use client"; import { ComponentRecommendation } from "@/app/db/schema/recommendations"; -import { useState } from "react"; +import { Fragment, useState } from "react"; import { formatNumber } from "@/app/utils"; +import { Dialog, Transition } from "@headlessui/react"; +import RecommendationTable from "@/app/components/building-passport/RecommendationTable"; +import { ColumnDef } from "@tanstack/react-table"; +import { Checkbox } from "@/app/shadcn_components/ui/checkbox"; + +export const uvalueColumns: ColumnDef[] = [ + { + accessorKey: "description", + header: "Description", + }, + { + accessorKey: "estimatedCost", + header: "Estimated Cost", + }, + { + accessorKey: "newUValue", + header: "New U-Value", + }, + { + accessorKey: "default", + id: "default", + header: ({ table }) => ( + table.toggleAllPageRowsSelected(!!value)} + aria-label="Select all" + /> + ), + cell: ({ row }) => ( + row.toggleSelected(!!value)} + aria-label="Select row" + /> + ), + enableSorting: false, + enableHiding: false, + }, +]; + +export function RecommendationModal({ + title, + isOpen = false, + setIsOpen, + recommendationData, +}: { + title: string; + isOpen: boolean; + setIsOpen: (isOpen: boolean) => void; + recommendationData: ComponentRecommendation[]; +}) { + const [portfolioName, setPortfolioName] = useState(""); + const [budget, setBudget] = useState(undefined); + const [selectedOutcome, setSelectedOutcome] = useState("None"); + const [buttonDisabled, setButtonDisabled] = useState(true); + + function closeModal() { + setIsOpen(false); + } + + function handlePortfolioNameChange(e: React.ChangeEvent) { + if (e.target.value.length > 0) { + setButtonDisabled(false); + } else { + setButtonDisabled(true); + } + setPortfolioName(e.target.value); + } + + return ( + <> + + + +
+ + +
+
+ + + + {title} + + +
+ + + + +
+
+
+
+
+
+
+ + ); +} export default function RecommendationCard({ componentType, @@ -17,12 +160,13 @@ export default function RecommendationCard({ const [cardComponent, setCardComponent] = useState(defaultComponent); + const [modalIsOpen, setModalIsOpen] = useState(false); + return (
{ - console.log("clicked"); - // replace with your modal opening logic + setModalIsOpen(true); }} >

{componentType}

@@ -30,17 +174,23 @@ export default function RecommendationCard({ - + {cardComponent.newUValue && ( - + )}
Estimated Cost:Estimated Cost: {"£" + formatNumber(cardComponent.estimatedCost)}
New U-Value:New U-Value: {cardComponent.newUValue}
+
); } diff --git a/src/app/components/building-passport/RecommendationTable.tsx b/src/app/components/building-passport/RecommendationTable.tsx new file mode 100644 index 0000000..dbc4640 --- /dev/null +++ b/src/app/components/building-passport/RecommendationTable.tsx @@ -0,0 +1,84 @@ +"use client"; + +import { + flexRender, + getCoreRowModel, + useReactTable, + ColumnDef, +} from "@tanstack/react-table"; + +import { + Table, + TableBody, + TableCell, + TableHead, + TableHeader, + TableRow, +} from "@/app/shadcn_components/ui/table"; + +import { ComponentRecommendation } from "@/app/db/schema/recommendations"; + +interface DataTableProps { + columns: ColumnDef[]; + data: T[]; +} + +export default function RecommendationTable({ + data, + columns, +}: DataTableProps) { + // Initialise the table + + const table = useReactTable({ + data, + columns, + getCoreRowModel: getCoreRowModel(), + }); + + return ( +
+ + + {table.getHeaderGroups().map((headerGroup) => ( + + {headerGroup.headers.map((header) => { + return ( + + {header.isPlaceholder + ? null + : flexRender( + header.column.columnDef.header, + header.getContext() + )} + + ); + })} + + ))} + + + {table.getRowModel().rows?.length ? ( + table.getRowModel().rows.map((row) => ( + + {row.getVisibleCells().map((cell) => ( + + {flexRender(cell.column.columnDef.cell, cell.getContext())} + + ))} + + )) + ) : ( + + + No results. + + + )} + +
+
+ ); +} diff --git a/src/app/shadcn_components/ui/checkbox.tsx b/src/app/shadcn_components/ui/checkbox.tsx new file mode 100644 index 0000000..df61a13 --- /dev/null +++ b/src/app/shadcn_components/ui/checkbox.tsx @@ -0,0 +1,30 @@ +"use client" + +import * as React from "react" +import * as CheckboxPrimitive from "@radix-ui/react-checkbox" +import { Check } from "lucide-react" + +import { cn } from "@/lib/utils" + +const Checkbox = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + + + + + +)) +Checkbox.displayName = CheckboxPrimitive.Root.displayName + +export { Checkbox }