mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Disable the query tool editor input if any SQL is being loaded to prevent users from typing. #6357
This commit is contained in:
parent
45cafd2cff
commit
85d4473af4
@ -207,8 +207,8 @@ export default function QueryToolComponent({params, pgWindow, pgAdmin, selectedN
|
|||||||
database_name: _.unescape(params.database_name) || getDatabaseLabel(selectedNodeInfo),
|
database_name: _.unescape(params.database_name) || getDatabaseLabel(selectedNodeInfo),
|
||||||
is_selected: true,
|
is_selected: true,
|
||||||
}],
|
}],
|
||||||
|
editor_disabled:true
|
||||||
});
|
});
|
||||||
|
|
||||||
const [selectedText, setSelectedText] = useState('');
|
const [selectedText, setSelectedText] = useState('');
|
||||||
|
|
||||||
const setQtState = (state)=>{
|
const setQtState = (state)=>{
|
||||||
@ -312,27 +312,32 @@ export default function QueryToolComponent({params, pgWindow, pgAdmin, selectedN
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const getSQLScript = ()=>{
|
const getSQLScript = () => {
|
||||||
// Fetch the SQL for Scripts (eg: CREATE/UPDATE/DELETE/SELECT)
|
// Fetch the SQL for Scripts (eg: CREATE/UPDATE/DELETE/SELECT)
|
||||||
// Call AJAX only if script type url is present
|
// Call AJAX only if script type URL is present
|
||||||
if(qtState.params.is_query_tool && qtState.params.query_url) {
|
if (qtState.params.is_query_tool && qtState.params.query_url) {
|
||||||
api.get(qtState.params.query_url)
|
api.get(qtState.params.query_url)
|
||||||
.then((res)=>{
|
.then((res) => {
|
||||||
eventBus.current.fireEvent(QUERY_TOOL_EVENTS.EDITOR_SET_SQL, res.data);
|
eventBus.current.fireEvent(QUERY_TOOL_EVENTS.EDITOR_SET_SQL, res.data);
|
||||||
|
setQtState({ editor_disabled: false });
|
||||||
})
|
})
|
||||||
.catch((err)=>{
|
.catch((err) => {
|
||||||
eventBus.current.fireEvent(QUERY_TOOL_EVENTS.HANDLE_API_ERROR, err);
|
eventBus.current.fireEvent(QUERY_TOOL_EVENTS.HANDLE_API_ERROR, err);
|
||||||
|
setQtState({ editor_disabled: true });
|
||||||
});
|
});
|
||||||
} else if(qtState.params.sql_id) {
|
} else if (qtState.params.sql_id) {
|
||||||
let sqlValue = localStorage.getItem(qtState.params.sql_id);
|
let sqlValue = localStorage.getItem(qtState.params.sql_id);
|
||||||
localStorage.removeItem(qtState.params.sql_id);
|
localStorage.removeItem(qtState.params.sql_id);
|
||||||
if(sqlValue) {
|
if (sqlValue) {
|
||||||
eventBus.current.fireEvent(QUERY_TOOL_EVENTS.EDITOR_SET_SQL, sqlValue);
|
eventBus.current.fireEvent(QUERY_TOOL_EVENTS.EDITOR_SET_SQL, sqlValue);
|
||||||
}
|
}
|
||||||
|
setQtState({ editor_disabled: false });
|
||||||
|
} else {
|
||||||
|
setQtState({ editor_disabled: false });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const initializeQueryTool = (password)=>{
|
const initializeQueryTool = (password)=>{
|
||||||
let selectedConn = _.find(qtState.connection_list, (c)=>c.is_selected);
|
let selectedConn = _.find(qtState.connection_list, (c)=>c.is_selected);
|
||||||
let baseUrl = '';
|
let baseUrl = '';
|
||||||
@ -871,6 +876,7 @@ export default function QueryToolComponent({params, pgWindow, pgAdmin, selectedN
|
|||||||
params: qtState.params,
|
params: qtState.params,
|
||||||
preferences: qtState.preferences,
|
preferences: qtState.preferences,
|
||||||
mainContainerRef: containerRef,
|
mainContainerRef: containerRef,
|
||||||
|
editor_disabled: qtState.editor_disabled,
|
||||||
toggleQueryTool: () => setQtState((prev)=>{
|
toggleQueryTool: () => setQtState((prev)=>{
|
||||||
return {
|
return {
|
||||||
...prev,
|
...prev,
|
||||||
@ -901,7 +907,7 @@ export default function QueryToolComponent({params, pgWindow, pgAdmin, selectedN
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
}), [qtState.params, qtState.preferences, containerRef.current]);
|
}), [qtState.params, qtState.preferences, containerRef.current, qtState.editor_disabled]);
|
||||||
|
|
||||||
const queryToolConnContextValue = React.useMemo(()=>({
|
const queryToolConnContextValue = React.useMemo(()=>({
|
||||||
connected: qtState.connected,
|
connected: qtState.connected,
|
||||||
|
@ -64,7 +64,6 @@ export default function Query({onTextSelect}) {
|
|||||||
const lastCursorPos = React.useRef();
|
const lastCursorPos = React.useRef();
|
||||||
const pgAdmin = usePgAdmin();
|
const pgAdmin = usePgAdmin();
|
||||||
const preferencesStore = usePreferences();
|
const preferencesStore = usePreferences();
|
||||||
|
|
||||||
const queryToolPref = queryToolCtx.preferences.sqleditor;
|
const queryToolPref = queryToolCtx.preferences.sqleditor;
|
||||||
|
|
||||||
const highlightError = (cmObj, {errormsg: result, data}, executeCursor)=>{
|
const highlightError = (cmObj, {errormsg: result, data}, executeCursor)=>{
|
||||||
@ -175,6 +174,7 @@ export default function Query({onTextSelect}) {
|
|||||||
editor.current.removeErrorMark();
|
editor.current.removeErrorMark();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
eventBus.registerListener(QUERY_TOOL_EVENTS.LOAD_FILE, (fileName, storage)=>{
|
eventBus.registerListener(QUERY_TOOL_EVENTS.LOAD_FILE, (fileName, storage)=>{
|
||||||
queryToolCtx.api.post(url_for('sqleditor.load_file'), {
|
queryToolCtx.api.post(url_for('sqleditor.load_file'), {
|
||||||
@ -504,6 +504,7 @@ export default function Query({onTextSelect}) {
|
|||||||
autocomplete={true}
|
autocomplete={true}
|
||||||
customKeyMap={shortcutOverrideKeys}
|
customKeyMap={shortcutOverrideKeys}
|
||||||
onTextSelect={onTextSelect}
|
onTextSelect={onTextSelect}
|
||||||
|
disabled={queryToolCtx.editor_disabled}
|
||||||
/>;
|
/>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user