Fixed an issue where unexpected error messages are displayed when users change the language via preferences. Fixes #7267

This commit is contained in:
Nikhil Mohite
2022-03-24 16:08:13 +05:30
committed by Akshay Joshi
parent 473afd950c
commit 0b4a874f30
6 changed files with 27 additions and 8 deletions

View File

@@ -166,6 +166,7 @@ export default function PreferencesComponent({ ...props }) {
const [initValues, setInitValues] = React.useState({});
const [loadTree, setLoadTree] = React.useState(0);
const api = getApiInstance();
const firstTreeElement = React.useRef('');
useEffect(() => {
const pref_url = url_for('preferences.index');
@@ -194,6 +195,10 @@ export default function PreferencesComponent({ ...props }) {
'isExpanded': true,
};
if(firstTreeElement.current.length == 0) {
firstTreeElement.current = node.label;
}
node.children.forEach(subNode => {
let sid = Math.floor(Math.random() * 1000);
let nodeData = {
@@ -258,7 +263,7 @@ export default function PreferencesComponent({ ...props }) {
let _val = element.value.split('|');
preferencesValues[element.id] = { 'warning': _val[0], 'alert': _val[1] };
} else if (subNode.label == 'Results grid' && node.label == 'Query Tool') {
} else if (subNode.label == gettext('Results grid') && node.label == gettext('Query Tool')) {
setResultsOptions(element, subNode, preferencesValues, type);
} else {
element.type = type;
@@ -327,10 +332,10 @@ export default function PreferencesComponent({ ...props }) {
}
function addNote(node, subNode, nodeData, preferencesData, note = '') {
// Check and add the note for the element.
if (subNode.label == 'Nodes' && node.label == 'Browser') {
if (subNode.label == gettext('Nodes') && node.label == gettext('Browser')) {
note = [gettext('This settings is to Show/Hide nodes in the browser tree.')].join('');
} else {
note = [gettext(note)].join('');
note = [note].join('');
}
if (note && note.length > 0) {
@@ -374,7 +379,7 @@ export default function PreferencesComponent({ ...props }) {
// Listen added preferences tree node event to expand the newly added node on tree load.
pgAdmin.Browser.Events.on('preferences:tree:added', (item) => {
if (item._parent._fileName == 'Browser' && item._parent.isExpanded && !prefTreeInit.current) {
if (item._parent._fileName == firstTreeElement.current && item._parent.isExpanded && !prefTreeInit.current) {
pgAdmin.Browser.ptree.tree.setActiveFile(item._parent._children[0], false);
}
else if (item.type == FileType.Directory) {

View File

@@ -40,7 +40,7 @@ export default function PreferencesTree({ pgBrowser, data }) {
},
sortComparator: (a, b) => {
// No nee to sort Query tool options.
if (a._parent && a._parent._fileName == 'Query Tool') return 0;
if (a._parent && a._parent._fileName == gettext('Query Tool')) return 0;
// Sort alphabetically
if (a.constructor === b.constructor) {
return pgAdmin.natural_sort(a.fileName, b.fileName);