Skip to content

Commit

Permalink
[WEB-830] chore: project filter dropdown custom date select option im…
Browse files Browse the repository at this point in the history
…provement (#4069)

* chore: project filter dropdown custom date select option improvement

* fix: project filter custom date
  • Loading branch information
anmolsinghbhatia authored Apr 3, 2024
1 parent 68ebcfd commit e7fc942
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions web/components/headers/projects.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export const ProjectsHeader = observer(() => {
if (Array.isArray(value))
value.forEach((val) => {
if (!newValues.includes(val)) newValues.push(val);
else newValues.splice(newValues.indexOf(val), 1);
});
else {
if (filters?.[key]?.includes(value)) newValues.splice(newValues.indexOf(value), 1);
Expand Down
15 changes: 14 additions & 1 deletion web/components/project/dropdowns/filters/created-at.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { DateFilterModal } from "@/components/core";
import { FilterHeader, FilterOption } from "@/components/issues";
// constants
import { DATE_BEFORE_FILTER_OPTIONS } from "@/constants/filters";
// helpers
import { isDate } from "@/helpers/date-time.helper";

type Props = {
appliedFilters: string[] | null;
Expand All @@ -24,6 +26,17 @@ export const FilterCreatedDate: React.FC<Props> = observer((props) => {
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 (
<>
{isDateFilterModalOpen && (
Expand Down Expand Up @@ -52,7 +65,7 @@ export const FilterCreatedDate: React.FC<Props> = observer((props) => {
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>
Expand Down
4 changes: 4 additions & 0 deletions web/helpers/date-time.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,3 +224,7 @@ export const getDate = (date: string | Date | undefined | null): Date | undefine
return undefined;
}
};
export const isDate = (date: string) => {
const datePattern = /^\d{4}-\d{2}-\d{2}$/;
return datePattern.test(date);
};

0 comments on commit e7fc942

Please sign in to comment.