From a21b61cc7e9434cb873dca54f3fb0f9122a58932 Mon Sep 17 00:00:00 2001 From: Jan Prochazka Date: Thu, 14 Jan 2021 17:49:36 +0100 Subject: [PATCH] filter this value in formview --- packages/datalib/src/FormViewDisplay.ts | 17 ++++++++++++++++- packages/web/src/formview/FormView.js | 13 ++++++++++--- .../web/src/formview/FormViewContextMenu.js | 6 +++++- 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/packages/datalib/src/FormViewDisplay.ts b/packages/datalib/src/FormViewDisplay.ts index 9b3eac39..fb7c11ad 100644 --- a/packages/datalib/src/FormViewDisplay.ts +++ b/packages/datalib/src/FormViewDisplay.ts @@ -1,7 +1,7 @@ import _ from 'lodash'; import { GridConfig, GridCache, GridConfigColumns, createGridCache, GroupFunc } from './GridConfig'; 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 { ChangeSetFieldDefinition, ChangeSetRowDefinition } from './ChangeSet'; 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) { this.setConfig((cfg) => ({ ...cfg, diff --git a/packages/web/src/formview/FormView.js b/packages/web/src/formview/FormView.js index 6b58f67a..4f4bae68 100644 --- a/packages/web/src/formview/FormView.js +++ b/packages/web/src/formview/FormView.js @@ -152,6 +152,10 @@ export default function FormView(props) { })); }; + const handleFilterThisValue = isDataCell(currentCell) + ? () => formDisplay.filterCellValue(getCellColumn(currentCell), rowData) + : null; + const handleContextMenu = (event) => { event.preventDefault(); showMenu( @@ -161,9 +165,7 @@ export default function FormView(props) { switchToTable={handleSwitchToTable} onNavigate={onNavigate} addToFilter={() => formDisplay.addFilterColumn(getCellColumn(currentCell))} - filterThisValue={ - isDataCell(currentCell) ? () => formDisplay.filterCellValue(getCellColumn(currentCell), rowData) : null - } + filterThisValue={handleFilterThisValue} /> ); }; @@ -338,6 +340,11 @@ export default function FormView(props) { copyToClipboard(); } + if (event.keyCode == keycodes.f && event.ctrlKey) { + event.preventDefault(); + if (handleFilterThisValue) handleFilterThisValue(); + } + if (event.keyCode == keycodes.f5) { event.preventDefault(); onReload(); diff --git a/packages/web/src/formview/FormViewContextMenu.js b/packages/web/src/formview/FormViewContextMenu.js index 5c416ff3..2d55a750 100644 --- a/packages/web/src/formview/FormViewContextMenu.js +++ b/packages/web/src/formview/FormViewContextMenu.js @@ -8,7 +8,11 @@ export default function FormViewContextMenu({ switchToTable, onNavigate, addToFi Table view {addToFilter && Add to filter} - {filterThisValue && Filter this value} + {filterThisValue && ( + + Filter this value + + )} onNavigate('begin')} keyText="Ctrl+Home"> Navigate to begin