mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
5a32d10f96
* chore: replaced marimekko graph with a bar graph * chore: add bar onClick handler * chore: custom date filter for widgets * style: priority graph * chore: workspace profile activity pagination * chore: profile activity pagination * chore: user profile activity pagination * chore: workspace user activity csv download * chore: download activity button added * chore: workspace user pagination * chore: collabrator pagination * chore: field change * chore: recent collaborators pagination * chore: changed the collabrators * chore: collabrators list changed * fix: distinct users * chore: search filter in collaborators * fix: import error * chore: update priority graph x-axis values * chore: admin and member request validation * chore: update csv download request method * chore: search implementation for the collaborators widget * refactor: priority distribution card * chore: add enum for duration filters * chore: update inbox types * chore: add todos for refactoring --------- Co-authored-by: NarayanBavisetti <narayan3119@gmail.com>
94 lines
3.3 KiB
TypeScript
94 lines
3.3 KiB
TypeScript
import { endOfMonth, endOfWeek, endOfYear, startOfMonth, startOfWeek, startOfYear } from "date-fns";
|
|
// helpers
|
|
import { renderFormattedDate, renderFormattedPayloadDate } from "./date-time.helper";
|
|
// types
|
|
import { EDurationFilters, TIssuesListTypes } from "@plane/types";
|
|
// constants
|
|
import { DURATION_FILTER_OPTIONS } from "constants/dashboard";
|
|
|
|
/**
|
|
* @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 "";
|
|
}
|
|
};
|