From 11cda36cf90a08763aa9e760e6303fcc5f2f774d Mon Sep 17 00:00:00 2001 From: Varun Murlidhar Date: Fri, 5 Apr 2024 15:18:37 -0400 Subject: [PATCH] Pass row content into drawer --- compass/components/Table/Index.tsx | 13 ++++++++++++- compass/components/Table/RowOpenAction.tsx | 4 ++-- compass/components/page/Drawer.tsx | 17 +++++++++++------ compass/package-lock.json | 1 - 4 files changed, 25 insertions(+), 10 deletions(-) diff --git a/compass/components/Table/Index.tsx b/compass/components/Table/Index.tsx index 7b5ee92..7beaff7 100644 --- a/compass/components/Table/Index.tsx +++ b/compass/components/Table/Index.tsx @@ -8,6 +8,7 @@ import { getCoreRowModel, useReactTable, } from "@tanstack/react-table"; + import { useState } from "react"; import { RowOptionMenu } from "./RowOptionMenu"; import { RowOpenAction } from "./RowOpenAction"; @@ -39,7 +40,7 @@ export const Table = () => { }), columnHelper.accessor("username", { header: () => <> Username, - cell: (info) => , + cell: (info) => , }), columnHelper.accessor("role", { cell: (info) => , @@ -61,6 +62,16 @@ export const Table = () => { getCoreRowModel: getCoreRowModel(), }); + const handleRowData = (row: any) => { + const rowData: any = {}; + row.cells.forEach((cell: any) => { + rowData[cell.column.id] = cell.value; + }); + // Use rowData object containing data from all columns for the current row + console.log(rowData); + return rowData; + }; + return (
diff --git a/compass/components/Table/RowOpenAction.tsx b/compass/components/Table/RowOpenAction.tsx index 30d1cd3..0543dfc 100644 --- a/compass/components/Table/RowOpenAction.tsx +++ b/compass/components/Table/RowOpenAction.tsx @@ -1,7 +1,7 @@ import Drawer from "@/components/page/Drawer"; import {ChangeEvent, useState} from "react"; -export const RowOpenAction = ({ title }) => { +export const RowOpenAction = ({ title, rowData }) => { const [pageContent, setPageContent] = useState("") const handleDrawerContentChange = (newContent) => { @@ -14,7 +14,7 @@ export const RowOpenAction = ({ title }) => {
{title} - {pageContent} + {pageContent}
); diff --git a/compass/components/page/Drawer.tsx b/compass/components/page/Drawer.tsx index d848923..8991247 100644 --- a/compass/components/page/Drawer.tsx +++ b/compass/components/page/Drawer.tsx @@ -15,6 +15,7 @@ type DrawerProps = { disabled?: boolean; editableContent?: any; onSave?: (content: any) => void; + rowContent?: any; }; interface EditContent { @@ -23,7 +24,7 @@ interface EditContent { } -const Drawer: FunctionComponent = ({ title, children, onSave, editableContent }) => { +const Drawer: FunctionComponent = ({ title, children, onSave, editableContent, rowContent }) => { const [isOpen, setIsOpen] = useState(false); const [isFull, setIsFull] = useState(false); const [isEditing, setIsEditing] = useState(false); @@ -56,8 +57,8 @@ const Drawer: FunctionComponent = ({ title, children, onSave, edita const newContents = editContents.map((item, idx) => idx === index ? { ...item, content: event.target.value } : item); setEditContents(newContents); }; - const drawerClassName = `fixed top-0 right-0 h-full bg-white shadow-xl transform ease-in-out duration-300 ${ - isOpen ? "translate-x-0" : "translate-x-full" + const drawerClassName = `fixed top-0 right-0 h-full bg-white transform ease-in-out duration-300 ${ + isOpen ? "translate-x-0 shadow-xl" : "translate-x-full" } ${isFull ? "w-full" : "w-1/2"}`; @@ -97,17 +98,21 @@ const Drawer: FunctionComponent = ({ title, children, onSave, edita const favoriteIcon = isFavorite ? : + // const buttonStyle = `ml-2 uppercase opacity-0 group-hover:opacity-100 text-gray-500 font-medium border bg-white ${isOpen ? `border-gray-200` : ``} shadow hover:bg-gray-50 p-2 rounded-md` + return (
- } text="Resources" onClick={() => handleCardClick("Resources", )}/> + {/* } text="Open" onClick={() => handleCardClick("Resources", )}/> */} + +
-
+
{currentCardIcon} -

{currentCardText}

+

{rowContent.username}