mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2024-11-22 08:46:39 -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),
|
||||
is_selected: true,
|
||||
}],
|
||||
editor_disabled:true
|
||||
});
|
||||
|
||||
const [selectedText, setSelectedText] = useState('');
|
||||
|
||||
const setQtState = (state)=>{
|
||||
@ -313,23 +313,28 @@ export default function QueryToolComponent({params, pgWindow, pgAdmin, selectedN
|
||||
},
|
||||
};
|
||||
|
||||
const getSQLScript = ()=>{
|
||||
const getSQLScript = () => {
|
||||
// Fetch the SQL for Scripts (eg: CREATE/UPDATE/DELETE/SELECT)
|
||||
// Call AJAX only if script type url is present
|
||||
if(qtState.params.is_query_tool && qtState.params.query_url) {
|
||||
// Call AJAX only if script type URL is present
|
||||
if (qtState.params.is_query_tool && 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);
|
||||
setQtState({ editor_disabled: false });
|
||||
})
|
||||
.catch((err)=>{
|
||||
.catch((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);
|
||||
localStorage.removeItem(qtState.params.sql_id);
|
||||
if(sqlValue) {
|
||||
if (sqlValue) {
|
||||
eventBus.current.fireEvent(QUERY_TOOL_EVENTS.EDITOR_SET_SQL, sqlValue);
|
||||
}
|
||||
setQtState({ editor_disabled: false });
|
||||
} else {
|
||||
setQtState({ editor_disabled: false });
|
||||
}
|
||||
};
|
||||
|
||||
@ -871,6 +876,7 @@ export default function QueryToolComponent({params, pgWindow, pgAdmin, selectedN
|
||||
params: qtState.params,
|
||||
preferences: qtState.preferences,
|
||||
mainContainerRef: containerRef,
|
||||
editor_disabled: qtState.editor_disabled,
|
||||
toggleQueryTool: () => setQtState((prev)=>{
|
||||
return {
|
||||
...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(()=>({
|
||||
connected: qtState.connected,
|
||||
|
@ -64,7 +64,6 @@ export default function Query({onTextSelect}) {
|
||||
const lastCursorPos = React.useRef();
|
||||
const pgAdmin = usePgAdmin();
|
||||
const preferencesStore = usePreferences();
|
||||
|
||||
const queryToolPref = queryToolCtx.preferences.sqleditor;
|
||||
|
||||
const highlightError = (cmObj, {errormsg: result, data}, executeCursor)=>{
|
||||
@ -176,6 +175,7 @@ export default function Query({onTextSelect}) {
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
eventBus.registerListener(QUERY_TOOL_EVENTS.LOAD_FILE, (fileName, storage)=>{
|
||||
queryToolCtx.api.post(url_for('sqleditor.load_file'), {
|
||||
'file_name': decodeURI(fileName),
|
||||
@ -504,6 +504,7 @@ export default function Query({onTextSelect}) {
|
||||
autocomplete={true}
|
||||
customKeyMap={shortcutOverrideKeys}
|
||||
onTextSelect={onTextSelect}
|
||||
disabled={queryToolCtx.editor_disabled}
|
||||
/>;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user