Skip to content

Commit

Permalink
Fix the issue where backend APIs are called even if System Stat exten…
Browse files Browse the repository at this point in the history
…sion is not installed for the database.
  • Loading branch information
khushboovashi committed Oct 4, 2023
1 parent 9c903f9 commit 0b3c798
Showing 1 changed file with 42 additions and 33 deletions.
75 changes: 42 additions & 33 deletions web/pgadmin/dashboard/static/js/Dashboard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ export default function Dashboard({
const [activeOnly, setActiveOnly] = useState(false);
const [schemaDict, setSchemaDict] = React.useState({});
const [systemStatsTabVal, setSystemStatsTabVal] = useState(0);
const [ldid, setLdid] = useState(0);

const systemStatsTabChanged = (e, tabVal) => {
setSystemStatsTabVal(tabVal);
Expand Down Expand Up @@ -772,7 +773,6 @@ export default function Dashboard({
}

if (sid && props.serverConnected) {

if (tabVal === 0) {
url = url_for('dashboard.activity');
} else if (tabVal === 1) {
Expand All @@ -789,50 +789,59 @@ export default function Dashboard({
else url += sid;

if (did && !props.dbConnected) return;
if (did) ssExtensionCheckUrl += '/' + sid + '/' + did;
if (did && did > 0) ssExtensionCheckUrl += '/' + sid + '/' + did;
else ssExtensionCheckUrl += '/' + sid;

const api = getApiInstance();
if (node) {
api({
url: url,
type: 'GET',
})
.then((res) => {
setdashData(parseData(res.data));
if (mainTabVal == 0) {
api({
url: url,
type: 'GET',
})
.catch((error) => {
Notify.alert(
gettext('Failed to retrieve data from the server.'),
_.isUndefined(error.response) ? error.message : error.response.data.errormsg
);
// show failed message.
setMsg(gettext('Failed to retrieve data from the server.'));
});

api({
url: ssExtensionCheckUrl,
type: 'GET',
})
.then((res) => {
const data = res.data;
if(data['ss_present'] == false){
setSsMsg(gettext('System stats extension is not installed. You can install the extension in a database using the "CREATE EXTENSION system_stats;" SQL command. Reload the pgAdmin once you installed.'));
} else {
setSsMsg(gettext(''));
}
.then((res) => {
setdashData(parseData(res.data));
})
.catch((error) => {
Notify.alert(
gettext('Failed to retrieve data from the server.'),
_.isUndefined(error.response) ? error.message : error.response.data.errormsg
);
// show failed message.
setMsg(gettext('Failed to retrieve data from the server.'));
});
}
else if (mainTabVal == 1) {
api({
url: ssExtensionCheckUrl,
type: 'GET',
})
.catch(() => {
setSsMsg(gettext('Failed to verify the presence of system stats extension.'));
});
.then((res) => {
const data = res.data;
if(data['ss_present'] == false){
setSsMsg(gettext('System stats extension is not installed. You can install the extension in a database using the "CREATE EXTENSION system_stats;" SQL command. Reload the pgAdmin once you installed.'));
setLdid(0);
} else {
setSsMsg('installed');
setLdid(did);
}
})
.catch(() => {
setSsMsg(gettext('Failed to verify the presence of system stats extension.'));
setLdid(0);
});
} else {
setSsMsg('');
setLdid(0);
}
} else {
setMsg(message);
}
}
if (message != '') {
setMsg(message);
}
}, [nodeData, tabVal, did, preferences, refresh, props.dbConnected]);
}, [nodeData, tabVal, did, preferences, refresh, props.dbConnected, mainTabVal]);

const filteredDashData = useMemo(()=>{
if (tabVal == 0 && activeOnly) {
Expand Down Expand Up @@ -985,7 +994,7 @@ export default function Dashboard({
{/* System Statistics */}
<TabPanel value={mainTabVal} index={1} classNameRoot={classes.tabPanel}>
<Box height="100%" display="flex" flexDirection="column">
{ssMsg === '' ?
{ssMsg === 'installed' && did === ldid ?
<>
<Box>
<Tabs
Expand Down

0 comments on commit 0b3c798

Please sign in to comment.