mirror of
https://github.com/Kingsrook/qqq-frontend-material-dashboard.git
synced 2025-07-17 21:00:45 +00:00
Merge pull request #43 from Kingsrook/feature/CE-798-quick-filters-fixes
Feature/ce 798 quick filters fixes
This commit is contained in:
@ -30,7 +30,7 @@ import Box from "@mui/material/Box";
|
|||||||
import Button from "@mui/material/Button";
|
import Button from "@mui/material/Button";
|
||||||
import Menu from "@mui/material/Menu";
|
import Menu from "@mui/material/Menu";
|
||||||
import TextField from "@mui/material/TextField";
|
import TextField from "@mui/material/TextField";
|
||||||
import React, {SyntheticEvent, useContext, useState} from "react";
|
import React, {SyntheticEvent, useContext, useReducer, useState} from "react";
|
||||||
import QContext from "QContext";
|
import QContext from "QContext";
|
||||||
import {QFilterCriteriaWithId} from "qqq/components/query/CustomFilterPanel";
|
import {QFilterCriteriaWithId} from "qqq/components/query/CustomFilterPanel";
|
||||||
import {getDefaultCriteriaValue, getOperatorOptions, getValueModeRequiredCount, OperatorOption, validateCriteria} from "qqq/components/query/FilterCriteriaRow";
|
import {getDefaultCriteriaValue, getOperatorOptions, getValueModeRequiredCount, OperatorOption, validateCriteria} from "qqq/components/query/FilterCriteriaRow";
|
||||||
@ -148,7 +148,10 @@ export default function QuickFilter({tableMetaData, fullFieldName, fieldMetaData
|
|||||||
const [anchorEl, setAnchorEl] = useState(null);
|
const [anchorEl, setAnchorEl] = useState(null);
|
||||||
const [isMouseOver, setIsMouseOver] = useState(false);
|
const [isMouseOver, setIsMouseOver] = useState(false);
|
||||||
|
|
||||||
const [criteria, setCriteria] = useState(criteriaParamIsCriteria(criteriaParam) ? criteriaParam as QFilterCriteriaWithId : null);
|
////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// copy the criteriaParam to a new object in here - so changes won't apply until user closes the menu //
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
const [criteria, setCriteria] = useState(criteriaParamIsCriteria(criteriaParam) ? Object.assign({}, criteriaParam) as QFilterCriteriaWithId : null);
|
||||||
const [id, setId] = useState(criteriaParamIsCriteria(criteriaParam) ? (criteriaParam as QFilterCriteriaWithId).id : ++seedId);
|
const [id, setId] = useState(criteriaParamIsCriteria(criteriaParam) ? (criteriaParam as QFilterCriteriaWithId).id : ++seedId);
|
||||||
|
|
||||||
const [operatorSelectedValue, setOperatorSelectedValue] = useState(getOperatorSelectedValue(operatorOptions, criteria, defaultOperator));
|
const [operatorSelectedValue, setOperatorSelectedValue] = useState(getOperatorSelectedValue(operatorOptions, criteria, defaultOperator));
|
||||||
@ -158,6 +161,11 @@ export default function QuickFilter({tableMetaData, fullFieldName, fieldMetaData
|
|||||||
|
|
||||||
const {accentColor} = useContext(QContext);
|
const {accentColor} = useContext(QContext);
|
||||||
|
|
||||||
|
//////////////////////
|
||||||
|
// ole' faithful... //
|
||||||
|
//////////////////////
|
||||||
|
const [, forceUpdate] = useReducer((x) => x + 1, 0);
|
||||||
|
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
**
|
**
|
||||||
@ -182,15 +190,30 @@ export default function QuickFilter({tableMetaData, fullFieldName, fieldMetaData
|
|||||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
if (criteriaParamIsCriteria(criteriaParam) && JSON.stringify(criteriaParam) !== JSON.stringify(criteria))
|
if (criteriaParamIsCriteria(criteriaParam) && JSON.stringify(criteriaParam) !== JSON.stringify(criteria))
|
||||||
{
|
{
|
||||||
const newCriteria = criteriaParam as QFilterCriteriaWithId;
|
if(isOpen)
|
||||||
|
{
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// this was firing too-often for case where: there was a criteria originally //
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
console.log("Not handling outside change (A), because dropdown is-open");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// copy the criteriaParam to a new object in here - so changes won't apply until user closes the menu //
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
const newCriteria = Object.assign({}, criteriaParam) as QFilterCriteriaWithId;
|
||||||
setCriteria(newCriteria);
|
setCriteria(newCriteria);
|
||||||
const operatorOption = operatorOptions.filter(o => o.value == newCriteria.operator)[0];
|
const operatorOption = operatorOptions.filter(o => o.value == newCriteria.operator)[0];
|
||||||
setOperatorSelectedValue(operatorOption);
|
setOperatorSelectedValue(operatorOption);
|
||||||
setOperatorInputValue(operatorOption.label);
|
setOperatorInputValue(operatorOption.label);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
** Test if we need to construct a new criteria object
|
** Test if we need to construct a new criteria object
|
||||||
|
** This is (at least for some cases) for when the criteria gets changed
|
||||||
|
** from outside of this component - e.g., a reset on the query screen
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
const criteriaNeedsReset = (): boolean =>
|
const criteriaNeedsReset = (): boolean =>
|
||||||
{
|
{
|
||||||
@ -199,6 +222,16 @@ export default function QuickFilter({tableMetaData, fullFieldName, fieldMetaData
|
|||||||
const defaultOperatorOption = operatorOptions.filter(o => o.value == defaultOperator)[0];
|
const defaultOperatorOption = operatorOptions.filter(o => o.value == defaultOperator)[0];
|
||||||
if(criteria.operator !== defaultOperatorOption?.value || JSON.stringify(criteria.values) !== JSON.stringify(getDefaultCriteriaValue()))
|
if(criteria.operator !== defaultOperatorOption?.value || JSON.stringify(criteria.values) !== JSON.stringify(getDefaultCriteriaValue()))
|
||||||
{
|
{
|
||||||
|
if(isOpen)
|
||||||
|
{
|
||||||
|
//////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// this was firing too-often for case where: there was no criteria originally, //
|
||||||
|
// so, by adding this is-open check, we eliminated those. //
|
||||||
|
//////////////////////////////////////////////////////////////////////////////////
|
||||||
|
console.log("Not handling outside change (B), because dropdown is-open");
|
||||||
|
return (false);
|
||||||
|
}
|
||||||
|
|
||||||
return (true);
|
return (true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -207,7 +240,7 @@ export default function QuickFilter({tableMetaData, fullFieldName, fieldMetaData
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
** Construct a new criteria object - resetting the values tied to the oprator
|
** Construct a new criteria object - resetting the values tied to the operator
|
||||||
** autocomplete at the same time.
|
** autocomplete at the same time.
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
const makeNewCriteria = (): QFilterCriteria =>
|
const makeNewCriteria = (): QFilterCriteria =>
|
||||||
@ -241,6 +274,11 @@ export default function QuickFilter({tableMetaData, fullFieldName, fieldMetaData
|
|||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
const closeMenu = () =>
|
const closeMenu = () =>
|
||||||
{
|
{
|
||||||
|
//////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// when closing the menu, that's when we'll update the criteria from the caller //
|
||||||
|
//////////////////////////////////////////////////////////////////////////////////
|
||||||
|
updateCriteria(criteria, false, false);
|
||||||
|
|
||||||
setIsOpen(false);
|
setIsOpen(false);
|
||||||
setAnchorEl(null);
|
setAnchorEl(null);
|
||||||
};
|
};
|
||||||
@ -286,7 +324,8 @@ export default function QuickFilter({tableMetaData, fullFieldName, fieldMetaData
|
|||||||
setOperatorInputValue("");
|
setOperatorInputValue("");
|
||||||
}
|
}
|
||||||
|
|
||||||
updateCriteria(criteria, false, false);
|
setCriteria(criteria);
|
||||||
|
forceUpdate();
|
||||||
};
|
};
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
@ -320,7 +359,8 @@ export default function QuickFilter({tableMetaData, fullFieldName, fieldMetaData
|
|||||||
criteria.values[valueIndex] = value;
|
criteria.values[valueIndex] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
updateCriteria(criteria, true, false);
|
setCriteria(criteria);
|
||||||
|
forceUpdate();
|
||||||
};
|
};
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
@ -480,7 +520,12 @@ export default function QuickFilter({tableMetaData, fullFieldName, fieldMetaData
|
|||||||
<Box display="inline-block" width={widthAndMaxWidth} maxWidth={widthAndMaxWidth} className="operatorColumn">
|
<Box display="inline-block" width={widthAndMaxWidth} maxWidth={widthAndMaxWidth} className="operatorColumn">
|
||||||
<Autocomplete
|
<Autocomplete
|
||||||
id={"criteriaOperator"}
|
id={"criteriaOperator"}
|
||||||
renderInput={(params) => (<TextField {...params} label={"Operator"} variant="standard" autoComplete="off" type="search" InputProps={{...params.InputProps}} />)}
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// ok, so, by default, if you type an 'o' as the first letter in the FilterCriteriaRowValues box, //
|
||||||
|
// something is causing THIS element to become selected, if the first letter in its label is 'O'. //
|
||||||
|
// ... work around is to put invisible ‌ entity as first character in label instead... //
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
renderInput={(params) => (<TextField {...params} label={<>‌Operator</>} variant="standard" autoComplete="off" type="search" InputProps={{...params.InputProps}} />)}
|
||||||
options={operatorOptions}
|
options={operatorOptions}
|
||||||
value={operatorSelectedValue as any}
|
value={operatorSelectedValue as any}
|
||||||
inputValue={operatorInputValue}
|
inputValue={operatorInputValue}
|
||||||
|
@ -64,7 +64,6 @@ class FilterUtils
|
|||||||
let rs = [];
|
let rs = [];
|
||||||
for (let i = 0; i < param.length; i++)
|
for (let i = 0; i < param.length; i++)
|
||||||
{
|
{
|
||||||
console.log(param[i]);
|
|
||||||
if (param[i] && param[i].id && param[i].label)
|
if (param[i] && param[i].id && param[i].label)
|
||||||
{
|
{
|
||||||
/////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////
|
||||||
@ -361,7 +360,12 @@ class FilterUtils
|
|||||||
else if (value.type == "ThisOrLastPeriod")
|
else if (value.type == "ThisOrLastPeriod")
|
||||||
{
|
{
|
||||||
const expression = new ThisOrLastPeriodExpression(value);
|
const expression = new ThisOrLastPeriodExpression(value);
|
||||||
labels.push(expression.toString());
|
let startOfPrefix = "";
|
||||||
|
if(fieldMetaData.type == QFieldType.DATE_TIME || expression.timeUnit != "DAYS")
|
||||||
|
{
|
||||||
|
startOfPrefix = "start of ";
|
||||||
|
}
|
||||||
|
labels.push(`${startOfPrefix}${expression.toString()}`);
|
||||||
}
|
}
|
||||||
else if(fieldMetaData.type == QFieldType.BOOLEAN)
|
else if(fieldMetaData.type == QFieldType.BOOLEAN)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user