mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-01-26 08:16:44 -06:00
862f101772
1. Replace the current layout library wcDocker with ReactJS based rc-dock. #6479 2. Have close buttons on individual panel tabs instead of common. #2821 3. Changes in the context menu on panel tabs - Add close, close all and close others menu items. #5394 4. Allow closing all the tabs, including SQL and Properties. #4733 5. Changes in docking behaviour of different tabs based on user requests and remove lock layout menu. 6. Fix an issue where the scroll position of panels was not remembered on Firefox. #2986 7. Reset layout now will not require page refresh and is done spontaneously. 8. Use the zustand store for storing preferences instead of plain JS objects. This will help reflecting preferences immediately. 9. The above fix incorrect format (no indent) of SQL stored functions/procedures. #6720 10. New version check is moved to an async request now instead of app start to improve startup performance. 11. Remove jQuery and Bootstrap completely. 12. Replace jasmine and karma test runner with jest. Migrate all the JS test cases to jest. This will save time in writing and debugging JS tests. 13. Other important code improvements and cleanup.
278 lines
7.5 KiB
JavaScript
278 lines
7.5 KiB
JavaScript
/////////////////////////////////////////////////////////////
|
|
//
|
|
// pgAdmin 4 - PostgreSQL Tools
|
|
//
|
|
// Copyright (C) 2013 - 2023, The pgAdmin Development Team
|
|
// This software is released under the PostgreSQL Licence
|
|
//
|
|
//////////////////////////////////////////////////////////////
|
|
|
|
import _ from 'lodash';
|
|
import React, { useEffect } from 'react';
|
|
import PgTable from 'sources/components/PgTable';
|
|
import gettext from 'sources/gettext';
|
|
import PropTypes from 'prop-types';
|
|
import getApiInstance from 'sources/api_instance';
|
|
import { makeStyles } from '@material-ui/core/styles';
|
|
import { getURL } from '../../../static/utils/utils';
|
|
import Loader from 'sources/components/Loader';
|
|
import EmptyPanelMessage from '../../../../static/js/components/EmptyPanelMessage';
|
|
import { compareSizeVals, toPrettySize } from '../../../../static/js/utils';
|
|
import withStandardTabInfo from '../../../../static/js/helpers/withStandardTabInfo';
|
|
import { BROWSER_PANELS } from '../../../../browser/static/js/constants';
|
|
import { usePgAdmin } from '../../../../static/js/BrowserComponent';
|
|
|
|
const useStyles = makeStyles((theme) => ({
|
|
emptyPanel: {
|
|
minHeight: '100%',
|
|
minWidth: '100%',
|
|
background: theme.otherVars.emptySpaceBg,
|
|
overflow: 'auto',
|
|
padding: '8px',
|
|
display: 'flex',
|
|
},
|
|
panelIcon: {
|
|
width: '80%',
|
|
margin: '0 auto',
|
|
marginTop: '25px !important',
|
|
position: 'relative',
|
|
textAlign: 'center',
|
|
},
|
|
panelMessage: {
|
|
marginLeft: '0.5rem',
|
|
fontSize: '0.875rem',
|
|
},
|
|
autoResizer: {
|
|
height: '100% !important',
|
|
width: '100% !important',
|
|
background: theme.palette.grey[400],
|
|
padding: '7.5px',
|
|
overflowX: 'auto !important',
|
|
overflowY: 'hidden !important',
|
|
minHeight: '100%',
|
|
minWidth: '100%',
|
|
},
|
|
}));
|
|
|
|
function getColumn(data, singleLineStatistics) {
|
|
let columns = [], column;
|
|
if (!singleLineStatistics) {
|
|
if (!_.isUndefined(data)) {
|
|
data.forEach((row) => {
|
|
if (row.name == gettext('Total Size')) {
|
|
column = {
|
|
Header: row.name,
|
|
accessor: row.name,
|
|
sortable: true,
|
|
resizable: true,
|
|
disableGlobalFilter: false,
|
|
sortType: ((rowA, rowB, id) => {
|
|
return compareSizeVals(rowA.values[id], rowB.values[id]);
|
|
})
|
|
};
|
|
}else{
|
|
column = {
|
|
Header: row.name,
|
|
accessor: row.name,
|
|
sortable: true,
|
|
resizable: true,
|
|
disableGlobalFilter: false,
|
|
};
|
|
|
|
}
|
|
columns.push(column);
|
|
});
|
|
}
|
|
return columns;
|
|
} else {
|
|
columns = [
|
|
{
|
|
Header: gettext('Statistics'),
|
|
accessor: 'name',
|
|
sortable: true,
|
|
resizable: true,
|
|
disableGlobalFilter: false,
|
|
},
|
|
{
|
|
Header: 'Value',
|
|
accessor: 'value',
|
|
sortable: true,
|
|
resizable: true,
|
|
disableGlobalFilter: false,
|
|
},
|
|
];
|
|
}
|
|
return columns;
|
|
}
|
|
|
|
function getTableData(res, node) {
|
|
let nodeStats = [],
|
|
colData;
|
|
if (res.data.data) {
|
|
let data = res.data.data;
|
|
if (node.hasCollectiveStatistics || data['rows'].length > 1) {
|
|
data.rows.forEach((row) => {
|
|
// Prettify the field values
|
|
if (!_.isEmpty(node.statsPrettifyFields)) {
|
|
node.statsPrettifyFields.forEach((field) => {
|
|
row[field] = toPrettySize(row[field]);
|
|
});
|
|
}
|
|
nodeStats.push({ ...row, icon: '' });
|
|
});
|
|
colData = getColumn(data.columns, false);
|
|
} else {
|
|
nodeStats = createSingleLineStatistics(data, node.statsPrettifyFields);
|
|
colData = getColumn(data.columns, true);
|
|
}
|
|
}
|
|
return [nodeStats, colData];
|
|
}
|
|
|
|
function createSingleLineStatistics(data, prettifyFields) {
|
|
let row = data['rows'][0],
|
|
columns = data['columns'],
|
|
res = [],
|
|
name,
|
|
value;
|
|
|
|
for (let idx in columns) {
|
|
name = columns[idx]['name'];
|
|
if (row && row[name]) {
|
|
value =
|
|
_.indexOf(prettifyFields, name) != -1
|
|
? toPrettySize(row[name])
|
|
: row[name];
|
|
} else {
|
|
value = null;
|
|
}
|
|
|
|
res.push({
|
|
name: name,
|
|
value: value,
|
|
icon: '',
|
|
});
|
|
}
|
|
|
|
return res;
|
|
}
|
|
|
|
// {nodeData, node, treeNodeInfo, isActive, isStale, setIsStale}
|
|
function Statistics({ nodeData, nodeItem, node, treeNodeInfo, isActive, isStale, setIsStale }) {
|
|
const classes = useStyles();
|
|
const [tableData, setTableData] = React.useState([]);
|
|
|
|
const [msg, setMsg] = React.useState('');
|
|
const [loaderText, setLoaderText] = React.useState('');
|
|
const [columns, setColumns] = React.useState([
|
|
{
|
|
Header: 'Statictics',
|
|
accessor: 'name',
|
|
sortable: true,
|
|
resizable: true,
|
|
disableGlobalFilter: false,
|
|
},
|
|
{
|
|
Header: 'Value',
|
|
accessor: 'value',
|
|
sortable: true,
|
|
resizable: true,
|
|
disableGlobalFilter: false,
|
|
},
|
|
]);
|
|
const pgAdmin = usePgAdmin();
|
|
|
|
useEffect(() => {
|
|
if(!isStale || !isActive) {
|
|
return;
|
|
}
|
|
|
|
let url,
|
|
message = gettext('Please select an object in the tree view.');
|
|
|
|
if (node) {
|
|
url = getURL(nodeData, true, treeNodeInfo, node, nodeItem, 'stats');
|
|
|
|
message = gettext('No statistics are available for the selected object.');
|
|
|
|
const api = getApiInstance();
|
|
if (node.hasStatistics) {
|
|
setLoaderText('Loading...');
|
|
api({
|
|
url: url,
|
|
type: 'GET',
|
|
})
|
|
.then((res) => {
|
|
let [nodeStats, colData] = getTableData(res, node);
|
|
setTableData(nodeStats);
|
|
if (!_.isUndefined(colData)) {
|
|
setColumns(colData);
|
|
}
|
|
setLoaderText('');
|
|
})
|
|
.catch((err) => {
|
|
// show failed message.
|
|
setLoaderText('');
|
|
|
|
if (err?.response?.data?.info == 'CRYPTKEY_MISSING') {
|
|
pgAdmin.Browser.notifier.pgNotifier('error', err.request, 'The master password is not set', function(mesg) {
|
|
setTimeout(function() {
|
|
if (mesg == 'CRYPTKEY_SET') {
|
|
setMsg('No statistics are available for the selected object.');
|
|
} else if (mesg == 'CRYPTKEY_NOT_SET') {
|
|
setMsg(gettext('The master password is not set.'));
|
|
}
|
|
}, 100);
|
|
});
|
|
} else {
|
|
pgAdmin.Browser.notifier.alert(
|
|
gettext('Failed to retrieve data from the server.'),
|
|
gettext(err.message)
|
|
);
|
|
setMsg(gettext('Failed to retrieve data from the server.'));
|
|
}
|
|
});
|
|
} else {
|
|
setLoaderText('');
|
|
setMsg('No statistics are available for the selected object.');
|
|
}
|
|
}
|
|
if (message != '') {
|
|
setMsg(message);
|
|
}
|
|
setIsStale(false);
|
|
}, [isStale, isActive]);
|
|
|
|
return (
|
|
<>
|
|
{tableData.length > 0 ? (
|
|
<PgTable
|
|
className={classes.autoResizer}
|
|
columns={columns}
|
|
data={tableData}
|
|
msg={msg}
|
|
type={'panel'}
|
|
></PgTable>
|
|
) : (
|
|
<div className={classes.emptyPanel}>
|
|
<Loader message={loaderText} />
|
|
<EmptyPanelMessage text={gettext(msg)}/>
|
|
</div>
|
|
)}
|
|
</>
|
|
);
|
|
}
|
|
|
|
Statistics.propTypes = {
|
|
res: PropTypes.array,
|
|
nodeData: PropTypes.object,
|
|
nodeItem: PropTypes.object,
|
|
treeNodeInfo: PropTypes.object,
|
|
node: PropTypes.func,
|
|
isActive: PropTypes.bool,
|
|
isStale: PropTypes.bool,
|
|
setIsStale: PropTypes.func,
|
|
};
|
|
|
|
export default withStandardTabInfo(Statistics, BROWSER_PANELS.STATISTICS);
|