Fixed an issue where browser tree state is not remembered when reopening pgAdmin. #5777

pull/6126/head
Pravesh Sharma 2023-04-13 13:02:46 +05:30 committed by GitHub
parent 097080ba97
commit c2a54f3524
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 11 deletions

View File

@ -11,7 +11,7 @@ import _ from 'lodash';
import url_for from 'sources/url_for'; import url_for from 'sources/url_for';
import gettext from 'sources/gettext'; import gettext from 'sources/gettext';
import pgAdmin from 'sources/pgadmin'; import pgAdmin from 'sources/pgadmin';
import getApiInstance from '../api_instance'; import getApiInstance, { callFetch } from '../api_instance';
export const pgBrowser = pgAdmin.Browser = pgAdmin.Browser || {}; export const pgBrowser = pgAdmin.Browser = pgAdmin.Browser || {};
@ -86,16 +86,23 @@ _.extend(pgBrowser.browserTreeState, {
if(self.last_state == JSON.stringify(self.current_state)) if(self.last_state == JSON.stringify(self.current_state))
return; return;
getApiInstance().post( /* Using fetch with keepalive as the browser may
url_for('settings.save_tree_state'), cancel the axios request on tab close. keepalive will
JSON.stringify(self.current_state) make sure the request is completed */
).then(()=> { callFetch(
self.last_state = JSON.stringify(self.current_state); url_for('settings.save_tree_state'), {
self.fetch_state(); keepalive: true,
}).catch(function(error) { method: 'POST',
console.warn( body: JSON.stringify(self.current_state)
gettext('Error resetting the tree saved state."'), error); })
}); .then(()=> {
self.last_state = JSON.stringify(self.current_state);
self.fetch_state();
})
.catch((error)=> {
console.warn(
gettext('Error resetting the tree saved state."'), error);
});
}, },
fetch_state: function() { fetch_state: function() {