-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: Adding the functionality of running and deleting an action under modularised flow #36746
Changes from all commits
6c6dd15
21c3cb8
ea4cf33
d0cf24c
785658a
6f49630
43a2315
a1c8050
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,11 +1,10 @@ | ||||||
import React, { useCallback } from "react"; | ||||||
import React from "react"; | ||||||
import { IDEToolbar } from "IDE"; | ||||||
import { Button, Menu, MenuContent, MenuTrigger, Tooltip } from "@appsmith/ads"; | ||||||
import { modText } from "utils/helpers"; | ||||||
import { usePluginActionContext } from "../PluginActionContext"; | ||||||
import { useDispatch } from "react-redux"; | ||||||
import AnalyticsUtil from "ee/utils/AnalyticsUtil"; | ||||||
import { runAction } from "actions/pluginActionActions"; | ||||||
import { useHandleRunClick } from "PluginActionEditor/hooks"; | ||||||
import { useToggle } from "@mantine/hooks"; | ||||||
|
||||||
interface PluginActionToolbarProps { | ||||||
runOptions?: React.ReactNode; | ||||||
|
@@ -14,25 +13,9 @@ interface PluginActionToolbarProps { | |||||
} | ||||||
|
||||||
const PluginActionToolbar = (props: PluginActionToolbarProps) => { | ||||||
const { action, datasource, plugin } = usePluginActionContext(); | ||||||
const dispatch = useDispatch(); | ||||||
const handleRunClick = useCallback(() => { | ||||||
AnalyticsUtil.logEvent("RUN_QUERY_CLICK", { | ||||||
actionName: action.name, | ||||||
actionId: action.id, | ||||||
pluginName: plugin.name, | ||||||
datasourceId: datasource?.id, | ||||||
isMock: datasource?.isMock, | ||||||
}); | ||||||
dispatch(runAction(action.id)); | ||||||
}, [ | ||||||
action.id, | ||||||
action.name, | ||||||
datasource?.id, | ||||||
datasource?.isMock, | ||||||
dispatch, | ||||||
plugin.name, | ||||||
]); | ||||||
const { action } = usePluginActionContext(); | ||||||
const { handleRunClick } = useHandleRunClick(); | ||||||
const [isMenuOpen, toggleMenuOpen] = useToggle([false, true]); | ||||||
|
||||||
return ( | ||||||
<IDEToolbar> | ||||||
|
@@ -44,7 +27,7 @@ const PluginActionToolbar = (props: PluginActionToolbarProps) => { | |||||
placement="topRight" | ||||||
showArrow={false} | ||||||
> | ||||||
<Button kind="primary" onClick={handleRunClick} size="sm"> | ||||||
<Button kind="primary" onClick={() => handleRunClick()} size="sm"> | ||||||
Run | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's turn our attention to the Run button, students. I see you've made a change to the Let's go back to the previous implementation: - <Button kind="primary" onClick={() => handleRunClick()} size="sm">
+ <Button kind="primary" onClick={handleRunClick} size="sm"> This way, we're passing the function directly, which is more efficient. Always remember, in React, every little optimization counts! 📝 Committable suggestion
Suggested change
|
||||||
</Button> | ||||||
</Tooltip> | ||||||
|
@@ -54,7 +37,7 @@ const PluginActionToolbar = (props: PluginActionToolbarProps) => { | |||||
size="sm" | ||||||
startIcon="settings-2-line" | ||||||
/> | ||||||
<Menu key={action.id}> | ||||||
<Menu onOpenChange={toggleMenuOpen} open={isMenuOpen}> | ||||||
<MenuTrigger> | ||||||
<Button | ||||||
isIconButton | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
export { useActionSettingsConfig } from "ee/PluginActionEditor/hooks/useActionSettingsConfig"; | ||
export { useHandleDeleteClick } from "ee/PluginActionEditor/hooks/useHandleDeleteClick"; | ||
export { useHandleRunClick } from "ee/PluginActionEditor/hooks/useHandleRunClick"; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { deleteAction } from "actions/pluginActionActions"; | ||
import { usePluginActionContext } from "PluginActionEditor/PluginActionContext"; | ||
import { useCallback } from "react"; | ||
import { useDispatch } from "react-redux"; | ||
|
||
function useHandleDeleteClick() { | ||
const { action } = usePluginActionContext(); | ||
const dispatch = useDispatch(); | ||
|
||
const handleDeleteClick = useCallback( | ||
({ onSuccess }: { onSuccess?: () => void }) => { | ||
dispatch( | ||
deleteAction({ | ||
id: action?.id ?? "", | ||
name: action?.name ?? "", | ||
onSuccess, | ||
}), | ||
); | ||
}, | ||
[action.id, action.name, dispatch], | ||
ankitakinger marked this conversation as resolved.
Show resolved
Hide resolved
|
||
); | ||
|
||
return { handleDeleteClick }; | ||
} | ||
|
||
export { useHandleDeleteClick }; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { runAction } from "actions/pluginActionActions"; | ||
import type { PaginationField } from "api/ActionAPI"; | ||
import { usePluginActionContext } from "PluginActionEditor/PluginActionContext"; | ||
import { useCallback } from "react"; | ||
import { useDispatch } from "react-redux"; | ||
|
||
function useHandleRunClick() { | ||
const { action } = usePluginActionContext(); | ||
const dispatch = useDispatch(); | ||
|
||
const handleRunClick = useCallback( | ||
(paginationField?: PaginationField) => { | ||
dispatch(runAction(action?.id ?? "", paginationField)); | ||
}, | ||
[action.id, dispatch], | ||
); | ||
|
||
return { handleRunClick }; | ||
} | ||
|
||
export { useHandleRunClick }; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "ce/PluginActionEditor/hooks/useHandleDeleteClick"; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "ce/PluginActionEditor/hooks/useHandleRunClick"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This creates a new function on every render and should be avoided
() => handleRunClick()
, instead it's better to usehandleRunClick
.