data filter control

This commit is contained in:
Jan Prochazka 2024-08-19 09:00:44 +02:00
parent 2ef4b534e3
commit 84cd9d53b5
2 changed files with 161 additions and 161 deletions

View File

@ -0,0 +1,146 @@
import { StructuredFilterType } from 'dbgate-types';
export const NumberFilterType: StructuredFilterType = {
compilerType: 'sqlTree',
supportEquals: true,
supportNumberLikeComparison: true,
supportNullTesting: true,
supportSqlCondition: true,
};
export const StringFilterType: StructuredFilterType = {
compilerType: 'sqlTree',
supportEquals: true,
supportStringInclusion: true,
supportEmpty: true,
supportNumberLikeComparison: true,
supportNullTesting: true,
supportSqlCondition: true,
};
export const LogicalFilterType: StructuredFilterType = {
compilerType: 'sqlTree',
supportBooleanValues: true,
supportNullTesting: true,
supportSqlCondition: true,
};
export const DatetimeFilterType: StructuredFilterType = {
compilerType: 'sqlTree',
supportNullTesting: true,
supportSqlCondition: true,
supportDatetimeSymbols: true,
supportDatetimeComparison: true,
};
export const MongoFilterType: StructuredFilterType = {
compilerType: 'mongoCondition',
supportEquals: true,
supportArrayTesting: true,
supportNumberLikeComparison: true,
supportStringInclusion: true,
supportBooleanValues: true,
};
export const EvalFilterType: StructuredFilterType = {
compilerType: 'sqlTree',
supportEquals: true,
supportStringInclusion: true,
supportEmpty: true,
supportNumberLikeComparison: true,
supportNullTesting: true,
};
// export const NumberFilterType: StructuredFilterType = {
// compilerType: 'sqlTree',
// allowedOperators: [
// { value: '=', label: 'equals' },
// { value: '<>', label: 'does not equal' },
// { value: '<', label: 'is smaller' },
// { value: '>', label: 'is greater' },
// { value: '<=', label: 'is smaller or equal' },
// { value: '>=', label: 'is greater or equal' },
// { value: 'NULL', label: 'is NULL' },
// { value: 'NOT NULL', label: 'is not NULL' },
// { value: 'sql', label: 'SQL condition' },
// { value: 'sqlRight', label: 'SQL condition - right side only' },
// ],
// };
// export const StringFilterType: StructuredFilterType = {
// compilerType: 'sqlTree',
// allowedOperators: [
// { value: '+', label: 'contains' },
// { value: '~', label: 'does not contain' },
// { value: '^', label: 'begins with' },
// { value: '!^', label: 'does not begin with' },
// { value: '$', label: 'ends with' },
// { value: '!$', label: 'does not end with' },
// { value: '=', label: 'equals' },
// { value: '<>', label: 'does not equal' },
// { value: '<', label: 'is smaller' },
// { value: '>', label: 'is greater' },
// { value: '<=', label: 'is smaller or equal' },
// { value: '>=', label: 'is greater or equal' },
// { value: 'NULL', label: 'is NULL' },
// { value: 'NOT NULL', label: 'is not NULL' },
// { value: 'sql', label: 'SQL condition' },
// { value: 'sqlRight', label: 'SQL condition - right side only' },
// ],
// };
// export const DatetimeFilterType: StructuredFilterType = {
// compilerType: 'sqlTree',
// allowedOperators: [
// { value: '=', label: 'equals' },
// { value: '<>', label: 'does not equal' },
// { value: '<', label: 'is before' },
// { value: '>', label: 'is after' },
// { value: '<=', label: 'is before or equal' },
// { value: '>=', label: 'is after or equal' },
// { value: 'NULL', label: 'is NULL' },
// { value: 'NOT NULL', label: 'is not NULL' },
// { value: 'sql', label: 'SQL condition' },
// { value: 'sqlRight', label: 'SQL condition - right side only' },
// ],
// };
// export const MongoFilterType: StructuredFilterType = {
// compilerType: 'mongoCondition',
// allowedOperators: [
// { value: '=', label: 'equals' },
// { value: '<>', label: 'does not equal' },
// { value: '<', label: 'is smaller' },
// { value: '>', label: 'is greater' },
// { value: '<=', label: 'is smaller or equal' },
// { value: '>=', label: 'is greater or equal' },
// { value: '+', label: 'contains' },
// { value: '~', label: 'does not contain' },
// { value: '^', label: 'begins with' },
// { value: '!^', label: 'does not begin with' },
// { value: '$', label: 'ends with' },
// { value: '!$', label: 'does not end with' },
// { value: 'EXISTS', label: 'field exists' },
// { value: 'NOT EXISTS', label: 'field does not exist' },
// ],
// };
// export const EvalFilterType: StructuredFilterType = {
// compilerType: 'sqlTree',
// allowedOperators: [
// { value: '=', label: 'equals' },
// { value: '<>', label: 'does not equal' },
// { value: '<', label: 'is smaller' },
// { value: '>', label: 'is greater' },
// { value: '<=', label: 'is smaller or equal' },
// { value: '>=', label: 'is greater or equal' },
// { value: '+', label: 'contains' },
// { value: '~', label: 'does not contain' },
// { value: '^', label: 'begins with' },
// { value: '!^', label: 'does not begin with' },
// { value: '$', label: 'ends with' },
// { value: '!$', label: 'does not end with' },
// { value: 'NULL', label: 'is NULL' },
// { value: 'NOT NULL', label: 'is not NULL' },
// ],
// };

View File

@ -73,6 +73,20 @@
);
}
if (structuredFilterType.supportExistsTesting) {
res.push(
{ onClick: () => setFilter('EXISTS'), text: 'Field exists' },
{ onClick: () => setFilter('NOT EXISTS'), text: 'Field does not exist' }
);
}
if (structuredFilterType.supportArrayTesting) {
res.push(
{ onClick: () => setFilter('NOT EMPTY ARRAY'), text: 'Array is not empty' },
{ onClick: () => setFilter('EMPTY ARRAY'), text: 'Array is empty' }
);
}
if (structuredFilterType.supportNullTesting) {
res.push(
{ onClick: () => setFilter('NULL'), text: 'Is Null' },
@ -161,167 +175,7 @@
);
}
switch (filterType) {
case 'number':
return [
{ onClick: () => setFilter(''), text: 'Clear Filter' },
{ onClick: () => filterMultipleValues(), text: 'Filter multiple values' },
{ onClick: () => openFilterWindow('='), text: 'Equals...' },
{ onClick: () => openFilterWindow('<>'), text: 'Does Not Equal...' },
{ onClick: () => setFilter('NULL'), text: 'Is Null' },
{ onClick: () => setFilter('NOT NULL'), text: 'Is Not Null' },
{ onClick: () => openFilterWindow('>'), text: 'Greater Than...' },
{ onClick: () => openFilterWindow('>='), text: 'Greater Than Or Equal To...' },
{ onClick: () => openFilterWindow('<'), text: 'Less Than...' },
{ onClick: () => openFilterWindow('<='), text: 'Less Than Or Equal To...' },
{ divider: true },
{ onClick: () => openFilterWindow('sql'), text: 'SQL condition ...' },
{ onClick: () => openFilterWindow('sqlRight'), text: 'SQL condition - right side ...' },
];
case 'logical':
return [
{ onClick: () => setFilter(''), text: 'Clear Filter' },
{ onClick: () => filterMultipleValues(), text: 'Filter multiple values' },
{ onClick: () => setFilter('NULL'), text: 'Is Null' },
{ onClick: () => setFilter('NOT NULL'), text: 'Is Not Null' },
{ onClick: () => setFilter('TRUE'), text: 'Is True' },
{ onClick: () => setFilter('FALSE'), text: 'Is False' },
{ onClick: () => setFilter('TRUE, NULL'), text: 'Is True or NULL' },
{ onClick: () => setFilter('FALSE, NULL'), text: 'Is False or NULL' },
{ divider: true },
{ onClick: () => openFilterWindow('sql'), text: 'SQL condition ...' },
{ onClick: () => openFilterWindow('sqlRight'), text: 'SQL condition - right side ...' },
];
case 'datetime':
return [
{ onClick: () => setFilter(''), text: 'Clear Filter' },
{ onClick: () => filterMultipleValues(), text: 'Filter multiple values' },
{ onClick: () => setFilter('NULL'), text: 'Is Null' },
{ onClick: () => setFilter('NOT NULL'), text: 'Is Not Null' },
{ divider: true },
{ onClick: () => openFilterWindow('<='), text: 'Before...' },
{ onClick: () => openFilterWindow('>='), text: 'After...' },
{ onClick: () => openFilterWindow('>=;<='), text: 'Between...' },
{ divider: true },
{ onClick: () => setFilter('TOMORROW'), text: 'Tomorrow' },
{ onClick: () => setFilter('TODAY'), text: 'Today' },
{ onClick: () => setFilter('YESTERDAY'), text: 'Yesterday' },
{ divider: true },
{ onClick: () => setFilter('NEXT WEEK'), text: 'Next Week' },
{ onClick: () => setFilter('THIS WEEK'), text: 'This Week' },
{ onClick: () => setFilter('LAST WEEK'), text: 'Last Week' },
{ divider: true },
{ onClick: () => setFilter('NEXT MONTH'), text: 'Next Month' },
{ onClick: () => setFilter('THIS MONTH'), text: 'This Month' },
{ onClick: () => setFilter('LAST MONTH'), text: 'Last Month' },
{ divider: true },
{ onClick: () => setFilter('NEXT YEAR'), text: 'Next Year' },
{ onClick: () => setFilter('THIS YEAR'), text: 'This Year' },
{ onClick: () => setFilter('LAST YEAR'), text: 'Last Year' },
{ divider: true },
{ onClick: () => openFilterWindow('sql'), text: 'SQL condition ...' },
{ onClick: () => openFilterWindow('sqlRight'), text: 'SQL condition - right side ...' },
];
case 'string':
return [
{ onClick: () => setFilter(''), text: 'Clear Filter' },
{ onClick: () => filterMultipleValues(), text: 'Filter multiple values' },
{ onClick: () => openFilterWindow('='), text: 'Equals...' },
{ onClick: () => openFilterWindow('<>'), text: 'Does Not Equal...' },
{ onClick: () => setFilter('NULL'), text: 'Is Null' },
{ onClick: () => setFilter('NOT NULL'), text: 'Is Not Null' },
{ onClick: () => setFilter('EMPTY, NULL'), text: 'Is Empty Or Null' },
{ onClick: () => setFilter('NOT EMPTY NOT NULL'), text: 'Has Not Empty Value' },
{ divider: true },
{ onClick: () => openFilterWindow('+'), text: 'Contains...' },
{ onClick: () => openFilterWindow('~'), text: 'Does Not Contain...' },
{ onClick: () => openFilterWindow('^'), text: 'Begins With...' },
{ onClick: () => openFilterWindow('!^'), text: 'Does Not Begin With...' },
{ onClick: () => openFilterWindow('$'), text: 'Ends With...' },
{ onClick: () => openFilterWindow('!$'), text: 'Does Not End With...' },
{ divider: true },
{ onClick: () => openFilterWindow('sql'), text: 'SQL condition ...' },
{ onClick: () => openFilterWindow('sqlRight'), text: 'SQL condition - right side ...' },
];
case 'mongo':
return [
{ onClick: () => setFilter(''), text: 'Clear Filter' },
{ onClick: () => filterMultipleValues(), text: 'Filter multiple values' },
{ onClick: () => openFilterWindow('='), text: 'Equals...' },
{ onClick: () => openFilterWindow('<>'), text: 'Does Not Equal...' },
{ onClick: () => setFilter('EXISTS'), text: 'Field exists' },
{ onClick: () => setFilter('NOT EXISTS'), text: 'Field does not exist' },
{ onClick: () => setFilter('NOT EMPTY ARRAY'), text: 'Array is not empty' },
{ onClick: () => setFilter('EMPTY ARRAY'), text: 'Array is empty' },
{ onClick: () => openFilterWindow('>'), text: 'Greater Than...' },
{ onClick: () => openFilterWindow('>='), text: 'Greater Than Or Equal To...' },
{ onClick: () => openFilterWindow('<'), text: 'Less Than...' },
{ onClick: () => openFilterWindow('<='), text: 'Less Than Or Equal To...' },
{ divider: true },
{ onClick: () => openFilterWindow('+'), text: 'Contains...' },
{ onClick: () => openFilterWindow('~'), text: 'Does Not Contain...' },
{ onClick: () => openFilterWindow('^'), text: 'Begins With...' },
{ onClick: () => openFilterWindow('!^'), text: 'Does Not Begin With...' },
{ onClick: () => openFilterWindow('$'), text: 'Ends With...' },
{ onClick: () => openFilterWindow('!$'), text: 'Does Not End With...' },
{ divider: true },
{ onClick: () => setFilter('TRUE'), text: 'Is True' },
{ onClick: () => setFilter('FALSE'), text: 'Is False' },
];
case 'eval':
return [
{ onClick: () => setFilter(''), text: 'Clear Filter' },
{ onClick: () => filterMultipleValues(), text: 'Filter multiple values' },
{ onClick: () => openFilterWindow('='), text: 'Equals...' },
{ onClick: () => openFilterWindow('<>'), text: 'Does Not Equal...' },
{ onClick: () => setFilter('NULL'), text: 'Is Null' },
{ onClick: () => setFilter('NOT NULL'), text: 'Is Not Null' },
{ divider: true },
{ onClick: () => openFilterWindow('>'), text: 'Greater Than...' },
{ onClick: () => openFilterWindow('>='), text: 'Greater Than Or Equal To...' },
{ onClick: () => openFilterWindow('<'), text: 'Less Than...' },
{ onClick: () => openFilterWindow('<='), text: 'Less Than Or Equal To...' },
{ divider: true },
{ onClick: () => openFilterWindow('+'), text: 'Contains...' },
{ onClick: () => openFilterWindow('~'), text: 'Does Not Contain...' },
{ onClick: () => openFilterWindow('^'), text: 'Begins With...' },
{ onClick: () => openFilterWindow('!^'), text: 'Does Not Begin With...' },
{ onClick: () => openFilterWindow('$'), text: 'Ends With...' },
{ onClick: () => openFilterWindow('!$'), text: 'Does Not End With...' },
];
}
// return [
// { text: 'Clear filter', onClick: () => (value = '') },
// { text: 'Is Null', onClick: () => (value = 'NULL') },
// { text: 'Is Not Null', onClick: () => (value = 'NOT NULL') },
// ];
return res;
}
const handleKeyDown = ev => {