From 5d2d9b4741e217a008fb9f4aa88e7a1d4faaa4c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fred=20Lef=C3=A9v=C3=A8re-Laoide?= <90181748+FredLL-Avaiga@users.noreply.github.com> Date: Wed, 29 Nov 2023 17:33:32 +0100 Subject: [PATCH] Table filter layout (#505) (#1030) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Fred Lefévère-Laoide --- .../src/components/Taipy/TableFilter.tsx | 254 +++++++++--------- 1 file changed, 122 insertions(+), 132 deletions(-) diff --git a/frontend/taipy-gui/src/components/Taipy/TableFilter.tsx b/frontend/taipy-gui/src/components/Taipy/TableFilter.tsx index ae579417d..5ff2c5638 100644 --- a/frontend/taipy-gui/src/components/Taipy/TableFilter.tsx +++ b/frontend/taipy-gui/src/components/Taipy/TableFilter.tsx @@ -12,26 +12,26 @@ */ import React, { ChangeEvent, useCallback, useEffect, useRef, useState } from "react"; -import Box from "@mui/material/Box"; +import CheckIcon from "@mui/icons-material/Check"; +import ClearIcon from "@mui/icons-material/Clear"; +import DeleteIcon from "@mui/icons-material/Delete"; +import FilterListIcon from "@mui/icons-material/FilterList"; +import SendIcon from "@mui/icons-material/Send"; import Button from "@mui/material/Button"; -import Popover, { PopoverOrigin } from "@mui/material/Popover"; +import FormControl from "@mui/material/FormControl"; +import Grid from "@mui/material/Grid"; import IconButton from "@mui/material/IconButton"; import InputLabel from "@mui/material/InputLabel"; import MenuItem from "@mui/material/MenuItem"; -import Select, { SelectChangeEvent } from "@mui/material/Select"; -import Tooltip from "@mui/material/Tooltip"; -import FormControl from "@mui/material/FormControl"; import OutlinedInput from "@mui/material/OutlinedInput"; +import Popover, { PopoverOrigin } from "@mui/material/Popover"; +import Select, { SelectChangeEvent } from "@mui/material/Select"; import TextField from "@mui/material/TextField"; -import CheckIcon from "@mui/icons-material/Check"; -import ClearIcon from "@mui/icons-material/Clear"; -import DeleteIcon from "@mui/icons-material/Delete"; -import FilterListIcon from "@mui/icons-material/FilterList"; -import SendIcon from "@mui/icons-material/Send"; +import Tooltip from "@mui/material/Tooltip"; import { DateField, LocalizationProvider } from "@mui/x-date-pickers"; import { AdapterDateFns } from "@mui/x-date-pickers/AdapterDateFns"; -import { ColumnDesc, defaultDateFormat, iconInRowSx, iconsWrapperSx } from "./tableUtils"; +import { ColumnDesc, defaultDateFormat, iconInRowSx } from "./tableUtils"; import { getDateTime, getTypeFromDf } from "../../utils"; import { getSuffixedClassNames } from "./utils"; @@ -83,34 +83,12 @@ const actionsByType = { }, } as Record>; +const gridSx = { p: "0.5em" }; +const rightButtonSx = { ml: "auto" }; + const getActionsByType = (colType?: string) => (colType && colType in actionsByType && actionsByType[colType]) || actionsByType["string"]; -const filtersSx = { - display: "flex", - flexDirection: "column", - alignItems: "stretch", - p: 4, -}; - -const filterBoxSx = { - display: "flex", - flexDirection: "row", - gap: 2, -}; - -const buttonBoxSx = { - display: "flex", - flexDirection: "row", - justifyContent: "space-between", - mt: 2, - gap: 2, -}; - -const colSx = { width: "15em" }; -const actSx = { width: "10em" }; -const valSx = { width: "15em" }; - const getFilterDesc = (columns: Record, colId?: string, act?: string, val?: string) => { if (colId && act && val !== undefined) { const colType = getTypeFromDf(columns[colId].type); @@ -216,83 +194,89 @@ const FilterRow = (props: FilterRowProps) => { const colFormat = colId in columns && columns[colId].format ? columns[colId].format : defaultDateFormat; return ( - - - Column - - - - Action - - - {colType == "number" ? ( - - ) : colType == "boolean" ? ( + + - Boolean - }> + {colsOrder.map((col) => + columns[col].filter ? ( + + {columns[col].title || columns[col].dfid} + + ) : null + )} - ) : colType == "date" ? ( - - ) : ( - - )} - - - - - - - - - - - - - - - + + + + Action + + + + + {colType == "number" ? ( + + ) : colType == "boolean" ? ( + + Boolean + + + ) : colType == "date" ? ( + + ) : ( + + )} + + + + + + + + + + + + + + + + + + + + ); }; @@ -331,7 +315,9 @@ const TableFilter = (props: TableFilterProps) => { }, [onValidate, onShowFilterClick]); useEffect(() => { - columns && appliedFilters && setFilters(appliedFilters.filter((fd) => Object.values(columns).some((cd) => cd.dfid === fd.col))); + columns && + appliedFilters && + setFilters(appliedFilters.filter((fd) => Object.values(columns).some((cd) => cd.dfid === fd.col))); }, [columns, appliedFilters]); return ( @@ -354,7 +340,7 @@ const TableFilter = (props: TableFilterProps) => { onClose={onShowFilterClick} className={getSuffixedClassNames(className, "-filter")} > - + {filters.map((fd, idx) => ( { setFilter={updateFilter} /> - - - - - + + + + + + + + + );