diff --git a/console/src/components/Services/Data/TableBrowseRows/FilterActions.js b/console/src/components/Services/Data/TableBrowseRows/FilterActions.js index cb59fd905e255..ad0e4bcec772d 100644 --- a/console/src/components/Services/Data/TableBrowseRows/FilterActions.js +++ b/console/src/components/Services/Data/TableBrowseRows/FilterActions.js @@ -43,6 +43,15 @@ const setOffset = offset => ({ type: SET_OFFSET, offset }); const setNextPage = () => ({ type: SET_NEXTPAGE }); const setPrevPage = () => ({ type: SET_PREVPAGE }); +const parseArray = val => { + if (Array.isArray(val)) return val; + try { + return JSON.parse(val); + } catch (err) { + return ''; + } +}; + const runQuery = tableSchema => { return (dispatch, getState) => { const state = getState().tables.view.curFilter; @@ -61,6 +70,12 @@ const runQuery = tableSchema => { const colName = Object.keys(w)[0]; const opName = Object.keys(w[colName])[0]; const val = w[colName][opName]; + + if (['$in', '$nin'].includes(opName)) { + w[colName][opName] = parseArray(val); + return w; + } + const colType = tableSchema.columns.find(c => c.column_name === colName) .data_type; if (Integers.indexOf(colType) > 0) { diff --git a/console/src/components/Services/Data/TableBrowseRows/FilterQuery.js b/console/src/components/Services/Data/TableBrowseRows/FilterQuery.js index 7973982ad5b29..b9a0d36c04042 100644 --- a/console/src/components/Services/Data/TableBrowseRows/FilterQuery.js +++ b/console/src/components/Services/Data/TableBrowseRows/FilterQuery.js @@ -64,12 +64,22 @@ const renderOps = (opName, onChange, key) => ( ) : null} {Operators.map((o, i) => ( ))} ); +const getDefaultValue = (possibleValue, opName) => { + if (possibleValue) { + if (Array.isArray(possibleValue)) return JSON.stringify(possibleValue); + return possibleValue; + } + + const operator = Operators.find(op => op.value === opName); + return operator && operator.defaultValue ? operator.defaultValue : ''; +}; + const renderWheres = (whereAnd, tableSchema, dispatch) => { const styles = require('../../../Common/FilterQuery/FilterQuery.scss'); return whereAnd.map((clause, i) => { @@ -93,6 +103,7 @@ const renderWheres = (whereAnd, tableSchema, dispatch) => { /> ); } + return (
@@ -103,7 +114,7 @@ const renderWheres = (whereAnd, tableSchema, dispatch) => { { dispatch(setFilterVal(e.target.value, i)); if (i + 1 === whereAnd.length) { @@ -187,7 +198,7 @@ class FilterQuery extends Component { dispatch(runQuery(tableSchema)); }} > -
+
', value: '$gt' }, - { name: '<', value: '$lt' }, - { name: '>=', value: '$gte' }, - { name: '<=', value: '$lte' }, - { name: 'like', value: '$like' }, - { name: 'not like', value: '$nlike' }, - { name: 'ilike', value: '$ilike' }, - { name: 'not ilike', value: '$nilike' }, - { name: 'similar', value: '$similar' }, - { name: 'not similar', value: '$nsimilar' }, + { name: 'equals', value: '$eq', graphqlOp: '_eq' }, + { name: 'not equals', value: '$ne', graphqlOp: '_neq' }, + { name: 'in', value: '$in', graphqlOp: '_in', defaultValue: '[]' }, + { name: 'not in', value: '$nin', graphqlOp: '_nin', defaultValue: '[]' }, + { name: '>', value: '$gt', graphqlOp: '_gt' }, + { name: '<', value: '$lt', graphqlOp: '_lt' }, + { name: '>=', value: '$gte', graphqlOp: '_gte' }, + { name: '<=', value: '$lte', graphqlOp: '_lte' }, + { name: 'like', value: '$like', graphqlOp: '_like', defaultValue: '%%' }, + { + name: 'not like', + value: '$nlike', + graphqlOp: '_nlike', + defaultValue: '%%', + }, + { + name: 'like (case-insensitive)', + value: '$ilike', + graphqlOp: '_ilike', + defaultValue: '%%', + }, + { + name: 'not like (case-insensitive)', + value: '$nilike', + graphqlOp: '_nilike', + defaultValue: '%%', + }, + { name: 'similar', value: '$similar', graphqlOp: '_similar' }, + { name: 'not similar', value: '$nsimilar', graphqlOp: '_nsimilar' }, ]; export const Integers = [