mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
chore: project date filter updated (#4273)
This commit is contained in:
parent
87737dbfbe
commit
deaa63488b
@ -51,16 +51,19 @@ export const ProjectsHeader = observer(() => {
|
|||||||
const handleFilters = useCallback(
|
const handleFilters = useCallback(
|
||||||
(key: keyof TProjectFilters, value: string | string[]) => {
|
(key: keyof TProjectFilters, value: string | string[]) => {
|
||||||
if (!workspaceSlug) return;
|
if (!workspaceSlug) return;
|
||||||
const newValues = filters?.[key] ?? [];
|
let newValues = filters?.[key] ?? [];
|
||||||
|
if (Array.isArray(value)) {
|
||||||
if (Array.isArray(value))
|
if (key === "created_at" && newValues.find((v) => v.includes("custom"))) newValues = [];
|
||||||
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 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);
|
||||||
else newValues.push(value);
|
else {
|
||||||
|
if (key === "created_at") newValues = [value];
|
||||||
|
else newValues.push(value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
updateFilters(workspaceSlug, { [key]: newValues });
|
updateFilters(workspaceSlug, { [key]: newValues });
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { observer } from "mobx-react-lite";
|
import { observer } from "mobx-react-lite";
|
||||||
import { X } from "lucide-react";
|
import { X } from "lucide-react";
|
||||||
// helpers
|
// helpers
|
||||||
import { DATE_BEFORE_FILTER_OPTIONS } from "@/constants/filters";
|
import { PROJECT_CREATED_AT_FILTER_OPTIONS } from "@/constants/filters";
|
||||||
import { renderFormattedDate } from "@/helpers/date-time.helper";
|
import { renderFormattedDate } from "@/helpers/date-time.helper";
|
||||||
import { capitalizeFirstLetter } from "@/helpers/string.helper";
|
import { capitalizeFirstLetter } from "@/helpers/string.helper";
|
||||||
// constants
|
// constants
|
||||||
@ -18,7 +18,7 @@ export const AppliedDateFilters: React.FC<Props> = observer((props) => {
|
|||||||
const getDateLabel = (value: string): string => {
|
const getDateLabel = (value: string): string => {
|
||||||
let dateLabel = "";
|
let dateLabel = "";
|
||||||
|
|
||||||
const dateDetails = DATE_BEFORE_FILTER_OPTIONS.find((d) => d.value === value);
|
const dateDetails = PROJECT_CREATED_AT_FILTER_OPTIONS.find((d) => d.value === value);
|
||||||
|
|
||||||
if (dateDetails) dateLabel = dateDetails.name;
|
if (dateDetails) dateLabel = dateDetails.name;
|
||||||
else {
|
else {
|
||||||
|
@ -4,7 +4,7 @@ import { observer } from "mobx-react-lite";
|
|||||||
import { DateFilterModal } from "@/components/core";
|
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 { PROJECT_CREATED_AT_FILTER_OPTIONS } from "@/constants/filters";
|
||||||
// helpers
|
// helpers
|
||||||
import { isInDateFormat } from "@/helpers/date-time.helper";
|
import { isInDateFormat } from "@/helpers/date-time.helper";
|
||||||
|
|
||||||
@ -16,13 +16,12 @@ type Props = {
|
|||||||
|
|
||||||
export const FilterCreatedDate: React.FC<Props> = observer((props) => {
|
export const FilterCreatedDate: React.FC<Props> = observer((props) => {
|
||||||
const { appliedFilters, handleUpdate, searchQuery } = props;
|
const { appliedFilters, handleUpdate, searchQuery } = props;
|
||||||
|
// state
|
||||||
const [previewEnabled, setPreviewEnabled] = useState(true);
|
const [previewEnabled, setPreviewEnabled] = useState(true);
|
||||||
const [isDateFilterModalOpen, setIsDateFilterModalOpen] = useState(false);
|
const [isDateFilterModalOpen, setIsDateFilterModalOpen] = useState(false);
|
||||||
|
// derived values
|
||||||
const appliedFiltersCount = appliedFilters?.length ?? 0;
|
const appliedFiltersCount = appliedFilters?.length ?? 0;
|
||||||
|
const filteredOptions = PROJECT_CREATED_AT_FILTER_OPTIONS.filter((d) =>
|
||||||
const filteredOptions = DATE_BEFORE_FILTER_OPTIONS.filter((d) =>
|
|
||||||
d.name.toLowerCase().includes(searchQuery.toLowerCase())
|
d.name.toLowerCase().includes(searchQuery.toLowerCase())
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -62,10 +61,15 @@ export const FilterCreatedDate: React.FC<Props> = observer((props) => {
|
|||||||
isChecked={appliedFilters?.includes(option.value) ? true : false}
|
isChecked={appliedFilters?.includes(option.value) ? true : false}
|
||||||
onClick={() => handleUpdate(option.value)}
|
onClick={() => handleUpdate(option.value)}
|
||||||
title={option.name}
|
title={option.name}
|
||||||
multiple
|
multiple={false}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
<FilterOption isChecked={isCustomDateSelected()} onClick={handleCustomDate} title="Custom" multiple />
|
<FilterOption
|
||||||
|
isChecked={isCustomDateSelected()}
|
||||||
|
onClick={handleCustomDate}
|
||||||
|
title="Custom"
|
||||||
|
multiple={false}
|
||||||
|
/>
|
||||||
</>
|
</>
|
||||||
) : (
|
) : (
|
||||||
<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>
|
||||||
|
@ -31,3 +31,22 @@ export const DATE_BEFORE_FILTER_OPTIONS = [
|
|||||||
value: "1_months;before;fromnow",
|
value: "1_months;before;fromnow",
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
export const PROJECT_CREATED_AT_FILTER_OPTIONS = [
|
||||||
|
{
|
||||||
|
name: "Today",
|
||||||
|
value: "today;custom;custom",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Yesterday",
|
||||||
|
value: "yesterday;custom;custom",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Last 7 days",
|
||||||
|
value: "last_7_days;custom;custom",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Last 30 days",
|
||||||
|
value: "last_30_days;custom;custom",
|
||||||
|
},
|
||||||
|
];
|
||||||
|
@ -36,6 +36,14 @@ export const satisfiesDateFilter = (date: Date, filter: string): boolean => {
|
|||||||
const [value, operator, from] = filter.split(";");
|
const [value, operator, from] = filter.split(";");
|
||||||
|
|
||||||
const dateValue = getDate(value);
|
const dateValue = getDate(value);
|
||||||
|
|
||||||
|
if (operator === "custom" && from === "custom") {
|
||||||
|
if (value === "today") return differenceInCalendarDays(date, new Date()) === 0;
|
||||||
|
if (value === "yesterday") return differenceInCalendarDays(date, new Date()) === -1;
|
||||||
|
if (value === "last_7_days") return differenceInCalendarDays(date, new Date()) >= -7;
|
||||||
|
if (value === "last_30_days") return differenceInCalendarDays(date, new Date()) >= -30;
|
||||||
|
}
|
||||||
|
|
||||||
if (!from && dateValue) {
|
if (!from && dateValue) {
|
||||||
if (operator === "after") return date >= dateValue;
|
if (operator === "after") return date >= dateValue;
|
||||||
if (operator === "before") return date <= dateValue;
|
if (operator === "before") return date <= dateValue;
|
||||||
|
Loading…
Reference in New Issue
Block a user