Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>;
}
Loading