mirror of
https://github.com/Kingsrook/qqq-frontend-material-dashboard.git
synced 2025-07-19 05:40:44 +00:00
Checkpoint; nearing completion of custom filter panel
This commit is contained in:
@ -25,13 +25,42 @@ import {QFieldType} from "@kingsrook/qqq-frontend-core/lib/model/metaData/QField
|
||||
import {QInstance} from "@kingsrook/qqq-frontend-core/lib/model/metaData/QInstance";
|
||||
import {QTableMetaData} from "@kingsrook/qqq-frontend-core/lib/model/metaData/QTableMetaData";
|
||||
import {QRecord} from "@kingsrook/qqq-frontend-core/lib/model/QRecord";
|
||||
import {getGridDateOperators, GridColDef, GridRowsProp} from "@mui/x-data-grid-pro";
|
||||
import {GridColDef, GridFilterItem, GridRowsProp} from "@mui/x-data-grid-pro";
|
||||
import {GridFilterOperator} from "@mui/x-data-grid/models/gridFilterOperator";
|
||||
import React from "react";
|
||||
import {Link} from "react-router-dom";
|
||||
import {buildQGridPvsOperators, QGridBooleanOperators, QGridNumericOperators, QGridStringOperators} from "qqq/pages/records/query/GridFilterOperators";
|
||||
import ValueUtils from "qqq/utils/qqq/ValueUtils";
|
||||
|
||||
|
||||
const emptyApplyFilterFn = (filterItem: GridFilterItem, column: GridColDef): null => null;
|
||||
|
||||
function NullInputComponent()
|
||||
{
|
||||
return (<React.Fragment />);
|
||||
}
|
||||
|
||||
const makeGridFilterOperator = (value: string, label: string, takesValues: boolean = false): GridFilterOperator =>
|
||||
{
|
||||
const rs: GridFilterOperator = {value: value, label: label, getApplyFilterFn: emptyApplyFilterFn};
|
||||
if (takesValues)
|
||||
{
|
||||
rs.InputComponent = NullInputComponent;
|
||||
}
|
||||
return (rs);
|
||||
};
|
||||
|
||||
const QGridDateOperators = [
|
||||
makeGridFilterOperator("equals", "equals", true),
|
||||
makeGridFilterOperator("isNot", "not equals", true),
|
||||
makeGridFilterOperator("after", "is after", true),
|
||||
makeGridFilterOperator("onOrAfter", "is on or after", true),
|
||||
makeGridFilterOperator("before", "is before", true),
|
||||
makeGridFilterOperator("onOrBefore", "is on or before", true),
|
||||
makeGridFilterOperator("isEmpty", "is empty"),
|
||||
makeGridFilterOperator("isNotEmpty", "is not empty"),
|
||||
];
|
||||
|
||||
export default class DataGridUtils
|
||||
{
|
||||
|
||||
@ -40,7 +69,7 @@ export default class DataGridUtils
|
||||
*******************************************************************************/
|
||||
public static makeRows = (results: QRecord[], tableMetaData: QTableMetaData): GridRowsProp[] =>
|
||||
{
|
||||
const fields = [ ...tableMetaData.fields.values() ];
|
||||
const fields = [...tableMetaData.fields.values()];
|
||||
const rows = [] as any[];
|
||||
let rowIndex = 0;
|
||||
results.forEach((record: QRecord) =>
|
||||
@ -188,6 +217,7 @@ export default class DataGridUtils
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@ -220,12 +250,12 @@ export default class DataGridUtils
|
||||
case QFieldType.DATE:
|
||||
columnType = "date";
|
||||
columnWidth = 100;
|
||||
filterOperators = getGridDateOperators();
|
||||
filterOperators = QGridDateOperators;
|
||||
break;
|
||||
case QFieldType.DATE_TIME:
|
||||
columnType = "dateTime";
|
||||
columnWidth = 200;
|
||||
filterOperators = getGridDateOperators(true);
|
||||
filterOperators = QGridDateOperators;
|
||||
break;
|
||||
case QFieldType.BOOLEAN:
|
||||
columnType = "string"; // using boolean gives an odd 'no' for nulls.
|
||||
|
@ -264,10 +264,10 @@ class FilterUtils
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
return ([null, null]);
|
||||
}
|
||||
return (FilterUtils.prepFilterValuesForBackend(value, fieldMetaData));
|
||||
return (FilterUtils.cleanseCriteriaValueForQQQ(value, fieldMetaData));
|
||||
}
|
||||
|
||||
return (FilterUtils.prepFilterValuesForBackend([value], fieldMetaData));
|
||||
return (FilterUtils.cleanseCriteriaValueForQQQ([value], fieldMetaData));
|
||||
};
|
||||
|
||||
|
||||
@ -278,7 +278,7 @@ class FilterUtils
|
||||
**
|
||||
** Or, if the values are date-times, convert them to UTC.
|
||||
*******************************************************************************/
|
||||
private static prepFilterValuesForBackend = (param: any[], fieldMetaData: QFieldMetaData): number[] | string[] =>
|
||||
private static cleanseCriteriaValueForQQQ = (param: any[], fieldMetaData: QFieldMetaData): number[] | string[] =>
|
||||
{
|
||||
if (param === null || param === undefined)
|
||||
{
|
||||
@ -291,10 +291,15 @@ class FilterUtils
|
||||
console.log(param[i]);
|
||||
if (param[i] && param[i].id && param[i].label)
|
||||
{
|
||||
/////////////////////////////////////////////////////////////
|
||||
// if the param looks like a possible value, return its id //
|
||||
/////////////////////////////////////////////////////////////
|
||||
rs.push(param[i].id);
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
// if the param looks like a possible value, return its id //
|
||||
// during build of new custom filter panel, this ended up causing us //
|
||||
// problems (because we wanted the full PV object in the filter model for the frontend) //
|
||||
// so, we can keep the PV as-is here, and see calls to convertFilterPossibleValuesToIds //
|
||||
// to do what this used to do. //
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
// rs.push(param[i].id);
|
||||
rs.push(param[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -464,7 +469,16 @@ class FilterUtils
|
||||
amount = -amount;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////
|
||||
// shift the date/time by the input amount //
|
||||
/////////////////////////////////////////////
|
||||
value.setTime(value.getTime() + 1000 * amount);
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
// now also shift from local-timezone into UTC //
|
||||
/////////////////////////////////////////////////
|
||||
value.setTime(value.getTime() + 1000 * 60 * value.getTimezoneOffset());
|
||||
|
||||
values = [ValueUtils.formatDateTimeISO8601(value)];
|
||||
}
|
||||
}
|
||||
@ -598,7 +612,7 @@ class FilterUtils
|
||||
/*******************************************************************************
|
||||
** build a qqq filter from a grid and column sort model
|
||||
*******************************************************************************/
|
||||
public static buildQFilterFromGridFilter(tableMetaData: QTableMetaData, filterModel: GridFilterModel, columnSortModel: GridSortItem[], limit?: number): QQueryFilter
|
||||
public static buildQFilterFromGridFilter(tableMetaData: QTableMetaData, filterModel: GridFilterModel, columnSortModel: GridSortItem[], limit?: number, allowIncompleteCriteria = false): QQueryFilter
|
||||
{
|
||||
console.log("Building q filter with model:");
|
||||
console.log(filterModel);
|
||||
@ -638,13 +652,15 @@ class FilterUtils
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// if no value set and not 'empty' or 'not empty' operators, skip this filter //
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
if ((!item.value || item.value.length == 0) && item.operatorValue !== "isEmpty" && item.operatorValue !== "isNotEmpty")
|
||||
if ((!item.value || item.value.length == 0 || (item.value.length == 1 && item.value[0] == "")) && item.operatorValue !== "isEmpty" && item.operatorValue !== "isNotEmpty")
|
||||
{
|
||||
return;
|
||||
if (!allowIncompleteCriteria)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
var fieldMetadata = tableMetaData?.fields.get(item.columnField);
|
||||
|
||||
const fieldMetadata = tableMetaData?.fields.get(item.columnField);
|
||||
const operator = FilterUtils.gridCriteriaOperatorToQQQ(item.operatorValue);
|
||||
const values = FilterUtils.gridCriteriaValueToQQQ(operator, item.value, item.operatorValue, fieldMetadata);
|
||||
qFilter.addCriteria(new QFilterCriteria(item.columnField, operator, values));
|
||||
@ -664,6 +680,33 @@ class FilterUtils
|
||||
return qFilter;
|
||||
};
|
||||
|
||||
|
||||
public static convertFilterPossibleValuesToIds(inputFilter: QQueryFilter): QQueryFilter
|
||||
{
|
||||
const filter = Object.assign({}, inputFilter);
|
||||
|
||||
if (filter.criteria)
|
||||
{
|
||||
for (let i = 0; i < filter.criteria.length; i++)
|
||||
{
|
||||
const criteria = filter.criteria[i];
|
||||
if (criteria.values)
|
||||
{
|
||||
for (let j = 0; j < criteria.values.length; j++)
|
||||
{
|
||||
let value = criteria.values[j];
|
||||
if (value && value.id && value.label)
|
||||
{
|
||||
criteria.values[j] = value.id;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (filter);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default FilterUtils;
|
||||
|
Reference in New Issue
Block a user