Skip to content

Commit

Permalink
Rendered cell tooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
minhtuevo committed Nov 19, 2024
1 parent c71f7ce commit eddfc71
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions app/packages/core/src/plugins/SchemaIO/components/TableView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
TableContainer,
TableHead,
TableRow,
Tooltip,
useTheme,
} from "@mui/material";
import { isPlainObject } from "lodash";
Expand Down Expand Up @@ -65,6 +66,14 @@ export default function TableView(props: ViewPropsType) {
return computedRowActions;
}, []);

const getTooltips = useCallback((tooltipList) => {
const tooltipDict = {};
for (const { value, row, column } of tooltipList) {
tooltipDict[`${row},${column}`] = value; // Create a key from row and column
}
return tooltipDict;
}, []);

const handleCellClick = useCallback(
(row, column) => {
if (on_click_cell) {
Expand Down Expand Up @@ -95,6 +104,7 @@ export default function TableView(props: ViewPropsType) {
color: theme.palette.text.secondary,
};
const filled = variant === "filled";
const tooltipMap = getTooltips(tooltips);

return (
<Box {...getComponentProps(props, "container")}>
Expand Down Expand Up @@ -172,13 +182,14 @@ export default function TableView(props: ViewPropsType) {
selectedCells.has(coordinate) ||
isRowSelected ||
selectedColumns.has(columnIndex);
return (

const tooltip = tooltipMap[coordinate]; // Check if there's a tooltip for the cell

const cell = (
<TableCell
key={key}
sx={{
background: isSelected
? selectedCellColor
: "unset",
background: isSelected ? selectedCellColor : "unset",
}}
onClick={() => {
handleCellClick(rowIndex, columnIndex);
Expand All @@ -188,7 +199,16 @@ export default function TableView(props: ViewPropsType) {
{formatCellValue(item[key], props)}
</TableCell>
);

return tooltip ? (
<Tooltip key={key} title={tooltip} arrow>
{cell}
</Tooltip>
) : (
cell
);
})}

{hasRowActions && (
<TableCell
align="right"
Expand Down

0 comments on commit eddfc71

Please sign in to comment.