|
@@ -27,12 +27,14 @@ import Popover, { PopoverOrigin } from "@mui/material/Popover";
|
|
|
import Select, { SelectChangeEvent } from "@mui/material/Select";
|
|
|
import TextField from "@mui/material/TextField";
|
|
|
import Tooltip from "@mui/material/Tooltip";
|
|
|
+import Switch from "@mui/material/Switch";
|
|
|
import { DateField, LocalizationProvider } from "@mui/x-date-pickers";
|
|
|
import { AdapterDateFns } from "@mui/x-date-pickers/AdapterDateFnsV3";
|
|
|
|
|
|
import { ColumnDesc, defaultDateFormat, getSortByIndex, iconInRowSx, FilterDesc } from "./tableUtils";
|
|
|
import { getDateTime, getTypeFromDf } from "../../utils";
|
|
|
import { getSuffixedClassNames } from "./utils";
|
|
|
+import { MatchCase } from "../icons/MatchCase";
|
|
|
|
|
|
interface TableFilterProps {
|
|
|
columns: Record<string, ColumnDesc>;
|
|
@@ -92,7 +94,13 @@ const getActionsByType = (colType?: string) =>
|
|
|
(colType && colType in actionsByType && actionsByType[colType]) ||
|
|
|
(colType === "any" ? { ...actionsByType.string, ...actionsByType.number } : actionsByType.string);
|
|
|
|
|
|
-const getFilterDesc = (columns: Record<string, ColumnDesc>, colId?: string, act?: string, val?: string) => {
|
|
|
+const getFilterDesc = (
|
|
|
+ columns: Record<string, ColumnDesc>,
|
|
|
+ colId?: string,
|
|
|
+ act?: string,
|
|
|
+ val?: string,
|
|
|
+ matchCase?: boolean
|
|
|
+) => {
|
|
|
if (colId && act && val !== undefined) {
|
|
|
const colType = getTypeFromDf(columns[colId].type);
|
|
|
if (val === "" && (colType === "date" || colType === "number" || colType === "boolean")) {
|
|
@@ -113,6 +121,7 @@ const getFilterDesc = (columns: Record<string, ColumnDesc>, colId?: string, act?
|
|
|
: val
|
|
|
: val,
|
|
|
type: colType,
|
|
|
+ matchCase: !!matchCase,
|
|
|
} as FilterDesc;
|
|
|
} catch (e) {
|
|
|
console.info("could not parse value ", val, e);
|
|
@@ -126,9 +135,15 @@ const FilterRow = (props: FilterRowProps) => {
|
|
|
const [colId, setColId] = useState<string>("");
|
|
|
const [action, setAction] = useState<string>("");
|
|
|
const [val, setVal] = useState<string>("");
|
|
|
+ const [matchCase, setMatchCase] = useState<boolean>(false);
|
|
|
const [enableCheck, setEnableCheck] = useState(false);
|
|
|
const [enableDel, setEnableDel] = useState(false);
|
|
|
|
|
|
+ // Function to handle case-sensitivity toggle
|
|
|
+ const toggleMatchCase = useCallback(() => {
|
|
|
+ setMatchCase((prev) => !prev);
|
|
|
+ }, []);
|
|
|
+
|
|
|
const onColSelect = useCallback(
|
|
|
(e: SelectChangeEvent<string>) => {
|
|
|
setColId(e.target.value);
|
|
@@ -136,6 +151,7 @@ const FilterRow = (props: FilterRowProps) => {
|
|
|
},
|
|
|
[columns, action, val]
|
|
|
);
|
|
|
+
|
|
|
const onActSelect = useCallback(
|
|
|
(e: SelectChangeEvent<string>) => {
|
|
|
setAction(e.target.value);
|
|
@@ -143,6 +159,7 @@ const FilterRow = (props: FilterRowProps) => {
|
|
|
},
|
|
|
[columns, colId, val]
|
|
|
);
|
|
|
+
|
|
|
const onValueChange = useCallback(
|
|
|
(e: ChangeEvent<HTMLInputElement>) => {
|
|
|
setVal(e.target.value);
|
|
@@ -150,13 +167,16 @@ const FilterRow = (props: FilterRowProps) => {
|
|
|
},
|
|
|
[columns, colId, action]
|
|
|
);
|
|
|
+
|
|
|
const onValueAutoComp = useCallback(
|
|
|
(e: SyntheticEvent, value: string | null) => {
|
|
|
- setVal(value || "");
|
|
|
- setEnableCheck(!!getFilterDesc(columns, colId, action, value || ""));
|
|
|
+ const inputValue = value || "";
|
|
|
+ setVal(inputValue);
|
|
|
+ setEnableCheck(!!getFilterDesc(columns, colId, action, inputValue));
|
|
|
},
|
|
|
[columns, colId, action]
|
|
|
);
|
|
|
+
|
|
|
const onValueSelect = useCallback(
|
|
|
(e: SelectChangeEvent<string>) => {
|
|
|
setVal(e.target.value);
|
|
@@ -164,6 +184,7 @@ const FilterRow = (props: FilterRowProps) => {
|
|
|
},
|
|
|
[columns, colId, action]
|
|
|
);
|
|
|
+
|
|
|
const onDateChange = useCallback(
|
|
|
(v: Date | null) => {
|
|
|
const dv = !(v instanceof Date) || isNaN(v.valueOf()) ? "" : v.toISOString();
|
|
@@ -174,10 +195,11 @@ const FilterRow = (props: FilterRowProps) => {
|
|
|
);
|
|
|
|
|
|
const onDeleteClick = useCallback(() => setFilter(idx, undefined as unknown as FilterDesc, true), [idx, setFilter]);
|
|
|
+
|
|
|
const onCheckClick = useCallback(() => {
|
|
|
- const fd = getFilterDesc(columns, colId, action, val);
|
|
|
+ const fd = getFilterDesc(columns, colId, action, val, matchCase);
|
|
|
fd && setFilter(idx, fd);
|
|
|
- }, [idx, setFilter, columns, colId, action, val]);
|
|
|
+ }, [idx, setFilter, columns, colId, action, val, matchCase]);
|
|
|
|
|
|
useEffect(() => {
|
|
|
if (filter && idx > -1) {
|
|
@@ -280,9 +302,24 @@ const FilterRow = (props: FilterRowProps) => {
|
|
|
onChange={onValueChange}
|
|
|
label={`${val ? "" : "Empty "}String`}
|
|
|
margin="dense"
|
|
|
+ slotProps={{
|
|
|
+ input: {
|
|
|
+ endAdornment: (
|
|
|
+ <Switch
|
|
|
+ onChange={toggleMatchCase}
|
|
|
+ checked={matchCase}
|
|
|
+ size="small"
|
|
|
+ checkedIcon={<MatchCase />}
|
|
|
+ icon={<MatchCase color="disabled" />}
|
|
|
+ inputProps={{ "aria-label": "Case Sensitive Toggle" }}
|
|
|
+ />
|
|
|
+ ),
|
|
|
+ },
|
|
|
+ }}
|
|
|
/>
|
|
|
)}
|
|
|
</Grid>
|
|
|
+
|
|
|
<Grid size={1}>
|
|
|
<Tooltip title="Validate">
|
|
|
<span>
|