filter behaviour WIP

This commit is contained in:
Jan Prochazka 2024-08-19 12:49:26 +02:00
parent 2a48e0c4a0
commit c3609e8c7b
24 changed files with 105 additions and 76 deletions

View File

@ -2,6 +2,7 @@ import _ from 'lodash';
import { GridDisplay, ChangeCacheFunc, ChangeConfigFunc, DisplayColumn } from './GridDisplay'; import { GridDisplay, ChangeCacheFunc, ChangeConfigFunc, DisplayColumn } from './GridDisplay';
import type { EngineDriver, ViewInfo, ColumnInfo, CollectionInfo } from 'dbgate-types'; import type { EngineDriver, ViewInfo, ColumnInfo, CollectionInfo } from 'dbgate-types';
import { GridConfig, GridCache } from './GridConfig'; import { GridConfig, GridCache } from './GridConfig';
import { mongoFilterBehaviour, standardFilterBehaviours } from 'dbgate-tools';
function getObjectKeys(obj) { function getObjectKeys(obj) {
if (_.isArray(obj)) { if (_.isArray(obj)) {
@ -52,7 +53,7 @@ function getColumnsForObject(basePath, obj, res: any[], display) {
} }
} }
function getDisplayColumn(basePath, columnName, display) { function getDisplayColumn(basePath, columnName, display: CollectionGridDisplay) {
const uniquePath = [...basePath, columnName]; const uniquePath = [...basePath, columnName];
const uniqueName = uniquePath.join('.'); const uniqueName = uniquePath.join('.');
return { return {
@ -62,7 +63,7 @@ function getDisplayColumn(basePath, columnName, display) {
uniquePath, uniquePath,
isStructured: true, isStructured: true,
parentHeaderText: createHeaderText(basePath), parentHeaderText: createHeaderText(basePath),
filterType: 'mongo', filterBehaviour: display?.driver?.getFilterBehaviour(null, standardFilterBehaviours) ?? mongoFilterBehaviour,
pureName: display.collection?.pureName, pureName: display.collection?.pureName,
schemaName: display.collection?.schemaName, schemaName: display.collection?.schemaName,
}; };
@ -95,7 +96,7 @@ export class CollectionGridDisplay extends GridDisplay {
cache: GridCache, cache: GridCache,
setCache: ChangeCacheFunc, setCache: ChangeCacheFunc,
loadedRows, loadedRows,
changeSet, changeSet,
readOnly = false readOnly = false
) { ) {
super(config, setConfig, cache, setCache, driver); super(config, setConfig, cache, setCache, driver);

View File

@ -10,12 +10,13 @@ import type {
CollectionInfo, CollectionInfo,
SqlDialect, SqlDialect,
ViewInfo, ViewInfo,
FilterBehaviour,
} from 'dbgate-types'; } from 'dbgate-types';
import { parseFilter, getFilterType } from 'dbgate-filterparser'; import { parseFilter } from 'dbgate-filterparser';
import { filterName } from 'dbgate-tools'; import { filterName } from 'dbgate-tools';
import { ChangeSetFieldDefinition, ChangeSetRowDefinition } from './ChangeSet'; import { ChangeSetFieldDefinition, ChangeSetRowDefinition } from './ChangeSet';
import { Expression, Select, treeToSql, dumpSqlSelect, Condition, CompoudCondition } from 'dbgate-sqltree'; import { Expression, Select, treeToSql, dumpSqlSelect, Condition, CompoudCondition } from 'dbgate-sqltree';
import { isTypeLogical } from 'dbgate-tools'; import { isTypeLogical, standardFilterBehaviours, detectSqlFilterBehaviour, stringFilterBehaviour } from 'dbgate-tools';
export interface DisplayColumn { export interface DisplayColumn {
schemaName: string; schemaName: string;
@ -33,7 +34,7 @@ export interface DisplayColumn {
isChecked?: boolean; isChecked?: boolean;
hintColumnNames?: string[]; hintColumnNames?: string[];
dataType?: string; dataType?: string;
filterType?: boolean; filterBehaviour?: FilterBehaviour;
isStructured?: boolean; isStructured?: boolean;
} }
@ -92,7 +93,7 @@ export abstract class GridDisplay {
isLoadedCorrectly = true; isLoadedCorrectly = true;
supportsReload = false; supportsReload = false;
isDynamicStructure = false; isDynamicStructure = false;
filterTypeOverride = null; filterBehaviourOverride = null;
setColumnVisibility(uniquePath: string[], isVisible: boolean) { setColumnVisibility(uniquePath: string[], isVisible: boolean) {
const uniqueName = uniquePath.join('.'); const uniqueName = uniquePath.join('.');
@ -192,7 +193,11 @@ export abstract class GridDisplay {
const column = displayedColumnInfo[uniqueName]; const column = displayedColumnInfo[uniqueName];
if (!column) continue; if (!column) continue;
try { try {
const condition = parseFilter(filter, getFilterType(column.dataType)); const condition = parseFilter(
filter,
this.driver?.getFilterBehaviour(column.dataType, standardFilterBehaviours) ??
detectSqlFilterBehaviour(column.dataType)
);
if (condition) { if (condition) {
conditions.push( conditions.push(
_.cloneDeepWith(condition, (expr: Expression) => { _.cloneDeepWith(condition, (expr: Expression) => {
@ -220,7 +225,7 @@ export abstract class GridDisplay {
}; };
for (const column of this.baseTableOrView.columns) { for (const column of this.baseTableOrView.columns) {
try { try {
const condition = parseFilter(this.config.multiColumnFilter, getFilterType(column.dataType)); const condition = parseFilter(this.config.multiColumnFilter, detectSqlFilterBehaviour(column.dataType));
if (condition) { if (condition) {
orCondition.conditions.push( orCondition.conditions.push(
_.cloneDeepWith(condition, (expr: Expression) => { _.cloneDeepWith(condition, (expr: Expression) => {
@ -748,10 +753,12 @@ export abstract class GridDisplay {
for (const name in filters) { for (const name in filters) {
const column = this.isDynamicStructure ? null : this.columns.find(x => x.columnName == name); const column = this.isDynamicStructure ? null : this.columns.find(x => x.columnName == name);
if (!this.isDynamicStructure && !column) continue; if (!this.isDynamicStructure && !column) continue;
const filterType = const filterBehaviour =
this.filterTypeOverride ?? (this.isDynamicStructure ? 'mongo' : getFilterType(column.dataType)); this.filterBehaviourOverride ??
this.driver?.getFilterBehaviour(column.dataType, standardFilterBehaviours) ??
detectSqlFilterBehaviour(column.dataType);
try { try {
const condition = parseFilter(filters[name], filterType); const condition = parseFilter(filters[name], filterBehaviour);
const replaced = _.cloneDeepWith(condition, (expr: Expression) => { const replaced = _.cloneDeepWith(condition, (expr: Expression) => {
if (expr.exprType == 'placeholder') if (expr.exprType == 'placeholder')
return { return {
@ -766,7 +773,7 @@ export abstract class GridDisplay {
} }
if (this.config.multiColumnFilter) { if (this.config.multiColumnFilter) {
const placeholderCondition = parseFilter(this.config.multiColumnFilter, 'string'); const placeholderCondition = parseFilter(this.config.multiColumnFilter, stringFilterBehaviour);
if (placeholderCondition) { if (placeholderCondition) {
conditions.push({ conditions.push({
conditionType: 'anyColumnPass', conditionType: 'anyColumnPass',

View File

@ -2,6 +2,7 @@ import _ from 'lodash';
import { GridDisplay, ChangeCacheFunc, ChangeConfigFunc } from './GridDisplay'; import { GridDisplay, ChangeCacheFunc, ChangeConfigFunc } from './GridDisplay';
import { GridConfig, GridCache } from './GridConfig'; import { GridConfig, GridCache } from './GridConfig';
import { analyseCollectionDisplayColumns } from './CollectionGridDisplay'; import { analyseCollectionDisplayColumns } from './CollectionGridDisplay';
import { evalFilterBehaviour } from 'dbgate-tools';
export class JslGridDisplay extends GridDisplay { export class JslGridDisplay extends GridDisplay {
constructor( constructor(
@ -22,7 +23,7 @@ export class JslGridDisplay extends GridDisplay {
this.sortable = true; this.sortable = true;
this.supportsReload = supportsReload; this.supportsReload = supportsReload;
this.isDynamicStructure = isDynamicStructure; this.isDynamicStructure = isDynamicStructure;
this.filterTypeOverride = 'eval'; this.filterBehaviourOverride = evalFilterBehaviour;
this.editable = editable; this.editable = editable;
this.editableStructure = editable ? structure : null; this.editableStructure = editable ? structure : null;

View File

@ -1,12 +0,0 @@
import { isTypeNumber, isTypeString, isTypeLogical, isTypeDateTime } from 'dbgate-tools';
import { FilterBehaviour } from 'dbgate-types';
import { DatetimeFilterBehaviour, LogicalFilterBehaviour, NumberFilterBehaviour, StringFilterBehaviour } from './filterTypes';
export function detectSqlFilterType(dataType: string): FilterBehaviour {
if (!dataType) return StringFilterBehaviour;
if (isTypeNumber(dataType)) return NumberFilterBehaviour;
if (isTypeString(dataType)) return StringFilterBehaviour;
if (isTypeLogical(dataType)) return LogicalFilterBehaviour;
if (isTypeDateTime(dataType)) return DatetimeFilterBehaviour;
return StringFilterBehaviour;
}

View File

@ -1,3 +1,2 @@
export * from './parseFilter'; export * from './parseFilter';
export * from './detectSqlFilterBehaviour';
export * from './filterTool'; export * from './filterTool';

View File

@ -1,8 +1,8 @@
const { parseFilter } = require('./parseFilter'); const { parseFilter } = require('./parseFilter');
const { StringFilterType } = require('./filterTypes'); const { stringFilterBehaviour } = require('dbgate-tools');
test('parse string', () => { test('parse string', () => {
const ast = parseFilter('"123"', StringFilterType); const ast = parseFilter('"123"', stringFilterBehaviour);
console.log(JSON.stringify(ast)); console.log(JSON.stringify(ast));
expect(ast).toEqual({ expect(ast).toEqual({
conditionType: 'like', conditionType: 'like',

View File

@ -0,0 +1,17 @@
import { FilterBehaviour } from 'dbgate-types';
import {
datetimeFilterBehaviour,
logicalFilterBehaviour,
numberFilterBehaviour,
stringFilterBehaviour,
} from './filterBehaviours';
import { isTypeDateTime, isTypeLogical, isTypeNumber, isTypeString } from './commonTypeParser';
export function detectSqlFilterBehaviour(dataType: string): FilterBehaviour {
if (!dataType) return stringFilterBehaviour;
if (isTypeNumber(dataType)) return numberFilterBehaviour;
if (isTypeString(dataType)) return stringFilterBehaviour;
if (isTypeLogical(dataType)) return logicalFilterBehaviour;
if (isTypeDateTime(dataType)) return datetimeFilterBehaviour;
return stringFilterBehaviour;
}

View File

@ -3,6 +3,7 @@ import { SqlDumper } from './SqlDumper';
import { splitQuery } from 'dbgate-query-splitter'; import { splitQuery } from 'dbgate-query-splitter';
import { dumpSqlSelect } from 'dbgate-sqltree'; import { dumpSqlSelect } from 'dbgate-sqltree';
import { EngineDriver, QueryResult, RunScriptOptions } from 'dbgate-types'; import { EngineDriver, QueryResult, RunScriptOptions } from 'dbgate-types';
import { detectSqlFilterBehaviour } from './detectSqlFilterBehaviour';
const dialect = { const dialect = {
limitSelect: true, limitSelect: true,
@ -150,4 +151,7 @@ export const driverBase = {
showConnectionField: (field, values) => false, showConnectionField: (field, values) => false,
showConnectionTab: field => true, showConnectionTab: field => true,
getAccessTokenFromAuth: async (connection, req) => null, getAccessTokenFromAuth: async (connection, req) => null,
getFilterBehaviour(dataType: string, standardFilterBehaviours) {
return detectSqlFilterBehaviour(dataType);
},
}; };

View File

@ -1,6 +1,6 @@
import { FilterBehaviour } from 'dbgate-types'; import { FilterBehaviour } from 'dbgate-types';
export const NumberFilterBehaviour: FilterBehaviour = { export const numberFilterBehaviour: FilterBehaviour = {
compilerType: 'sqlTree', compilerType: 'sqlTree',
supportEquals: true, supportEquals: true,
supportNumberLikeComparison: true, supportNumberLikeComparison: true,
@ -10,7 +10,7 @@ export const NumberFilterBehaviour: FilterBehaviour = {
allowNumberToken: true, allowNumberToken: true,
}; };
export const StringFilterBehaviour: FilterBehaviour = { export const stringFilterBehaviour: FilterBehaviour = {
compilerType: 'sqlTree', compilerType: 'sqlTree',
supportEquals: true, supportEquals: true,
supportStringInclusion: true, supportStringInclusion: true,
@ -23,14 +23,14 @@ export const StringFilterBehaviour: FilterBehaviour = {
allowHexString: true, allowHexString: true,
}; };
export const LogicalFilterBehaviour: FilterBehaviour = { export const logicalFilterBehaviour: FilterBehaviour = {
compilerType: 'sqlTree', compilerType: 'sqlTree',
supportBooleanValues: true, supportBooleanValues: true,
supportNullTesting: true, supportNullTesting: true,
supportSqlCondition: true, supportSqlCondition: true,
}; };
export const DatetimeFilterBehaviour: FilterBehaviour = { export const datetimeFilterBehaviour: FilterBehaviour = {
compilerType: 'sqlTree', compilerType: 'sqlTree',
supportNullTesting: true, supportNullTesting: true,
supportSqlCondition: true, supportSqlCondition: true,
@ -38,7 +38,7 @@ export const DatetimeFilterBehaviour: FilterBehaviour = {
supportDatetimeComparison: true, supportDatetimeComparison: true,
}; };
export const MongoFilterBehaviour: FilterBehaviour = { export const mongoFilterBehaviour: FilterBehaviour = {
compilerType: 'mongoCondition', compilerType: 'mongoCondition',
supportEquals: true, supportEquals: true,
supportArrayTesting: true, supportArrayTesting: true,
@ -48,7 +48,7 @@ export const MongoFilterBehaviour: FilterBehaviour = {
supportExistsTesting: true, supportExistsTesting: true,
}; };
export const EvalFilterBehaviour: FilterBehaviour = { export const evalFilterBehaviour: FilterBehaviour = {
compilerType: 'sqlTree', compilerType: 'sqlTree',
supportEquals: true, supportEquals: true,
supportStringInclusion: true, supportStringInclusion: true,
@ -58,3 +58,12 @@ export const EvalFilterBehaviour: FilterBehaviour = {
allowStringToken: true, allowStringToken: true,
}; };
export const standardFilterBehaviours = {
numberFilterBehaviour,
stringFilterBehaviour,
logicalFilterBehaviour,
datetimeFilterBehaviour,
mongoFilterBehaviour,
evalFilterBehaviour,
};

View File

@ -21,3 +21,5 @@ export * from './preloadedRowsTools';
export * from './ScriptWriter'; export * from './ScriptWriter';
export * from './getLogger'; export * from './getLogger';
export * from './getConnectionLabel'; export * from './getConnectionLabel';
export * from './detectSqlFilterBehaviour';
export * from './filterBehaviours';

View File

@ -72,7 +72,11 @@ export interface ServerSummary {
databases: ServerSummaryDatabase[]; databases: ServerSummaryDatabase[];
} }
export interface EngineDriver { export interface FilterBehaviourProvider {
getFilterBehaviour(dataType: string, standardFilterBehaviours: { string: FilterBehaviour }): FilterBehaviour;
}
export interface EngineDriver extends FilterBehaviourProvider {
engine: string; engine: string;
title: string; title: string;
defaultPort?: number; defaultPort?: number;
@ -154,7 +158,6 @@ export interface EngineDriver {
getRedirectAuthUrl(connection, options): Promise<{ url: string; sid: string }>; getRedirectAuthUrl(connection, options): Promise<{ url: string; sid: string }>;
getAuthTokenFromCode(connection, options): Promise<string>; getAuthTokenFromCode(connection, options): Promise<string>;
getAccessTokenFromAuth(connection, req): Promise<string | null>; getAccessTokenFromAuth(connection, req): Promise<string | null>;
getFilterType(dataType: string): FilterBehaviour;
analyserClass?: any; analyserClass?: any;
dumperClass?: any; dumperClass?: any;

View File

@ -19,7 +19,6 @@
import ValueLookupModal from '../modals/ValueLookupModal.svelte'; import ValueLookupModal from '../modals/ValueLookupModal.svelte';
export let isReadOnly = false; export let isReadOnly = false;
export let filterType;
export let filterBehaviour; export let filterBehaviour;
export let filter; export let filter;
export let setFilter; export let setFilter;
@ -51,7 +50,7 @@
$: if (onGetReference && domInput) onGetReference(domInput); $: if (onGetReference && domInput) onGetReference(domInput);
function openFilterWindow(condition1) { function openFilterWindow(condition1) {
showModal(SetFilterModal, { condition1, filterType, onFilter: setFilter }); showModal(SetFilterModal, { condition1, filterBehaviour, onFilter: setFilter });
} }
const filterMultipleValues = () => { const filterMultipleValues = () => {
@ -246,7 +245,7 @@
isOk = false; isOk = false;
isError = false; isError = false;
if (value) { if (value) {
parseFilter(value, filterType); parseFilter(value, filterBehaviour);
isOk = true; isOk = true;
} }
} catch (err) { } catch (err) {

View File

@ -78,7 +78,6 @@
export let display; export let display;
export let changeSetState; export let changeSetState;
export let dispatchChangeSet; export let dispatchChangeSet;
export let useEvalFilters = false;
export let isDetailView = false; export let isDetailView = false;
export let showReferences = false; export let showReferences = false;
@ -184,7 +183,6 @@
{...$$props} {...$$props}
{managerSize} {managerSize}
{isDynamicStructure} {isDynamicStructure}
{useEvalFilters}
{isFormView} {isFormView}
{hasMultiColumnFilter} {hasMultiColumnFilter}
driver={display?.driver} driver={display?.driver}

View File

@ -343,13 +343,13 @@
<script lang="ts"> <script lang="ts">
import { GridDisplay } from 'dbgate-datalib'; import { GridDisplay } from 'dbgate-datalib';
import { driverBase, parseCellValue } from 'dbgate-tools'; import { driverBase, parseCellValue, detectSqlFilterBehaviour } from 'dbgate-tools';
import { getContext, onDestroy } from 'svelte'; import { getContext, onDestroy } from 'svelte';
import _, { map } from 'lodash'; import _, { map } from 'lodash';
import registerCommand from '../commands/registerCommand'; import registerCommand from '../commands/registerCommand';
import ColumnHeaderControl from './ColumnHeaderControl.svelte'; import ColumnHeaderControl from './ColumnHeaderControl.svelte';
import DataGridRow from './DataGridRow.svelte'; import DataGridRow from './DataGridRow.svelte';
import { getFilterType, getFilterValueExpression } from 'dbgate-filterparser'; import { getFilterValueExpression } from 'dbgate-filterparser';
import stableStringify from 'json-stable-stringify'; import stableStringify from 'json-stable-stringify';
import contextMenu, { getContextMenu, registerMenu } from '../utility/contextMenu'; import contextMenu, { getContextMenu, registerMenu } from '../utility/contextMenu';
import { tick } from 'svelte'; import { tick } from 'svelte';
@ -435,7 +435,6 @@
export let tabControlHiddenTab = false; export let tabControlHiddenTab = false;
export let onCustomGridRefresh = null; export let onCustomGridRefresh = null;
export let onOpenQuery = null; export let onOpenQuery = null;
export let useEvalFilters = false;
export let jslid; export let jslid;
// export let generalAllowSave = false; // export let generalAllowSave = false;
@ -1901,7 +1900,9 @@
{jslid} {jslid}
{formatterFunction} {formatterFunction}
driver={display?.driver} driver={display?.driver}
filterType={useEvalFilters ? 'eval' : col.filterType || getFilterType(col.dataType)} filterBehaviour={display?.filterBehaviourOverride ??
col.filterBehaviour ??
detectSqlFilterBehaviour(col.dataType)}
filter={display.getFilter(col.uniqueName)} filter={display.getFilter(col.uniqueName)}
setFilter={value => display.setFilter(col.uniqueName, value)} setFilter={value => display.setFilter(col.uniqueName, value)}
showResizeSplitter showResizeSplitter

View File

@ -87,7 +87,6 @@
formViewComponent={JslFormView} formViewComponent={JslFormView}
setLoadedRows={handleSetLoadedRows} setLoadedRows={handleSetLoadedRows}
isDynamicStructure={!!infoUsed?.__isDynamicStructure} isDynamicStructure={!!infoUsed?.__isDynamicStructure}
useEvalFilters
showMacros={!!dispatchChangeSet} showMacros={!!dispatchChangeSet}
expandMacros={!!dispatchChangeSet} expandMacros={!!dispatchChangeSet}
onRunMacro={handleRunMacro} onRunMacro={handleRunMacro}

View File

@ -10,7 +10,7 @@ import {
referenceIsConnecting, referenceIsConnecting,
mergeSelectsFromDesigner, mergeSelectsFromDesigner,
findQuerySource, findQuerySource,
findDesignerFilterType, findDesignerFilterBehaviour,
} from './designerTools'; } from './designerTools';
import { parseFilter } from 'dbgate-filterparser'; import { parseFilter } from 'dbgate-filterparser';
@ -83,7 +83,7 @@ export class DesignerQueryDumper {
} }
try { try {
const condition = parseFilter(column[filterField], findDesignerFilterType(column, this.designer)); const condition = parseFilter(column[filterField], findDesignerFilterBehaviour(column, this.designer));
if (condition) { if (condition) {
conditions.push( conditions.push(
_.cloneDeepWith(condition, expr => { _.cloneDeepWith(condition, expr => {

View File

@ -1,6 +1,6 @@
<script lang="ts"> <script lang="ts">
import { presetDarkPalettes, presetPalettes } from '@ant-design/colors'; import { presetDarkPalettes, presetPalettes } from '@ant-design/colors';
import { filterName } from 'dbgate-tools'; import { filterName, stringFilterBehaviour } from 'dbgate-tools';
import { tick } from 'svelte'; import { tick } from 'svelte';
import { createDatabaseObjectMenu } from '../appobj/DatabaseObjectAppObject.svelte'; import { createDatabaseObjectMenu } from '../appobj/DatabaseObjectAppObject.svelte';
@ -303,7 +303,7 @@
</div> </div>
{#if settings?.getMutliColumnFilter && settings?.setMutliColumnFilter} {#if settings?.getMutliColumnFilter && settings?.setMutliColumnFilter}
<DataFilterControl <DataFilterControl
filterType="string" filterBehaviour={stringFilterBehaviour}
filter={settings?.getMutliColumnFilter(designerId)} filter={settings?.getMutliColumnFilter(designerId)}
setFilter={value => settings?.setMutliColumnFilter(designerId, value)} setFilter={value => settings?.setMutliColumnFilter(designerId, value)}
placeholder="Data filter" placeholder="Data filter"

View File

@ -5,7 +5,7 @@ import type { EngineDriver } from 'dbgate-types';
import type { DesignerInfo, DesignerTableInfo, DesignerReferenceInfo, DesignerJoinType } from './types'; import type { DesignerInfo, DesignerTableInfo, DesignerReferenceInfo, DesignerJoinType } from './types';
import { DesignerComponentCreator } from './DesignerComponentCreator'; import { DesignerComponentCreator } from './DesignerComponentCreator';
import { DesignerQueryDumper } from './DesignerQueryDumper'; import { DesignerQueryDumper } from './DesignerQueryDumper';
import { getFilterType } from 'dbgate-filterparser'; import { detectSqlFilterBehaviour } from 'dbgate-tools';
export function referenceIsConnecting( export function referenceIsConnecting(
reference: DesignerReferenceInfo, reference: DesignerReferenceInfo,
@ -133,13 +133,13 @@ export function isConnectedByReference(
return array1 == array2; return array1 == array2;
} }
export function findDesignerFilterType({ designerId, columnName }, designer) { export function findDesignerFilterBehaviour({ designerId, columnName }, designer) {
const table = (designer.tables || []).find(x => x.designerId == designerId); const table = (designer.tables || []).find(x => x.designerId == designerId);
if (table) { if (table) {
const column = (table.columns || []).find(x => x.columnName == columnName); const column = (table.columns || []).find(x => x.columnName == columnName);
if (column) { if (column) {
const { dataType } = column; const { dataType } = column;
return getFilterType(dataType); return detectSqlFilterBehaviour(dataType);
} }
} }
return 'string'; return 'string';

View File

@ -8,7 +8,7 @@
<script> <script>
import DataFilterControl from '../datagrid/DataFilterControl.svelte'; import DataFilterControl from '../datagrid/DataFilterControl.svelte';
import { findDesignerFilterType } from '../designer/designerTools'; import { findDesignerFilterBehaviour } from '../designer/designerTools';
import CheckboxField from '../forms/CheckboxField.svelte'; import CheckboxField from '../forms/CheckboxField.svelte';
import SelectField from '../forms/SelectField.svelte'; import SelectField from '../forms/SelectField.svelte';
import TextField from '../forms/TextField.svelte'; import TextField from '../forms/TextField.svelte';
@ -238,7 +238,7 @@
</svelte:fragment> </svelte:fragment>
<svelte:fragment slot="5" let:row let:filterField> <svelte:fragment slot="5" let:row let:filterField>
<DataFilterControl <DataFilterControl
filterType={findDesignerFilterType(row, value)} filterBehaviour={findDesignerFilterBehaviour(row, value)}
filter={row[filterField]} filter={row[filterField]}
setFilter={filter => { setFilter={filter => {
changeColumn({ ...row, [filterField]: filter }); changeColumn({ ...row, [filterField]: filter });

View File

@ -1,5 +1,5 @@
<script lang="ts"> <script lang="ts">
import { getFilterType } from 'dbgate-filterparser'; import { detectSqlFilterBehaviour, standardFilterBehaviours, mongoFilterBehaviour } from 'dbgate-tools';
import DataFilterControl from '../datagrid/DataFilterControl.svelte'; import DataFilterControl from '../datagrid/DataFilterControl.svelte';
@ -17,22 +17,20 @@
export let schemaName; export let schemaName;
export let pureName; export let pureName;
export let useEvalFilters;
export let isDynamicStructure; export let isDynamicStructure;
export let isFormView; export let isFormView;
$: column = isFormView $: column = isFormView ? display.formColumns?.find(x => x.uniqueName == uniqueName) : display?.findColumn(uniqueName);
? display.formColumns?.find(x => x.uniqueName == uniqueName)
: display?.findColumn(uniqueName);
function computeFilterType(column, isDynamicStructure, useEvalFilters) { function computeFilterBehavoir(column, display, isDynamicStructure) {
if (useEvalFilters) return 'eval'; if (display?.filterBehaviourOverride) {
if (isDynamicStructure) return 'mongo'; return display?.filterBehaviourOverride;
if (column) {
return column.filterType || getFilterType(column.dataType);
} }
return 'string'; const fromDriver = display?.driver?.getFilterBehaviour(column.dataType, standardFilterBehaviours);
if (fromDriver) return fromDriver;
if (isDynamicStructure) return mongoFilterBehaviour;
return detectSqlFilterBehaviour(column.dataType);
} }
</script> </script>
@ -51,7 +49,7 @@
</InlineButton> </InlineButton>
</div> </div>
<DataFilterControl <DataFilterControl
filterType={computeFilterType(column, isDynamicStructure, useEvalFilters)} filterBehaviour={computeFilterBehavoir(column, display, isDynamicStructure)}
filter={filters[uniqueName]} filter={filters[uniqueName]}
setFilter={value => display.setFilter(uniqueName, value)} setFilter={value => display.setFilter(uniqueName, value)}
{driver} {driver}

View File

@ -20,7 +20,6 @@
export let pureName; export let pureName;
export let isDynamicStructure; export let isDynamicStructure;
export let useEvalFilters;
export let isFormView; export let isFormView;
export let hasMultiColumnFilter; export let hasMultiColumnFilter;
@ -93,7 +92,6 @@
{#each allFilterNames as uniqueName} {#each allFilterNames as uniqueName}
<FormViewFilterColumn <FormViewFilterColumn
{isDynamicStructure} {isDynamicStructure}
{useEvalFilters}
{isFormView} {isFormView}
{uniqueName} {uniqueName}
{display} {display}

View File

@ -13,7 +13,7 @@
export let condition1; export let condition1;
export let onFilter; export let onFilter;
export let filterType; export let filterBehaviour;
const hasOperand = condition => { const hasOperand = condition => {
return condition != 'NULL' && condition != 'NOT NULL' && condition != 'EXISTS' && condition != 'NOT EXISTS'; return condition != 'NULL' && condition != 'NOT NULL' && condition != 'EXISTS' && condition != 'NOT EXISTS';
@ -24,7 +24,9 @@
if (!value) return null; if (!value) return null;
if (condition == 'sql') return `{${value}}`; if (condition == 'sql') return `{${value}}`;
if (condition == 'sqlRight') return `{$$ ${value}}`; if (condition == 'sqlRight') return `{$$ ${value}}`;
if (filterType == 'string') return `${condition}"${value}"`; if (filterBehaviour.allowStringToken) {
return `${condition}"${value}"`;
}
return `${condition}${value}`; return `${condition}${value}`;
}; };
@ -48,7 +50,7 @@
<div class="row">Show rows where</div> <div class="row">Show rows where</div>
<div class="row"> <div class="row">
<div class="col-6 mr-1"> <div class="col-6 mr-1">
<SetFilterModal_Select {filterType} name="condition1" /> <SetFilterModal_Select {filterBehaviour} name="condition1" />
</div> </div>
<div class="col-6 mr-1"> <div class="col-6 mr-1">
<FormValues let:values> <FormValues let:values>
@ -66,7 +68,7 @@
<div class="row"> <div class="row">
<div class="col-6 mr-1"> <div class="col-6 mr-1">
<SetFilterModal_Select {filterType} name="condition2" /> <SetFilterModal_Select {filterBehaviour} name="condition2" />
</div> </div>
<div class="col-6 mr-1"> <div class="col-6 mr-1">
<FormValues let:values> <FormValues let:values>

View File

@ -2,7 +2,6 @@
import FormSelectFieldRaw from '../forms/FormSelectFieldRaw.svelte'; import FormSelectFieldRaw from '../forms/FormSelectFieldRaw.svelte';
export let name; export let name;
export let filterType;
export let filterBehaviour; export let filterBehaviour;
function getOptions() { function getOptions() {

View File

@ -93,6 +93,10 @@ const driver = {
} }
return res; return res;
}, },
getFilterBehaviour(dataType, standardFilterBehaviours) {
return standardFilterBehaviours.mongoFilterBehaviour;
},
}; };
module.exports = driver; module.exports = driver;