2024-03-12 14:06:40 +00:00
|
|
|
import { ArrowDownWideNarrow, Check, ChevronDown } from "lucide-react";
|
2024-03-19 14:38:35 +00:00
|
|
|
import { TProjectOrderByOptions } from "@plane/types";
|
2024-03-12 14:06:40 +00:00
|
|
|
// ui
|
|
|
|
import { CustomMenu, getButtonStyling } from "@plane/ui";
|
|
|
|
// helpers
|
2024-03-19 14:38:35 +00:00
|
|
|
import { PROJECT_ORDER_BY_OPTIONS } from "@/constants/project";
|
|
|
|
import { cn } from "@/helpers/common.helper";
|
2024-03-12 14:06:40 +00:00
|
|
|
// types
|
|
|
|
// constants
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
onChange: (value: TProjectOrderByOptions) => void;
|
|
|
|
value: TProjectOrderByOptions | undefined;
|
2024-04-28 19:24:02 +00:00
|
|
|
isMobile?: boolean;
|
2024-03-12 14:06:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const DISABLED_ORDERING_OPTIONS = ["sort_order"];
|
|
|
|
|
|
|
|
export const ProjectOrderByDropdown: React.FC<Props> = (props) => {
|
2024-04-28 19:24:02 +00:00
|
|
|
const { onChange, value, isMobile = false } = props;
|
2024-03-12 14:06:40 +00:00
|
|
|
|
|
|
|
const orderByDetails = PROJECT_ORDER_BY_OPTIONS.find((option) => value?.includes(option.key));
|
|
|
|
|
|
|
|
const isDescending = value?.[0] === "-";
|
|
|
|
const isOrderingDisabled = !!value && DISABLED_ORDERING_OPTIONS.includes(value);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<CustomMenu
|
2024-04-28 19:24:02 +00:00
|
|
|
className={`${isMobile ? "flex w-full justify-center" : ""}`}
|
2024-03-12 14:06:40 +00:00
|
|
|
customButton={
|
2024-04-28 19:24:02 +00:00
|
|
|
<>
|
|
|
|
{isMobile ? (
|
|
|
|
<div className="flex text-sm items-center gap-2 neutral-primary text-custom-text-200">
|
|
|
|
<ArrowDownWideNarrow className="h-3 w-3" />
|
|
|
|
{orderByDetails?.label}
|
|
|
|
<ChevronDown className="h-3 w-3" strokeWidth={2} />
|
|
|
|
</div>
|
|
|
|
) : (
|
|
|
|
<div className={cn(getButtonStyling("neutral-primary", "sm"), "px-2 text-custom-text-200")}>
|
|
|
|
<ArrowDownWideNarrow className="h-3 w-3" />
|
|
|
|
{orderByDetails?.label}
|
|
|
|
<ChevronDown className="h-3 w-3" strokeWidth={2} />
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</>
|
2024-03-12 14:06:40 +00:00
|
|
|
}
|
|
|
|
placement="bottom-end"
|
|
|
|
closeOnSelect
|
|
|
|
>
|
|
|
|
{PROJECT_ORDER_BY_OPTIONS.map((option) => (
|
|
|
|
<CustomMenu.MenuItem
|
|
|
|
key={option.key}
|
|
|
|
className="flex items-center justify-between gap-2"
|
|
|
|
onClick={() => {
|
2024-03-22 12:56:44 +00:00
|
|
|
if (isDescending)
|
|
|
|
onChange(option.key == "sort_order" ? option.key : (`-${option.key}` as TProjectOrderByOptions));
|
2024-03-12 14:06:40 +00:00
|
|
|
else onChange(option.key);
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{option.label}
|
|
|
|
{value?.includes(option.key) && <Check className="h-3 w-3" />}
|
|
|
|
</CustomMenu.MenuItem>
|
|
|
|
))}
|
2024-04-17 15:02:25 +00:00
|
|
|
<hr className="my-2 border-custom-border-200" />
|
2024-03-12 14:06:40 +00:00
|
|
|
<CustomMenu.MenuItem
|
|
|
|
className="flex items-center justify-between gap-2"
|
|
|
|
onClick={() => {
|
|
|
|
if (isDescending) onChange(value.slice(1) as TProjectOrderByOptions);
|
|
|
|
}}
|
|
|
|
disabled={isOrderingDisabled}
|
|
|
|
>
|
|
|
|
Ascending
|
|
|
|
{!isOrderingDisabled && !isDescending && <Check className="h-3 w-3" />}
|
|
|
|
</CustomMenu.MenuItem>
|
|
|
|
<CustomMenu.MenuItem
|
|
|
|
className="flex items-center justify-between gap-2"
|
|
|
|
onClick={() => {
|
|
|
|
if (!isDescending) onChange(`-${value}` as TProjectOrderByOptions);
|
|
|
|
}}
|
|
|
|
disabled={isOrderingDisabled}
|
|
|
|
>
|
|
|
|
Descending
|
|
|
|
{!isOrderingDisabled && isDescending && <Check className="h-3 w-3" />}
|
|
|
|
</CustomMenu.MenuItem>
|
|
|
|
</CustomMenu>
|
|
|
|
);
|
|
|
|
};
|