diff --git a/web/pgadmin/static/js/components/CodeMirror.jsx b/web/pgadmin/static/js/components/CodeMirror.jsx index c220ccb88..e6856123f 100644 --- a/web/pgadmin/static/js/components/CodeMirror.jsx +++ b/web/pgadmin/static/js/components/CodeMirror.jsx @@ -134,7 +134,7 @@ export function FindDialog({editor, show, replace, onClose}) { const search = ()=>{ if(editor) { let query = parseQuery(findVal, useRegex, matchCase); - searchCursor.current = editor.getSearchCursor(query, editor.getCursor(true), !matchCase); + searchCursor.current = editor.getSearchCursor(query, 0, !matchCase); if(findVal != '') { editor.removeOverlay(highlightsearch.current); highlightsearch.current = searchOverlay(query, matchCase); @@ -221,6 +221,8 @@ export function FindDialog({editor, show, replace, onClose}) { }; const onReplaceAll = ()=>{ + /* search from start */ + search(); while(searchCursor.current.from()) { onReplace(); } @@ -253,10 +255,13 @@ export function FindDialog({editor, show, replace, onClose}) { />} - } size="xs" noBorder onClick={onFindPrev} /> - } size="xs" noBorder onClick={onFindNext}/> + } size="xs" noBorder onClick={onFindPrev} + style={{marginRight: '2px'}} /> + } size="xs" noBorder onClick={onFindNext} + style={{marginRight: '2px'}} /> {replace && <> - } size="xs" noBorder onClick={onReplace} /> + } size="xs" noBorder onClick={onReplace} + style={{marginRight: '2px'}} /> } size="xs" noBorder onClick={onReplaceAll}/> } diff --git a/web/pgadmin/tools/sqleditor/static/js/components/QueryToolComponent.jsx b/web/pgadmin/tools/sqleditor/static/js/components/QueryToolComponent.jsx index 7738dc33f..02ca27367 100644 --- a/web/pgadmin/tools/sqleditor/static/js/components/QueryToolComponent.jsx +++ b/web/pgadmin/tools/sqleditor/static/js/components/QueryToolComponent.jsx @@ -68,6 +68,11 @@ function setPanelTitle(panel, title, qtState, dirty=false) { setQueryToolDockerTitle(panel, true, title, qtState.current_file ? true : false); } } + +function onBeforeUnload(e) { + e.preventDefault(); + e.returnValue = 'prevent'; +} export default function QueryToolComponent({params, pgWindow, pgAdmin, selectedNodeInfo, panel, eventBusObj}) { const containerRef = React.useRef(null); const forceClose = React.useRef(false); @@ -111,7 +116,8 @@ export default function QueryToolComponent({params, pgWindow, pgAdmin, selectedN const modal = useModal(); /* Connection status poller */ - let pollTime = qtState.preferences.sqleditor.connection_status_fetch_time > 0 && !qtState.obtaining_conn ? + let pollTime = qtState.preferences.sqleditor.connection_status_fetch_time > 0 + && !qtState.obtaining_conn && qtState.preferences?.sqleditor?.connection_status ? qtState.preferences.sqleditor.connection_status_fetch_time*1000 : -1; /* No need to poll when the query is executing. Query poller will the txn status */ if(qtState.connection_status === CONNECTION_STATUS.TRANSACTION_STATUS_ACTIVE && qtState.connected) { @@ -299,6 +305,7 @@ export default function QueryToolComponent({params, pgWindow, pgAdmin, selectedN /* WC docker events */ panel?.on(window.wcDocker.EVENT.CLOSING, function() { + window.removeEventListener('beforeunload', onBeforeUnload); if(!forceClose.current) { eventBus.current.fireEvent(QUERY_TOOL_EVENTS.WARN_SAVE_DATA_CLOSE); } else { @@ -313,6 +320,8 @@ export default function QueryToolComponent({params, pgWindow, pgAdmin, selectedN pgAdmin.Browser.Events.on('pgadmin-storage:finish_btn:create_file', (fileName)=>{ eventBus.current.fireEvent(QUERY_TOOL_EVENTS.SAVE_FILE, fileName); }, pgAdmin); + + window.addEventListener('beforeunload', onBeforeUnload); }, []); useEffect(()=>{ diff --git a/web/pgadmin/tools/sqleditor/static/js/components/QueryToolDataGrid/Editors.jsx b/web/pgadmin/tools/sqleditor/static/js/components/QueryToolDataGrid/Editors.jsx index 16e62a51d..a37a98c63 100644 --- a/web/pgadmin/tools/sqleditor/static/js/components/QueryToolDataGrid/Editors.jsx +++ b/web/pgadmin/tools/sqleditor/static/js/components/QueryToolDataGrid/Editors.jsx @@ -93,7 +93,7 @@ const useStyles = makeStyles((theme)=>({ lineHeight: '16px', '&.checked, &.unchecked': { - background: theme.palette.background.default, + background: theme.palette.grey[200], }, '&.checked:after': { content: '\'\\2713\'', diff --git a/web/pgadmin/tools/sqleditor/static/js/components/sections/MainToolBar.jsx b/web/pgadmin/tools/sqleditor/static/js/components/sections/MainToolBar.jsx index e2d6f9bdd..13bcf507b 100644 --- a/web/pgadmin/tools/sqleditor/static/js/components/sections/MainToolBar.jsx +++ b/web/pgadmin/tools/sqleditor/static/js/components/sections/MainToolBar.jsx @@ -43,6 +43,7 @@ const useStyles = makeStyles((theme)=>({ alignItems: 'center', gap: '4px', backgroundColor: theme.otherVars.editorToolbarBg, + flexWrap: 'wrap', ...theme.mixins.panelBorder.bottom, }, })); @@ -322,7 +323,7 @@ export function MainToolBar({containerRef, onFilterClick, onManageMacros}) { eventBus.fireEvent(QUERY_TOOL_EVENTS.EXECUTION_START, 'ROLLBACK;', null, true); }; const executeMacro = (m)=>{ - eventBus.fireEvent(QUERY_TOOL_EVENTS.EXECUTION_START, m.sql, null, true); + eventBus.fireEvent(QUERY_TOOL_EVENTS.TRIGGER_EXECUTION, null, m.sql); }; const onLimitChange=(e)=>{ setLimit(e.target.value); diff --git a/web/pgadmin/tools/sqleditor/static/js/components/sections/Query.jsx b/web/pgadmin/tools/sqleditor/static/js/components/sections/Query.jsx index 42dc05a3b..fa7c23707 100644 --- a/web/pgadmin/tools/sqleditor/static/js/components/sections/Query.jsx +++ b/web/pgadmin/tools/sqleditor/static/js/components/sections/Query.jsx @@ -237,11 +237,20 @@ export default function Query() { } }; - const triggerExecution = (explainObject)=>{ + const triggerExecution = (explainObject, macroSQL)=>{ if(queryToolCtx.params.is_query_tool) { - let query = editor.current?.getSelection() || editor.current?.getValue() || ''; + let external = null; + let query = editor.current?.getSelection(); + if(!_.isUndefined(macroSQL)) { + const regex = /\$SELECTION\$/gi; + query = macroSQL.replace(regex, query); + external = true; + } else{ + /* Normal execution */ + query = query || editor.current?.getValue() || ''; + } if(query) { - eventBus.fireEvent(QUERY_TOOL_EVENTS.EXECUTION_START, query, explainObject); + eventBus.fireEvent(QUERY_TOOL_EVENTS.EXECUTION_START, query, explainObject, external); } } else { eventBus.fireEvent(QUERY_TOOL_EVENTS.EXECUTION_START, null, null);