diff --git a/app/client/src/PluginActionEditor/components/PluginActionToolbar/components/DocsMenuItem.tsx b/app/client/src/PluginActionEditor/components/PluginActionToolbar/components/DocsMenuItem.tsx new file mode 100644 index 000000000000..a44260d52718 --- /dev/null +++ b/app/client/src/PluginActionEditor/components/PluginActionToolbar/components/DocsMenuItem.tsx @@ -0,0 +1,26 @@ +import React, { useCallback } from "react"; +import { MenuItem } from "@appsmith/ads"; +import { createMessage, DOCUMENTATION } from "ee/constants/messages"; +import { DocsLink, openDoc } from "constants/DocumentationLinks"; +import { usePluginActionContext } from "../../../PluginActionContext"; + +export const DocsMenuItem = () => { + const { plugin } = usePluginActionContext(); + const onDocsClick = useCallback(() => { + openDoc(DocsLink.QUERY, plugin.documentationLink, plugin.name); + }, [plugin]); + + if (!plugin.documentationLink) { + return null; + } + + return ( + + {createMessage(DOCUMENTATION)} + + ); +}; diff --git a/app/client/src/PluginActionEditor/index.ts b/app/client/src/PluginActionEditor/index.ts index f0f9b933f1a7..2cb13d4a5e6d 100644 --- a/app/client/src/PluginActionEditor/index.ts +++ b/app/client/src/PluginActionEditor/index.ts @@ -13,3 +13,5 @@ export type { export { default as PluginActionNameEditor } from "./components/PluginActionNameEditor"; export type { PluginActionEditorState } from "./store/pluginEditorReducer"; + +export { DocsMenuItem } from "./components/PluginActionToolbar/components/DocsMenuItem"; diff --git a/app/client/src/ce/pages/Editor/AppPluginActionEditor/components/AppPluginActionToolbar.tsx b/app/client/src/ce/pages/Editor/AppPluginActionEditor/components/AppPluginActionToolbar.tsx index 8606cee42fb3..6e17b78ba5a4 100644 --- a/app/client/src/ce/pages/Editor/AppPluginActionEditor/components/AppPluginActionToolbar.tsx +++ b/app/client/src/ce/pages/Editor/AppPluginActionEditor/components/AppPluginActionToolbar.tsx @@ -1,9 +1,9 @@ import React from "react"; import { PluginActionToolbar } from "PluginActionEditor"; -import AppPluginActionMenu from "./PluginActionMoreActions"; +import { ToolbarMenu } from "./ToolbarMenu"; const AppPluginActionToolbar = () => { - return } />; + return } />; }; export default AppPluginActionToolbar; diff --git a/app/client/src/ce/pages/Editor/AppPluginActionEditor/components/PluginActionMoreActions.tsx b/app/client/src/ce/pages/Editor/AppPluginActionEditor/components/PluginActionMoreActions.tsx deleted file mode 100644 index d07d692c5e7f..000000000000 --- a/app/client/src/ce/pages/Editor/AppPluginActionEditor/components/PluginActionMoreActions.tsx +++ /dev/null @@ -1,182 +0,0 @@ -import React, { useCallback, useMemo, useState } from "react"; -import { - getHasDeleteActionPermission, - getHasManageActionPermission, -} from "ee/utils/BusinessFeatures/permissionPageHelpers"; -import { useFeatureFlag } from "utils/hooks/useFeatureFlag"; -import { FEATURE_FLAG } from "ee/entities/FeatureFlag"; -import { usePluginActionContext } from "PluginActionEditor"; -import { - MenuItem, - MenuSub, - MenuSubContent, - MenuSubTrigger, -} from "@appsmith/ads"; -import { - CONFIRM_CONTEXT_DELETE, - CONTEXT_COPY, - CONTEXT_DELETE, - CONTEXT_MOVE, - createMessage, -} from "ee/constants/messages"; -import { useDispatch, useSelector } from "react-redux"; -import { - copyActionRequest, - moveActionRequest, -} from "actions/pluginActionActions"; -import { getCurrentPageId } from "selectors/editorSelectors"; -import type { Page } from "entities/Page"; -import { getPageList } from "ee/selectors/entitiesSelector"; -import { ConvertToModuleCTA } from "./ConvertToModule"; -import { useHandleDeleteClick } from "PluginActionEditor/hooks"; - -const PageMenuItem = (props: { - page: Page; - onSelect: (id: string) => void; -}) => { - const handleOnSelect = useCallback(() => { - props.onSelect(props.page.pageId); - }, [props]); - - return {props.page.pageName}; -}; - -const Copy = () => { - const menuPages = useSelector(getPageList); - const { action } = usePluginActionContext(); - const dispatch = useDispatch(); - - const copyActionToPage = useCallback( - (pageId: string) => - dispatch( - copyActionRequest({ - id: action.id, - destinationPageId: pageId, - name: action.name, - }), - ), - [action.id, action.name, dispatch], - ); - - return ( - - - {createMessage(CONTEXT_COPY)} - - - {menuPages.map((page) => { - return ( - - ); - })} - - - ); -}; - -const Move = () => { - const dispatch = useDispatch(); - const { action } = usePluginActionContext(); - - const currentPageId = useSelector(getCurrentPageId); - const allPages = useSelector(getPageList); - const menuPages = useMemo(() => { - return allPages.filter((page) => page.pageId !== currentPageId); - }, [allPages, currentPageId]); - - const moveActionToPage = useCallback( - (destinationPageId: string) => - dispatch( - moveActionRequest({ - id: action.id, - destinationPageId, - originalPageId: currentPageId, - name: action.name, - }), - ), - [dispatch, action.id, action.name, currentPageId], - ); - - return ( - - - {createMessage(CONTEXT_MOVE)} - - - {menuPages.length > 1 ? ( - menuPages.map((page) => { - return ( - - ); - }) - ) : ( - No pages - )} - - - ); -}; - -const Delete = () => { - const { handleDeleteClick } = useHandleDeleteClick(); - const [confirmDelete, setConfirmDelete] = useState(false); - - const handleSelect = useCallback( - (e?: Event) => { - e?.preventDefault(); - confirmDelete ? handleDeleteClick({}) : setConfirmDelete(true); - }, - [confirmDelete, handleDeleteClick], - ); - - const menuLabel = confirmDelete - ? createMessage(CONFIRM_CONTEXT_DELETE) - : createMessage(CONTEXT_DELETE); - - return ( - - {menuLabel} - - ); -}; - -const AppPluginActionMenu = () => { - const { action } = usePluginActionContext(); - - const isFeatureEnabled = useFeatureFlag(FEATURE_FLAG.license_gac_enabled); - const isChangePermitted = getHasManageActionPermission( - isFeatureEnabled, - action.userPermissions, - ); - const isDeletePermitted = getHasDeleteActionPermission( - isFeatureEnabled, - action?.userPermissions, - ); - - return ( - <> - - {isChangePermitted && ( - <> - - - - )} - {isDeletePermitted && } - - ); -}; - -export default AppPluginActionMenu; diff --git a/app/client/src/ce/pages/Editor/AppPluginActionEditor/components/ToolbarMenu/Copy.tsx b/app/client/src/ce/pages/Editor/AppPluginActionEditor/components/ToolbarMenu/Copy.tsx new file mode 100644 index 000000000000..de4037213c46 --- /dev/null +++ b/app/client/src/ce/pages/Editor/AppPluginActionEditor/components/ToolbarMenu/Copy.tsx @@ -0,0 +1,45 @@ +import { useDispatch, useSelector } from "react-redux"; +import { getPageList } from "ee/selectors/entitiesSelector"; +import { usePluginActionContext } from "PluginActionEditor"; +import React, { useCallback } from "react"; +import { copyActionRequest } from "actions/pluginActionActions"; +import { MenuSub, MenuSubContent, MenuSubTrigger } from "@appsmith/ads"; +import { CONTEXT_COPY, createMessage } from "ee/constants/messages"; +import { PageMenuItem } from "./PageMenuItem"; + +export const Copy = () => { + const menuPages = useSelector(getPageList); + const { action } = usePluginActionContext(); + const dispatch = useDispatch(); + + const copyActionToPage = useCallback( + (pageId: string) => + dispatch( + copyActionRequest({ + id: action.id, + destinationPageId: pageId, + name: action.name, + }), + ), + [action.id, action.name, dispatch], + ); + + return ( + + + {createMessage(CONTEXT_COPY)} + + + {menuPages.map((page) => { + return ( + + ); + })} + + + ); +}; diff --git a/app/client/src/ce/pages/Editor/AppPluginActionEditor/components/ToolbarMenu/Delete.tsx b/app/client/src/ce/pages/Editor/AppPluginActionEditor/components/ToolbarMenu/Delete.tsx new file mode 100644 index 000000000000..498726f28163 --- /dev/null +++ b/app/client/src/ce/pages/Editor/AppPluginActionEditor/components/ToolbarMenu/Delete.tsx @@ -0,0 +1,35 @@ +import { useHandleDeleteClick } from "PluginActionEditor/hooks"; +import React, { useCallback, useState } from "react"; +import { + CONFIRM_CONTEXT_DELETE, + CONTEXT_DELETE, + createMessage, +} from "ee/constants/messages"; +import { MenuItem } from "@appsmith/ads"; + +export const Delete = () => { + const { handleDeleteClick } = useHandleDeleteClick(); + const [confirmDelete, setConfirmDelete] = useState(false); + + const handleSelect = useCallback( + (e?: Event) => { + e?.preventDefault(); + confirmDelete ? handleDeleteClick({}) : setConfirmDelete(true); + }, + [confirmDelete, handleDeleteClick], + ); + + const menuLabel = confirmDelete + ? createMessage(CONFIRM_CONTEXT_DELETE) + : createMessage(CONTEXT_DELETE); + + return ( + + {menuLabel} + + ); +}; diff --git a/app/client/src/ce/pages/Editor/AppPluginActionEditor/components/ToolbarMenu/Move.tsx b/app/client/src/ce/pages/Editor/AppPluginActionEditor/components/ToolbarMenu/Move.tsx new file mode 100644 index 000000000000..88fe248884f1 --- /dev/null +++ b/app/client/src/ce/pages/Editor/AppPluginActionEditor/components/ToolbarMenu/Move.tsx @@ -0,0 +1,61 @@ +import { useDispatch, useSelector } from "react-redux"; +import { usePluginActionContext } from "PluginActionEditor"; +import { getCurrentPageId } from "selectors/editorSelectors"; +import { getPageList } from "ee/selectors/entitiesSelector"; +import React, { useCallback, useMemo } from "react"; +import { moveActionRequest } from "actions/pluginActionActions"; +import { + MenuItem, + MenuSub, + MenuSubContent, + MenuSubTrigger, +} from "@appsmith/ads"; +import { CONTEXT_MOVE, createMessage } from "ee/constants/messages"; +import { PageMenuItem } from "./PageMenuItem"; + +export const Move = () => { + const dispatch = useDispatch(); + const { action } = usePluginActionContext(); + + const currentPageId = useSelector(getCurrentPageId); + const allPages = useSelector(getPageList); + const menuPages = useMemo(() => { + return allPages.filter((page) => page.pageId !== currentPageId); + }, [allPages, currentPageId]); + + const moveActionToPage = useCallback( + (destinationPageId: string) => + dispatch( + moveActionRequest({ + id: action.id, + destinationPageId, + originalPageId: currentPageId, + name: action.name, + }), + ), + [dispatch, action.id, action.name, currentPageId], + ); + + return ( + + + {createMessage(CONTEXT_MOVE)} + + + {menuPages.length > 1 ? ( + menuPages.map((page) => { + return ( + + ); + }) + ) : ( + No pages + )} + + + ); +}; diff --git a/app/client/src/ce/pages/Editor/AppPluginActionEditor/components/ToolbarMenu/PageMenuItem.tsx b/app/client/src/ce/pages/Editor/AppPluginActionEditor/components/ToolbarMenu/PageMenuItem.tsx new file mode 100644 index 000000000000..129f9c9a2edf --- /dev/null +++ b/app/client/src/ce/pages/Editor/AppPluginActionEditor/components/ToolbarMenu/PageMenuItem.tsx @@ -0,0 +1,14 @@ +import type { Page } from "entities/Page"; +import React, { useCallback } from "react"; +import { MenuItem } from "@appsmith/ads"; + +export const PageMenuItem = (props: { + page: Page; + onSelect: (id: string) => void; +}) => { + const handleOnSelect = useCallback(() => { + props.onSelect(props.page.pageId); + }, [props]); + + return {props.page.pageName}; +}; diff --git a/app/client/src/ce/pages/Editor/AppPluginActionEditor/components/ToolbarMenu/ToolbarMenu.tsx b/app/client/src/ce/pages/Editor/AppPluginActionEditor/components/ToolbarMenu/ToolbarMenu.tsx new file mode 100644 index 000000000000..37ffe8876711 --- /dev/null +++ b/app/client/src/ce/pages/Editor/AppPluginActionEditor/components/ToolbarMenu/ToolbarMenu.tsx @@ -0,0 +1,45 @@ +import React from "react"; +import { + getHasDeleteActionPermission, + getHasManageActionPermission, +} from "ee/utils/BusinessFeatures/permissionPageHelpers"; +import { useFeatureFlag } from "utils/hooks/useFeatureFlag"; +import { FEATURE_FLAG } from "ee/entities/FeatureFlag"; +import { + usePluginActionContext, + DocsMenuItem as Docs, +} from "PluginActionEditor"; +import { ConvertToModuleCTA } from "../ConvertToModule"; +import { Move } from "./Move"; +import { Copy } from "./Copy"; +import { Delete } from "./Delete"; +import { MenuSeparator } from "@appsmith/ads"; + +export const ToolbarMenu = () => { + const { action } = usePluginActionContext(); + + const isFeatureEnabled = useFeatureFlag(FEATURE_FLAG.license_gac_enabled); + const isChangePermitted = getHasManageActionPermission( + isFeatureEnabled, + action.userPermissions, + ); + const isDeletePermitted = getHasDeleteActionPermission( + isFeatureEnabled, + action?.userPermissions, + ); + + return ( + <> + + {isChangePermitted && ( + <> + + + + )} + + + {isDeletePermitted && } + + ); +}; diff --git a/app/client/src/ce/pages/Editor/AppPluginActionEditor/components/ToolbarMenu/index.ts b/app/client/src/ce/pages/Editor/AppPluginActionEditor/components/ToolbarMenu/index.ts new file mode 100644 index 000000000000..2b4a2600ac1b --- /dev/null +++ b/app/client/src/ce/pages/Editor/AppPluginActionEditor/components/ToolbarMenu/index.ts @@ -0,0 +1 @@ +export { ToolbarMenu } from "./ToolbarMenu";