From 12d60c7ed91bd3f93fb4696187a347ea86def7e0 Mon Sep 17 00:00:00 2001 From: Jan Prochazka Date: Mon, 19 Aug 2024 13:16:13 +0200 Subject: [PATCH] fixes --- packages/datalib/src/PerspectiveTreeNode.ts | 18 +++++++++++++----- packages/filterparser/src/parseFilter.ts | 4 +++- packages/tools/src/filterBehaviours.ts | 4 ++-- packages/types/engines.d.ts | 2 +- .../src/datagrid/CollectionDataGridCore.svelte | 3 ++- 5 files changed, 21 insertions(+), 10 deletions(-) diff --git a/packages/datalib/src/PerspectiveTreeNode.ts b/packages/datalib/src/PerspectiveTreeNode.ts index 557c7745..5176cafd 100644 --- a/packages/datalib/src/PerspectiveTreeNode.ts +++ b/packages/datalib/src/PerspectiveTreeNode.ts @@ -9,7 +9,15 @@ import type { TableInfo, ViewInfo, } from 'dbgate-types'; -import { detectSqlFilterBehaviour, equalFullName, isCollectionInfo, isTableInfo, isViewInfo, stringFilterBehaviour } from 'dbgate-tools'; +import { + detectSqlFilterBehaviour, + equalFullName, + isCollectionInfo, + isTableInfo, + isViewInfo, + mongoFilterBehaviour, + stringFilterBehaviour, +} from 'dbgate-tools'; import { ChangePerspectiveConfigFunc, createPerspectiveNodeConfig, @@ -346,7 +354,7 @@ export abstract class PerspectiveTreeNode { const base = this.getBaseTableFromThis() as TableInfo | ViewInfo; if (!base) return null; try { - const condition = parseFilter(this.nodeConfig?.multiColumnFilter, 'string'); + const condition = parseFilter(this.nodeConfig?.multiColumnFilter, stringFilterBehaviour); if (condition) { const orCondition: CompoudCondition = { conditionType: 'or', @@ -380,7 +388,7 @@ export abstract class PerspectiveTreeNode { const pattern = this.dataProvider?.dataPatterns?.[this.designerId]; if (!pattern) return null; - const condition = parseFilter(this.nodeConfig?.multiColumnFilter, 'mongo'); + const condition = parseFilter(this.nodeConfig?.multiColumnFilter, mongoFilterBehaviour); if (!condition) return null; const res = pattern.columns.map(col => { return _cloneDeepWith(condition, expr => { @@ -951,7 +959,7 @@ export class PerspectivePatternColumnNode extends PerspectiveTreeNode { get filterBehaviour(): FilterBehaviour { if (this.tableColumn) return detectSqlFilterBehaviour(this.tableColumn.dataType); - return 'mongo'; + return mongoFilterBehaviour; } get preloadedLevelData() { @@ -1093,7 +1101,7 @@ export class PerspectivePatternColumnNode extends PerspectiveTreeNode { parseFilterCondition(source = null): {} { const filter = this.getFilter(); if (!filter) return null; - const condition = parseFilter(filter, 'mongo'); + const condition = parseFilter(filter, mongoFilterBehaviour); if (!condition) return null; return _cloneDeepWith(condition, expr => { if (expr.__placeholder__) { diff --git a/packages/filterparser/src/parseFilter.ts b/packages/filterparser/src/parseFilter.ts index 9ddda646..52769a8a 100644 --- a/packages/filterparser/src/parseFilter.ts +++ b/packages/filterparser/src/parseFilter.ts @@ -227,7 +227,9 @@ function getParser(filterBehaviour: FilterBehaviour) { export function parseFilter(value: string, filterBehaviour: FilterBehaviour): Condition { const parser = getParser(filterBehaviour); + console.log('value', value); + console.log('filterBehaviour', filterBehaviour); const ast = parser.list.tryParse(value); - // console.log('AST', ast); + console.log('AST', ast); return ast; } diff --git a/packages/tools/src/filterBehaviours.ts b/packages/tools/src/filterBehaviours.ts index ac2cc2ce..1a1e0710 100644 --- a/packages/tools/src/filterBehaviours.ts +++ b/packages/tools/src/filterBehaviours.ts @@ -31,7 +31,7 @@ export const logicalFilterBehaviour: FilterBehaviour = { }; export const datetimeFilterBehaviour: FilterBehaviour = { - compilerType: 'sqlTree', + compilerType: 'datetime', supportNullTesting: true, supportSqlCondition: true, supportDatetimeSymbols: true, @@ -59,7 +59,7 @@ export const evalFilterBehaviour: FilterBehaviour = { allowStringToken: true, }; -export const standardFilterBehaviours = { +export const standardFilterBehaviours: { [id: string]: FilterBehaviour } = { numberFilterBehaviour, stringFilterBehaviour, logicalFilterBehaviour, diff --git a/packages/types/engines.d.ts b/packages/types/engines.d.ts index 629b49b2..5523cea3 100644 --- a/packages/types/engines.d.ts +++ b/packages/types/engines.d.ts @@ -73,7 +73,7 @@ export interface ServerSummary { } export interface FilterBehaviourProvider { - getFilterBehaviour(dataType: string, standardFilterBehaviours: { string: FilterBehaviour }): FilterBehaviour; + getFilterBehaviour(dataType: string, standardFilterBehaviours: { [id: string]: FilterBehaviour }): FilterBehaviour; } export interface EngineDriver extends FilterBehaviourProvider { diff --git a/packages/web/src/datagrid/CollectionDataGridCore.svelte b/packages/web/src/datagrid/CollectionDataGridCore.svelte index 2062fede..d5da3b59 100644 --- a/packages/web/src/datagrid/CollectionDataGridCore.svelte +++ b/packages/web/src/datagrid/CollectionDataGridCore.svelte @@ -26,7 +26,7 @@ for (const uniqueName in filters || {}) { if (!filters[uniqueName]) continue; try { - const ast = parseFilter(filters[uniqueName], 'mongo'); + const ast = parseFilter(filters[uniqueName], mongoFilterBehaviour); // console.log('AST', ast); const cond = _.cloneDeepWith(ast, expr => { if (expr.__placeholder__) { @@ -123,6 +123,7 @@ import ChangeSetGrider from './ChangeSetGrider'; import LoadingDataGridCore from './LoadingDataGridCore.svelte'; + import { mongoFilterBehaviour } from 'dbgate-tools'; export let conid; export let display;