( viewMode: SheetViewMode, worksheetFilter: WorksheetFilter, // Only the "my" tree is wired to the parent's multi-select state. For // other views (shared / draft) the context-menu entry is hidden so a // right-click on a shared worksheet cannot populate the my tree's // checkedNodes — which the toolbar's Delete + Move-to-folder flows act on. canMultiSelect = false )
| 41 | // --------------------------------------------------------------------------- |
| 42 | |
| 43 | export function useDropdown( |
| 44 | viewMode: SheetViewMode, |
| 45 | worksheetFilter: WorksheetFilter, |
| 46 | // Only the "my" tree is wired to the parent's multi-select state. For |
| 47 | // other views (shared / draft) the context-menu entry is hidden so a |
| 48 | // right-click on a shared worksheet cannot populate the my tree's |
| 49 | // checkedNodes — which the toolbar's Delete + Move-to-folder flows act on. |
| 50 | canMultiSelect = false |
| 51 | ) { |
| 52 | const { t } = useTranslation(); |
| 53 | |
| 54 | const me = useCurrentUser(); |
| 55 | |
| 56 | // ------------------------------------------------------------------ |
| 57 | // Context state — current right-click target |
| 58 | // ------------------------------------------------------------------ |
| 59 | const [currentNode, setCurrentNode] = useState< |
| 60 | WorksheetFolderNode | undefined |
| 61 | >(undefined); |
| 62 | const [showSharePanel, setShowSharePanel] = useState(false); |
| 63 | |
| 64 | // ------------------------------------------------------------------ |
| 65 | // Reactive reads from Pinia / Vue stores |
| 66 | // ------------------------------------------------------------------ |
| 67 | const worksheetEntity = useAppStore((s) => |
| 68 | viewMode === "draft" || !currentNode?.worksheet |
| 69 | ? undefined |
| 70 | : s.getWorksheetByName(currentNode.worksheet.name) |
| 71 | ); |
| 72 | |
| 73 | // ------------------------------------------------------------------ |
| 74 | // Derived: allowed-to-create-new |
| 75 | // ------------------------------------------------------------------ |
| 76 | const allowCreateNew = |
| 77 | !worksheetFilter.keyword && !worksheetFilter.onlyShowStarred; |
| 78 | |
| 79 | // ------------------------------------------------------------------ |
| 80 | // Menu options — computed from current state |
| 81 | // ------------------------------------------------------------------ |
| 82 | const options = useMemo((): MenuItem[] => { |
| 83 | if (viewMode === "draft" || !currentNode) { |
| 84 | return []; |
| 85 | } |
| 86 | |
| 87 | type ItemDef = { |
| 88 | key: DropdownOptionType; |
| 89 | label: string; |
| 90 | }; |
| 91 | |
| 92 | const items: ItemDef[] = []; |
| 93 | |
| 94 | if (currentNode.worksheet) { |
| 95 | if (!worksheetEntity) { |
| 96 | return []; |
| 97 | } |
| 98 | const isCreator = worksheetEntity.creator === `users/${me?.email ?? ""}`; |
| 99 | items.push({ |
| 100 | key: "duplicate", |
no test coverage detected