From 39dc84a38cf158a0052bd40cab3f18eca8db98e2 Mon Sep 17 00:00:00 2001 From: Sidney Alcantara Date: Tue, 15 Nov 2022 18:14:44 +1100 Subject: [PATCH] re-enable cell validation tooltips --- src/components/Table/CellValidation.tsx | 85 +++++++++---------- src/components/Table/Table.tsx | 4 +- .../{TableHeaderGroup.tsx => TableHeader.tsx} | 8 +- 3 files changed, 45 insertions(+), 52 deletions(-) rename src/components/Table/{TableHeaderGroup.tsx => TableHeader.tsx} (97%) diff --git a/src/components/Table/CellValidation.tsx b/src/components/Table/CellValidation.tsx index e19dde1b..6e566487 100644 --- a/src/components/Table/CellValidation.tsx +++ b/src/components/Table/CellValidation.tsx @@ -17,7 +17,6 @@ import { selectedCellAtom, contextMenuTargetAtom, } from "@src/atoms/tableScope"; -import { TABLE_PADDING } from "./Table"; import type { TableRow } from "@src/types/table"; const Dot = styled("div")(({ theme }) => ({ @@ -73,51 +72,29 @@ export const CellValidation = memo(function MemoizedCellValidation({ const isInvalid = validationRegex && !new RegExp(validationRegex).test(value); const isMissing = required && value === undefined; - const renderedCell = ( - - {flexRender(cell.column.columnDef.cell, { - ...cell.getContext(), - focusInsideCell: isSelectedCell && focusInsideCell, - setFocusInsideCell: (focusInside: boolean) => - setSelectedCell({ - path: row.original._rowy_ref.path, - columnKey: cell.column.id, - focusInside, - }), - disabled: - !canEditCells || cell.column.columnDef.meta?.editable === false, - rowHeight, - })} - - ); + let renderedValidationTooltip = null; - // if (isInvalid) - // return ( - // - // } - // title="Invalid data" - // message="This row will not be saved until all the required fields contain valid data" - // placement="right" - // render={({ openTooltip }) => } - // /> - // {children} - // - // ); - - // if (isMissing) - // return ( - // - // } - // title="Required field" - // message="This row will not be saved until all the required fields contain valid data" - // placement="right" - // render={({ openTooltip }) => } - // /> - // {children} - // - // ); + if (isInvalid) { + renderedValidationTooltip = ( + } + title="Invalid data" + message="This row will not be saved until all the required fields contain valid data" + placement="right" + render={({ openTooltip }) => } + /> + ); + } else if (isMissing) { + renderedValidationTooltip = ( + } + title="Required field" + message="This row will not be saved until all the required fields contain valid data" + placement="right" + render={({ openTooltip }) => } + /> + ); + } return ( - {renderedCell} + {renderedValidationTooltip} + + {flexRender(cell.column.columnDef.cell, { + ...cell.getContext(), + focusInsideCell: isSelectedCell && focusInsideCell, + setFocusInsideCell: (focusInside: boolean) => + setSelectedCell({ + path: row.original._rowy_ref.path, + columnKey: cell.column.id, + focusInside, + }), + disabled: + !canEditCells || cell.column.columnDef.meta?.editable === false, + rowHeight, + })} + ); }); diff --git a/src/components/Table/Table.tsx b/src/components/Table/Table.tsx index c7395447..886fdcff 100644 --- a/src/components/Table/Table.tsx +++ b/src/components/Table/Table.tsx @@ -10,7 +10,7 @@ import { DropResult } from "react-beautiful-dnd"; import { get } from "lodash-es"; import StyledTable from "./Styled/StyledTable"; -import TableHeaderGroup from "./TableHeaderGroup"; +import TableHeader from "./TableHeader"; import TableBody from "./TableBody"; import FinalColumn from "./FinalColumn/FinalColumn"; import ContextMenu from "./ContextMenu"; @@ -215,7 +215,7 @@ export default function Table({ padding: `0 ${TABLE_PADDING}px`, }} > - []; handleDropColumn: (result: DropResult) => void; canAddColumns: boolean; @@ -22,13 +22,13 @@ export interface ITableHeaderGroupProps { lastFrozen?: string; } -export const TableHeaderGroup = memo(function TableHeaderGroup({ +export const TableHeader = memo(function TableHeader({ headerGroups, handleDropColumn, canAddColumns, canEditColumns, lastFrozen, -}: ITableHeaderGroupProps) { +}: ITableHeaderProps) { const [selectedCell, setSelectedCell] = useAtom(selectedCellAtom, tableScope); const focusInsideCell = selectedCell?.focusInside ?? false; @@ -190,4 +190,4 @@ export const TableHeaderGroup = memo(function TableHeaderGroup({ ); }); -export default TableHeaderGroup; +export default TableHeader;