diff --git a/client/src/components/report-center-modal/report-center-modal-filters-sorters-component.jsx b/client/src/components/report-center-modal/report-center-modal-filters-sorters-component.jsx index 7c7b3cc98..60a437bfc 100644 --- a/client/src/components/report-center-modal/report-center-modal-filters-sorters-component.jsx +++ b/client/src/components/report-center-modal/report-center-modal-filters-sorters-component.jsx @@ -119,7 +119,7 @@ function FiltersSection({filters, form, bodyshop}) { const type = filters.find(f => f.name === name)?.type; const reflector = filters.find(f => f.name === name)?.reflector; const operator = form.getFieldValue(['filters', field.name, "operator"]); - const operatorType = getWhereOperatorsByType(type).find((o) => o.value === operator)?.type; + const operatorType = operator ? getWhereOperatorsByType(type).find((o) => o.value === operator)?.type : null; return trigger.parentNode} @@ -184,7 +185,8 @@ function FiltersSection({filters, form, bodyshop}) { if (type === "number") { return ( form.setFieldValue(fieldPath, value)}/> + disabled={!operator} + onChange={(value) => form.setFieldValue(fieldPath, value)}/> ); } @@ -192,6 +194,7 @@ function FiltersSection({filters, form, bodyshop}) { if (type === "date") { return ( form.setFieldValue(fieldPath, date)} /> ); @@ -201,14 +204,15 @@ function FiltersSection({filters, form, bodyshop}) { if (type === "boolean" || type === "bool") { return ( form.setFieldValue(fieldPath, e.target.value)}/> + disabled={!operator} + onChange={(e) => form.setFieldValue(fieldPath, e.target.value)}/> ); })() } diff --git a/client/src/components/report-center-modal/report-center-modal-utils.js b/client/src/components/report-center-modal/report-center-modal-utils.js index 2f9fc5e87..7fd5c54a9 100644 --- a/client/src/components/report-center-modal/report-center-modal-utils.js +++ b/client/src/components/report-center-modal/report-center-modal-utils.js @@ -38,6 +38,14 @@ const generateOptionsFromObject = (bodyshop, path, labelPath, valuePath) => { })), 'value'); } +const generateOptionsFromArray = (bodyshop, path) => { + const options = getValueFromPath(bodyshop, path); + return uniqBy(options.map((value) => ({ + label: value, + value: value, + })), 'value'); +} + /** * Generate special reflections * @param bodyshop @@ -46,15 +54,15 @@ const generateOptionsFromObject = (bodyshop, path, labelPath, valuePath) => { */ const generateSpecialReflections = (bodyshop, finalPath) => { switch (finalPath) { + // Special case because Referral Sources is an Array, not an Object. + case 'referral_source': + return generateOptionsFromArray(bodyshop, 'md_referral_sources'); + case 'class': + return generateOptionsFromArray(bodyshop, 'md_classes'); case 'cost_centers': return generateOptionsFromObject(bodyshop, 'md_responsibility_centers.costs', 'name', 'name'); - // Special case because Categories is an Array, not an Object. case 'categories': - const catOptions = getValueFromPath(bodyshop, 'md_categories'); - return uniqBy(catOptions.map((value) => ({ - label: value, - value: value, - })), 'value'); + return generateOptionsFromArray(bodyshop, 'md_categories'); case 'insurance_companies': return generateOptionsFromObject(bodyshop, 'md_ins_cos', 'name', 'name'); case 'employee_teams': @@ -118,4 +126,4 @@ const generateInternalReflections = ({bodyshop, upperPath, finalPath}) => { } }; -export {generateInternalReflections,} \ No newline at end of file +export {generateInternalReflections,} diff --git a/client/src/translations/en_us/common.json b/client/src/translations/en_us/common.json index c3b8b86e1..172bf8141 100644 --- a/client/src/translations/en_us/common.json +++ b/client/src/translations/en_us/common.json @@ -2708,7 +2708,9 @@ "advanced_filters_filters": "Filters", "advanced_filters_hide": "Hide", "advanced_filters_show": "Show", - "advanced_filters_sorter_direction": "Direction", + "advanced_filters_true": "True", + "advanced_filters_false": "False", + "advanced_filters_sorter_direction": "Direction", "advanced_filters_sorter_field": "Field", "advanced_filters_sorters": "Sorters", "dates": "Dates", diff --git a/client/src/translations/es/common.json b/client/src/translations/es/common.json index 4ab898459..d6204cb54 100644 --- a/client/src/translations/es/common.json +++ b/client/src/translations/es/common.json @@ -2708,6 +2708,8 @@ "advanced_filters_filters": "", "advanced_filters_hide": "", "advanced_filters_show": "", + "advanced_filters_true": "", + "advanced_filters_false": "", "advanced_filters_sorter_direction": "", "advanced_filters_sorter_field": "", "advanced_filters_sorters": "", diff --git a/client/src/translations/fr/common.json b/client/src/translations/fr/common.json index e14ebe4af..e8570c6ec 100644 --- a/client/src/translations/fr/common.json +++ b/client/src/translations/fr/common.json @@ -2708,6 +2708,8 @@ "advanced_filters_filters": "", "advanced_filters_hide": "", "advanced_filters_show": "", + "advanced_filters_true": "", + "advanced_filters_false": "", "advanced_filters_sorter_direction": "", "advanced_filters_sorter_field": "", "advanced_filters_sorters": "", diff --git a/client/src/utils/graphQLmodifier.js b/client/src/utils/graphQLmodifier.js index 96f31f94c..c74fd9b94 100644 --- a/client/src/utils/graphQLmodifier.js +++ b/client/src/utils/graphQLmodifier.js @@ -19,6 +19,30 @@ const STRING_OPERATORS = [ {value: "_nin", label: "not in", type: "array"} ]; +/** + * The available operators for filtering (dates) + * @type {[{label: string, value: string},{label: string, value: string},{label: string, value: string},{label: string, value: string},{label: string, value: string},null,null,null]} + */ +const DATE_OPERATORS = [ + {value: "_eq", label: "equals"}, + {value: "_neq", label: "does not equal"}, + {value: "_gt", label: "greater than"}, + {value: "_lt", label: "less than"}, + {value: "_gte", label: "greater than or equal"}, + {value: "_lte", label: "less than or equal"}, + {value: "_in", label: "in", type: "array"}, + {value: "_nin", label: "not in", type: "array"} +]; + +/** + * The available operators for filtering (booleans) + * @type {[{label: string, value: string},{label: string, value: string}]} + */ +const BOOLEAN_OPERATORS = [ + {value: "_eq", label: "equals"}, + {value: "_neq", label: "does not equal"}, +]; + /** * The available operators for filtering (numbers) * @type {[{label: string, value: string},{label: string, value: string},{label: string, value: string},{label: string, value: string},{label: string, value: string},null,null,null]} @@ -58,8 +82,11 @@ export function getOrderOperatorsByType() { */ export function getWhereOperatorsByType(type = 'string') { const operators = { - string: STRING_OPERATORS, - number: NUMBER_OPERATORS + string: STRING_OPERATORS, + number: NUMBER_OPERATORS, + boolean: BOOLEAN_OPERATORS, + bool: BOOLEAN_OPERATORS, + date: DATE_OPERATORS }; return operators[type]; }