Skip to content

Commit

Permalink
feat: update row preview component response props to row data (#117) (#…
Browse files Browse the repository at this point in the history
…118)

* feat: update row preview component response props to row data (#117)

* feat: updated typescript for optional table instance (#117)

---------

Co-authored-by: Fran McDade <[email protected]>
  • Loading branch information
frano-m and Fran McDade authored Jul 5, 2024
1 parent b3c1d98 commit fcdb375
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export const DEFAULT_DRAWER_PROPS: Partial<MDrawerProps> = {
PaperProps: {
elevation: 2,
},
SlideProps: { appear: true },
anchor: "right",
disableEnforceFocus: true,
disableScrollLock: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { Drawer, DrawerTitle } from "./rowDrawer.styles";
export interface RowDrawerProps<T extends RowData>
extends Omit<MDrawerProps, "content" | "title"> {
className?: string;
tableInstance: Table<T>;
tableInstance?: Table<T>;
title: ReactNode;
}

Expand All @@ -24,13 +24,14 @@ export const RowDrawer = <T extends RowData>({
title,
...props /* Spread props to allow for Mui Drawer specific prop overrides. */
}: RowDrawerProps<T>): JSX.Element => {
const { getIsRowPreview, resetRowPreview, toggleRowPreview } = tableInstance;
const { getIsRowPreview, resetRowPreview, toggleRowPreview } =
tableInstance || {};
return (
<Drawer
{...DEFAULT_DRAWER_PROPS}
className={className}
onTransitionExited={resetRowPreview}
open={getIsRowPreview()}
open={getIsRowPreview?.()}
{...props}
>
<DrawerTitle
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Grid, Typography } from "@mui/material";
import { RowData, Table } from "@tanstack/react-table";
import { RowData } from "@tanstack/react-table";
import React from "react";
import { ListConfig } from "../../../../../../../../../../config/entities";
import { TEXT_BODY_400 } from "../../../../../../../../../../theme/common/typography";
Expand All @@ -14,19 +14,17 @@ interface RowDetailProps<T extends RowData> {
columns: ListConfig<T>["columns"];
expanded?: boolean;
minColumns?: number;
tableInstance: Table<T>;
rowData: T;
}

export const RowDetail = <T extends RowData>({
className,
columns,
expanded = true,
minColumns = MIN_COLUMNS,
tableInstance,
rowData,
}: RowDetailProps<T>): JSX.Element | null => {
const [showMore, setShowMore] = React.useState<boolean>(expanded);
const { getRowPreviewRow } = tableInstance;
const { original: rowData } = getRowPreviewRow() || {};
const visibleColumns = showMore ? columns : columns.slice(0, minColumns);
const buttonText = showMore ? "Show less" : "Show more";
const onToggleShowMore = (): void => setShowMore(!showMore);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,14 @@ export const RowPreview = <T extends RowData>({
tableInstance,
}: RowPreviewProps<T>): JSX.Element | null => {
if (!rowPreviewView) return null;
const { getRowPreviewRow } = tableInstance;
const { original: response } = getRowPreviewRow() || {};
if (!response) return null;
return (
<ComponentCreator components={rowPreviewView} response={tableInstance} />
<ComponentCreator
components={rowPreviewView}
response={response}
viewContext={{ tableInstance }}
/>
);
};
3 changes: 2 additions & 1 deletion src/config/entities.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TabProps as MTabProps, Theme, ThemeOptions } from "@mui/material";
import { CellContext, ColumnSort, RowData } from "@tanstack/react-table";
import { CellContext, ColumnSort, RowData, Table } from "@tanstack/react-table";
import { JSXElementConstructor, ReactNode } from "react";
import { SelectCategoryValueView, SelectedFilter } from "../common/entities";
import { HeroTitle } from "../components/common/Title/title";
Expand Down Expand Up @@ -435,4 +435,5 @@ export interface ViewContext<T extends RowData, TData = unknown> {
exploreState: ExploreState;
fileManifestState: FileManifestState;
systemStatus: SystemStatus;
tableInstance?: Table<T>;
}

0 comments on commit fcdb375

Please sign in to comment.