PromucFlow_constructor/app/client/src/PluginActionEditor/PluginActionEditor.tsx
Hetu Nandu f593ed3465
chore: [Plugin Action Editor] Convert to Module (#36305)
## Description

CE PR for: https://github.com/appsmithorg/appsmith-ee/pull/5134




## Automation

/ok-to-test tags="@tag.Sanity"

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/10845636973>
> Commit: 1f40848b28f4a3fbb3461578334ee613f608c7bd
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=10845636973&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.Sanity`
> Spec:
> <hr>Fri, 13 Sep 2024 08:48:25 UTC
<!-- end of auto-generated comment: Cypress test results  -->


## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [x] No


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **New Features**
- Enhanced flexibility for child components in the Plugin Action Editor,
allowing single or multiple React nodes.
	- Introduced a new toolbar with a dropdown menu for additional actions.
- Added components for converting actions into modules, including
callouts and disablers for better user feedback.
- **Bug Fixes**
- Improved user experience by providing notifications during the action
conversion process.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2024-09-13 14:29:20 +05:30

90 lines
2.4 KiB
TypeScript

import React from "react";
import { useLocation } from "react-router";
import { identifyEntityFromPath } from "../navigation/FocusEntity";
import { useSelector } from "react-redux";
import {
getActionByBaseId,
getDatasource,
getEditorConfig,
getPlugin,
getPluginSettingConfigs,
} from "ee/selectors/entitiesSelector";
import { PluginActionContextProvider } from "./PluginActionContext";
import { get } from "lodash";
import EntityNotFoundPane from "pages/Editor/EntityNotFoundPane";
import { getIsEditorInitialized } from "selectors/editorSelectors";
import Spinner from "components/editorComponents/Spinner";
import CenteredWrapper from "components/designSystems/appsmith/CenteredWrapper";
import { Text } from "@appsmith/ads";
interface ChildrenProps {
children: React.ReactNode | React.ReactNode[];
}
const PluginActionEditor = (props: ChildrenProps) => {
const { pathname } = useLocation();
const isEditorInitialized = useSelector(getIsEditorInitialized);
const entity = identifyEntityFromPath(pathname);
const action = useSelector((state) => getActionByBaseId(state, entity.id));
const pluginId = get(action, "pluginId", "");
const plugin = useSelector((state) => getPlugin(state, pluginId));
const datasourceId = get(action, "datasource.id", "");
const datasource = useSelector((state) => getDatasource(state, datasourceId));
const settingsConfig = useSelector((state) =>
getPluginSettingConfigs(state, pluginId),
);
const editorConfig = useSelector((state) => getEditorConfig(state, pluginId));
if (!isEditorInitialized) {
return (
<CenteredWrapper>
<Spinner size={30} />
</CenteredWrapper>
);
}
if (!action) {
return <EntityNotFoundPane />;
}
if (!plugin) {
return (
<CenteredWrapper>
<Text color="var(--ads-v2-color-fg-error)" kind="heading-m">
Plugin not installed!
</Text>
</CenteredWrapper>
);
}
if (!settingsConfig || !editorConfig) {
return (
<CenteredWrapper>
<Text color="var(--ads-v2-color-fg-error)" kind="heading-m">
Editor config not found!
</Text>
</CenteredWrapper>
);
}
return (
<PluginActionContextProvider
action={action}
datasource={datasource}
editorConfig={editorConfig}
plugin={plugin}
settingsConfig={settingsConfig}
>
{props.children}
</PluginActionContextProvider>
);
};
export default PluginActionEditor;