GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fix Query Tool tabs auto-running their query after a session restore … · pgadmin-org/pgadmin4@e78c7fe

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • web/pgadmin/tools/sqleditor/static/js/components
    • QueryToolComponent.jsx
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎web/pgadmin/tools/sqleditor/static/js/components/QueryToolComponent.jsx‎

Copy file name to clipboardExpand all lines: web/pgadmin/tools/sqleditor/static/js/components/QueryToolComponent.jsx
+43-12Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ function connectionCancelledError() {
127127
export default function QueryToolComponent({params, pgWindow, pgAdmin, selectedNodeInfo, qtPanelDocker, qtPanelId, eventBusObj}) {
128128
const containerRef = React.useRef(null);
129129
const preferencesStore = usePreferences();
130+
const isQueryTool = params.is_query_tool === true || params.is_query_tool === 'true';
130131
const [qtState, setQtState] = useState({
131132
preferences: {
132133
browser: preferencesStore.getPreferencesForModule('browser'),
@@ -147,7 +148,8 @@ export default function QueryToolComponent({params, pgWindow, pgAdmin, selectedN
147148
params: {
148149
...params,
149150
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',
151153
node_name: retrieveNodeName(selectedNodeInfo),
152154
dbname: _.unescape(params.database_name) || getDatabaseLabel(selectedNodeInfo),
153155
server_cursor: preferencesStore.getPreferencesForModule('sqleditor').server_cursor === true,
@@ -163,7 +165,7 @@ export default function QueryToolComponent({params, pgWindow, pgAdmin, selectedN
163165
bgcolor: params.bgcolor,
164166
conn_title: getTitle(
165167
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),
167169
server_name: _.unescape(params.server_name),
168170
database_name: _.unescape(params.database_name) || getDatabaseLabel(selectedNodeInfo),
169171
is_selected: true,
@@ -304,15 +306,20 @@ export default function QueryToolComponent({params, pgWindow, pgAdmin, selectedN
304306
eventBus.current.fireEvent(QUERY_TOOL_EVENTS.HANDLE_API_ERROR, err);
305307
setQtStatePartial({ editor_disabled: true });
306308
});
307-
} else if (qtState.params.sql_id && qtState.params.restore != 'true') {
309+
} else if (qtState.params.sql_id && qtState.params.restore !== true) {
308310
let sqlValue = localStorage.getItem(qtState.params.sql_id);
309311
localStorage.removeItem(qtState.params.sql_id);
310312
if (sqlValue) {
311313
eventBus.current.fireEvent(QUERY_TOOL_EVENTS.EDITOR_SET_SQL, sqlValue);
312314
}
313315
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+
});
316323
} else {
317324
setQtStatePartial({ editor_disabled: false });
318325
}
@@ -356,7 +363,14 @@ export default function QueryToolComponent({params, pgWindow, pgAdmin, selectedN
356363
if(toolContent?.fileName)eventBus.current.fireEvent(QUERY_TOOL_EVENTS.LOAD_FILE_DONE, toolContent.fileName, true);
357364
}
358365
}
359-
setQtStatePartial({ editor_disabled: false });
366+
setQtStatePartial(prev => ({
367+
...prev,
368+
editor_disabled: false,
369+
params: {
370+
...prev.params,
371+
restore: false
372+
}
373+
}));
360374
};
361375

362376
const initializeQueryTool = (password, explainObject=null, macroSQL='', executeCursor=false, executeServerCursor=false, reexecute=false)=>{
@@ -998,15 +1012,31 @@ export default function QueryToolComponent({params, pgWindow, pgAdmin, selectedN
9981012
eol: qtState.eol,
9991013
connection_list: qtState.connection_list,
10001014
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) => ({
10031033
...prev,
10041034
params: {
10051035
...prev.params,
1006-
is_query_tool: true
1007-
}
1008-
};
1009-
}),
1036+
is_query_tool: true,
1037+
},
1038+
}));
1039+
},
10101040
updateTitle: (title) => {
10111041
setPanelTitle(qtPanelDocker, qtPanelId, title, qtState, isDirtyRef.current);
10121042
setQtStatePartial((prev) => {
@@ -1098,6 +1128,7 @@ QueryToolComponent.propTypes = {
10981128
bgcolor: PropTypes.string,
10991129
fgcolor: PropTypes.string,
11001130
is_query_tool: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]).isRequired,
1131+
restore: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),
11011132
server_cursor: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),
11021133
user: PropTypes.string,
11031134
role: PropTypes.string,

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.