Files
plane/apps/web/helpers/dashboard.helper.ts
chuan 8ebde8aa05
Some checks failed
Branch Build CE / Build Setup (push) Has been cancelled
Branch Build CE / Build-Push Admin Docker Image (push) Has been cancelled
Branch Build CE / Build-Push Web Docker Image (push) Has been cancelled
Branch Build CE / Build-Push Space Docker Image (push) Has been cancelled
Branch Build CE / Build-Push Live Collaboration Docker Image (push) Has been cancelled
Branch Build CE / Build-Push API Server Docker Image (push) Has been cancelled
Branch Build CE / Build-Push Proxy Docker Image (push) Has been cancelled
Branch Build CE / Build-Push AIO Docker Image (push) Has been cancelled
Branch Build CE / Upload Build Assets (push) Has been cancelled
Branch Build CE / Build Release (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
Codespell / Check for spelling errors (push) Has been cancelled
Sync Repositories / sync_changes (push) Has been cancelled
Initial commit: Plane
Synced from upstream: 8853637e981ed7d8a6cff32bd98e7afe20f54362
2025-11-07 00:00:52 +08:00

96 lines
3.3 KiB
TypeScript

import { endOfMonth, endOfWeek, endOfYear, startOfMonth, startOfWeek, startOfYear } from "date-fns";
// helpers
// types
import { DURATION_FILTER_OPTIONS, EDurationFilters } from "@plane/constants";
import type { TIssuesListTypes } from "@plane/types";
// constants
import { renderFormattedDate, renderFormattedPayloadDate } from "@plane/utils";
// -------------------- DEPRECATED --------------------
/**
* @description returns date range based on the duration filter
* @param duration
*/
export const getCustomDates = (duration: EDurationFilters, customDates: string[]): string => {
const today = new Date();
let firstDay, lastDay;
switch (duration) {
case EDurationFilters.NONE:
return "";
case EDurationFilters.TODAY:
firstDay = renderFormattedPayloadDate(today);
lastDay = renderFormattedPayloadDate(today);
return `${firstDay};after,${lastDay};before`;
case EDurationFilters.THIS_WEEK:
firstDay = renderFormattedPayloadDate(startOfWeek(today));
lastDay = renderFormattedPayloadDate(endOfWeek(today));
return `${firstDay};after,${lastDay};before`;
case EDurationFilters.THIS_MONTH:
firstDay = renderFormattedPayloadDate(startOfMonth(today));
lastDay = renderFormattedPayloadDate(endOfMonth(today));
return `${firstDay};after,${lastDay};before`;
case EDurationFilters.THIS_YEAR:
firstDay = renderFormattedPayloadDate(startOfYear(today));
lastDay = renderFormattedPayloadDate(endOfYear(today));
return `${firstDay};after,${lastDay};before`;
case EDurationFilters.CUSTOM:
return customDates.join(",");
}
};
/**
* @description returns redirection filters for the issues list
* @param type
*/
export const getRedirectionFilters = (type: TIssuesListTypes): string => {
const today = renderFormattedPayloadDate(new Date());
const filterParams =
type === "pending"
? "?state_group=backlog,unstarted,started"
: type === "upcoming"
? `?target_date=${today};after`
: type === "overdue"
? `?target_date=${today};before`
: "?state_group=completed";
return filterParams;
};
/**
* @description returns the tab key based on the duration filter
* @param duration
* @param tab
*/
export const getTabKey = (duration: EDurationFilters, tab: TIssuesListTypes | undefined): TIssuesListTypes => {
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";
}
};
/**
* @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 "";
}
};