mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
chore: updated tab navigation logic in the issue modal
This commit is contained in:
parent
3503f50572
commit
3d3bd3f804
@ -1,4 +1,4 @@
|
|||||||
import { Fragment, ReactNode, useRef, useState } from "react";
|
import { Fragment, ReactNode, useEffect, useRef, useState } from "react";
|
||||||
import { observer } from "mobx-react-lite";
|
import { observer } from "mobx-react-lite";
|
||||||
import { ChevronDown } from "lucide-react";
|
import { ChevronDown } from "lucide-react";
|
||||||
import { Combobox } from "@headlessui/react";
|
import { Combobox } from "@headlessui/react";
|
||||||
@ -8,7 +8,6 @@ import { cn } from "@/helpers/common.helper";
|
|||||||
import { useCycle } from "@/hooks/store";
|
import { useCycle } from "@/hooks/store";
|
||||||
import { useDropdownKeyDown } from "@/hooks/use-dropdown-key-down";
|
import { useDropdownKeyDown } from "@/hooks/use-dropdown-key-down";
|
||||||
import useOutsideClickDetector from "@/hooks/use-outside-click-detector";
|
import useOutsideClickDetector from "@/hooks/use-outside-click-detector";
|
||||||
import useOutsideKeydownDetector from "@/hooks/use-outside-keydown-detector";
|
|
||||||
// components
|
// components
|
||||||
import { DropdownButton } from "../buttons";
|
import { DropdownButton } from "../buttons";
|
||||||
// icons
|
// icons
|
||||||
@ -24,6 +23,8 @@ type Props = TDropdownProps & {
|
|||||||
dropdownArrow?: boolean;
|
dropdownArrow?: boolean;
|
||||||
dropdownArrowClassName?: string;
|
dropdownArrowClassName?: string;
|
||||||
onChange: (val: string | null) => void;
|
onChange: (val: string | null) => void;
|
||||||
|
isDropdownOpened?: boolean;
|
||||||
|
onOpen?: () => void;
|
||||||
onClose?: () => void;
|
onClose?: () => void;
|
||||||
projectId: string;
|
projectId: string;
|
||||||
value: string | null;
|
value: string | null;
|
||||||
@ -41,6 +42,8 @@ export const CycleDropdown: React.FC<Props> = observer((props) => {
|
|||||||
dropdownArrowClassName = "",
|
dropdownArrowClassName = "",
|
||||||
hideIcon = false,
|
hideIcon = false,
|
||||||
onChange,
|
onChange,
|
||||||
|
isDropdownOpened,
|
||||||
|
onOpen: onDropdownOpen,
|
||||||
onClose,
|
onClose,
|
||||||
placeholder = "Cycle",
|
placeholder = "Cycle",
|
||||||
placement,
|
placement,
|
||||||
@ -68,6 +71,7 @@ export const CycleDropdown: React.FC<Props> = observer((props) => {
|
|||||||
|
|
||||||
const toggleDropdown = () => {
|
const toggleDropdown = () => {
|
||||||
setIsOpen((prevIsOpen) => !prevIsOpen);
|
setIsOpen((prevIsOpen) => !prevIsOpen);
|
||||||
|
if (!isOpen) onDropdownOpen && onDropdownOpen();
|
||||||
if (isOpen) onClose && onClose();
|
if (isOpen) onClose && onClose();
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -85,7 +89,13 @@ export const CycleDropdown: React.FC<Props> = observer((props) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
useOutsideClickDetector(dropdownRef, handleClose);
|
useOutsideClickDetector(dropdownRef, handleClose);
|
||||||
useOutsideKeydownDetector(dropdownRef, handleClose);
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (isDropdownOpened && !isOpen) setIsOpen(true);
|
||||||
|
}, [isDropdownOpened, isOpen]);
|
||||||
|
useEffect(() => {
|
||||||
|
if (isDropdownOpened === false) setIsOpen(false);
|
||||||
|
}, [isDropdownOpened]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Combobox
|
<Combobox
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import React, { useRef, useState } from "react";
|
import React, { useEffect, useRef, useState } from "react";
|
||||||
import { DayPicker, Matcher } from "react-day-picker";
|
import { DayPicker, Matcher } from "react-day-picker";
|
||||||
import { usePopper } from "react-popper";
|
import { usePopper } from "react-popper";
|
||||||
import { CalendarDays, X } from "lucide-react";
|
import { CalendarDays, X } from "lucide-react";
|
||||||
@ -9,7 +9,6 @@ import { renderFormattedDate, getDate } from "@/helpers/date-time.helper";
|
|||||||
// hooks
|
// hooks
|
||||||
import { useDropdownKeyDown } from "@/hooks/use-dropdown-key-down";
|
import { useDropdownKeyDown } from "@/hooks/use-dropdown-key-down";
|
||||||
import useOutsideClickDetector from "@/hooks/use-outside-click-detector";
|
import useOutsideClickDetector from "@/hooks/use-outside-click-detector";
|
||||||
import useOutsideKeydownDetector from "@/hooks/use-outside-keydown-detector";
|
|
||||||
// components
|
// components
|
||||||
import { DropdownButton } from "./buttons";
|
import { DropdownButton } from "./buttons";
|
||||||
// types
|
// types
|
||||||
@ -24,6 +23,8 @@ type Props = TDropdownProps & {
|
|||||||
minDate?: Date;
|
minDate?: Date;
|
||||||
maxDate?: Date;
|
maxDate?: Date;
|
||||||
onChange: (val: Date | null) => void;
|
onChange: (val: Date | null) => void;
|
||||||
|
isDropdownOpened?: boolean;
|
||||||
|
onOpen?: () => void;
|
||||||
onClose?: () => void;
|
onClose?: () => void;
|
||||||
value: Date | string | null;
|
value: Date | string | null;
|
||||||
closeOnSelect?: boolean;
|
closeOnSelect?: boolean;
|
||||||
@ -44,6 +45,8 @@ export const DateDropdown: React.FC<Props> = (props) => {
|
|||||||
minDate,
|
minDate,
|
||||||
maxDate,
|
maxDate,
|
||||||
onChange,
|
onChange,
|
||||||
|
isDropdownOpened,
|
||||||
|
onOpen: onDropdownOpen,
|
||||||
onClose,
|
onClose,
|
||||||
placeholder = "Date",
|
placeholder = "Date",
|
||||||
placement,
|
placement,
|
||||||
@ -85,7 +88,10 @@ export const DateDropdown: React.FC<Props> = (props) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const toggleDropdown = () => {
|
const toggleDropdown = () => {
|
||||||
if (!isOpen) onOpen();
|
if (!isOpen) {
|
||||||
|
onOpen();
|
||||||
|
onDropdownOpen && onDropdownOpen();
|
||||||
|
}
|
||||||
setIsOpen((prevIsOpen) => !prevIsOpen);
|
setIsOpen((prevIsOpen) => !prevIsOpen);
|
||||||
if (isOpen) onClose && onClose();
|
if (isOpen) onClose && onClose();
|
||||||
};
|
};
|
||||||
@ -104,12 +110,18 @@ export const DateDropdown: React.FC<Props> = (props) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
useOutsideClickDetector(dropdownRef, handleClose);
|
useOutsideClickDetector(dropdownRef, handleClose);
|
||||||
useOutsideKeydownDetector(dropdownRef, handleClose);
|
|
||||||
|
|
||||||
const disabledDays: Matcher[] = [];
|
const disabledDays: Matcher[] = [];
|
||||||
if (minDate) disabledDays.push({ before: minDate });
|
if (minDate) disabledDays.push({ before: minDate });
|
||||||
if (maxDate) disabledDays.push({ after: maxDate });
|
if (maxDate) disabledDays.push({ after: maxDate });
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (isDropdownOpened && !isOpen) setIsOpen(true);
|
||||||
|
}, [isDropdownOpened, isOpen]);
|
||||||
|
useEffect(() => {
|
||||||
|
if (isDropdownOpened === false) setIsOpen(false);
|
||||||
|
}, [isDropdownOpened]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Combobox
|
<Combobox
|
||||||
as="div"
|
as="div"
|
||||||
|
@ -9,7 +9,6 @@ import { cn } from "@/helpers/common.helper";
|
|||||||
import { useApplication, useEstimate } from "@/hooks/store";
|
import { useApplication, useEstimate } from "@/hooks/store";
|
||||||
import { useDropdownKeyDown } from "@/hooks/use-dropdown-key-down";
|
import { useDropdownKeyDown } from "@/hooks/use-dropdown-key-down";
|
||||||
import useOutsideClickDetector from "@/hooks/use-outside-click-detector";
|
import useOutsideClickDetector from "@/hooks/use-outside-click-detector";
|
||||||
import useOutsideKeydownDetector from "@/hooks/use-outside-keydown-detector";
|
|
||||||
// components
|
// components
|
||||||
import { DropdownButton } from "./buttons";
|
import { DropdownButton } from "./buttons";
|
||||||
// helpers
|
// helpers
|
||||||
@ -23,6 +22,8 @@ type Props = TDropdownProps & {
|
|||||||
dropdownArrow?: boolean;
|
dropdownArrow?: boolean;
|
||||||
dropdownArrowClassName?: string;
|
dropdownArrowClassName?: string;
|
||||||
onChange: (val: number | null) => void;
|
onChange: (val: number | null) => void;
|
||||||
|
isDropdownOpened?: boolean;
|
||||||
|
onOpen?: () => void;
|
||||||
onClose?: () => void;
|
onClose?: () => void;
|
||||||
projectId: string;
|
projectId: string;
|
||||||
value: number | null;
|
value: number | null;
|
||||||
@ -48,6 +49,8 @@ export const EstimateDropdown: React.FC<Props> = observer((props) => {
|
|||||||
dropdownArrowClassName = "",
|
dropdownArrowClassName = "",
|
||||||
hideIcon = false,
|
hideIcon = false,
|
||||||
onChange,
|
onChange,
|
||||||
|
isDropdownOpened,
|
||||||
|
onOpen: onDropdownOpen,
|
||||||
onClose,
|
onClose,
|
||||||
placeholder = "Estimate",
|
placeholder = "Estimate",
|
||||||
placement,
|
placement,
|
||||||
@ -121,7 +124,10 @@ export const EstimateDropdown: React.FC<Props> = observer((props) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const toggleDropdown = () => {
|
const toggleDropdown = () => {
|
||||||
if (!isOpen) onOpen();
|
if (!isOpen) {
|
||||||
|
onOpen();
|
||||||
|
onDropdownOpen && onDropdownOpen();
|
||||||
|
}
|
||||||
setIsOpen((prevIsOpen) => !prevIsOpen);
|
setIsOpen((prevIsOpen) => !prevIsOpen);
|
||||||
if (isOpen) onClose && onClose();
|
if (isOpen) onClose && onClose();
|
||||||
};
|
};
|
||||||
@ -147,7 +153,6 @@ export const EstimateDropdown: React.FC<Props> = observer((props) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
useOutsideClickDetector(dropdownRef, handleClose);
|
useOutsideClickDetector(dropdownRef, handleClose);
|
||||||
useOutsideKeydownDetector(dropdownRef, handleClose);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isOpen && inputRef.current) {
|
if (isOpen && inputRef.current) {
|
||||||
@ -155,6 +160,13 @@ export const EstimateDropdown: React.FC<Props> = observer((props) => {
|
|||||||
}
|
}
|
||||||
}, [isOpen]);
|
}, [isOpen]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (isDropdownOpened && !isOpen) setIsOpen(true);
|
||||||
|
}, [isDropdownOpened, isOpen]);
|
||||||
|
useEffect(() => {
|
||||||
|
if (isDropdownOpened === false) setIsOpen(false);
|
||||||
|
}, [isDropdownOpened]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Combobox
|
<Combobox
|
||||||
as="div"
|
as="div"
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { Fragment, useRef, useState } from "react";
|
import { Fragment, useEffect, useRef, useState } from "react";
|
||||||
import { observer } from "mobx-react-lite";
|
import { observer } from "mobx-react-lite";
|
||||||
import { ChevronDown } from "lucide-react";
|
import { ChevronDown } from "lucide-react";
|
||||||
import { Combobox } from "@headlessui/react";
|
import { Combobox } from "@headlessui/react";
|
||||||
@ -7,7 +7,6 @@ import { cn } from "@/helpers/common.helper";
|
|||||||
import { useMember } from "@/hooks/store";
|
import { useMember } from "@/hooks/store";
|
||||||
import { useDropdownKeyDown } from "@/hooks/use-dropdown-key-down";
|
import { useDropdownKeyDown } from "@/hooks/use-dropdown-key-down";
|
||||||
import useOutsideClickDetector from "@/hooks/use-outside-click-detector";
|
import useOutsideClickDetector from "@/hooks/use-outside-click-detector";
|
||||||
import useOutsideKeydownDetector from "@/hooks/use-outside-keydown-detector";
|
|
||||||
// components
|
// components
|
||||||
import { DropdownButton } from "../buttons";
|
import { DropdownButton } from "../buttons";
|
||||||
import { BUTTON_VARIANTS_WITH_TEXT } from "../constants";
|
import { BUTTON_VARIANTS_WITH_TEXT } from "../constants";
|
||||||
@ -20,6 +19,8 @@ import { MemberDropdownProps } from "./types";
|
|||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
projectId?: string;
|
projectId?: string;
|
||||||
|
isDropdownOpened?: boolean;
|
||||||
|
onOpen?: () => void;
|
||||||
onClose?: () => void;
|
onClose?: () => void;
|
||||||
} & MemberDropdownProps;
|
} & MemberDropdownProps;
|
||||||
|
|
||||||
@ -36,6 +37,8 @@ export const MemberDropdown: React.FC<Props> = observer((props) => {
|
|||||||
hideIcon = false,
|
hideIcon = false,
|
||||||
multiple,
|
multiple,
|
||||||
onChange,
|
onChange,
|
||||||
|
isDropdownOpened,
|
||||||
|
onOpen: onDropdownOpen,
|
||||||
onClose,
|
onClose,
|
||||||
placeholder = "Members",
|
placeholder = "Members",
|
||||||
placement,
|
placement,
|
||||||
@ -68,6 +71,7 @@ export const MemberDropdown: React.FC<Props> = observer((props) => {
|
|||||||
|
|
||||||
const toggleDropdown = () => {
|
const toggleDropdown = () => {
|
||||||
setIsOpen((prevIsOpen) => !prevIsOpen);
|
setIsOpen((prevIsOpen) => !prevIsOpen);
|
||||||
|
if (!isOpen) onDropdownOpen && onDropdownOpen();
|
||||||
if (isOpen) onClose && onClose();
|
if (isOpen) onClose && onClose();
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -85,7 +89,13 @@ export const MemberDropdown: React.FC<Props> = observer((props) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
useOutsideClickDetector(dropdownRef, handleClose);
|
useOutsideClickDetector(dropdownRef, handleClose);
|
||||||
useOutsideKeydownDetector(dropdownRef, handleClose);
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (isDropdownOpened && !isOpen) setIsOpen(true);
|
||||||
|
}, [isDropdownOpened, isOpen]);
|
||||||
|
useEffect(() => {
|
||||||
|
if (isDropdownOpened === false) setIsOpen(false);
|
||||||
|
}, [isDropdownOpened]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Combobox
|
<Combobox
|
||||||
|
@ -8,7 +8,6 @@ import { cn } from "@/helpers/common.helper";
|
|||||||
import { useModule } from "@/hooks/store";
|
import { useModule } from "@/hooks/store";
|
||||||
import { useDropdownKeyDown } from "@/hooks/use-dropdown-key-down";
|
import { useDropdownKeyDown } from "@/hooks/use-dropdown-key-down";
|
||||||
import useOutsideClickDetector from "@/hooks/use-outside-click-detector";
|
import useOutsideClickDetector from "@/hooks/use-outside-click-detector";
|
||||||
import useOutsideKeydownDetector from "@/hooks/use-outside-keydown-detector";
|
|
||||||
import { usePlatformOS } from "@/hooks/use-platform-os";
|
import { usePlatformOS } from "@/hooks/use-platform-os";
|
||||||
// components
|
// components
|
||||||
import { DropdownButton } from "../buttons";
|
import { DropdownButton } from "../buttons";
|
||||||
@ -26,6 +25,8 @@ type Props = TDropdownProps & {
|
|||||||
dropdownArrowClassName?: string;
|
dropdownArrowClassName?: string;
|
||||||
projectId: string;
|
projectId: string;
|
||||||
showCount?: boolean;
|
showCount?: boolean;
|
||||||
|
isDropdownOpened?: boolean;
|
||||||
|
onOpen?: () => void;
|
||||||
onClose?: () => void;
|
onClose?: () => void;
|
||||||
} & (
|
} & (
|
||||||
| {
|
| {
|
||||||
@ -158,6 +159,8 @@ export const ModuleDropdown: React.FC<Props> = observer((props) => {
|
|||||||
hideIcon = false,
|
hideIcon = false,
|
||||||
multiple,
|
multiple,
|
||||||
onChange,
|
onChange,
|
||||||
|
isDropdownOpened,
|
||||||
|
onOpen: onDropdownOpen,
|
||||||
onClose,
|
onClose,
|
||||||
placeholder = "Module",
|
placeholder = "Module",
|
||||||
placement,
|
placement,
|
||||||
@ -185,6 +188,7 @@ export const ModuleDropdown: React.FC<Props> = observer((props) => {
|
|||||||
|
|
||||||
const toggleDropdown = () => {
|
const toggleDropdown = () => {
|
||||||
setIsOpen((prevIsOpen) => !prevIsOpen);
|
setIsOpen((prevIsOpen) => !prevIsOpen);
|
||||||
|
if (!isOpen) onDropdownOpen && onDropdownOpen();
|
||||||
if (isOpen) onClose && onClose();
|
if (isOpen) onClose && onClose();
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -202,7 +206,6 @@ export const ModuleDropdown: React.FC<Props> = observer((props) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
useOutsideClickDetector(dropdownRef, handleClose);
|
useOutsideClickDetector(dropdownRef, handleClose);
|
||||||
useOutsideKeydownDetector(dropdownRef, handleClose);
|
|
||||||
|
|
||||||
const comboboxProps: any = {
|
const comboboxProps: any = {
|
||||||
value,
|
value,
|
||||||
@ -217,6 +220,13 @@ export const ModuleDropdown: React.FC<Props> = observer((props) => {
|
|||||||
}
|
}
|
||||||
}, [isOpen]);
|
}, [isOpen]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (isDropdownOpened && !isOpen) setIsOpen(true);
|
||||||
|
}, [isDropdownOpened, isOpen]);
|
||||||
|
useEffect(() => {
|
||||||
|
if (isDropdownOpened === false) setIsOpen(false);
|
||||||
|
}, [isDropdownOpened]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Combobox
|
<Combobox
|
||||||
as="div"
|
as="div"
|
||||||
|
@ -10,7 +10,6 @@ import { ISSUE_PRIORITIES } from "@/constants/issue";
|
|||||||
import { cn } from "@/helpers/common.helper";
|
import { cn } from "@/helpers/common.helper";
|
||||||
import { useDropdownKeyDown } from "@/hooks/use-dropdown-key-down";
|
import { useDropdownKeyDown } from "@/hooks/use-dropdown-key-down";
|
||||||
import useOutsideClickDetector from "@/hooks/use-outside-click-detector";
|
import useOutsideClickDetector from "@/hooks/use-outside-click-detector";
|
||||||
import useOutsideKeydownDetector from "@/hooks/use-outside-keydown-detector";
|
|
||||||
import { usePlatformOS } from "@/hooks/use-platform-os";
|
import { usePlatformOS } from "@/hooks/use-platform-os";
|
||||||
// icons
|
// icons
|
||||||
// helpers
|
// helpers
|
||||||
@ -25,6 +24,8 @@ type Props = TDropdownProps & {
|
|||||||
dropdownArrowClassName?: string;
|
dropdownArrowClassName?: string;
|
||||||
highlightUrgent?: boolean;
|
highlightUrgent?: boolean;
|
||||||
onChange: (val: TIssuePriorities) => void;
|
onChange: (val: TIssuePriorities) => void;
|
||||||
|
isDropdownOpened?: boolean;
|
||||||
|
onOpen?: () => void;
|
||||||
onClose?: () => void;
|
onClose?: () => void;
|
||||||
value: TIssuePriorities;
|
value: TIssuePriorities;
|
||||||
};
|
};
|
||||||
@ -284,6 +285,8 @@ export const PriorityDropdown: React.FC<Props> = (props) => {
|
|||||||
hideIcon = false,
|
hideIcon = false,
|
||||||
highlightUrgent = true,
|
highlightUrgent = true,
|
||||||
onChange,
|
onChange,
|
||||||
|
isDropdownOpened,
|
||||||
|
onOpen: onDropdownOpen,
|
||||||
onClose,
|
onClose,
|
||||||
placement,
|
placement,
|
||||||
showTooltip = false,
|
showTooltip = false,
|
||||||
@ -337,6 +340,7 @@ export const PriorityDropdown: React.FC<Props> = (props) => {
|
|||||||
|
|
||||||
const toggleDropdown = () => {
|
const toggleDropdown = () => {
|
||||||
setIsOpen((prevIsOpen) => !prevIsOpen);
|
setIsOpen((prevIsOpen) => !prevIsOpen);
|
||||||
|
if (!isOpen) onDropdownOpen && onDropdownOpen();
|
||||||
if (isOpen) onClose && onClose();
|
if (isOpen) onClose && onClose();
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -361,7 +365,6 @@ export const PriorityDropdown: React.FC<Props> = (props) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
useOutsideClickDetector(dropdownRef, handleClose);
|
useOutsideClickDetector(dropdownRef, handleClose);
|
||||||
useOutsideKeydownDetector(dropdownRef, handleClose);
|
|
||||||
|
|
||||||
const ButtonToRender = BORDER_BUTTON_VARIANTS.includes(buttonVariant)
|
const ButtonToRender = BORDER_BUTTON_VARIANTS.includes(buttonVariant)
|
||||||
? BorderButton
|
? BorderButton
|
||||||
@ -375,6 +378,13 @@ export const PriorityDropdown: React.FC<Props> = (props) => {
|
|||||||
}
|
}
|
||||||
}, [isOpen]);
|
}, [isOpen]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (isDropdownOpened && !isOpen) setIsOpen(true);
|
||||||
|
}, [isDropdownOpened, isOpen]);
|
||||||
|
useEffect(() => {
|
||||||
|
if (isDropdownOpened === false) setIsOpen(false);
|
||||||
|
}, [isDropdownOpened]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Combobox
|
<Combobox
|
||||||
as="div"
|
as="div"
|
||||||
|
@ -9,7 +9,6 @@ import { cn } from "@/helpers/common.helper";
|
|||||||
import { useApplication, useProjectState } from "@/hooks/store";
|
import { useApplication, useProjectState } from "@/hooks/store";
|
||||||
import { useDropdownKeyDown } from "@/hooks/use-dropdown-key-down";
|
import { useDropdownKeyDown } from "@/hooks/use-dropdown-key-down";
|
||||||
import useOutsideClickDetector from "@/hooks/use-outside-click-detector";
|
import useOutsideClickDetector from "@/hooks/use-outside-click-detector";
|
||||||
import useOutsideKeydownDetector from "@/hooks/use-outside-keydown-detector";
|
|
||||||
// components
|
// components
|
||||||
import { DropdownButton } from "./buttons";
|
import { DropdownButton } from "./buttons";
|
||||||
// icons
|
// icons
|
||||||
@ -24,6 +23,8 @@ type Props = TDropdownProps & {
|
|||||||
dropdownArrow?: boolean;
|
dropdownArrow?: boolean;
|
||||||
dropdownArrowClassName?: string;
|
dropdownArrowClassName?: string;
|
||||||
onChange: (val: string) => void;
|
onChange: (val: string) => void;
|
||||||
|
isDropdownOpened?: boolean;
|
||||||
|
onOpen?: () => void;
|
||||||
onClose?: () => void;
|
onClose?: () => void;
|
||||||
projectId: string;
|
projectId: string;
|
||||||
value: string;
|
value: string;
|
||||||
@ -41,6 +42,8 @@ export const StateDropdown: React.FC<Props> = observer((props) => {
|
|||||||
dropdownArrowClassName = "",
|
dropdownArrowClassName = "",
|
||||||
hideIcon = false,
|
hideIcon = false,
|
||||||
onChange,
|
onChange,
|
||||||
|
isDropdownOpened,
|
||||||
|
onOpen: onDropdownOpen,
|
||||||
onClose,
|
onClose,
|
||||||
placement,
|
placement,
|
||||||
projectId,
|
projectId,
|
||||||
@ -103,7 +106,10 @@ export const StateDropdown: React.FC<Props> = observer((props) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const toggleDropdown = () => {
|
const toggleDropdown = () => {
|
||||||
if (!isOpen) onOpen();
|
if (!isOpen) {
|
||||||
|
onOpen();
|
||||||
|
onDropdownOpen && onDropdownOpen();
|
||||||
|
}
|
||||||
setIsOpen((prevIsOpen) => !prevIsOpen);
|
setIsOpen((prevIsOpen) => !prevIsOpen);
|
||||||
if (isOpen) onClose && onClose();
|
if (isOpen) onClose && onClose();
|
||||||
};
|
};
|
||||||
@ -129,13 +135,18 @@ export const StateDropdown: React.FC<Props> = observer((props) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
useOutsideClickDetector(dropdownRef, handleClose);
|
useOutsideClickDetector(dropdownRef, handleClose);
|
||||||
useOutsideKeydownDetector(dropdownRef, handleClose);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isOpen && inputRef.current) {
|
if (isOpen && inputRef.current) {
|
||||||
inputRef.current.focus();
|
inputRef.current.focus();
|
||||||
}
|
}
|
||||||
}, [isOpen]);
|
}, [isOpen]);
|
||||||
|
useEffect(() => {
|
||||||
|
if (isDropdownOpened && !isOpen) setIsOpen(true);
|
||||||
|
}, [isDropdownOpened, isOpen]);
|
||||||
|
useEffect(() => {
|
||||||
|
if (isDropdownOpened === false) setIsOpen(false);
|
||||||
|
}, [isDropdownOpened]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Combobox
|
<Combobox
|
||||||
|
@ -5,9 +5,9 @@ import { Controller, useForm } from "react-hook-form";
|
|||||||
import { LayoutPanelTop, Sparkle, X } from "lucide-react";
|
import { LayoutPanelTop, Sparkle, X } from "lucide-react";
|
||||||
import { RichTextEditorWithRef } from "@plane/rich-text-editor";
|
import { RichTextEditorWithRef } from "@plane/rich-text-editor";
|
||||||
import type { TIssue, ISearchIssueResponse } from "@plane/types";
|
import type { TIssue, ISearchIssueResponse } from "@plane/types";
|
||||||
// editor
|
|
||||||
// hooks
|
// hooks
|
||||||
import { Button, CustomMenu, Input, Loader, ToggleSwitch, TOAST_TYPE, setToast } from "@plane/ui";
|
import { Button, CustomMenu, Input, Loader, ToggleSwitch, TOAST_TYPE, setToast } from "@plane/ui";
|
||||||
|
// components
|
||||||
import { GptAssistantPopover } from "@/components/core";
|
import { GptAssistantPopover } from "@/components/core";
|
||||||
import {
|
import {
|
||||||
CycleDropdown,
|
CycleDropdown,
|
||||||
@ -22,17 +22,15 @@ import {
|
|||||||
import { ParentIssuesListModal } from "@/components/issues";
|
import { ParentIssuesListModal } from "@/components/issues";
|
||||||
import { IssueLabelSelect } from "@/components/issues/select";
|
import { IssueLabelSelect } from "@/components/issues/select";
|
||||||
import { CreateLabelModal } from "@/components/labels";
|
import { CreateLabelModal } from "@/components/labels";
|
||||||
|
// helpers
|
||||||
import { renderFormattedPayloadDate, getDate } from "@/helpers/date-time.helper";
|
import { renderFormattedPayloadDate, getDate } from "@/helpers/date-time.helper";
|
||||||
import { getChangedIssuefields } from "@/helpers/issue.helper";
|
import { getChangedIssuefields } from "@/helpers/issue.helper";
|
||||||
import { shouldRenderProject } from "@/helpers/project.helper";
|
import { shouldRenderProject } from "@/helpers/project.helper";
|
||||||
|
// hooks
|
||||||
import { useApplication, useEstimate, useIssueDetail, useMention, useProject, useWorkspace } from "@/hooks/store";
|
import { useApplication, useEstimate, useIssueDetail, useMention, useProject, useWorkspace } from "@/hooks/store";
|
||||||
// services
|
// services
|
||||||
import { AIService } from "@/services/ai.service";
|
import { AIService } from "@/services/ai.service";
|
||||||
import { FileService } from "@/services/file.service";
|
import { FileService } from "@/services/file.service";
|
||||||
// components
|
|
||||||
// ui
|
|
||||||
// helpers
|
|
||||||
// types
|
|
||||||
|
|
||||||
const defaultValues: Partial<TIssue> = {
|
const defaultValues: Partial<TIssue> = {
|
||||||
project_id: "",
|
project_id: "",
|
||||||
@ -66,6 +64,19 @@ export interface IssueFormProps {
|
|||||||
const aiService = new AIService();
|
const aiService = new AIService();
|
||||||
const fileService = new FileService();
|
const fileService = new FileService();
|
||||||
|
|
||||||
|
type TCurrentDropdownChoices =
|
||||||
|
| "state_id"
|
||||||
|
| "priority"
|
||||||
|
| "assignee_ids"
|
||||||
|
| "label_ids"
|
||||||
|
| "start_date"
|
||||||
|
| "target_date"
|
||||||
|
| "cycle_id"
|
||||||
|
| "module_ids"
|
||||||
|
| "estimate_point"
|
||||||
|
| "parent_id"
|
||||||
|
| undefined;
|
||||||
|
|
||||||
const TAB_INDICES = [
|
const TAB_INDICES = [
|
||||||
"name",
|
"name",
|
||||||
"description_html",
|
"description_html",
|
||||||
@ -109,6 +120,8 @@ export const IssueFormRoot: FC<IssueFormProps> = observer((props) => {
|
|||||||
const [selectedParentIssue, setSelectedParentIssue] = useState<ISearchIssueResponse | null>(null);
|
const [selectedParentIssue, setSelectedParentIssue] = useState<ISearchIssueResponse | null>(null);
|
||||||
const [gptAssistantModal, setGptAssistantModal] = useState(false);
|
const [gptAssistantModal, setGptAssistantModal] = useState(false);
|
||||||
const [iAmFeelingLucky, setIAmFeelingLucky] = useState(false);
|
const [iAmFeelingLucky, setIAmFeelingLucky] = useState(false);
|
||||||
|
const [currentDropdownState, setCurrentDropdownState] = useState<TCurrentDropdownChoices>(undefined);
|
||||||
|
const handleCurrentDropdownState = (value: TCurrentDropdownChoices) => setCurrentDropdownState(value);
|
||||||
|
|
||||||
// refs
|
// refs
|
||||||
const editorRef = useRef<any>(null);
|
const editorRef = useRef<any>(null);
|
||||||
@ -493,10 +506,15 @@ export const IssueFormRoot: FC<IssueFormProps> = observer((props) => {
|
|||||||
projectId={projectId}
|
projectId={projectId}
|
||||||
buttonVariant="border-with-text"
|
buttonVariant="border-with-text"
|
||||||
tabIndex={getTabIndex("state_id")}
|
tabIndex={getTabIndex("state_id")}
|
||||||
|
// handling the current dropdown state
|
||||||
|
isDropdownOpened={currentDropdownState === "state_id" ? true : false}
|
||||||
|
onOpen={() => handleCurrentDropdownState("state_id")}
|
||||||
|
onClose={() => handleCurrentDropdownState(undefined)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Controller
|
<Controller
|
||||||
control={control}
|
control={control}
|
||||||
name="priority"
|
name="priority"
|
||||||
@ -510,6 +528,10 @@ export const IssueFormRoot: FC<IssueFormProps> = observer((props) => {
|
|||||||
}}
|
}}
|
||||||
buttonVariant="border-with-text"
|
buttonVariant="border-with-text"
|
||||||
tabIndex={getTabIndex("priority")}
|
tabIndex={getTabIndex("priority")}
|
||||||
|
// handling the current dropdown state
|
||||||
|
isDropdownOpened={currentDropdownState === "priority" ? true : false}
|
||||||
|
onOpen={() => handleCurrentDropdownState("priority")}
|
||||||
|
onClose={() => handleCurrentDropdownState(undefined)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
@ -531,6 +553,10 @@ export const IssueFormRoot: FC<IssueFormProps> = observer((props) => {
|
|||||||
placeholder="Assignees"
|
placeholder="Assignees"
|
||||||
multiple
|
multiple
|
||||||
tabIndex={getTabIndex("assignee_ids")}
|
tabIndex={getTabIndex("assignee_ids")}
|
||||||
|
// handling the current dropdown state
|
||||||
|
isDropdownOpened={currentDropdownState === "assignee_ids" ? true : false}
|
||||||
|
onOpen={() => handleCurrentDropdownState("assignee_ids")}
|
||||||
|
onClose={() => handleCurrentDropdownState(undefined)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
@ -539,7 +565,7 @@ export const IssueFormRoot: FC<IssueFormProps> = observer((props) => {
|
|||||||
control={control}
|
control={control}
|
||||||
name="label_ids"
|
name="label_ids"
|
||||||
render={({ field: { value, onChange } }) => (
|
render={({ field: { value, onChange } }) => (
|
||||||
<div className="h-7">
|
<div className="h-7" tabIndex={getTabIndex("label_ids")}>
|
||||||
<IssueLabelSelect
|
<IssueLabelSelect
|
||||||
setIsOpen={setLabelModal}
|
setIsOpen={setLabelModal}
|
||||||
value={value}
|
value={value}
|
||||||
@ -549,6 +575,10 @@ export const IssueFormRoot: FC<IssueFormProps> = observer((props) => {
|
|||||||
}}
|
}}
|
||||||
projectId={projectId}
|
projectId={projectId}
|
||||||
tabIndex={getTabIndex("label_ids")}
|
tabIndex={getTabIndex("label_ids")}
|
||||||
|
// handling the current dropdown state
|
||||||
|
isDropdownOpened={currentDropdownState === "label_ids" ? true : false}
|
||||||
|
onOpen={() => handleCurrentDropdownState("label_ids")}
|
||||||
|
onClose={() => handleCurrentDropdownState(undefined)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
@ -565,6 +595,10 @@ export const IssueFormRoot: FC<IssueFormProps> = observer((props) => {
|
|||||||
maxDate={maxDate ?? undefined}
|
maxDate={maxDate ?? undefined}
|
||||||
placeholder="Start date"
|
placeholder="Start date"
|
||||||
tabIndex={getTabIndex("start_date")}
|
tabIndex={getTabIndex("start_date")}
|
||||||
|
// handling the current dropdown state
|
||||||
|
isDropdownOpened={currentDropdownState === "start_date" ? true : false}
|
||||||
|
onOpen={() => handleCurrentDropdownState("start_date")}
|
||||||
|
onClose={() => handleCurrentDropdownState(undefined)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
@ -581,6 +615,10 @@ export const IssueFormRoot: FC<IssueFormProps> = observer((props) => {
|
|||||||
minDate={minDate ?? undefined}
|
minDate={minDate ?? undefined}
|
||||||
placeholder="Due date"
|
placeholder="Due date"
|
||||||
tabIndex={getTabIndex("target_date")}
|
tabIndex={getTabIndex("target_date")}
|
||||||
|
// handling the current dropdown state
|
||||||
|
isDropdownOpened={currentDropdownState === "target_date" ? true : false}
|
||||||
|
onOpen={() => handleCurrentDropdownState("target_date")}
|
||||||
|
onClose={() => handleCurrentDropdownState(undefined)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
@ -600,6 +638,10 @@ export const IssueFormRoot: FC<IssueFormProps> = observer((props) => {
|
|||||||
value={value}
|
value={value}
|
||||||
buttonVariant="border-with-text"
|
buttonVariant="border-with-text"
|
||||||
tabIndex={getTabIndex("cycle_id")}
|
tabIndex={getTabIndex("cycle_id")}
|
||||||
|
// handling the current dropdown state
|
||||||
|
isDropdownOpened={currentDropdownState === "cycle_id" ? true : false}
|
||||||
|
onOpen={() => handleCurrentDropdownState("cycle_id")}
|
||||||
|
onClose={() => handleCurrentDropdownState(undefined)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
@ -622,6 +664,10 @@ export const IssueFormRoot: FC<IssueFormProps> = observer((props) => {
|
|||||||
tabIndex={getTabIndex("module_ids")}
|
tabIndex={getTabIndex("module_ids")}
|
||||||
multiple
|
multiple
|
||||||
showCount
|
showCount
|
||||||
|
// handling the current dropdown state
|
||||||
|
isDropdownOpened={currentDropdownState === "module_ids" ? true : false}
|
||||||
|
onOpen={() => handleCurrentDropdownState("module_ids")}
|
||||||
|
onClose={() => handleCurrentDropdownState(undefined)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
@ -642,6 +688,10 @@ export const IssueFormRoot: FC<IssueFormProps> = observer((props) => {
|
|||||||
projectId={projectId}
|
projectId={projectId}
|
||||||
buttonVariant="border-with-text"
|
buttonVariant="border-with-text"
|
||||||
tabIndex={getTabIndex("estimate_point")}
|
tabIndex={getTabIndex("estimate_point")}
|
||||||
|
// handling the current dropdown state
|
||||||
|
isDropdownOpened={currentDropdownState === "estimate_point" ? true : false}
|
||||||
|
onOpen={() => handleCurrentDropdownState("estimate_point")}
|
||||||
|
onClose={() => handleCurrentDropdownState(undefined)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
@ -672,6 +722,8 @@ export const IssueFormRoot: FC<IssueFormProps> = observer((props) => {
|
|||||||
}
|
}
|
||||||
placement="bottom-start"
|
placement="bottom-start"
|
||||||
tabIndex={getTabIndex("parent_id")}
|
tabIndex={getTabIndex("parent_id")}
|
||||||
|
onOpen={() => handleCurrentDropdownState("parent_id")}
|
||||||
|
onMenuClose={() => handleCurrentDropdownState(undefined)}
|
||||||
>
|
>
|
||||||
{watch("parent_id") ? (
|
{watch("parent_id") ? (
|
||||||
<>
|
<>
|
||||||
|
@ -4,19 +4,20 @@ import { useRouter } from "next/router";
|
|||||||
import { usePopper } from "react-popper";
|
import { usePopper } from "react-popper";
|
||||||
import { Check, Component, Plus, Search, Tag } from "lucide-react";
|
import { Check, Component, Plus, Search, Tag } from "lucide-react";
|
||||||
import { Combobox } from "@headlessui/react";
|
import { Combobox } from "@headlessui/react";
|
||||||
// hooks
|
// components
|
||||||
import { IssueLabelsList } from "@/components/ui";
|
import { IssueLabelsList } from "@/components/ui";
|
||||||
|
// hooks
|
||||||
import { useLabel } from "@/hooks/store";
|
import { useLabel } from "@/hooks/store";
|
||||||
import { useDropdownKeyDown } from "@/hooks/use-dropdown-key-down";
|
import { useDropdownKeyDown } from "@/hooks/use-dropdown-key-down";
|
||||||
import useOutsideClickDetector from "@/hooks/use-outside-click-detector";
|
import useOutsideClickDetector from "@/hooks/use-outside-click-detector";
|
||||||
import useOutsideKeydownDetector from "@/hooks/use-outside-keydown-detector";
|
|
||||||
// ui
|
|
||||||
// icons
|
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
setIsOpen: React.Dispatch<React.SetStateAction<boolean>>;
|
setIsOpen: React.Dispatch<React.SetStateAction<boolean>>;
|
||||||
value: string[];
|
value: string[];
|
||||||
onChange: (value: string[]) => void;
|
onChange: (value: string[]) => void;
|
||||||
|
isDropdownOpened?: boolean;
|
||||||
|
onOpen?: () => void;
|
||||||
|
onClose?: () => void;
|
||||||
projectId: string;
|
projectId: string;
|
||||||
label?: JSX.Element;
|
label?: JSX.Element;
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
@ -24,7 +25,18 @@ type Props = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const IssueLabelSelect: React.FC<Props> = observer((props) => {
|
export const IssueLabelSelect: React.FC<Props> = observer((props) => {
|
||||||
const { setIsOpen, value, onChange, projectId, label, disabled = false, tabIndex } = props;
|
const {
|
||||||
|
setIsOpen,
|
||||||
|
value,
|
||||||
|
onChange,
|
||||||
|
isDropdownOpened,
|
||||||
|
onOpen: onDropdownOpen,
|
||||||
|
onClose,
|
||||||
|
projectId,
|
||||||
|
label,
|
||||||
|
disabled = false,
|
||||||
|
tabIndex,
|
||||||
|
} = props;
|
||||||
// router
|
// router
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { workspaceSlug } = router.query;
|
const { workspaceSlug } = router.query;
|
||||||
@ -60,7 +72,11 @@ export const IssueLabelSelect: React.FC<Props> = observer((props) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const toggleDropdown = () => {
|
const toggleDropdown = () => {
|
||||||
if (!isDropdownOpen) onOpen();
|
if (!isDropdownOpen) {
|
||||||
|
onOpen();
|
||||||
|
onDropdownOpen && onDropdownOpen();
|
||||||
|
}
|
||||||
|
if (isDropdownOpen) onClose && onClose();
|
||||||
setIsDropdownOpen((prevIsOpen) => !prevIsOpen);
|
setIsDropdownOpen((prevIsOpen) => !prevIsOpen);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -77,7 +93,6 @@ export const IssueLabelSelect: React.FC<Props> = observer((props) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
useOutsideClickDetector(dropdownRef, handleClose);
|
useOutsideClickDetector(dropdownRef, handleClose);
|
||||||
useOutsideKeydownDetector(dropdownRef, handleClose);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isDropdownOpen && inputRef.current) {
|
if (isDropdownOpen && inputRef.current) {
|
||||||
@ -85,6 +100,13 @@ export const IssueLabelSelect: React.FC<Props> = observer((props) => {
|
|||||||
}
|
}
|
||||||
}, [isDropdownOpen]);
|
}, [isDropdownOpen]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (isDropdownOpened && !isDropdownOpen) setIsDropdownOpen(true);
|
||||||
|
}, [isDropdownOpened, isDropdownOpen]);
|
||||||
|
useEffect(() => {
|
||||||
|
if (isDropdownOpened === false) setIsDropdownOpen(false);
|
||||||
|
}, [isDropdownOpened]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Combobox
|
<Combobox
|
||||||
as="div"
|
as="div"
|
||||||
|
@ -1,19 +0,0 @@
|
|||||||
import React, { useEffect } from "react";
|
|
||||||
|
|
||||||
const useOutsideKeydownDetector = (ref: React.RefObject<HTMLElement>, callback: () => void) => {
|
|
||||||
const handleKeyDown = (event: KeyboardEvent) => {
|
|
||||||
if (ref.current && !ref.current.contains(event.target as Node)) {
|
|
||||||
callback();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
document.addEventListener("keydown", handleKeyDown);
|
|
||||||
|
|
||||||
return () => {
|
|
||||||
document.removeEventListener("keydown", handleKeyDown);
|
|
||||||
};
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
export default useOutsideKeydownDetector;
|
|
Loading…
Reference in New Issue
Block a user