2024-01-18 10:19:54 +00:00
|
|
|
import { endOfMonth, endOfWeek, endOfYear, startOfMonth, startOfWeek, startOfYear } from "date-fns";
|
|
|
|
// helpers
|
2024-03-06 08:54:36 +00:00
|
|
|
import { renderFormattedDate, renderFormattedPayloadDate } from "./date-time.helper";
|
2024-01-18 10:19:54 +00:00
|
|
|
// types
|
2024-03-06 13:16:36 +00:00
|
|
|
import { TIssuesListTypes } from "@plane/types";
|
2024-03-06 08:54:36 +00:00
|
|
|
// constants
|
2024-03-06 13:16:36 +00:00
|
|
|
import { DURATION_FILTER_OPTIONS, EDurationFilters } from "constants/dashboard";
|
2024-01-18 10:19:54 +00:00
|
|
|
|
2024-02-08 12:27:22 +00:00
|
|
|
/**
|
|
|
|
* @description returns date range based on the duration filter
|
|
|
|
* @param duration
|
|
|
|
*/
|
2024-03-06 08:54:36 +00:00
|
|
|
export const getCustomDates = (duration: EDurationFilters, customDates: string[]): string => {
|
2024-01-18 10:19:54 +00:00
|
|
|
const today = new Date();
|
|
|
|
let firstDay, lastDay;
|
|
|
|
|
|
|
|
switch (duration) {
|
2024-03-06 08:54:36 +00:00
|
|
|
case EDurationFilters.NONE:
|
2024-02-05 13:42:33 +00:00
|
|
|
return "";
|
2024-03-06 08:54:36 +00:00
|
|
|
case EDurationFilters.TODAY:
|
2024-01-18 10:19:54 +00:00
|
|
|
firstDay = renderFormattedPayloadDate(today);
|
|
|
|
lastDay = renderFormattedPayloadDate(today);
|
|
|
|
return `${firstDay};after,${lastDay};before`;
|
2024-03-06 08:54:36 +00:00
|
|
|
case EDurationFilters.THIS_WEEK:
|
2024-01-18 10:19:54 +00:00
|
|
|
firstDay = renderFormattedPayloadDate(startOfWeek(today));
|
|
|
|
lastDay = renderFormattedPayloadDate(endOfWeek(today));
|
|
|
|
return `${firstDay};after,${lastDay};before`;
|
2024-03-06 08:54:36 +00:00
|
|
|
case EDurationFilters.THIS_MONTH:
|
2024-01-18 10:19:54 +00:00
|
|
|
firstDay = renderFormattedPayloadDate(startOfMonth(today));
|
|
|
|
lastDay = renderFormattedPayloadDate(endOfMonth(today));
|
|
|
|
return `${firstDay};after,${lastDay};before`;
|
2024-03-06 08:54:36 +00:00
|
|
|
case EDurationFilters.THIS_YEAR:
|
2024-01-18 10:19:54 +00:00
|
|
|
firstDay = renderFormattedPayloadDate(startOfYear(today));
|
|
|
|
lastDay = renderFormattedPayloadDate(endOfYear(today));
|
|
|
|
return `${firstDay};after,${lastDay};before`;
|
2024-03-06 08:54:36 +00:00
|
|
|
case EDurationFilters.CUSTOM:
|
|
|
|
return customDates.join(",");
|
2024-01-18 10:19:54 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2024-02-08 12:27:22 +00:00
|
|
|
/**
|
|
|
|
* @description returns redirection filters for the issues list
|
|
|
|
* @param type
|
|
|
|
*/
|
2024-01-18 10:19:54 +00:00
|
|
|
export const getRedirectionFilters = (type: TIssuesListTypes): string => {
|
|
|
|
const today = renderFormattedPayloadDate(new Date());
|
|
|
|
|
|
|
|
const filterParams =
|
2024-02-05 13:42:33 +00:00
|
|
|
type === "pending"
|
|
|
|
? "?state_group=backlog,unstarted,started"
|
|
|
|
: type === "upcoming"
|
2024-03-06 15:20:38 +00:00
|
|
|
? `?target_date=${today};after`
|
|
|
|
: type === "overdue"
|
|
|
|
? `?target_date=${today};before`
|
|
|
|
: "?state_group=completed";
|
2024-01-18 10:19:54 +00:00
|
|
|
|
|
|
|
return filterParams;
|
|
|
|
};
|
2024-02-08 12:27:22 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @description returns the tab key based on the duration filter
|
|
|
|
* @param duration
|
|
|
|
* @param tab
|
|
|
|
*/
|
2024-03-06 08:54:36 +00:00
|
|
|
export const getTabKey = (duration: EDurationFilters, tab: TIssuesListTypes | undefined): TIssuesListTypes => {
|
2024-02-08 12:27:22 +00:00
|
|
|
if (!tab) return "completed";
|
|
|
|
|
|
|
|
if (tab === "completed") return tab;
|
|
|
|
|
|
|
|
if (duration === "none") return "pending";
|
|
|
|
else {
|
|
|
|
if (["upcoming", "overdue"].includes(tab)) return tab;
|
|
|
|
else return "upcoming";
|
|
|
|
}
|
|
|
|
};
|
2024-03-06 08:54:36 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @description returns the label for the duration filter dropdown
|
|
|
|
* @param duration
|
|
|
|
* @param customDates
|
|
|
|
*/
|
|
|
|
export const getDurationFilterDropdownLabel = (duration: EDurationFilters, customDates: string[]): string => {
|
|
|
|
if (duration !== "custom") return DURATION_FILTER_OPTIONS.find((option) => option.key === duration)?.label ?? "";
|
|
|
|
else {
|
|
|
|
const afterDate = customDates.find((date) => date.includes("after"))?.split(";")[0];
|
|
|
|
const beforeDate = customDates.find((date) => date.includes("before"))?.split(";")[0];
|
|
|
|
|
|
|
|
if (afterDate && beforeDate) return `${renderFormattedDate(afterDate)} - ${renderFormattedDate(beforeDate)}`;
|
|
|
|
else if (afterDate) return `After ${renderFormattedDate(afterDate)}`;
|
|
|
|
else if (beforeDate) return `Before ${renderFormattedDate(beforeDate)}`;
|
|
|
|
else return "";
|
|
|
|
}
|
|
|
|
};
|