From 28869498ae5d376ae090da71538ea23c66970aae Mon Sep 17 00:00:00 2001 From: Mo Tarbin Date: Tue, 3 Feb 2026 00:46:10 -0500 Subject: [PATCH] add points condition evaluation and update filter builder for points selection --- src/utils/Colors.jsx | 4 ++ src/utils/FilterEngine.js | 26 ++++++++ .../Modals/Inputs/AdvancedFilterBuilder.jsx | 63 +++++++++++++++---- 3 files changed, 81 insertions(+), 12 deletions(-) diff --git a/src/utils/Colors.jsx b/src/utils/Colors.jsx index 89768f0..475e628 100644 --- a/src/utils/Colors.jsx +++ b/src/utils/Colors.jsx @@ -30,6 +30,10 @@ export const FILTER_COLORS = [ ...LABEL_COLORS.filter(color => color.name !== 'Default'), ] +export const PROJECT_COLORS = [ + ...LABEL_COLORS.filter(color => color.name !== 'Default'), +] + export const COLORS = { salmon: '#ff7961', teal: '#26a69a', diff --git a/src/utils/FilterEngine.js b/src/utils/FilterEngine.js index 1a263e1..56b0ea3 100644 --- a/src/utils/FilterEngine.js +++ b/src/utils/FilterEngine.js @@ -37,6 +37,9 @@ export const evaluateCondition = (chore, condition, context = {}) => { case 'project': return evaluateProject(chore, operator, value) + case 'points': + return evaluatePoints(chore, operator, value) + default: console.warn(`Unknown condition type: ${type}`) return true @@ -254,6 +257,29 @@ const evaluateProject = (chore, operator, value) => { return operator === 'is' ? isInProject : !isInProject } +/** + * Evaluate points condition + */ +const evaluatePoints = (chore, operator, value) => { + const chorePoints = chore.points || 0 + const targetValue = Number(value) + + switch (operator) { + case 'equals': + return Number(chorePoints) === targetValue + case 'greaterThan': + return Number(chorePoints) > targetValue + case 'lessThan': + return Number(chorePoints) < targetValue + case 'greaterThanOrEqual': + return Number(chorePoints) >= targetValue + case 'lessThanOrEqual': + return Number(chorePoints) <= targetValue + default: + return false + } +} + /** * Apply a complete filter (with multiple conditions) to chores * @param {Array} chores - The chores to filter diff --git a/src/views/Modals/Inputs/AdvancedFilterBuilder.jsx b/src/views/Modals/Inputs/AdvancedFilterBuilder.jsx index 921dc33..de85ab3 100644 --- a/src/views/Modals/Inputs/AdvancedFilterBuilder.jsx +++ b/src/views/Modals/Inputs/AdvancedFilterBuilder.jsx @@ -1,4 +1,4 @@ -import { Add, Delete, Save } from '@mui/icons-material' +import { Add, Delete } from '@mui/icons-material' import { Box, Button, @@ -76,7 +76,7 @@ const AdvancedFilterBuilder = ({ const previewChores = useMemo(() => { const validConditions = conditions.filter(c => { - if (c.type === 'dueDate') return true + if (c.type === 'dueDate' || c.type === 'points') return true return c.value && (Array.isArray(c.value) ? c.value.length > 0 : true) }) @@ -135,6 +135,9 @@ const AdvancedFilterBuilder = ({ updated[index].value = null } else if (value === 'status') { updated[index].value = [3] + } else if (value === 'points') { + updated[index].operator = 'greaterThan' + updated[index].value = 0 } } @@ -154,7 +157,7 @@ const AdvancedFilterBuilder = ({ } const validConditions = conditions.filter(c => { - if (c.type === 'dueDate') return true + if (c.type === 'dueDate' || c.type === 'points') return true return c.value && (Array.isArray(c.value) ? c.value.length > 0 : true) }) @@ -404,7 +407,7 @@ const AdvancedFilterBuilder = ({ case 'status': return ( ) + case 'points': + return ( + + + + updateCondition(index, 'value', parseInt(e.target.value) || 0) + } + sx={{ flex: 1 }} + slotProps={{ + input: { + min: 0, + }, + }} + /> + + ) + default: return null } @@ -465,13 +506,8 @@ const AdvancedFilterBuilder = ({ - } @@ -649,12 +685,15 @@ const AdvancedFilterBuilder = ({ + - {condition.type === 'dueDate' ? 'Condition' : 'Value'} + {condition.type === 'dueDate' || condition.type === 'points' + ? 'Condition' + : 'Value'} {renderValueSelector(condition, index)}