mirror of
https://github.com/outline/outline.git
synced 2026-06-13 03:14:59 +03:00
f8e70c2c39
Adds missing stable dependencies (e.g. `t`, prop callbacks, store refs, `setFocusedCommentId`) and removes unnecessary ones across hooks where the fix is straightforward. For the two MobX-observed `.orderedData` deps in `History.tsx`, keeps the original deps and silences the false positive with `eslint-disable-next-line` so the memos still recompute when the underlying observable arrays change. Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
73 lines
1.9 KiB
TypeScript
73 lines
1.9 KiB
TypeScript
import { useMemo } from "react";
|
|
import { useMenuAction } from "./useMenuAction";
|
|
import { ActionSeparator, createAction } from "~/actions";
|
|
import {
|
|
deleteCollection,
|
|
editCollection,
|
|
editCollectionPermissions,
|
|
starCollection,
|
|
unstarCollection,
|
|
searchInCollection,
|
|
createTemplate,
|
|
archiveCollection,
|
|
restoreCollection,
|
|
subscribeCollection,
|
|
unsubscribeCollection,
|
|
createDocument,
|
|
exportCollection,
|
|
importDocument,
|
|
sortCollection,
|
|
} from "~/actions/definitions/collections";
|
|
import { ActiveCollectionSection } from "~/actions/sections";
|
|
import { InputIcon } from "outline-icons";
|
|
import usePolicy from "./usePolicy";
|
|
import useStores from "./useStores";
|
|
import { useTranslation } from "react-i18next";
|
|
|
|
type Props = {
|
|
/** Collection ID for which the actions are generated */
|
|
collectionId: string;
|
|
/** Invoked when the "Rename" menu item is clicked */
|
|
onRename?: () => void;
|
|
};
|
|
|
|
export function useCollectionMenuAction({ collectionId, onRename }: Props) {
|
|
const { collections } = useStores();
|
|
const { t } = useTranslation();
|
|
const collection = collections.get(collectionId);
|
|
const can = usePolicy(collection);
|
|
|
|
const actions = useMemo(
|
|
() => [
|
|
restoreCollection,
|
|
starCollection,
|
|
unstarCollection,
|
|
subscribeCollection,
|
|
unsubscribeCollection,
|
|
ActionSeparator,
|
|
createDocument,
|
|
importDocument,
|
|
ActionSeparator,
|
|
createAction({
|
|
name: `${t("Rename")}…`,
|
|
section: ActiveCollectionSection,
|
|
icon: <InputIcon />,
|
|
visible: !!can.update && !!onRename,
|
|
perform: () => requestAnimationFrame(() => onRename?.()),
|
|
}),
|
|
editCollection,
|
|
editCollectionPermissions,
|
|
createTemplate,
|
|
sortCollection,
|
|
exportCollection,
|
|
archiveCollection,
|
|
searchInCollection,
|
|
ActionSeparator,
|
|
deleteCollection,
|
|
],
|
|
[t, can.update, onRename]
|
|
);
|
|
|
|
return useMenuAction(actions);
|
|
}
|