import { FC, Fragment, useMemo, useRef, useState } from "react"; import { observer } from "mobx-react-lite"; import { Menu, Transition } from "@headlessui/react"; import { usePopper } from "react-popper"; import { Copy, Eye, Globe2, Link2, Pencil, Trash } from "lucide-react"; // types import { TViewEditDropdownOptions, TViewOperations } from "../types"; type TViewEditDropdown = { workspaceSlug: string; projectId: string | undefined; viewId: string; viewOperations: TViewOperations; }; export const ViewEditDropdown: FC = observer((props) => { const { viewId, viewOperations } = props; // refs const dropdownRef = useRef(null); // popper-js refs const [referenceElement, setReferenceElement] = useState(null); const [popperElement, setPopperElement] = useState(null); // popper-js init const { styles, attributes } = usePopper(referenceElement, popperElement, { placement: "bottom-end", modifiers: [ { name: "preventOverflow", options: { padding: 12, }, }, { name: "offset", options: { offset: [0, 10], }, }, ], }); // dropdown options const dropdownOptions: TViewEditDropdownOptions[] = useMemo( () => [ { icon: Pencil, key: "rename", label: "Rename", onClick: () => viewOperations.localViewCreateEdit(viewId), children: undefined, }, // { // icon: Eye, // key: "accessability", // label: "Change Accessability", // onClick: () => {}, // children: [ // { // icon: Eye, // key: "private", // label: "Private", // onClick: () => viewOperations.create({}), // children: undefined, // }, // { // icon: Globe2, // key: "public", // label: "Public", // onClick: () => viewOperations.create({}), // children: undefined, // }, // ], // }, // { // icon: Copy, // key: "duplicate", // label: "Duplicate view", // onClick: () => viewOperations.remove(viewId), // children: undefined, // }, // { // icon: Link2, // key: "copy_link", // label: "Copy view link", // onClick: () => viewOperations.remove(viewId), // children: undefined, // }, // { // icon: Trash, // key: "delete", // label: "Delete view", // onClick: () => viewOperations.remove(viewId), // children: undefined, // }, ], [viewOperations, viewId] ); return (
{dropdownOptions && dropdownOptions.length > 0 && dropdownOptions.map((option) => (
{option.label}
))}
); });