114 lines
3.1 KiB
JavaScript
114 lines
3.1 KiB
JavaScript
"use strict";
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
exports.getGridSingleSelectQuickFilterFn = exports.getGridSingleSelectOperators = void 0;
|
|
|
|
var _GridFilterInputSingleSelect = require("../components/panel/filterPanel/GridFilterInputSingleSelect");
|
|
|
|
var _GridFilterInputMultipleSingleSelect = require("../components/panel/filterPanel/GridFilterInputMultipleSingleSelect");
|
|
|
|
const parseObjectValue = value => {
|
|
if (value == null || typeof value !== 'object') {
|
|
return value;
|
|
}
|
|
|
|
return value.value;
|
|
};
|
|
|
|
const getGridSingleSelectQuickFilterFn = (value, column, apiRef) => {
|
|
if (!value) {
|
|
return null;
|
|
}
|
|
|
|
const {
|
|
valueOptions,
|
|
valueFormatter,
|
|
field
|
|
} = column;
|
|
const potentialValues = [parseObjectValue(value).toString()];
|
|
const iterableColumnValues = typeof valueOptions === 'function' ? valueOptions({
|
|
field
|
|
}) : valueOptions || [];
|
|
|
|
if (iterableColumnValues) {
|
|
iterableColumnValues.forEach(option => {
|
|
// for each valueOption, check if the formatted value
|
|
let optionValue;
|
|
let optionLabel;
|
|
|
|
if (typeof option === 'object') {
|
|
optionValue = option.value;
|
|
optionLabel = option.label;
|
|
} else {
|
|
optionValue = option;
|
|
|
|
if (valueFormatter) {
|
|
optionLabel = valueFormatter({
|
|
value: option,
|
|
field,
|
|
api: apiRef.current
|
|
});
|
|
} else {
|
|
optionLabel = option;
|
|
}
|
|
}
|
|
|
|
if (optionLabel.slice(0, value.length).toLowerCase() === value.toLowerCase()) {
|
|
if (!potentialValues.includes(optionValue)) {
|
|
potentialValues.push(optionValue.toString());
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
return ({
|
|
value: columnValue
|
|
}) => {
|
|
return columnValue != null ? potentialValues.includes(parseObjectValue(columnValue).toString()) : false;
|
|
};
|
|
};
|
|
|
|
exports.getGridSingleSelectQuickFilterFn = getGridSingleSelectQuickFilterFn;
|
|
|
|
const getGridSingleSelectOperators = () => [{
|
|
value: 'is',
|
|
getApplyFilterFn: filterItem => {
|
|
if (filterItem.value == null || filterItem.value === '') {
|
|
return null;
|
|
}
|
|
|
|
return ({
|
|
value
|
|
}) => parseObjectValue(value) === parseObjectValue(filterItem.value);
|
|
},
|
|
InputComponent: _GridFilterInputSingleSelect.GridFilterInputSingleSelect
|
|
}, {
|
|
value: 'not',
|
|
getApplyFilterFn: filterItem => {
|
|
if (filterItem.value == null || filterItem.value === '') {
|
|
return null;
|
|
}
|
|
|
|
return ({
|
|
value
|
|
}) => parseObjectValue(value) !== parseObjectValue(filterItem.value);
|
|
},
|
|
InputComponent: _GridFilterInputSingleSelect.GridFilterInputSingleSelect
|
|
}, {
|
|
value: 'isAnyOf',
|
|
getApplyFilterFn: filterItem => {
|
|
if (!Array.isArray(filterItem.value) || filterItem.value.length === 0) {
|
|
return null;
|
|
}
|
|
|
|
const filterItemValues = filterItem.value.map(parseObjectValue);
|
|
return ({
|
|
value
|
|
}) => filterItemValues.includes(parseObjectValue(value));
|
|
},
|
|
InputComponent: _GridFilterInputMultipleSingleSelect.GridFilterInputMultipleSingleSelect
|
|
}];
|
|
|
|
exports.getGridSingleSelectOperators = getGridSingleSelectOperators; |