Skip to content

Commit ebedc80

Browse files
authored
FIREFLY-805:Merge PR #1108 from FIREFLY-805_to_rc
FIREFLY-805: Filter does not work on boolean type column, cherry-picked to rc-2021.2
2 parents 8a0425a + 0ab62e5 commit ebedc80

File tree

6 files changed

+37
-37
lines changed

6 files changed

+37
-37
lines changed

src/firefly/js/tables/FilterInfo.js

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,8 @@ export class FilterInfo {
137137
for (let i = 0; i < parts.length; i += 2) {
138138
const [cname, op, val] = parseInput(parts[i]);
139139
if (cname) {
140-
let isNumeric = false;
141-
if (columns) {
142-
const col = columns.find((c) => c.name === cname);
143-
// assume all expressions are numeric
144-
isNumeric = !col || isColumnType(col, COL_TYPE.NUMBER);
145-
}
146-
parts[i] = `${cname} ${autoCorrectCondition(op + ' ' + val, isNumeric)}`;
140+
const col = columns?.find((c) => c.name === cname);
141+
parts[i] = `${cname} ${autoCorrectCondition(op + ' ' + val, col)}`;
147142
}
148143
}
149144
return parts.join('');
@@ -388,11 +383,11 @@ function likeToRegexp(text) {
388383
* @returns {string}
389384
*/
390385
function autoCorrectConditions(conditions, tbl_id, cname) {
391-
const isNumeric = isColumnType(getColumn(getTblById(tbl_id), cname), COL_TYPE.NUMBER);
386+
const col = getColumn(getTblById(tbl_id), cname);
392387
if (conditions) {
393388
const parts = conditions.split(COND_SEP);
394389
for (let i = 0; i < parts.length; i += 2) { // separate them into parts
395-
parts[i] = autoCorrectCondition(parts[i], isNumeric); // auto correct if needed
390+
parts[i] = autoCorrectCondition(parts[i], col); // auto correct if needed
396391
}
397392
return parts.join(''); // put them back
398393
} else {
@@ -420,11 +415,13 @@ function autoCorrectConditions(conditions, tbl_id, cname) {
420415
* ex: =abc => ='abc' after auto-correction for text column
421416
* =abc => =abc after auto-correction for numeric column
422417
*
423-
* @param v
424-
* @param isNumeric
418+
* @param v filter expression
419+
* @param col column to operate on
425420
* @returns {*}
426421
*/
427-
function autoCorrectCondition(v, isNumeric=false) {
422+
function autoCorrectCondition(v, col) {
423+
424+
const useQuote = col && isColumnType(col, COL_TYPE.USE_STRING);
428425

429426
const encloseByQuote = (txt, quote="'") => {
430427
return `${quote}${txt}${quote}`;
@@ -439,7 +436,7 @@ function autoCorrectCondition(v, isNumeric=false) {
439436
// empty string or string with no value
440437
if (!op && !val) return v.trim();
441438

442-
op = op ? op.toLowerCase() : (isNumeric ? '=' : 'like'); // no operator is treated as 'like'
439+
op = op ? op.toLowerCase() : (useQuote ? 'like' : '='); // no operator is treated as 'like'
443440

444441
switch (op) {
445442
case 'like':
@@ -453,7 +450,7 @@ function autoCorrectCondition(v, isNumeric=false) {
453450
let valList = val.match(/^\((.*)\)$/) ? val.substring(1, val.length-1) : val;
454451

455452
valList = valList.split(',').map((s) => {
456-
return isNumeric ? s : encloseString(s.trim());
453+
return useQuote ? encloseString(s.trim()) : s;
457454
}).join(', ');
458455

459456
val = `(${valList})`;
@@ -464,7 +461,7 @@ function autoCorrectCondition(v, isNumeric=false) {
464461
case '<':
465462
case '>=':
466463
case '<=':
467-
val = isNumeric && !isNaN(val) ? val : encloseString(val);
464+
val = useQuote ? encloseString(val) : val;
468465
break;
469466
case 'is':
470467
case 'is not':

src/firefly/js/tables/TableUtil.js

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,17 @@ const local = {
5050
};
5151
export default local;
5252

53-
export const COL_TYPE = new Enum(['ALL', 'NUMBER', 'TEXT', 'INT', 'FLOAT']);
53+
const TEXT = ['char', 'c', 's', 'str'];
54+
const INT = ['long', 'l', 'int', 'i'];
55+
const FLOAT = ['double', 'd', 'float', 'f'];
56+
const BOOL = ['boolean','bool'];
57+
const DATE = ['date'];
58+
const NUMBER= [...INT, ...FLOAT];
59+
const USE_STRING = [...TEXT, ...DATE];
60+
61+
// export const COL_TYPE = new Enum(['ALL', 'NUMBER', 'TEXT', 'INT', 'FLOAT']);
62+
export const COL_TYPE = new Enum({ANY:[],TEXT, INT, FLOAT, BOOL, DATE, NUMBER, USE_STRING});
5463

55-
const colTypes = {
56-
[COL_TYPE.TEXT]: ['char', 'c', 's', 'str'],
57-
[COL_TYPE.INT]: ['long', 'l', 'int', 'i'],
58-
[COL_TYPE.FLOAT]: ['double', 'd', 'float', 'f'],
59-
[COL_TYPE.NUMBER]: ['long', 'l', 'int', 'i', 'double', 'd', 'float', 'f'],
60-
};
6164

6265
/**
6366
* @param {TableColumn} col
@@ -67,7 +70,7 @@ const colTypes = {
6770
export function isColumnType(col={}, type) {
6871
const flg = '_t-' + type.key; // for efficiency
6972
if (!has(col, flg)) {
70-
col[flg] = !colTypes[type] || isOfType(col.type, type);
73+
col[flg] = isOfType(col.type, type);
7174
}
7275
return col[flg];
7376
}
@@ -79,7 +82,7 @@ export function isColumnType(col={}, type) {
7982
* @returns {boolean}
8083
*/
8184
export function isOfType(s, type) {
82-
return colTypes[type].includes(s);
85+
return type === COL_TYPE.ANY || COL_TYPE[type].value.includes(s);
8386
}
8487

8588
export function isClientTable(tbl_id) {
@@ -1244,13 +1247,13 @@ export function monitorChanges(actions, accept, callback, watcherId) {
12441247
* @summary returns the non-hidden columns of the given table. If type is given, it
12451248
* will only return columns that match type.
12461249
* @param {TableModel} tableModel
1247-
* @param {COL_TYPE} type one of predefined COL_TYPE. defaults to 'ALL'.
1250+
* @param {COL_TYPE} type one of predefined COL_TYPE. defaults to 'ANY'.
12481251
* @returns {Array<TableColumn>}
12491252
* @public
12501253
* @memberof firefly.util.table
12511254
* @func getColumns
12521255
*/
1253-
export function getColumns(tableModel, type=COL_TYPE.ALL) {
1256+
export function getColumns(tableModel, type=COL_TYPE.ANY) {
12541257
return getColsByType(getAllColumns(tableModel), type);
12551258
}
12561259

@@ -1269,10 +1272,10 @@ export function getAllColumns(tableModel) {
12691272
/**
12701273
* @summary returns only the non-hidden columns matching the given type.
12711274
* @param {Array<TableColumn>} tblColumns
1272-
* @param {COL_TYPE} type one of predefined COL_TYPE. defaults to 'ALL'.
1275+
* @param {COL_TYPE} type one of predefined COL_TYPE. defaults to 'ANY'.
12731276
* @returns {Array<TableColumn>}
12741277
*/
1275-
export function getColsByType(tblColumns=[], type=COL_TYPE.ALL) {
1278+
export function getColsByType(tblColumns=[], type=COL_TYPE.ANY) {
12761279
return tblColumns.filter((col) =>
12771280
get(col, 'visibility') !== 'hidden' &&
12781281
isColumnType(col, type));

src/firefly/js/tables/__tests__/TableUtil-test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ describe('TableUtil: ', () => {
6262
expect(TblUtil.isColumnType(char3, TblUtil.COL_TYPE.TEXT)).toBe(true);
6363
expect(TblUtil.isColumnType(char4, TblUtil.COL_TYPE.TEXT)).toBe(true);
6464

65-
expect(TblUtil.isColumnType(char1, TblUtil.COL_TYPE.ALL)).toBe(true);
66-
expect(TblUtil.isColumnType(int1, TblUtil.COL_TYPE.ALL)).toBe(true);
67-
expect(TblUtil.isColumnType(float1, TblUtil.COL_TYPE.ALL)).toBe(true);
65+
expect(TblUtil.isColumnType(char1, TblUtil.COL_TYPE.ANY)).toBe(true);
66+
expect(TblUtil.isColumnType(int1, TblUtil.COL_TYPE.ANY)).toBe(true);
67+
expect(TblUtil.isColumnType(float1, TblUtil.COL_TYPE.ANY)).toBe(true);
6868

6969
expect(TblUtil.isColumnType(int1, TblUtil.COL_TYPE.NUMBER)).toBe(true);
7070
expect(TblUtil.isColumnType(float1, TblUtil.COL_TYPE.NUMBER)).toBe(true);

src/firefly/js/tables/ui/TableRenderer.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,9 @@ function EnumSelect({col, tbl_id, filterInfoCls, onFilter}) {
145145
let value = getFieldVal(groupKey, fieldKey);
146146
if (value) {
147147
value = value.split(',').map((s) => s === '%EMPTY' ? '' : s).join(); // convert %EMPTY back into ''
148-
value = isColumnType(col, COL_TYPE.NUMBER) ? value :
149-
value.split(',')
150-
.map((s) => `'${s.trim()}'`).join(',');
148+
if (isColumnType(col, COL_TYPE.TEXT)) {
149+
value = value.split(',').map((s) => `'${s.trim()}'`).join(',');
150+
}
151151
value = `IN (${value})`;
152152
}
153153
onFilter({fieldKey: name, valid: true, value});

src/firefly/js/ui/tap/AdvancedADQL.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,5 +271,5 @@ export function insertAtCursor (input, textToInsert, fieldKey, groupKey, prismLi
271271
});
272272

273273
// trigger prismLive style sync
274-
window.setTimeout( () => prismLive.syncStyles(), 10);
274+
prismLive && window.setTimeout( () => prismLive.syncStyles(), 10);
275275
}

src/firefly/js/util/__tests__/Expression-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ describe('A test suite for expr/Expression.js', function () {
111111
expect(se).toHaveProperty('details');
112112
expect(se).toHaveProperty('where');
113113
expect(se).toHaveProperty('why');
114-
console.log(se);
114+
// console.log(se);
115115
});
116116

117117
it('invalid expression', function () {
@@ -122,7 +122,7 @@ describe('A test suite for expr/Expression.js', function () {
122122
expect(se).toHaveProperty('details');
123123
expect(se).toHaveProperty('where');
124124
expect(se).toHaveProperty('why');
125-
console.log(se);
125+
// console.log(se);
126126
});
127127

128128

0 commit comments

Comments
 (0)