diff --git a/app/client/src/ce/hooks/datasourceEditorHooks.tsx b/app/client/src/ce/hooks/datasourceEditorHooks.tsx
new file mode 100644
index 0000000000..631b7e7707
--- /dev/null
+++ b/app/client/src/ce/hooks/datasourceEditorHooks.tsx
@@ -0,0 +1,119 @@
+import React from "react";
+import { useSelector } from "react-redux";
+import NewActionButton from "pages/Editor/DataSourceEditor/NewActionButton";
+import { EditorNames } from "./";
+import type { Datasource } from "entities/Datasource";
+import type { ApiDatasourceForm } from "entities/Datasource/RestAPIForm";
+import { Button } from "design-system";
+import {
+ GENERATE_NEW_PAGE_BUTTON_TEXT,
+ createMessage,
+} from "@appsmith/constants/messages";
+import AnalyticsUtil from "utils/AnalyticsUtil";
+import history from "utils/history";
+import { generateTemplateFormURL } from "@appsmith/RouteBuilder";
+import {
+ getCurrentApplication,
+ getCurrentPageId,
+ getPagePermissions,
+} from "selectors/editorSelectors";
+import { useShowPageGenerationOnHeader } from "pages/Editor/DataSourceEditor/hooks";
+import type { AppState } from "@appsmith/reducers";
+import {
+ getHasCreatePagePermission,
+ hasCreateDSActionPermissionInApp,
+} from "@appsmith/utils/BusinessFeatures/permissionPageHelpers";
+import { FEATURE_FLAG } from "@appsmith/entities/FeatureFlag";
+import { useFeatureFlag } from "utils/hooks/useFeatureFlag";
+
+export interface HeaderActionProps {
+ datasource: Datasource | ApiDatasourceForm | undefined;
+ isPluginAuthorized: boolean;
+ pluginType: string;
+ showReconnectButton?: boolean;
+}
+
+export const useHeaderActions = (
+ editorType: string,
+ {
+ datasource,
+ isPluginAuthorized,
+ pluginType,
+ showReconnectButton = false,
+ }: HeaderActionProps,
+) => {
+ const pageId = useSelector(getCurrentPageId);
+ const isFeatureEnabled = useFeatureFlag(FEATURE_FLAG.license_gac_enabled);
+ const userAppPermissions = useSelector(
+ (state: AppState) => getCurrentApplication(state)?.userPermissions ?? [],
+ );
+ const pagePermissions = useSelector((state: AppState) =>
+ getPagePermissions(state),
+ );
+ const showGenerateButton = useShowPageGenerationOnHeader(
+ datasource as Datasource,
+ );
+
+ if (editorType === EditorNames.APPLICATION) {
+ const canCreateDatasourceActions = hasCreateDSActionPermissionInApp(
+ isFeatureEnabled,
+ datasource?.userPermissions ?? [],
+ pagePermissions,
+ );
+ const canCreatePages = getHasCreatePagePermission(
+ isFeatureEnabled,
+ userAppPermissions,
+ );
+ const canGeneratePage = canCreateDatasourceActions && canCreatePages;
+
+ const routeToGeneratePage = () => {
+ if (!showGenerateButton) {
+ // disable button when it doesn't support page generation
+ return;
+ }
+ AnalyticsUtil.logEvent("DATASOURCE_CARD_GEN_CRUD_PAGE_ACTION");
+ history.push(
+ generateTemplateFormURL({
+ pageId,
+ params: {
+ datasourceId: (datasource as Datasource).id,
+ new_page: true,
+ },
+ }),
+ );
+ };
+
+ const newActionButton = (
+
+ );
+
+ const generatePageButton =
+ showGenerateButton && !showReconnectButton ? (
+
+ ) : null;
+
+ return {
+ newActionButton,
+ generatePageButton,
+ };
+ }
+
+ return {};
+};
diff --git a/app/client/src/ce/hooks/index.ts b/app/client/src/ce/hooks/index.ts
new file mode 100644
index 0000000000..03e0e0e80e
--- /dev/null
+++ b/app/client/src/ce/hooks/index.ts
@@ -0,0 +1,27 @@
+import {
+ BUILDER_BASE_PATH_DEPRECATED,
+ BUILDER_VIEWER_PATH_PREFIX,
+} from "constants/routes";
+import { matchPath } from "react-router";
+
+export const EditorNames = {
+ APPLICATION: "appEditor",
+};
+
+export interface EditorType {
+ [key: string]: string;
+}
+
+export const editorType: EditorType = {
+ [BUILDER_VIEWER_PATH_PREFIX]: EditorNames.APPLICATION,
+};
+
+export const useEditorType = (path: string) => {
+ const basePath = matchPath(path, {
+ path: [BUILDER_VIEWER_PATH_PREFIX, BUILDER_BASE_PATH_DEPRECATED],
+ });
+
+ return basePath
+ ? editorType[basePath.path]
+ : editorType[BUILDER_VIEWER_PATH_PREFIX];
+};
diff --git a/app/client/src/ce/reducers/uiReducers/editorReducer.tsx b/app/client/src/ce/reducers/uiReducers/editorReducer.tsx
index d82bf44b9e..5520a13dd5 100644
--- a/app/client/src/ce/reducers/uiReducers/editorReducer.tsx
+++ b/app/client/src/ce/reducers/uiReducers/editorReducer.tsx
@@ -42,6 +42,18 @@ export const initialState: EditorReduxState = {
};
export const handlers = {
+ [ReduxActionTypes.RESET_EDITOR_REQUEST]: (state: EditorReduxState) => {
+ return {
+ ...state,
+ currentPageId: undefined,
+ currentPageName: undefined,
+ currentLayoutId: undefined,
+ currentApplicationId: undefined,
+ pageWidgetId: undefined,
+ pageActions: undefined,
+ layoutOnLoadActionErrors: undefined,
+ };
+ },
[ReduxActionTypes.RESET_EDITOR_SUCCESS]: (state: EditorReduxState) => {
return { ...state, initialized: false };
},
diff --git a/app/client/src/constants/routes/appRoutes.ts b/app/client/src/constants/routes/appRoutes.ts
index b29a299326..00a5f403ae 100644
--- a/app/client/src/constants/routes/appRoutes.ts
+++ b/app/client/src/constants/routes/appRoutes.ts
@@ -4,6 +4,7 @@
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { match } = require("path-to-regexp");
+export const BUILDER_BASE_PATH_DEPRECATED = "/applications";
export const BUILDER_VIEWER_PATH_PREFIX = "/app/";
export const BUILDER_PATH = `${BUILDER_VIEWER_PATH_PREFIX}:applicationSlug/:pageSlug(.*\-):pageId/edit`;
export const BUILDER_CUSTOM_PATH = `${BUILDER_VIEWER_PATH_PREFIX}:customSlug(.*\-):pageId/edit`;
diff --git a/app/client/src/ee/hooks/datasourceEditorHooks.tsx b/app/client/src/ee/hooks/datasourceEditorHooks.tsx
new file mode 100644
index 0000000000..1778e62819
--- /dev/null
+++ b/app/client/src/ee/hooks/datasourceEditorHooks.tsx
@@ -0,0 +1 @@
+export * from "ce/hooks/datasourceEditorHooks";
diff --git a/app/client/src/ee/hooks/index.ts b/app/client/src/ee/hooks/index.ts
new file mode 100644
index 0000000000..de9b260629
--- /dev/null
+++ b/app/client/src/ee/hooks/index.ts
@@ -0,0 +1 @@
+export * from "ce/hooks";
diff --git a/app/client/src/pages/Editor/DataSourceEditor/DSFormHeader.tsx b/app/client/src/pages/Editor/DataSourceEditor/DSFormHeader.tsx
index 3b47238010..59074acf28 100644
--- a/app/client/src/pages/Editor/DataSourceEditor/DSFormHeader.tsx
+++ b/app/client/src/pages/Editor/DataSourceEditor/DSFormHeader.tsx
@@ -1,6 +1,5 @@
import React, { useState } from "react";
import FormTitle from "./FormTitle";
-import NewActionButton from "./NewActionButton";
import { getAssetUrl } from "@appsmith/utils/airgapHelpers";
import type { Datasource } from "entities/Datasource";
import {
@@ -9,7 +8,6 @@ import {
CONTEXT_DELETE,
EDIT,
createMessage,
- GENERATE_NEW_PAGE_BUTTON_TEXT,
} from "@appsmith/constants/messages";
import AnalyticsUtil from "utils/AnalyticsUtil";
import { useDispatch, useSelector } from "react-redux";
@@ -20,21 +18,15 @@ import { MenuWrapper, StyledMenu } from "components/utils/formComponents";
import styled from "styled-components";
import { Button, MenuContent, MenuItem, MenuTrigger } from "design-system";
import { DatasourceEditEntryPoints } from "constants/Datasource";
-import { useShowPageGenerationOnHeader } from "./hooks";
-import { generateTemplateFormURL } from "@appsmith/RouteBuilder";
-import { getCurrentPageId } from "selectors/editorSelectors";
-import history from "utils/history";
import {
DB_NOT_SUPPORTED,
isEnvironmentConfigured,
} from "@appsmith/utils/Environments";
-import { getHasCreatePagePermission } from "@appsmith/utils/BusinessFeatures/permissionPageHelpers";
-import { useFeatureFlag } from "utils/hooks/useFeatureFlag";
-import { FEATURE_FLAG } from "@appsmith/entities/FeatureFlag";
-import type { AppState } from "@appsmith/reducers";
-import { getCurrentApplication } from "@appsmith/selectors/applicationSelectors";
import { getCurrentEnvironmentId } from "@appsmith/selectors/environmentSelectors";
import type { PluginType } from "entities/Action";
+import { useEditorType } from "@appsmith/hooks";
+import { useHistory } from "react-router";
+import { useHeaderActions } from "@appsmith/hooks/datasourceEditorHooks";
export const ActionWrapper = styled.div`
display: flex;
@@ -84,7 +76,6 @@ export const PluginImage = (props: any) => {
};
interface DSFormHeaderProps {
- canCreateDatasourceActions: boolean;
canDeleteDatasource: boolean;
canManageDatasource: boolean;
datasource: Datasource | ApiDatasourceForm | undefined;
@@ -105,7 +96,6 @@ interface DSFormHeaderProps {
export const DSFormHeader = (props: DSFormHeaderProps) => {
const {
- canCreateDatasourceActions,
canDeleteDatasource,
canManageDatasource,
datasource,
@@ -123,16 +113,8 @@ export const DSFormHeader = (props: DSFormHeaderProps) => {
const [confirmDelete, setConfirmDelete] = useState(false);
const dispatch = useDispatch();
-
- const pageId = useSelector(getCurrentPageId);
- const isFeatureEnabled = useFeatureFlag(FEATURE_FLAG.license_gac_enabled);
- const userAppPermissions = useSelector(
- (state: AppState) => getCurrentApplication(state)?.userPermissions ?? [],
- );
- const canCreatePages = getHasCreatePagePermission(
- isFeatureEnabled,
- userAppPermissions,
- );
+ const history = useHistory();
+ const editorType = useEditorType(history.location.pathname);
const deleteAction = () => {
if (isDeleting) return;
@@ -142,10 +124,6 @@ export const DSFormHeader = (props: DSFormHeaderProps) => {
const onCloseMenu = debounce(() => setConfirmDelete(false), 20);
- const showGenerateButton = useShowPageGenerationOnHeader(
- datasource as Datasource,
- );
-
const renderMenuOptions = () => {
return [