[WEB-830] chore: project filter dropdown custom date select option improvement (#4069)

* chore: project filter dropdown custom date select option improvement

* fix: project filter custom date
This commit is contained in:
Anmol Singh Bhatia 2024-04-03 18:03:16 +05:30 committed by GitHub
parent 68ebcfd04e
commit e7fc942514
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 19 additions and 1 deletions

View File

@ -57,6 +57,7 @@ export const ProjectsHeader = observer(() => {
if (Array.isArray(value)) if (Array.isArray(value))
value.forEach((val) => { value.forEach((val) => {
if (!newValues.includes(val)) newValues.push(val); if (!newValues.includes(val)) newValues.push(val);
else newValues.splice(newValues.indexOf(val), 1);
}); });
else { else {
if (filters?.[key]?.includes(value)) newValues.splice(newValues.indexOf(value), 1); if (filters?.[key]?.includes(value)) newValues.splice(newValues.indexOf(value), 1);

View File

@ -5,6 +5,8 @@ import { DateFilterModal } from "@/components/core";
import { FilterHeader, FilterOption } from "@/components/issues"; import { FilterHeader, FilterOption } from "@/components/issues";
// constants // constants
import { DATE_BEFORE_FILTER_OPTIONS } from "@/constants/filters"; import { DATE_BEFORE_FILTER_OPTIONS } from "@/constants/filters";
// helpers
import { isDate } from "@/helpers/date-time.helper";
type Props = { type Props = {
appliedFilters: string[] | null; appliedFilters: string[] | null;
@ -24,6 +26,17 @@ export const FilterCreatedDate: React.FC<Props> = observer((props) => {
d.name.toLowerCase().includes(searchQuery.toLowerCase()) d.name.toLowerCase().includes(searchQuery.toLowerCase())
); );
const isCustomDateSelected = () => {
const isValidDateSelected = appliedFilters?.filter((f) => isDate(f.split(";")[0])) || [];
return isValidDateSelected.length > 0 ? true : false;
};
const handleCustomDate = () => {
if (isCustomDateSelected()) {
const updateAppliedFilters = appliedFilters?.filter((f) => f.includes("-")) || [];
handleUpdate(updateAppliedFilters);
} else setIsDateFilterModalOpen(true);
};
return ( return (
<> <>
{isDateFilterModalOpen && ( {isDateFilterModalOpen && (
@ -52,7 +65,7 @@ export const FilterCreatedDate: React.FC<Props> = observer((props) => {
multiple multiple
/> />
))} ))}
<FilterOption isChecked={false} onClick={() => setIsDateFilterModalOpen(true)} title="Custom" multiple /> <FilterOption isChecked={isCustomDateSelected()} onClick={handleCustomDate} title="Custom" multiple />
</> </>
) : ( ) : (
<p className="text-xs italic text-custom-text-400">No matches found</p> <p className="text-xs italic text-custom-text-400">No matches found</p>

View File

@ -224,3 +224,7 @@ export const getDate = (date: string | Date | undefined | null): Date | undefine
return undefined; return undefined;
} }
}; };
export const isDate = (date: string) => {
const datePattern = /^\d{4}-\d{2}-\d{2}$/;
return datePattern.test(date);
};