{"version":3,"file":"Filter-CMZforsT.js","sources":["../../../frontend/src/Utils/filters.ts","../../../frontend/src/Components/Dashboard/Tables/Filter.tsx"],"sourcesContent":["import { useSearchParams } from 'react-router-dom';\n\nexport const FILTER_QUESTION_PREFIX = 'question_';\n\n// Get the question option ids from the keys starting with 'question_' in the filter object\nexport const getQuestionOptionIds = () => {\n const [searchParams] = useSearchParams();\n const filter = JSON.parse(searchParams.get('filter') || '{}');\n\n return Object.keys(filter)\n .filter((key) => key.startsWith(FILTER_QUESTION_PREFIX))\n .map((key) => filter[key])\n .flat();\n};\n\n// Remove the keys starting with 'question_' from the filter object\nexport const removeQuestionFilter = (filter: any) => {\n const newFilter = { ...filter };\n\n Object.keys(filter).forEach((key) => {\n if (key.startsWith(FILTER_QUESTION_PREFIX)) {\n delete newFilter[key];\n }\n });\n\n return newFilter;\n};\n\nexport const getFiltersValues = (searchQueryKey: string = 'filter') => {\n const [searchParams] = useSearchParams();\n const filter = JSON.parse(searchParams.get(searchQueryKey) || '{}');\n const questionOptionIds = getQuestionOptionIds();\n const cleanedFilter = removeQuestionFilter(filter);\n\n return {\n ...cleanedFilter,\n question_option_ids: questionOptionIds,\n };\n};\n\nexport const sortDirection = (sort: string | null) => (sort?.startsWith('-') ? 'desc' : 'asc');\n\nexport const toggleSortParamDirection = (direction: string, sortAttr: string) =>\n direction === 'desc' ? sortAttr : `-${sortAttr}`;\n\nexport const isSortActive = (sort: string | null, paramName: string | null) => {\n if (!sort || !paramName) {\n return false;\n }\n\n return sort.includes(paramName);\n};\n","import React from 'react';\nimport { Checkbox, Autocomplete, TextField, Popper } from '@mui/material';\nimport { useSearchParams } from 'react-router-dom';\nimport { useIntl } from 'react-intl';\n\ninterface FilterProps {\n name: string;\n label: string;\n items: any;\n placeholder?: string | React.ReactNode;\n blankOption?: boolean;\n searchQueryKey?: string;\n}\n\nfunction Filter({\n name,\n label,\n placeholder,\n items,\n blankOption,\n searchQueryKey = 'filter',\n}: FilterProps) {\n const intl = useIntl();\n const [searchParams, setSearchParams] = useSearchParams();\n const filter = JSON.parse(searchParams.get(searchQueryKey) || '{}');\n const value = filter[name] || [];\n\n items = blankOption\n ? [...items, { value: 'blank', label: intl.formatMessage({ id: 'DASHBOARD.FILTERS.BLANK' }) }]\n : items;\n\n const onFilterUpdate = (key: string, filterValue: any) => {\n // When updating a filter, we reset the page offset\n searchParams.delete('page');\n searchParams.set(searchQueryKey, JSON.stringify({ ...filter, [key]: filterValue }));\n setSearchParams(searchParams);\n };\n\n const CustomPopper = (props: any) => {\n return ;\n };\n\n return (\n option.label}\n value={items.filter((item: any) => value.includes(item.value))}\n onChange={(_event: any, newValue: any) =>\n onFilterUpdate(\n name,\n newValue.map((item: any) => item.value),\n )\n }\n renderOption={(props, option, { selected }) => (\n \n \n {option.label}\n \n )}\n renderInput={(params) => (\n \n )}\n limitTags={1}\n />\n );\n}\n\nexport default Filter;\n"],"names":["FILTER_QUESTION_PREFIX","getQuestionOptionIds","_useSearchParams","useSearchParams","_useSearchParams2","_slicedToArray","searchParams","filter","JSON","parse","get","Object","keys","key","startsWith","map","flat","removeQuestionFilter","newFilter","_objectSpread","forEach","getFiltersValues","searchQueryKey","arguments","length","undefined","_useSearchParams3","_useSearchParams4","questionOptionIds","cleanedFilter","question_option_ids","sortDirection","sort","toggleSortParamDirection","direction","sortAttr","concat","isSortActive","paramName","includes","Filter","_ref","name","label","placeholder","items","blankOption","_ref$searchQueryKey","intl","useIntl","setSearchParams","value","_toConsumableArray","formatMessage","id","onFilterUpdate","filterValue","set","stringify","_defineProperty","CustomPopper","props","createElement","Popper","_extends","style","width","minWidth","React","Autocomplete","multiple","disableCloseOnSelect","options","disablePortal","slotProps","popper","component","getOptionLabel","option","item","onChange","_event","newValue","renderOption","_ref2","selected","Checkbox","color","checked","renderInput","params","TextField","variant","limitTags"],"mappings":";u1BAEO,IAAMA,EAAyB,YAGzBC,EAAuB,UAAM,CACxCC,IAAAA,EAAuBC,IAAiBC,EAAAC,EAAAH,EAAA,CA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