filter this value in formview

This commit is contained in:
Jan Prochazka
2021-01-14 17:49:36 +01:00
parent 26b1c69f12
commit a21b61cc7e
3 changed files with 31 additions and 5 deletions

View File

@@ -1,7 +1,7 @@
import _ from 'lodash'; import _ from 'lodash';
import { GridConfig, GridCache, GridConfigColumns, createGridCache, GroupFunc } from './GridConfig'; import { GridConfig, GridCache, GridConfigColumns, createGridCache, GroupFunc } from './GridConfig';
import { ForeignKeyInfo, TableInfo, ColumnInfo, EngineDriver, NamedObjectInfo, DatabaseInfo } from 'dbgate-types'; import { ForeignKeyInfo, TableInfo, ColumnInfo, EngineDriver, NamedObjectInfo, DatabaseInfo } from 'dbgate-types';
import { parseFilter, getFilterType } from 'dbgate-filterparser'; import { parseFilter, getFilterType, getFilterValueExpression } from 'dbgate-filterparser';
import { filterName } from './filterName'; import { filterName } from './filterName';
import { ChangeSetFieldDefinition, ChangeSetRowDefinition } from './ChangeSet'; import { ChangeSetFieldDefinition, ChangeSetRowDefinition } from './ChangeSet';
import { Expression, Select, treeToSql, dumpSqlSelect, Condition } from 'dbgate-sqltree'; import { Expression, Select, treeToSql, dumpSqlSelect, Condition } from 'dbgate-sqltree';
@@ -30,6 +30,21 @@ export class FormViewDisplay {
})); }));
} }
filterCellValue(column, rowData) {
if (!column || !rowData) return;
const value = rowData[column.uniqueName];
const expr = getFilterValueExpression(value, column.dataType);
if (expr) {
this.setConfig((cfg) => ({
...cfg,
filters: {
...cfg.filters,
[column.uniqueName]: expr,
},
}));
}
}
setFilter(uniqueName, value) { setFilter(uniqueName, value) {
this.setConfig((cfg) => ({ this.setConfig((cfg) => ({
...cfg, ...cfg,

View File

@@ -152,6 +152,10 @@ export default function FormView(props) {
})); }));
}; };
const handleFilterThisValue = isDataCell(currentCell)
? () => formDisplay.filterCellValue(getCellColumn(currentCell), rowData)
: null;
const handleContextMenu = (event) => { const handleContextMenu = (event) => {
event.preventDefault(); event.preventDefault();
showMenu( showMenu(
@@ -161,9 +165,7 @@ export default function FormView(props) {
switchToTable={handleSwitchToTable} switchToTable={handleSwitchToTable}
onNavigate={onNavigate} onNavigate={onNavigate}
addToFilter={() => formDisplay.addFilterColumn(getCellColumn(currentCell))} addToFilter={() => formDisplay.addFilterColumn(getCellColumn(currentCell))}
filterThisValue={ filterThisValue={handleFilterThisValue}
isDataCell(currentCell) ? () => formDisplay.filterCellValue(getCellColumn(currentCell), rowData) : null
}
/> />
); );
}; };
@@ -338,6 +340,11 @@ export default function FormView(props) {
copyToClipboard(); copyToClipboard();
} }
if (event.keyCode == keycodes.f && event.ctrlKey) {
event.preventDefault();
if (handleFilterThisValue) handleFilterThisValue();
}
if (event.keyCode == keycodes.f5) { if (event.keyCode == keycodes.f5) {
event.preventDefault(); event.preventDefault();
onReload(); onReload();

View File

@@ -8,7 +8,11 @@ export default function FormViewContextMenu({ switchToTable, onNavigate, addToFi
Table view Table view
</DropDownMenuItem> </DropDownMenuItem>
{addToFilter && <DropDownMenuItem onClick={addToFilter}>Add to filter</DropDownMenuItem>} {addToFilter && <DropDownMenuItem onClick={addToFilter}>Add to filter</DropDownMenuItem>}
{filterThisValue && <DropDownMenuItem onClick={filterThisValue}>Filter this value</DropDownMenuItem>} {filterThisValue && (
<DropDownMenuItem onClick={filterThisValue} keyText="Ctrl+F">
Filter this value
</DropDownMenuItem>
)}
<DropDownMenuDivider /> <DropDownMenuDivider />
<DropDownMenuItem onClick={() => onNavigate('begin')} keyText="Ctrl+Home"> <DropDownMenuItem onClick={() => onNavigate('begin')} keyText="Ctrl+Home">
Navigate to begin Navigate to begin