@@ -127,6 +127,7 @@ function connectionCancelledError() { |
127 | 127 | export default function QueryToolComponent({params, pgWindow, pgAdmin, selectedNodeInfo, qtPanelDocker, qtPanelId, eventBusObj}) { |
128 | 128 | const containerRef = React.useRef(null); |
129 | 129 | const preferencesStore = usePreferences(); |
| 130 | + const isQueryTool = params.is_query_tool === true || params.is_query_tool === 'true'; |
130 | 131 | const [qtState, setQtState] = useState({ |
131 | 132 | preferences: { |
132 | 133 | browser: preferencesStore.getPreferencesForModule('browser'), |
@@ -147,7 +148,8 @@ export default function QueryToolComponent({params, pgWindow, pgAdmin, selectedN |
147 | 148 | params: { |
148 | 149 | ...params, |
149 | 150 | title: _.unescape(params.title), |
150 | | - is_query_tool: params.is_query_tool == 'true', |
| 151 | + is_query_tool: isQueryTool, |
| 152 | + restore: params.restore === true || params.restore === 'true', |
151 | 153 | node_name: retrieveNodeName(selectedNodeInfo), |
152 | 154 | dbname: _.unescape(params.database_name) || getDatabaseLabel(selectedNodeInfo), |
153 | 155 | server_cursor: preferencesStore.getPreferencesForModule('sqleditor').server_cursor === true, |
@@ -163,7 +165,7 @@ export default function QueryToolComponent({params, pgWindow, pgAdmin, selectedN |
163 | 165 | bgcolor: params.bgcolor, |
164 | 166 | conn_title: getTitle( |
165 | 167 | pgAdmin, null, selectedNodeInfo, true, _.unescape(params.server_name), _.unescape(params.database_name) || getDatabaseLabel(selectedNodeInfo), |
166 | | - _.unescape(params.role) || _.unescape(params.user), params.is_query_tool == 'true'), |
| 168 | + _.unescape(params.role) || _.unescape(params.user), isQueryTool), |
167 | 169 | server_name: _.unescape(params.server_name), |
168 | 170 | database_name: _.unescape(params.database_name) || getDatabaseLabel(selectedNodeInfo), |
169 | 171 | is_selected: true, |
@@ -304,15 +306,20 @@ export default function QueryToolComponent({params, pgWindow, pgAdmin, selectedN |
304 | 306 | eventBus.current.fireEvent(QUERY_TOOL_EVENTS.HANDLE_API_ERROR, err); |
305 | 307 | setQtStatePartial({ editor_disabled: true }); |
306 | 308 | }); |
307 | | - } else if (qtState.params.sql_id && qtState.params.restore != 'true') { |
| 309 | + } else if (qtState.params.sql_id && qtState.params.restore !== true) { |
308 | 310 | let sqlValue = localStorage.getItem(qtState.params.sql_id); |
309 | 311 | localStorage.removeItem(qtState.params.sql_id); |
310 | 312 | if (sqlValue) { |
311 | 313 | eventBus.current.fireEvent(QUERY_TOOL_EVENTS.EDITOR_SET_SQL, sqlValue); |
312 | 314 | } |
313 | 315 | setQtStatePartial({ editor_disabled: false }); |
314 | | - } else if (qtState.params.restore == 'true') { |
315 | | - restoreToolContent(); |
| 316 | + } else if (qtState.params.restore === true) { |
| 317 | + // Never leave the editor disabled if the restore fails, or the tab |
| 318 | + // comes back read-only with no indication of why. |
| 319 | + restoreToolContent().catch((err) => { |
| 320 | + eventBus.current.fireEvent(QUERY_TOOL_EVENTS.HANDLE_API_ERROR, err); |
| 321 | + setQtStatePartial({ editor_disabled: false }); |
| 322 | + }); |
316 | 323 | } else { |
317 | 324 | setQtStatePartial({ editor_disabled: false }); |
318 | 325 | } |
@@ -356,7 +363,14 @@ export default function QueryToolComponent({params, pgWindow, pgAdmin, selectedN |
356 | 363 | if(toolContent?.fileName)eventBus.current.fireEvent(QUERY_TOOL_EVENTS.LOAD_FILE_DONE, toolContent.fileName, true); |
357 | 364 | } |
358 | 365 | } |
359 | | - setQtStatePartial({ editor_disabled: false }); |
| 366 | + setQtStatePartial(prev => ({ |
| 367 | + ...prev, |
| 368 | + editor_disabled: false, |
| 369 | + params: { |
| 370 | + ...prev.params, |
| 371 | + restore: false |
| 372 | + } |
| 373 | + })); |
360 | 374 | }; |
361 | 375 |
|
362 | 376 | const initializeQueryTool = (password, explainObject=null, macroSQL='', executeCursor=false, executeServerCursor=false, reexecute=false)=>{ |
@@ -998,15 +1012,31 @@ export default function QueryToolComponent({params, pgWindow, pgAdmin, selectedN |
998 | 1012 | eol: qtState.eol, |
999 | 1013 | connection_list: qtState.connection_list, |
1000 | 1014 | current_file: qtState.current_file, |
1001 | | - toggleQueryTool: () => setQtStatePartial((prev)=>{ |
1002 | | - return { |
| 1015 | + toggleQueryTool: () => { |
| 1016 | + let panel = qtPanelDocker?.find(qtPanelId); |
| 1017 | + if (!panel) { |
| 1018 | + console.warn('toggleQueryTool: panel not found for qtPanelId', qtPanelId); |
| 1019 | + } else if (panel.metaData?.toolUrl) { |
| 1020 | + try { |
| 1021 | + const toolUrl = panel.metaData.toolUrl; |
| 1022 | + const url = new URL(toolUrl, window.location.origin); |
| 1023 | + url.searchParams.set('is_query_tool', 'true'); |
| 1024 | + panel.metaData = Object.assign({}, panel.metaData, { |
| 1025 | + toolUrl: url.pathname + url.search, |
| 1026 | + }); |
| 1027 | + qtPanelDocker?.saveLayout(); |
| 1028 | + } catch (e) { |
| 1029 | + console.warn(`Failed to update is_query_tool parameter for toolUrl "${panel?.metaData?.toolUrl}" using origin "${window.location.origin}":`, e); |
| 1030 | + } |
| 1031 | + } |
| 1032 | + setQtStatePartial((prev) => ({ |
1003 | 1033 | ...prev, |
1004 | 1034 | params: { |
1005 | 1035 | ...prev.params, |
1006 | | - is_query_tool: true |
1007 | | - } |
1008 | | - }; |
1009 | | - }), |
| 1036 | + is_query_tool: true, |
| 1037 | + }, |
| 1038 | + })); |
| 1039 | + }, |
1010 | 1040 | updateTitle: (title) => { |
1011 | 1041 | setPanelTitle(qtPanelDocker, qtPanelId, title, qtState, isDirtyRef.current); |
1012 | 1042 | setQtStatePartial((prev) => { |
@@ -1098,6 +1128,7 @@ QueryToolComponent.propTypes = { |
1098 | 1128 | bgcolor: PropTypes.string, |
1099 | 1129 | fgcolor: PropTypes.string, |
1100 | 1130 | is_query_tool: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]).isRequired, |
| 1131 | + restore: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]), |
1101 | 1132 | server_cursor: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]), |
1102 | 1133 | user: PropTypes.string, |
1103 | 1134 | role: PropTypes.string, |
|