-
Notifications
You must be signed in to change notification settings - Fork 863
Fix query tool auto execution after session restore #10055
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
Open
dev-hari-prasad
wants to merge
4
commits into
pgadmin-org:master
Choose a base branch
from
dev-hari-prasad:bug/prevent-query-auto-execution
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+28
−6
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0d9c38d
Fix query auto execution on session restore
dev-hari-prasad 29433f2
Clean up QueryToolComponent state and URL handling
dev-hari-prasad aefee3f
Update QueryToolComponent.jsx
dev-hari-prasad b8a2a4e
Refactoring: Clean up state initialization and URL checks
dev-hari-prasad File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -118,6 +118,7 @@ const FIXED_PREF = { | |
| export default function QueryToolComponent({params, pgWindow, pgAdmin, selectedNodeInfo, qtPanelDocker, qtPanelId, eventBusObj}) { | ||
| const containerRef = React.useRef(null); | ||
| const preferencesStore = usePreferences(); | ||
| const isQueryTool = params.is_query_tool === true || params.is_query_tool === 'true'; | ||
| const [qtState, setQtState] = useState({ | ||
| preferences: { | ||
| browser: preferencesStore.getPreferencesForModule('browser'), | ||
|
|
@@ -138,7 +139,8 @@ export default function QueryToolComponent({params, pgWindow, pgAdmin, selectedN | |
| params: { | ||
| ...params, | ||
| title: _.unescape(params.title), | ||
| is_query_tool: params.is_query_tool == 'true', | ||
| is_query_tool: isQueryTool, | ||
| restore: params.restore === true || params.restore === 'true', | ||
| node_name: retrieveNodeName(selectedNodeInfo), | ||
| dbname: _.unescape(params.database_name) || getDatabaseLabel(selectedNodeInfo), | ||
| server_cursor: preferencesStore.getPreferencesForModule('sqleditor').server_cursor === true, | ||
|
|
@@ -154,7 +156,7 @@ export default function QueryToolComponent({params, pgWindow, pgAdmin, selectedN | |
| bgcolor: params.bgcolor, | ||
| conn_title: getTitle( | ||
| pgAdmin, null, selectedNodeInfo, true, _.unescape(params.server_name), _.unescape(params.database_name) || getDatabaseLabel(selectedNodeInfo), | ||
| _.unescape(params.role) || _.unescape(params.user), params.is_query_tool == 'true'), | ||
| _.unescape(params.role) || _.unescape(params.user), isQueryTool), | ||
| server_name: _.unescape(params.server_name), | ||
| database_name: _.unescape(params.database_name) || getDatabaseLabel(selectedNodeInfo), | ||
| is_selected: true, | ||
|
|
@@ -290,14 +292,14 @@ export default function QueryToolComponent({params, pgWindow, pgAdmin, selectedN | |
| eventBus.current.fireEvent(QUERY_TOOL_EVENTS.HANDLE_API_ERROR, err); | ||
| setQtStatePartial({ editor_disabled: true }); | ||
| }); | ||
| } else if (qtState.params.sql_id && qtState.params.restore != 'true') { | ||
| } else if (qtState.params.sql_id && qtState.params.restore !== true) { | ||
| let sqlValue = localStorage.getItem(qtState.params.sql_id); | ||
| localStorage.removeItem(qtState.params.sql_id); | ||
| if (sqlValue) { | ||
| eventBus.current.fireEvent(QUERY_TOOL_EVENTS.EDITOR_SET_SQL, sqlValue); | ||
| } | ||
| setQtStatePartial({ editor_disabled: false }); | ||
| } else if (qtState.params.restore == 'true') { | ||
| } else if (qtState.params.restore === true) { | ||
| restoreToolContent(); | ||
| } else { | ||
| setQtStatePartial({ editor_disabled: false }); | ||
|
|
@@ -342,7 +344,14 @@ export default function QueryToolComponent({params, pgWindow, pgAdmin, selectedN | |
| if(toolContent?.fileName)eventBus.current.fireEvent(QUERY_TOOL_EVENTS.LOAD_FILE_DONE, toolContent.fileName, true); | ||
| } | ||
| } | ||
| setQtStatePartial({ editor_disabled: false }); | ||
| setQtStatePartial(prev => ({ | ||
| ...prev, | ||
| editor_disabled: false, | ||
| params: { | ||
| ...prev.params, | ||
| restore: false | ||
| } | ||
| })); | ||
| }; | ||
|
|
||
| const initializeQueryTool = (password, explainObject=null, macroSQL='', executeCursor=false, executeServerCursor=false, reexecute=false)=>{ | ||
|
|
@@ -380,7 +389,7 @@ export default function QueryToolComponent({params, pgWindow, pgAdmin, selectedN | |
| obtaining_conn: false, | ||
| }); | ||
| //this condition works if user is in View/Edit Data or user does not saved server or tunnel password and disconnected the server and executing the query | ||
| if(!qtState.params.is_query_tool || reexecute) { | ||
| if((!qtState.params.is_query_tool || reexecute) && qtState.params.restore !== true) { | ||
|
|
||
| eventBus.current.fireEvent(QUERY_TOOL_EVENTS.TRIGGER_EXECUTION, explainObject, macroSQL, executeCursor, executeServerCursor); | ||
| let msg = `${selectedConn['server_name']}/${selectedConn['database_name']} - Database connected`; | ||
| pgAdmin.Browser.notifier.success(_.escape(msg)); | ||
|
|
@@ -907,6 +916,18 @@ export default function QueryToolComponent({params, pgWindow, pgAdmin, selectedN | |
| connection_list: qtState.connection_list, | ||
| current_file: qtState.current_file, | ||
| toggleQueryTool: () => setQtStatePartial((prev)=>{ | ||
| let panel = qtPanelDocker?.find(qtPanelId); | ||
| if (panel?.metaData?.toolUrl) { | ||
| try { | ||
| const toolUrl = panel.metaData.toolUrl; | ||
| const isAbsolute = toolUrl.includes('://'); | ||
|
Contributor
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. IMO This check is not required |
||
| const url = isAbsolute ? new URL(toolUrl) : new URL(toolUrl, window.location.origin); | ||
| url.searchParams.set('is_query_tool', 'true'); | ||
| panel.metaData = Object.assign({}, panel.metaData, {toolUrl: url.toString()}); | ||
|
Comment on lines
+925
to
+926
|
||
| } catch (e) { | ||
| console.warn(`Failed to update is_query_tool parameter for toolUrl "${panel?.metaData?.toolUrl}" using origin "${window.location.origin}":`, e); | ||
| } | ||
| } | ||
| return { | ||
| ...prev, | ||
| params: { | ||
|
|
@@ -1000,6 +1021,7 @@ QueryToolComponent.propTypes = { | |
| bgcolor: PropTypes.string, | ||
| fgcolor: PropTypes.string, | ||
| is_query_tool: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]).isRequired, | ||
| restore: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]), | ||
| server_cursor: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]), | ||
| user: PropTypes.string, | ||
| role: PropTypes.string, | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Changes looks good.
I observed that
restoreToolContent()is async but is called withoutawaithere, can you fix that also?