Disable the query tool editor input if any SQL is being loaded to prevent users from typing. #6357

This commit is contained in:
Rohit Bhati 2024-06-06 18:06:49 +05:30 committed by GitHub
parent 45cafd2cff
commit 85d4473af4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 12 deletions

View File

@ -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)=>{
@ -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)
// 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 });
}
};
const initializeQueryTool = (password)=>{
let selectedConn = _.find(qtState.connection_list, (c)=>c.is_selected);
let baseUrl = '';
@ -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,

View File

@ -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)=>{
@ -175,6 +174,7 @@ export default function Query({onTextSelect}) {
editor.current.removeErrorMark();
}
});
eventBus.registerListener(QUERY_TOOL_EVENTS.LOAD_FILE, (fileName, storage)=>{
queryToolCtx.api.post(url_for('sqleditor.load_file'), {
@ -504,6 +504,7 @@ export default function Query({onTextSelect}) {
autocomplete={true}
customKeyMap={shortcutOverrideKeys}
onTextSelect={onTextSelect}
disabled={queryToolCtx.editor_disabled}
/>;
}