mirror of
https://github.com/dbgate/dbgate
synced 2024-11-07 20:26:23 +00:00
added missing datetime interval filters
This commit is contained in:
parent
a44f4f6208
commit
7c7c334d67
@ -1,4 +1,5 @@
|
|||||||
import P from 'parsimmon';
|
import P from 'parsimmon';
|
||||||
|
import moment from 'moment';
|
||||||
import { FilterType } from './types';
|
import { FilterType } from './types';
|
||||||
import { Condition } from 'dbgate-sqltree';
|
import { Condition } from 'dbgate-sqltree';
|
||||||
import { TransformType } from 'dbgate-types';
|
import { TransformType } from 'dbgate-types';
|
||||||
@ -34,7 +35,7 @@ function interpretEscapes(str) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const binaryCondition = (operator) => (value) => ({
|
const binaryCondition = operator => value => ({
|
||||||
conditionType: 'binary',
|
conditionType: 'binary',
|
||||||
operator,
|
operator,
|
||||||
left: {
|
left: {
|
||||||
@ -46,7 +47,7 @@ const binaryCondition = (operator) => (value) => ({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const likeCondition = (conditionType, likeString) => (value) => ({
|
const likeCondition = (conditionType, likeString) => value => ({
|
||||||
conditionType,
|
conditionType,
|
||||||
left: {
|
left: {
|
||||||
exprType: 'placeholder',
|
exprType: 'placeholder',
|
||||||
@ -57,7 +58,7 @@ const likeCondition = (conditionType, likeString) => (value) => ({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const compoudCondition = (conditionType) => (conditions) => {
|
const compoudCondition = conditionType => conditions => {
|
||||||
if (conditions.length == 1) return conditions[0];
|
if (conditions.length == 1) return conditions[0];
|
||||||
return {
|
return {
|
||||||
conditionType,
|
conditionType,
|
||||||
@ -65,7 +66,7 @@ const compoudCondition = (conditionType) => (conditions) => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const unaryCondition = (conditionType) => () => {
|
const unaryCondition = conditionType => () => {
|
||||||
return {
|
return {
|
||||||
conditionType,
|
conditionType,
|
||||||
expr: {
|
expr: {
|
||||||
@ -74,7 +75,7 @@ const unaryCondition = (conditionType) => () => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const binaryFixedValueCondition = (value) => () => {
|
const binaryFixedValueCondition = value => () => {
|
||||||
return {
|
return {
|
||||||
conditionType: 'binary',
|
conditionType: 'binary',
|
||||||
operator: '=',
|
operator: '=',
|
||||||
@ -88,7 +89,7 @@ const binaryFixedValueCondition = (value) => () => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const negateCondition = (condition) => {
|
const negateCondition = condition => {
|
||||||
return {
|
return {
|
||||||
conditionType: 'not',
|
conditionType: 'not',
|
||||||
condition,
|
condition,
|
||||||
@ -113,11 +114,11 @@ function getTransformCondition(transform: TransformType, value) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const yearCondition = () => (value) => {
|
const yearCondition = () => value => {
|
||||||
return getTransformCondition('YEAR', value);
|
return getTransformCondition('YEAR', value);
|
||||||
};
|
};
|
||||||
|
|
||||||
const yearMonthCondition = () => (value) => {
|
const yearMonthCondition = () => value => {
|
||||||
const m = value.match(/(\d\d\d\d)-(\d\d?)/);
|
const m = value.match(/(\d\d\d\d)-(\d\d?)/);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -126,7 +127,7 @@ const yearMonthCondition = () => (value) => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const yearMonthDayCondition = () => (value) => {
|
const yearMonthDayCondition = () => value => {
|
||||||
const m = value.match(/(\d\d\d\d)-(\d\d?)-(\d\d?)/);
|
const m = value.match(/(\d\d\d\d)-(\d\d?)-(\d\d?)/);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -139,6 +140,43 @@ const yearMonthDayCondition = () => (value) => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const fixedIntervalCondition = (start, end) => () => {
|
||||||
|
return {
|
||||||
|
conditionType: 'and',
|
||||||
|
conditions: [
|
||||||
|
{
|
||||||
|
conditionType: 'binary',
|
||||||
|
operator: '>=',
|
||||||
|
left: {
|
||||||
|
exprType: 'placeholder',
|
||||||
|
},
|
||||||
|
right: {
|
||||||
|
exprType: 'value',
|
||||||
|
value: start,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
conditionType: 'binary',
|
||||||
|
operator: '<',
|
||||||
|
left: {
|
||||||
|
exprType: 'placeholder',
|
||||||
|
},
|
||||||
|
right: {
|
||||||
|
exprType: 'value',
|
||||||
|
value: end,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const fixedMomentIntervalCondition = (intervalType, diff) => {
|
||||||
|
return fixedIntervalCondition(
|
||||||
|
moment().add(intervalType, diff).startOf(intervalType).toISOString(),
|
||||||
|
moment().add(intervalType, diff).endOf(intervalType).toISOString()
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
const createParser = (filterType: FilterType) => {
|
const createParser = (filterType: FilterType) => {
|
||||||
const langDef = {
|
const langDef = {
|
||||||
string1: () =>
|
string1: () =>
|
||||||
@ -172,36 +210,60 @@ const createParser = (filterType: FilterType) => {
|
|||||||
yearMonthNum: () => P.regexp(/\d\d\d\d-\d\d?/).map(yearMonthCondition()),
|
yearMonthNum: () => P.regexp(/\d\d\d\d-\d\d?/).map(yearMonthCondition()),
|
||||||
yearMonthDayNum: () => P.regexp(/\d\d\d\d-\d\d?-\d\d?/).map(yearMonthDayCondition()),
|
yearMonthDayNum: () => P.regexp(/\d\d\d\d-\d\d?-\d\d?/).map(yearMonthDayCondition()),
|
||||||
|
|
||||||
value: (r) => P.alt(...allowedValues.map((x) => r[x])),
|
value: r => P.alt(...allowedValues.map(x => r[x])),
|
||||||
valueTestEq: (r) => r.value.map(binaryCondition('=')),
|
valueTestEq: r => r.value.map(binaryCondition('=')),
|
||||||
valueTestStr: (r) => r.value.map(likeCondition('like', '%#VALUE#%')),
|
valueTestStr: r => r.value.map(likeCondition('like', '%#VALUE#%')),
|
||||||
|
|
||||||
comma: () => word(','),
|
comma: () => word(','),
|
||||||
not: () => word('NOT'),
|
not: () => word('NOT'),
|
||||||
notNull: (r) => r.not.then(r.null).map(unaryCondition('isNotNull')),
|
notNull: r => r.not.then(r.null).map(unaryCondition('isNotNull')),
|
||||||
null: () => word('NULL').map(unaryCondition('isNull')),
|
null: () => word('NULL').map(unaryCondition('isNull')),
|
||||||
empty: () => word('EMPTY').map(unaryCondition('isEmpty')),
|
empty: () => word('EMPTY').map(unaryCondition('isEmpty')),
|
||||||
notEmpty: (r) => r.not.then(r.empty).map(unaryCondition('isNotEmpty')),
|
notEmpty: r => r.not.then(r.empty).map(unaryCondition('isNotEmpty')),
|
||||||
true: () => word('TRUE').map(binaryFixedValueCondition(1)),
|
true: () => word('TRUE').map(binaryFixedValueCondition(1)),
|
||||||
false: () => word('FALSE').map(binaryFixedValueCondition(0)),
|
false: () => word('FALSE').map(binaryFixedValueCondition(0)),
|
||||||
trueNum: () => word('1').map(binaryFixedValueCondition(1)),
|
trueNum: () => word('1').map(binaryFixedValueCondition(1)),
|
||||||
falseNum: () => word('0').map(binaryFixedValueCondition(0)),
|
falseNum: () => word('0').map(binaryFixedValueCondition(0)),
|
||||||
eq: (r) => word('=').then(r.value).map(binaryCondition('=')),
|
|
||||||
ne: (r) => word('!=').then(r.value).map(binaryCondition('<>')),
|
|
||||||
lt: (r) => word('<').then(r.value).map(binaryCondition('<')),
|
|
||||||
gt: (r) => word('>').then(r.value).map(binaryCondition('>')),
|
|
||||||
le: (r) => word('<=').then(r.value).map(binaryCondition('<=')),
|
|
||||||
ge: (r) => word('>=').then(r.value).map(binaryCondition('>=')),
|
|
||||||
startsWith: (r) => word('^').then(r.value).map(likeCondition('like', '#VALUE#%')),
|
|
||||||
endsWith: (r) => word('$').then(r.value).map(likeCondition('like', '%#VALUE#')),
|
|
||||||
contains: (r) => word('+').then(r.value).map(likeCondition('like', '%#VALUE#%')),
|
|
||||||
startsWithNot: (r) => word('!^').then(r.value).map(likeCondition('like', '#VALUE#%')).map(negateCondition),
|
|
||||||
endsWithNot: (r) => word('!$').then(r.value).map(likeCondition('like', '%#VALUE#')).map(negateCondition),
|
|
||||||
containsNot: (r) => word('~').then(r.value).map(likeCondition('like', '%#VALUE#%')).map(negateCondition),
|
|
||||||
|
|
||||||
element: (r) => P.alt(...allowedElements.map((x) => r[x])).trim(whitespace),
|
this: () => word('THIS'),
|
||||||
factor: (r) => r.element.sepBy(whitespace).map(compoudCondition('and')),
|
last: () => word('LAST'),
|
||||||
list: (r) => r.factor.sepBy(r.comma).map(compoudCondition('or')),
|
next: () => word('NEXT'),
|
||||||
|
week: () => word('WEEK'),
|
||||||
|
month: () => word('MONTH'),
|
||||||
|
year: () => word('YEAR'),
|
||||||
|
|
||||||
|
yesterday: () => word('YESTERDAY').map(fixedMomentIntervalCondition('day', -1)),
|
||||||
|
today: () => word('TODAY').map(fixedMomentIntervalCondition('day', 0)),
|
||||||
|
tomorrow: () => word('TOMORROW').map(fixedMomentIntervalCondition('day', 1)),
|
||||||
|
|
||||||
|
lastWeek: r => r.last.then(r.week).map(fixedMomentIntervalCondition('week', -1)),
|
||||||
|
thisWeek: r => r.this.then(r.week).map(fixedMomentIntervalCondition('week', 0)),
|
||||||
|
nextWeek: r => r.next.then(r.week).map(fixedMomentIntervalCondition('week', 1)),
|
||||||
|
|
||||||
|
lastMonth: r => r.last.then(r.month).map(fixedMomentIntervalCondition('month', -1)),
|
||||||
|
thisMonth: r => r.this.then(r.month).map(fixedMomentIntervalCondition('month', 0)),
|
||||||
|
nextMonth: r => r.next.then(r.month).map(fixedMomentIntervalCondition('month', 1)),
|
||||||
|
|
||||||
|
lastYear: r => r.last.then(r.year).map(fixedMomentIntervalCondition('year', -1)),
|
||||||
|
thisYear: r => r.this.then(r.year).map(fixedMomentIntervalCondition('year', 0)),
|
||||||
|
nextYear: r => r.next.then(r.year).map(fixedMomentIntervalCondition('year', 1)),
|
||||||
|
|
||||||
|
eq: r => word('=').then(r.value).map(binaryCondition('=')),
|
||||||
|
ne: r => word('!=').then(r.value).map(binaryCondition('<>')),
|
||||||
|
lt: r => word('<').then(r.value).map(binaryCondition('<')),
|
||||||
|
gt: r => word('>').then(r.value).map(binaryCondition('>')),
|
||||||
|
le: r => word('<=').then(r.value).map(binaryCondition('<=')),
|
||||||
|
ge: r => word('>=').then(r.value).map(binaryCondition('>=')),
|
||||||
|
startsWith: r => word('^').then(r.value).map(likeCondition('like', '#VALUE#%')),
|
||||||
|
endsWith: r => word('$').then(r.value).map(likeCondition('like', '%#VALUE#')),
|
||||||
|
contains: r => word('+').then(r.value).map(likeCondition('like', '%#VALUE#%')),
|
||||||
|
startsWithNot: r => word('!^').then(r.value).map(likeCondition('like', '#VALUE#%')).map(negateCondition),
|
||||||
|
endsWithNot: r => word('!$').then(r.value).map(likeCondition('like', '%#VALUE#')).map(negateCondition),
|
||||||
|
containsNot: r => word('~').then(r.value).map(likeCondition('like', '%#VALUE#%')).map(negateCondition),
|
||||||
|
|
||||||
|
element: r => P.alt(...allowedElements.map(x => r[x])).trim(whitespace),
|
||||||
|
factor: r => r.element.sepBy(whitespace).map(compoudCondition('and')),
|
||||||
|
list: r => r.factor.sepBy(r.comma).map(compoudCondition('or')),
|
||||||
};
|
};
|
||||||
|
|
||||||
const allowedValues = []; // 'string1', 'string2', 'number', 'noQuotedString'];
|
const allowedValues = []; // 'string1', 'string2', 'number', 'noQuotedString'];
|
||||||
@ -222,7 +284,24 @@ const createParser = (filterType: FilterType) => {
|
|||||||
'containsNot'
|
'containsNot'
|
||||||
);
|
);
|
||||||
if (filterType == 'logical') allowedElements.push('true', 'false', 'trueNum', 'falseNum');
|
if (filterType == 'logical') allowedElements.push('true', 'false', 'trueNum', 'falseNum');
|
||||||
if (filterType == 'datetime') allowedElements.push('yearMonthDayNum', 'yearMonthNum', 'yearNum');
|
if (filterType == 'datetime')
|
||||||
|
allowedElements.push(
|
||||||
|
'yearMonthDayNum',
|
||||||
|
'yearMonthNum',
|
||||||
|
'yearNum',
|
||||||
|
'yesterday',
|
||||||
|
'today',
|
||||||
|
'tomorrow',
|
||||||
|
'lastWeek',
|
||||||
|
'thisWeek',
|
||||||
|
'nextWeek',
|
||||||
|
'lastMonth',
|
||||||
|
'thisMonth',
|
||||||
|
'nextMonth',
|
||||||
|
'lastYear',
|
||||||
|
'thisYear',
|
||||||
|
'nextYear'
|
||||||
|
);
|
||||||
|
|
||||||
// must be last
|
// must be last
|
||||||
if (filterType == 'string') allowedElements.push('valueTestStr');
|
if (filterType == 'string') allowedElements.push('valueTestStr');
|
||||||
@ -240,5 +319,6 @@ const parsers = {
|
|||||||
|
|
||||||
export function parseFilter(value: string, filterType: FilterType): Condition {
|
export function parseFilter(value: string, filterType: FilterType): Condition {
|
||||||
const ast = parsers[filterType].list.tryParse(value);
|
const ast = parsers[filterType].list.tryParse(value);
|
||||||
|
// console.log('AST', ast);
|
||||||
return ast;
|
return ast;
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ const FilterDiv = styled.div`
|
|||||||
const FilterInput = styled.input`
|
const FilterInput = styled.input`
|
||||||
flex: 1;
|
flex: 1;
|
||||||
min-width: 10px;
|
min-width: 10px;
|
||||||
background-color: ${(props) =>
|
background-color: ${props =>
|
||||||
props.state == 'ok'
|
props.state == 'ok'
|
||||||
? props.theme.input_background_green[1]
|
? props.theme.input_background_green[1]
|
||||||
: props.state == 'error'
|
: props.state == 'error'
|
||||||
@ -58,68 +58,68 @@ function DropDownContent({ filterType, setFilter, filterMultipleValues, openFilt
|
|||||||
case 'number':
|
case 'number':
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<DropDownMenuItem onClick={(x) => setFilter('')}>Clear Filter</DropDownMenuItem>
|
<DropDownMenuItem onClick={x => setFilter('')}>Clear Filter</DropDownMenuItem>
|
||||||
<DropDownMenuItem onClick={(x) => filterMultipleValues()}>Filter multiple values</DropDownMenuItem>
|
<DropDownMenuItem onClick={x => filterMultipleValues()}>Filter multiple values</DropDownMenuItem>
|
||||||
<DropDownMenuItem onClick={(x) => openFilterWindow('=')}>Equals...</DropDownMenuItem>
|
<DropDownMenuItem onClick={x => openFilterWindow('=')}>Equals...</DropDownMenuItem>
|
||||||
<DropDownMenuItem onClick={(x) => openFilterWindow('<>')}>Does Not Equal...</DropDownMenuItem>
|
<DropDownMenuItem onClick={x => openFilterWindow('<>')}>Does Not Equal...</DropDownMenuItem>
|
||||||
<DropDownMenuItem onClick={(x) => setFilter('NULL')}>Is Null</DropDownMenuItem>
|
<DropDownMenuItem onClick={x => setFilter('NULL')}>Is Null</DropDownMenuItem>
|
||||||
<DropDownMenuItem onClick={(x) => setFilter('NOT NULL')}>Is Not Null</DropDownMenuItem>
|
<DropDownMenuItem onClick={x => setFilter('NOT NULL')}>Is Not Null</DropDownMenuItem>
|
||||||
<DropDownMenuItem onClick={(x) => openFilterWindow('>')}>Greater Than...</DropDownMenuItem>
|
<DropDownMenuItem onClick={x => openFilterWindow('>')}>Greater Than...</DropDownMenuItem>
|
||||||
<DropDownMenuItem onClick={(x) => openFilterWindow('>=')}>Greater Than Or Equal To...</DropDownMenuItem>
|
<DropDownMenuItem onClick={x => openFilterWindow('>=')}>Greater Than Or Equal To...</DropDownMenuItem>
|
||||||
<DropDownMenuItem onClick={(x) => openFilterWindow('<')}>Less Than...</DropDownMenuItem>
|
<DropDownMenuItem onClick={x => openFilterWindow('<')}>Less Than...</DropDownMenuItem>
|
||||||
<DropDownMenuItem onClick={(x) => openFilterWindow('<=')}>Less Than Or Equal To...</DropDownMenuItem>
|
<DropDownMenuItem onClick={x => openFilterWindow('<=')}>Less Than Or Equal To...</DropDownMenuItem>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
case 'logical':
|
case 'logical':
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<DropDownMenuItem onClick={(x) => setFilter('')}>Clear Filter</DropDownMenuItem>
|
<DropDownMenuItem onClick={x => setFilter('')}>Clear Filter</DropDownMenuItem>
|
||||||
<DropDownMenuItem onClick={(x) => filterMultipleValues()}>Filter multiple values</DropDownMenuItem>
|
<DropDownMenuItem onClick={x => filterMultipleValues()}>Filter multiple values</DropDownMenuItem>
|
||||||
<DropDownMenuItem onClick={(x) => setFilter('NULL')}>Is Null</DropDownMenuItem>
|
<DropDownMenuItem onClick={x => setFilter('NULL')}>Is Null</DropDownMenuItem>
|
||||||
<DropDownMenuItem onClick={(x) => setFilter('NOT NULL')}>Is Not Null</DropDownMenuItem>
|
<DropDownMenuItem onClick={x => setFilter('NOT NULL')}>Is Not Null</DropDownMenuItem>
|
||||||
<DropDownMenuItem onClick={(x) => setFilter('TRUE')}>Is True</DropDownMenuItem>
|
<DropDownMenuItem onClick={x => setFilter('TRUE')}>Is True</DropDownMenuItem>
|
||||||
<DropDownMenuItem onClick={(x) => setFilter('FALSE')}>Is False</DropDownMenuItem>
|
<DropDownMenuItem onClick={x => setFilter('FALSE')}>Is False</DropDownMenuItem>
|
||||||
<DropDownMenuItem onClick={(x) => setFilter('TRUE, NULL')}>Is True or NULL</DropDownMenuItem>
|
<DropDownMenuItem onClick={x => setFilter('TRUE, NULL')}>Is True or NULL</DropDownMenuItem>
|
||||||
<DropDownMenuItem onClick={(x) => setFilter('FALSE, NULL')}>Is False or NULL</DropDownMenuItem>
|
<DropDownMenuItem onClick={x => setFilter('FALSE, NULL')}>Is False or NULL</DropDownMenuItem>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
case 'datetime':
|
case 'datetime':
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<DropDownMenuItem onClick={(x) => setFilter('')}>Clear Filter</DropDownMenuItem>
|
<DropDownMenuItem onClick={x => setFilter('')}>Clear Filter</DropDownMenuItem>
|
||||||
<DropDownMenuItem onClick={(x) => filterMultipleValues()}>Filter multiple values</DropDownMenuItem>
|
<DropDownMenuItem onClick={x => filterMultipleValues()}>Filter multiple values</DropDownMenuItem>
|
||||||
<DropDownMenuItem onClick={(x) => setFilter('NULL')}>Is Null</DropDownMenuItem>
|
<DropDownMenuItem onClick={x => setFilter('NULL')}>Is Null</DropDownMenuItem>
|
||||||
<DropDownMenuItem onClick={(x) => setFilter('NOT NULL')}>Is Not Null</DropDownMenuItem>
|
<DropDownMenuItem onClick={x => setFilter('NOT NULL')}>Is Not Null</DropDownMenuItem>
|
||||||
|
|
||||||
<DropDownMenuDivider />
|
<DropDownMenuDivider />
|
||||||
|
|
||||||
<DropDownMenuItem onClick={(x) => openFilterWindow('<=')}>Before...</DropDownMenuItem>
|
<DropDownMenuItem onClick={x => openFilterWindow('<=')}>Before...</DropDownMenuItem>
|
||||||
<DropDownMenuItem onClick={(x) => openFilterWindow('>=')}>After...</DropDownMenuItem>
|
<DropDownMenuItem onClick={x => openFilterWindow('>=')}>After...</DropDownMenuItem>
|
||||||
<DropDownMenuItem onClick={(x) => openFilterWindow('>=;<=')}>Between...</DropDownMenuItem>
|
<DropDownMenuItem onClick={x => openFilterWindow('>=;<=')}>Between...</DropDownMenuItem>
|
||||||
|
|
||||||
<DropDownMenuDivider />
|
<DropDownMenuDivider />
|
||||||
|
|
||||||
<DropDownMenuItem onClick={(x) => setFilter('TOMORROW')}>Tomorrow</DropDownMenuItem>
|
<DropDownMenuItem onClick={x => setFilter('TOMORROW')}>Tomorrow</DropDownMenuItem>
|
||||||
<DropDownMenuItem onClick={(x) => setFilter('TODAY')}>Today</DropDownMenuItem>
|
<DropDownMenuItem onClick={x => setFilter('TODAY')}>Today</DropDownMenuItem>
|
||||||
<DropDownMenuItem onClick={(x) => setFilter('YESTERDAY')}>Yesterday</DropDownMenuItem>
|
<DropDownMenuItem onClick={x => setFilter('YESTERDAY')}>Yesterday</DropDownMenuItem>
|
||||||
|
|
||||||
<DropDownMenuDivider />
|
<DropDownMenuDivider />
|
||||||
|
|
||||||
<DropDownMenuItem onClick={(x) => setFilter('NEXT WEEK')}>Next Week</DropDownMenuItem>
|
<DropDownMenuItem onClick={x => setFilter('NEXT WEEK')}>Next Week</DropDownMenuItem>
|
||||||
<DropDownMenuItem onClick={(x) => setFilter('THIS WEEK')}>This Week</DropDownMenuItem>
|
<DropDownMenuItem onClick={x => setFilter('THIS WEEK')}>This Week</DropDownMenuItem>
|
||||||
<DropDownMenuItem onClick={(x) => setFilter('LAST WEEK')}>Last Week</DropDownMenuItem>
|
<DropDownMenuItem onClick={x => setFilter('LAST WEEK')}>Last Week</DropDownMenuItem>
|
||||||
|
|
||||||
<DropDownMenuDivider />
|
<DropDownMenuDivider />
|
||||||
|
|
||||||
<DropDownMenuItem onClick={(x) => setFilter('NEXT MONTH')}>Next Month</DropDownMenuItem>
|
<DropDownMenuItem onClick={x => setFilter('NEXT MONTH')}>Next Month</DropDownMenuItem>
|
||||||
<DropDownMenuItem onClick={(x) => setFilter('THIS MONTH')}>This Month</DropDownMenuItem>
|
<DropDownMenuItem onClick={x => setFilter('THIS MONTH')}>This Month</DropDownMenuItem>
|
||||||
<DropDownMenuItem onClick={(x) => setFilter('LAST MONTH')}>Last Month</DropDownMenuItem>
|
<DropDownMenuItem onClick={x => setFilter('LAST MONTH')}>Last Month</DropDownMenuItem>
|
||||||
|
|
||||||
<DropDownMenuDivider />
|
<DropDownMenuDivider />
|
||||||
|
|
||||||
<DropDownMenuItem onClick={(x) => setFilter('NEXT YEAR')}>Next Year</DropDownMenuItem>
|
<DropDownMenuItem onClick={x => setFilter('NEXT YEAR')}>Next Year</DropDownMenuItem>
|
||||||
<DropDownMenuItem onClick={(x) => setFilter('THIS YEAR')}>This Year</DropDownMenuItem>
|
<DropDownMenuItem onClick={x => setFilter('THIS YEAR')}>This Year</DropDownMenuItem>
|
||||||
<DropDownMenuItem onClick={(x) => setFilter('LAST YEAR')}>Last Year</DropDownMenuItem>
|
<DropDownMenuItem onClick={x => setFilter('LAST YEAR')}>Last Year</DropDownMenuItem>
|
||||||
|
|
||||||
<DropDownMenuDivider />
|
<DropDownMenuDivider />
|
||||||
|
|
||||||
@ -151,24 +151,24 @@ function DropDownContent({ filterType, setFilter, filterMultipleValues, openFilt
|
|||||||
case 'string':
|
case 'string':
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<DropDownMenuItem onClick={(x) => setFilter('')}>Clear Filter</DropDownMenuItem>
|
<DropDownMenuItem onClick={x => setFilter('')}>Clear Filter</DropDownMenuItem>
|
||||||
<DropDownMenuItem onClick={(x) => filterMultipleValues()}>Filter multiple values</DropDownMenuItem>
|
<DropDownMenuItem onClick={x => filterMultipleValues()}>Filter multiple values</DropDownMenuItem>
|
||||||
|
|
||||||
<DropDownMenuItem onClick={(x) => openFilterWindow('=')}>Equals...</DropDownMenuItem>
|
<DropDownMenuItem onClick={x => openFilterWindow('=')}>Equals...</DropDownMenuItem>
|
||||||
<DropDownMenuItem onClick={(x) => openFilterWindow('<>')}>Does Not Equal...</DropDownMenuItem>
|
<DropDownMenuItem onClick={x => openFilterWindow('<>')}>Does Not Equal...</DropDownMenuItem>
|
||||||
<DropDownMenuItem onClick={(x) => setFilter('NULL')}>Is Null</DropDownMenuItem>
|
<DropDownMenuItem onClick={x => setFilter('NULL')}>Is Null</DropDownMenuItem>
|
||||||
<DropDownMenuItem onClick={(x) => setFilter('NOT NULL')}>Is Not Null</DropDownMenuItem>
|
<DropDownMenuItem onClick={x => setFilter('NOT NULL')}>Is Not Null</DropDownMenuItem>
|
||||||
<DropDownMenuItem onClick={(x) => setFilter('EMPTY, NULL')}>Is Empty Or Null</DropDownMenuItem>
|
<DropDownMenuItem onClick={x => setFilter('EMPTY, NULL')}>Is Empty Or Null</DropDownMenuItem>
|
||||||
<DropDownMenuItem onClick={(x) => setFilter('NOT EMPTY NOT NULL')}>Has Not Empty Value</DropDownMenuItem>
|
<DropDownMenuItem onClick={x => setFilter('NOT EMPTY NOT NULL')}>Has Not Empty Value</DropDownMenuItem>
|
||||||
|
|
||||||
<DropDownMenuDivider />
|
<DropDownMenuDivider />
|
||||||
|
|
||||||
<DropDownMenuItem onClick={(x) => openFilterWindow('+')}>Contains...</DropDownMenuItem>
|
<DropDownMenuItem onClick={x => openFilterWindow('+')}>Contains...</DropDownMenuItem>
|
||||||
<DropDownMenuItem onClick={(x) => openFilterWindow('~')}>Does Not Contain...</DropDownMenuItem>
|
<DropDownMenuItem onClick={x => openFilterWindow('~')}>Does Not Contain...</DropDownMenuItem>
|
||||||
<DropDownMenuItem onClick={(x) => openFilterWindow('^')}>Begins With...</DropDownMenuItem>
|
<DropDownMenuItem onClick={x => openFilterWindow('^')}>Begins With...</DropDownMenuItem>
|
||||||
<DropDownMenuItem onClick={(x) => openFilterWindow('!^')}>Does Not Begin With...</DropDownMenuItem>
|
<DropDownMenuItem onClick={x => openFilterWindow('!^')}>Does Not Begin With...</DropDownMenuItem>
|
||||||
<DropDownMenuItem onClick={(x) => openFilterWindow('$')}>Ends With...</DropDownMenuItem>
|
<DropDownMenuItem onClick={x => openFilterWindow('$')}>Ends With...</DropDownMenuItem>
|
||||||
<DropDownMenuItem onClick={(x) => openFilterWindow('!$')}>Does Not End With...</DropDownMenuItem>
|
<DropDownMenuItem onClick={x => openFilterWindow('!$')}>Does Not End With...</DropDownMenuItem>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -186,7 +186,7 @@ export default function DataFilterControl({
|
|||||||
const showMenu = useShowMenu();
|
const showMenu = useShowMenu();
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const [filterState, setFilterState] = React.useState('empty');
|
const [filterState, setFilterState] = React.useState('empty');
|
||||||
const setFilterText = (filter) => {
|
const setFilterText = filter => {
|
||||||
setFilter(filter);
|
setFilter(filter);
|
||||||
editorRef.current.value = filter || '';
|
editorRef.current.value = filter || '';
|
||||||
updateFilterState();
|
updateFilterState();
|
||||||
@ -196,19 +196,19 @@ export default function DataFilterControl({
|
|||||||
setFilter(editorRef.current.value);
|
setFilter(editorRef.current.value);
|
||||||
};
|
};
|
||||||
const filterMultipleValues = () => {
|
const filterMultipleValues = () => {
|
||||||
showModal((modalState) => (
|
showModal(modalState => (
|
||||||
<FilterMultipleValuesModal
|
<FilterMultipleValuesModal
|
||||||
modalState={modalState}
|
modalState={modalState}
|
||||||
onFilter={(mode, text) => setFilterText(createMultiLineFilter(mode, text))}
|
onFilter={(mode, text) => setFilterText(createMultiLineFilter(mode, text))}
|
||||||
/>
|
/>
|
||||||
));
|
));
|
||||||
};
|
};
|
||||||
const openFilterWindow = (operator) => {
|
const openFilterWindow = operator => {
|
||||||
showModal((modalState) => (
|
showModal(modalState => (
|
||||||
<SetFilterModal
|
<SetFilterModal
|
||||||
filterType={filterType}
|
filterType={filterType}
|
||||||
modalState={modalState}
|
modalState={modalState}
|
||||||
onFilter={(text) => setFilterText(text)}
|
onFilter={text => setFilterText(text)}
|
||||||
condition1={operator}
|
condition1={operator}
|
||||||
/>
|
/>
|
||||||
));
|
));
|
||||||
@ -220,7 +220,7 @@ export default function DataFilterControl({
|
|||||||
if (focusIndex) editorRef.current.focus();
|
if (focusIndex) editorRef.current.focus();
|
||||||
}, [focusIndex]);
|
}, [focusIndex]);
|
||||||
|
|
||||||
const handleKeyDown = (ev) => {
|
const handleKeyDown = ev => {
|
||||||
if (isReadOnly) return;
|
if (isReadOnly) return;
|
||||||
if (ev.keyCode == keycodes.enter) {
|
if (ev.keyCode == keycodes.enter) {
|
||||||
applyFilter();
|
applyFilter();
|
||||||
@ -248,6 +248,7 @@ export default function DataFilterControl({
|
|||||||
setFilterState('empty');
|
setFilterState('empty');
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
// console.log('PARSE ERROR', err);
|
||||||
setFilterState('error');
|
setFilterState('error');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -78,7 +78,7 @@ export default function SqlDataGridCore(props) {
|
|||||||
initialValues.sourceDatabaseName = database;
|
initialValues.sourceDatabaseName = database;
|
||||||
initialValues.sourceSql = display.getExportQuery();
|
initialValues.sourceSql = display.getExportQuery();
|
||||||
initialValues.sourceList = display.baseTable ? [display.baseTable.pureName] : [];
|
initialValues.sourceList = display.baseTable ? [display.baseTable.pureName] : [];
|
||||||
showModal((modalState) => <ImportExportModal modalState={modalState} initialValues={initialValues} />);
|
showModal(modalState => <ImportExportModal modalState={modalState} initialValues={initialValues} />);
|
||||||
}
|
}
|
||||||
function openActiveChart() {
|
function openActiveChart() {
|
||||||
openNewTab(
|
openNewTab(
|
||||||
@ -94,7 +94,7 @@ export default function SqlDataGridCore(props) {
|
|||||||
{
|
{
|
||||||
editor: {
|
editor: {
|
||||||
config: { chartType: 'bar' },
|
config: { chartType: 'bar' },
|
||||||
sql: display.getExportQuery((select) => {
|
sql: display.getExportQuery(select => {
|
||||||
select.orderBy = null;
|
select.orderBy = null;
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
@ -102,18 +102,22 @@ export default function SqlDataGridCore(props) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
function openQuery() {
|
function openQuery() {
|
||||||
openNewTab({
|
openNewTab(
|
||||||
title: 'Query',
|
{
|
||||||
icon: 'img sql-file',
|
title: 'Query',
|
||||||
tabComponent: 'QueryTab',
|
icon: 'img sql-file',
|
||||||
props: {
|
tabComponent: 'QueryTab',
|
||||||
initialScript: display.getExportQuery(),
|
props: {
|
||||||
schemaName: display.baseTable.schemaName,
|
schemaName: display.baseTable.schemaName,
|
||||||
pureName: display.baseTable.pureName,
|
pureName: display.baseTable.pureName,
|
||||||
conid,
|
conid,
|
||||||
database,
|
database,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
{
|
||||||
|
editor: display.getExportQuery(),
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleSave() {
|
function handleSave() {
|
||||||
@ -135,7 +139,7 @@ export default function SqlDataGridCore(props) {
|
|||||||
});
|
});
|
||||||
const { errorMessage } = resp.data || {};
|
const { errorMessage } = resp.data || {};
|
||||||
if (errorMessage) {
|
if (errorMessage) {
|
||||||
showModal((modalState) => (
|
showModal(modalState => (
|
||||||
<ErrorMessageModal modalState={modalState} message={errorMessage} title="Error when saving" />
|
<ErrorMessageModal modalState={modalState} message={errorMessage} title="Error when saving" />
|
||||||
));
|
));
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user