Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions app/client/src/PluginActionEditor/PluginActionContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,27 @@ interface ChildrenProps {
export const PluginActionContextProvider = (
props: ChildrenProps & PluginActionContextType,
) => {
const { action, children, datasource, editorConfig, plugin, settingsConfig } =
props;
const {
action,
actionResponse,
children,
datasource,
editorConfig,
plugin,
settingsConfig,
} = props;

// using useMemo to avoid unnecessary renders
const contextValue = useMemo(
() => ({
action,
actionResponse,
datasource,
editorConfig,
plugin,
settingsConfig,
}),
[action, datasource, editorConfig, plugin, settingsConfig],
[action, actionResponse, datasource, editorConfig, plugin, settingsConfig],
);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ const PluginActionToolbar = (props: PluginActionToolbarProps) => {
const { handleRunClick } = useHandleRunClick();
const [isMenuOpen, toggleMenuOpen] = useToggle([false, true]);

const onRunClick = () => {
handleRunClick();
};

return (
<IDEToolbar>
<IDEToolbar.Left>{props.children}</IDEToolbar.Left>
Expand All @@ -27,7 +31,7 @@ const PluginActionToolbar = (props: PluginActionToolbarProps) => {
placement="topRight"
showArrow={false}
>
<Button kind="primary" onClick={() => handleRunClick()} size="sm">
<Button kind="primary" onClick={onRunClick} size="sm">
Run
</Button>
</Tooltip>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,24 @@ import DebuggerLogs from "components/editorComponents/Debugger/DebuggerLogs";
import { PluginType } from "entities/Action";
import { ApiResponse } from "PluginActionEditor/components/PluginActionResponse/components/ApiResponse";
import { ApiResponseHeaders } from "PluginActionEditor/components/PluginActionResponse/components/ApiResponseHeaders";
import { noop } from "lodash";
import { EditorTheme } from "components/editorComponents/CodeEditor/EditorConfig";
import { getErrorCount } from "selectors/debuggerSelectors";
import { getPluginActionDebuggerState } from "PluginActionEditor/store";
import {
getPluginActionDebuggerState,
isActionRunning,
} from "PluginActionEditor/store";
import { doesPluginRequireDatasource } from "ee/entities/Engine/actionHelpers";
import useShowSchema from "components/editorComponents/ActionRightPane/useShowSchema";
import Schema from "components/editorComponents/Debugger/Schema";
import QueryResponseTab from "pages/Editor/QueryEditor/QueryResponseTab";
import type { SourceEntity } from "entities/AppsmithConsole";
import { ENTITY_TYPE as SOURCE_ENTITY_TYPE } from "ee/entities/AppsmithConsole/utils";
import { useHandleRunClick } from "PluginActionEditor/hooks";
import useDebuggerTriggerClick from "components/editorComponents/Debugger/hooks/useDebuggerTriggerClick";
import { useFeatureFlag } from "utils/hooks/useFeatureFlag";
import { FEATURE_FLAG } from "ee/entities/FeatureFlag";
import { getHasExecuteActionPermission } from "ee/utils/BusinessFeatures/permissionPageHelpers";
import { DEFAULT_DATASOURCE_NAME } from "constants/ApiEditorConstants/ApiEditorConstants";

function usePluginActionResponseTabs() {
const { action, actionResponse, datasource, plugin } =
Expand All @@ -42,8 +49,36 @@ function usePluginActionResponseTabs() {

const { responseTabHeight } = useSelector(getPluginActionDebuggerState);

const onDebugClick = useDebuggerTriggerClick();
const isRunning = useSelector(isActionRunning(action.id));

const isFeatureEnabled = useFeatureFlag(FEATURE_FLAG.license_gac_enabled);
const isExecutePermitted = getHasExecuteActionPermission(
isFeatureEnabled,
action?.userPermissions,
);
// this gets the url of the current action's datasource
const actionDatasourceUrl =
action?.datasource?.datasourceConfiguration?.url || "";
Comment thread
ankitakinger marked this conversation as resolved.
Outdated
const actionDatasourceUrlPath = action?.actionConfiguration?.path || "";
// this gets the name of the current action's datasource
const actionDatasourceName = action?.datasource.name || "";

Comment thread
ankitakinger marked this conversation as resolved.
Outdated
// if the url is empty and the action's datasource name is the default datasource name (this means the api does not have a datasource attached)
// or the user does not have permission,
// we block action execution.
const blockExecution =
(!actionDatasourceUrl &&
!actionDatasourceUrlPath &&
actionDatasourceName === DEFAULT_DATASOURCE_NAME) ||
!isExecutePermitted;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only related to API actions and should be extracted out into its own hook. Also should this condition not be applied at the toolbar run level as well?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes you're correct. It will be needed there too. Although, I just checked, both Query and Api uses different conditions for blocking execution. Should we return the value from the hook based on action type?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If they rely on completely different logic to decide this, it should be extracted out into separate utils.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've kept it in the same hook because PluginActionToolbar is common between Api and Query and so we will end up having Action type checked there if we have 2 separate hooks.


Comment thread
ankitakinger marked this conversation as resolved.
const tabs: BottomTab[] = [];

const onRunClick = () => {
handleRunClick();
};

if (IDEViewMode === EditorViewMode.FullScreen) {
tabs.push(
{
Expand All @@ -69,9 +104,9 @@ function usePluginActionResponseTabs() {
<ApiResponse
action={action}
actionResponse={actionResponse}
isRunDisabled={false}
isRunning={false}
onRunClick={handleRunClick}
isRunDisabled={blockExecution}
isRunning={isRunning}
onRunClick={onRunClick}
responseTabHeight={responseTabHeight}
theme={EditorTheme.LIGHT}
/>
Expand All @@ -83,10 +118,10 @@ function usePluginActionResponseTabs() {
panelComponent: (
<ApiResponseHeaders
actionResponse={actionResponse}
isRunDisabled={false}
isRunning={false}
onDebugClick={noop}
onRunClick={handleRunClick}
isRunDisabled={blockExecution}
isRunning={isRunning}
onDebugClick={onDebugClick}
onRunClick={onRunClick}
/>
),
},
Expand Down Expand Up @@ -132,8 +167,8 @@ function usePluginActionResponseTabs() {
actionName={action.name}
actionSource={actionSource}
currentActionConfig={action}
isRunning={false}
onRunClick={handleRunClick}
isRunning={isRunning}
onRunClick={onRunClick}
runErrorMessage={""} // TODO
/>
),
Expand Down