2024-09-12 04:41:54 +00:00
|
|
|
import React from "react";
|
|
|
|
|
import { useLocation } from "react-router";
|
|
|
|
|
import { identifyEntityFromPath } from "../navigation/FocusEntity";
|
|
|
|
|
import { useSelector } from "react-redux";
|
|
|
|
|
import {
|
|
|
|
|
getActionByBaseId,
|
2024-09-25 07:44:26 +00:00
|
|
|
getActionResponses,
|
2024-09-12 04:41:54 +00:00
|
|
|
getDatasource,
|
|
|
|
|
getEditorConfig,
|
|
|
|
|
getPlugin,
|
|
|
|
|
} from "ee/selectors/entitiesSelector";
|
|
|
|
|
import { PluginActionContextProvider } from "./PluginActionContext";
|
|
|
|
|
import { get } from "lodash";
|
|
|
|
|
import EntityNotFoundPane from "pages/Editor/EntityNotFoundPane";
|
|
|
|
|
import Spinner from "components/editorComponents/Spinner";
|
|
|
|
|
import CenteredWrapper from "components/designSystems/appsmith/CenteredWrapper";
|
|
|
|
|
import { Text } from "@appsmith/ads";
|
2024-09-16 11:10:37 +00:00
|
|
|
import { useIsEditorInitialised } from "IDE/hooks";
|
2024-09-20 14:07:10 +00:00
|
|
|
import { useActionSettingsConfig } from "./hooks";
|
2024-09-12 04:41:54 +00:00
|
|
|
|
|
|
|
|
interface ChildrenProps {
|
2024-09-13 08:59:20 +00:00
|
|
|
children: React.ReactNode | React.ReactNode[];
|
2024-09-12 04:41:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const PluginActionEditor = (props: ChildrenProps) => {
|
|
|
|
|
const { pathname } = useLocation();
|
|
|
|
|
|
2024-09-16 11:10:37 +00:00
|
|
|
const isEditorInitialized = useIsEditorInitialised();
|
2024-09-12 04:41:54 +00:00
|
|
|
|
|
|
|
|
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));
|
|
|
|
|
|
2024-09-20 14:07:10 +00:00
|
|
|
const settingsConfig = useActionSettingsConfig(action);
|
2024-09-12 04:41:54 +00:00
|
|
|
|
|
|
|
|
const editorConfig = useSelector((state) => getEditorConfig(state, pluginId));
|
|
|
|
|
|
2024-09-25 07:44:26 +00:00
|
|
|
const actionResponses = useSelector(getActionResponses);
|
|
|
|
|
|
2024-09-12 04:41:54 +00:00
|
|
|
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>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-25 07:44:26 +00:00
|
|
|
const actionResponse = actionResponses[action.id];
|
|
|
|
|
|
2024-09-12 04:41:54 +00:00
|
|
|
return (
|
|
|
|
|
<PluginActionContextProvider
|
|
|
|
|
action={action}
|
2024-09-25 07:44:26 +00:00
|
|
|
actionResponse={actionResponse}
|
2024-09-12 04:41:54 +00:00
|
|
|
datasource={datasource}
|
|
|
|
|
editorConfig={editorConfig}
|
|
|
|
|
plugin={plugin}
|
|
|
|
|
settingsConfig={settingsConfig}
|
|
|
|
|
>
|
|
|
|
|
{props.children}
|
|
|
|
|
</PluginActionContextProvider>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default PluginActionEditor;
|