[WEB-811] chore: filter dropdown custom date select improvement (#4043)

* fix: handled custom start_date and target_date custom filter in project-issues

* chore: filter dropdown improvement

---------

Co-authored-by: gurusainath <gurusainath007@gmail.com>
This commit is contained in:
Anmol Singh Bhatia 2024-03-22 18:38:39 +05:30 committed by GitHub
parent e4211e5817
commit 5c7886d7f3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 48 additions and 4 deletions

View File

@ -109,8 +109,10 @@ export const CycleIssuesHeader: React.FC = observer(() => {
const newValues = issueFilters?.filters?.[key] ?? []; const newValues = issueFilters?.filters?.[key] ?? [];
if (Array.isArray(value)) { if (Array.isArray(value)) {
// this validation is majorly for the filter start_date, target_date custom
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 (issueFilters?.filters?.[key]?.includes(value)) newValues.splice(newValues.indexOf(value), 1); if (issueFilters?.filters?.[key]?.includes(value)) newValues.splice(newValues.indexOf(value), 1);
@ -224,7 +226,9 @@ export const CycleIssuesHeader: React.FC = observer(() => {
className="ml-1.5 flex-shrink-0 truncate" className="ml-1.5 flex-shrink-0 truncate"
placement="bottom-start" placement="bottom-start"
> >
{currentProjectCycleIds?.map((cycleId) => <CycleDropdownOption key={cycleId} cycleId={cycleId} />)} {currentProjectCycleIds?.map((cycleId) => (
<CycleDropdownOption key={cycleId} cycleId={cycleId} />
))}
</CustomMenu> </CustomMenu>
} }
/> />

View File

@ -56,8 +56,10 @@ export const GlobalIssuesHeader: React.FC<Props> = observer((props) => {
const newValues = issueFilters?.filters?.[key] ?? []; const newValues = issueFilters?.filters?.[key] ?? [];
if (Array.isArray(value)) { if (Array.isArray(value)) {
// this validation is majorly for the filter start_date, target_date custom
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 (issueFilters?.filters?.[key]?.includes(value)) newValues.splice(newValues.indexOf(value), 1); if (issueFilters?.filters?.[key]?.includes(value)) newValues.splice(newValues.indexOf(value), 1);

View File

@ -110,8 +110,10 @@ export const ModuleIssuesHeader: React.FC = observer(() => {
const newValues = issueFilters?.filters?.[key] ?? []; const newValues = issueFilters?.filters?.[key] ?? [];
if (Array.isArray(value)) { if (Array.isArray(value)) {
// this validation is majorly for the filter start_date, target_date custom
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 (issueFilters?.filters?.[key]?.includes(value)) newValues.splice(newValues.indexOf(value), 1); if (issueFilters?.filters?.[key]?.includes(value)) newValues.splice(newValues.indexOf(value), 1);
@ -225,7 +227,9 @@ export const ModuleIssuesHeader: React.FC = observer(() => {
className="ml-1.5 flex-shrink-0" className="ml-1.5 flex-shrink-0"
placement="bottom-start" placement="bottom-start"
> >
{projectModuleIds?.map((moduleId) => <ModuleDropdownOption key={moduleId} moduleId={moduleId} />)} {projectModuleIds?.map((moduleId) => (
<ModuleDropdownOption key={moduleId} moduleId={moduleId} />
))}
</CustomMenu> </CustomMenu>
} }
/> />

View File

@ -38,8 +38,10 @@ export const ProjectDraftIssueHeader: FC = observer(() => {
const newValues = issueFilters?.filters?.[key] ?? []; const newValues = issueFilters?.filters?.[key] ?? [];
if (Array.isArray(value)) { if (Array.isArray(value)) {
// this validation is majorly for the filter start_date, target_date custom
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 (issueFilters?.filters?.[key]?.includes(value)) newValues.splice(newValues.indexOf(value), 1); if (issueFilters?.filters?.[key]?.includes(value)) newValues.splice(newValues.indexOf(value), 1);

View File

@ -60,8 +60,10 @@ export const ProjectIssuesHeader: React.FC = observer(() => {
const newValues = issueFilters?.filters?.[key] ?? []; const newValues = issueFilters?.filters?.[key] ?? [];
if (Array.isArray(value)) { if (Array.isArray(value)) {
// this validation is majorly for the filter start_date, target_date custom
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 (issueFilters?.filters?.[key]?.includes(value)) newValues.splice(newValues.indexOf(value), 1); if (issueFilters?.filters?.[key]?.includes(value)) newValues.splice(newValues.indexOf(value), 1);

View File

@ -74,8 +74,10 @@ export const ProjectViewIssuesHeader: React.FC = observer(() => {
const newValues = issueFilters?.filters?.[key] ?? []; const newValues = issueFilters?.filters?.[key] ?? [];
if (Array.isArray(value)) { if (Array.isArray(value)) {
// this validation is majorly for the filter start_date, target_date custom
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 (issueFilters?.filters?.[key]?.includes(value)) newValues.splice(newValues.indexOf(value), 1); if (issueFilters?.filters?.[key]?.includes(value)) newValues.splice(newValues.indexOf(value), 1);

View File

@ -25,6 +25,17 @@ export const FilterStartDate: React.FC<Props> = observer((props) => {
d.name.toLowerCase().includes(searchQuery.toLowerCase()) d.name.toLowerCase().includes(searchQuery.toLowerCase())
); );
const isCustomDateSelected = () => {
const isCustomFateApplied = appliedFilters?.filter((f) => f.includes("-")) || [];
return isCustomFateApplied.length > 0 ? true : false;
};
const handleCustomDate = () => {
if (isCustomDateSelected()) {
const updateAppliedFilters = appliedFilters?.filter((f) => f.includes("-")) || [];
handleUpdate(updateAppliedFilters);
} else setIsDateFilterModalOpen(true);
};
return ( return (
<> <>
{isDateFilterModalOpen && ( {isDateFilterModalOpen && (
@ -53,7 +64,7 @@ export const FilterStartDate: 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

@ -25,6 +25,17 @@ export const FilterTargetDate: React.FC<Props> = observer((props) => {
d.name.toLowerCase().includes(searchQuery.toLowerCase()) d.name.toLowerCase().includes(searchQuery.toLowerCase())
); );
const isCustomDateSelected = () => {
const isCustomFateApplied = appliedFilters?.filter((f) => f.includes("-")) || [];
return isCustomFateApplied.length > 0 ? true : false;
};
const handleCustomDate = () => {
if (isCustomDateSelected()) {
const updateAppliedFilters = appliedFilters?.filter((f) => f.includes("-")) || [];
handleUpdate(updateAppliedFilters);
} else setIsDateFilterModalOpen(true);
};
return ( return (
<> <>
{isDateFilterModalOpen && ( {isDateFilterModalOpen && (
@ -53,7 +64,7 @@ export const FilterTargetDate: 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

@ -52,8 +52,10 @@ export const IssuesMobileHeader = observer(() => {
const newValues = issueFilters?.filters?.[key] ?? []; const newValues = issueFilters?.filters?.[key] ?? [];
if (Array.isArray(value)) { if (Array.isArray(value)) {
// this validation is majorly for the filter start_date, target_date custom
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 (issueFilters?.filters?.[key]?.includes(value)) newValues.splice(newValues.indexOf(value), 1); if (issueFilters?.filters?.[key]?.includes(value)) newValues.splice(newValues.indexOf(value), 1);

View File

@ -54,8 +54,10 @@ export const ModuleMobileHeader = observer(() => {
const newValues = issueFilters?.filters?.[key] ?? []; const newValues = issueFilters?.filters?.[key] ?? [];
if (Array.isArray(value)) { if (Array.isArray(value)) {
// this validation is majorly for the filter start_date, target_date custom
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 (issueFilters?.filters?.[key]?.includes(value)) newValues.splice(newValues.indexOf(value), 1); if (issueFilters?.filters?.[key]?.includes(value)) newValues.splice(newValues.indexOf(value), 1);

View File

@ -44,8 +44,10 @@ export const ProfileIssuesFilter = observer(() => {
const newValues = issueFilters?.filters?.[key] ?? []; const newValues = issueFilters?.filters?.[key] ?? [];
if (Array.isArray(value)) { if (Array.isArray(value)) {
// this validation is majorly for the filter start_date, target_date custom
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 (issueFilters?.filters?.[key]?.includes(value)) newValues.splice(newValues.indexOf(value), 1); if (issueFilters?.filters?.[key]?.includes(value)) newValues.splice(newValues.indexOf(value), 1);