This commit is contained in:
Jan Prochazka
2020-05-13 17:56:09 +02:00
parent 99a6b1bb31
commit 97901d2d6f
3 changed files with 56 additions and 14 deletions

View File

@@ -69,14 +69,16 @@ export class TableGridDisplay extends GridDisplay {
const childAlias = `${column.uniqueName}_ref`; const childAlias = `${column.uniqueName}_ref`;
const subcolumns = this.getDisplayColumns(table, column.uniquePath); const subcolumns = this.getDisplayColumns(table, column.uniquePath);
this.addReferenceToSelect(select, parentAlias, column);
let added = false; let added = false;
if (this.addJoinsFromExpandedColumns(select, subcolumns, childAlias, columnSources)) added = true; if (this.addJoinsFromExpandedColumns(select, subcolumns, childAlias, columnSources)) added = true;
if (this.addAddedColumnsToSelect(select, subcolumns, childAlias, columnSources)) added = true; if (this.addAddedColumnsToSelect(select, subcolumns, childAlias, columnSources)) added = true;
if (added) { // if (added) {
this.addReferenceToSelect(select, parentAlias, column); // this.addReferenceToSelect(select, parentAlias, column);
res = true; // res = true;
} // }
} }
} }
} }
@@ -169,7 +171,7 @@ export class TableGridDisplay extends GridDisplay {
let res = false; let res = false;
if (this.addJoinsFromExpandedColumns(select, this.columns, 'basetbl', displayedColumnInfo)) res = true; if (this.addJoinsFromExpandedColumns(select, this.columns, 'basetbl', displayedColumnInfo)) res = true;
if (this.addHintsToSelect(select)) res = true; if (this.addHintsToSelect(select)) res = true;
if (select.from.relations) select.from.relations.reverse(); // if (select.from.relations) select.from.relations.reverse();
return res; return res;
} }

View File

@@ -471,6 +471,33 @@ export default function DataGridCore(props) {
} }
}, [display && display.focusedColumn]); }, [display && display.focusedColumn]);
const rowCountInfo = React.useMemo(() => {
if (selectedCells.length > 1 && selectedCells.every((x) => _.isNumber(x[0]) && _.isNumber(x[1]))) {
let sum = _.sumBy(selectedCells, (cell) => {
const row = loadedRows[cell[0]];
if (row) {
const colName = realColumnUniqueNames[cell[1]];
if (colName) {
const data = row[colName];
if (!data) return 0;
let num = +data;
if (_.isNaN(num)) return 0;
return num;
}
}
return 0;
});
let count = selectedCells.length;
let rowCount = getSelectedRowData().length;
return `Rows: ${rowCount.toLocaleString()}, Count: ${count.toLocaleString()}, Sum:${sum.toLocaleString()}`;
}
if (allRowCount == null) return 'Loading row count...';
return `Rows: ${allRowCount.toLocaleString()}`;
// if (this.isLoadingFirstPage) return "Loading first page...";
// if (this.isFirstPageError) return "Error loading first page";
// return `Rows: ${this.rowCount.toLocaleString()}`;
}, [selectedCells, allRowCount, loadedRows, visibleRealColumns]);
if (!loadedRows || !columns || columns.length == 0) if (!loadedRows || !columns || columns.length == 0)
return ( return (
<LoadingInfoWrapper> <LoadingInfoWrapper>
@@ -525,6 +552,16 @@ export default function DataGridCore(props) {
setAutofillDragStartCell(cell); setAutofillDragStartCell(cell);
} else { } else {
setCurrentCell(cell); setCurrentCell(cell);
if (event.ctrlKey) {
if (isRegularCell(cell)) {
if (selectedCells.find((x) => x[0] == cell[0] && x[1] == cell[1])) {
setSelectedCells(selectedCells.filter((x) => x[0] != cell[0] || x[1] != cell[1]));
} else {
setSelectedCells([...selectedCells, cell]);
}
}
} else {
setSelectedCells(getCellRange(cell, cell)); setSelectedCells(getCellRange(cell, cell));
setDragStartCell(cell); setDragStartCell(cell);
@@ -536,6 +573,7 @@ export default function DataGridCore(props) {
dispatchInsplaceEditor({ type: 'close' }); dispatchInsplaceEditor({ type: 'close' });
} }
} }
}
if (display.focusedColumn) display.focusColumn(null); if (display.focusedColumn) display.focusColumn(null);
} }
@@ -1131,7 +1169,7 @@ export default function DataGridCore(props) {
engine={display.engine} engine={display.engine}
onConfirm={handleConfirmSql} onConfirm={handleConfirmSql}
/> />
{allRowCount && <RowCountLabel>Rows: {allRowCount.toLocaleString()}</RowCountLabel>} {allRowCount && <RowCountLabel>{rowCountInfo}</RowCountLabel>}
{props.toolbarPortalRef && {props.toolbarPortalRef &&
tabVisible && tabVisible &&
ReactDOM.createPortal( ReactDOM.createPortal(

View File

@@ -118,6 +118,7 @@ export function useDatabaseInfo(args) {
async function getDbCore(args, objectTypeField = undefined) { async function getDbCore(args, objectTypeField = undefined) {
const db = await getDatabaseInfo(args); const db = await getDatabaseInfo(args);
if (!db) return null;
return db[objectTypeField || args.objectTypeField].find( return db[objectTypeField || args.objectTypeField].find(
(x) => x.pureName == args.pureName && x.schemaName == args.schemaName (x) => x.pureName == args.pureName && x.schemaName == args.schemaName
); );
@@ -125,6 +126,7 @@ async function getDbCore(args, objectTypeField = undefined) {
export function useDbCore(args, objectTypeField = undefined) { export function useDbCore(args, objectTypeField = undefined) {
const db = useDatabaseInfo(args); const db = useDatabaseInfo(args);
if (!db) return null;
return db[objectTypeField || args.objectTypeField].find( return db[objectTypeField || args.objectTypeField].find(
(x) => x.pureName == args.pureName && x.schemaName == args.schemaName (x) => x.pureName == args.pureName && x.schemaName == args.schemaName
); );