Repository: hasura/graphql-engine
File: console/src/components/Services/Data/TableBrowseRows/FilterActions.js (JavaScript)

Code before:
        w[colName][opName] = parseFloat(val);
        return w;
      }
      if (colType === 'boolean') {
        if (val === 'true') {
          w[colName][opName] = true;
        } else if (val === 'false') {
          w[colName][opName] = false;
        }
      }
      return w;
    });
    const newQuery = {
      where: { $and: finalWhereClauses },
      limit: state.limit,
      offset: state.offset,
      order_by: state.order_by.filter(w => w.column.trim() !== ''),
    };
    if (newQuery.where.$and.length === 0) {
      delete newQuery.where;
    }
    if (newQuery.order_by.length === 0) {
      delete newQuery.order_by;
    }
    dispatch({ type: 'ViewTable/V_SET_QUERY_OPTS', queryStuff: newQuery });
    dispatch(vMakeRequest()).then(() => dispatch(vMakeCountRequest()));
  };
};

const filterReducer = (state = defaultCurFilter, action) => {
  const i = action.index;
  const newFilter = {};
  switch (action.type) {
    case SET_DEFQUERY:
      const q = action.curQuery;
      if (
        'order_by' in q ||
        'limit' in q ||
        'offset' in q ||
        ('where' in q && '$and' in q.where)
      ) {
        const newCurFilterQ = {};
        newCurFilterQ.where =
          'where' in q && '$and' in q.where
            ? { $and: [...q.where.$and, { '': { '': '' } }] }
            : { ...defaultCurFilter.where };
        newCurFilterQ.order_by =
          'order_by' in q
            ? [...q.order_by, ...defaultCurFilter.order_by]
            : [...defaultCurFilter.order_by];
        newCurFilterQ.limit = 'limit' in q ? q.limit : defaultCurFilter.limit;

Review comment (refactor):
This is done twice, here and once in `ViewTable` as well.
Do you think there should be a function called `vMakeTableRequests` that abstracts out this part? Something like:

```js
const vMakeTableRequests = () => (dispatch, getState) => {
  dispatch(vMakeRequest()).then(() => dispatch(vMakeCountRequest()));
};
```
You can then call this one function everywhere. Later, if somebody is iterating some part of this code, they might not know to make the change in both places.

Code after:
        w[colName][opName] = parseFloat(val);
        return w;
      }
      if (colType === 'boolean') {
        if (val === 'true') {
          w[colName][opName] = true;
        } else if (val === 'false') {
          w[colName][opName] = false;
        }
      }
      return w;
    });
    const newQuery = {
      where: { $and: finalWhereClauses },
      limit: state.limit,
      offset: state.offset,
      order_by: state.order_by.filter(w => w.column.trim() !== ''),
    };
    if (newQuery.where.$and.length === 0) {
      delete newQuery.where;
    }
    if (newQuery.order_by.length === 0) {
      delete newQuery.order_by;
    }
    dispatch({ type: 'ViewTable/V_SET_QUERY_OPTS', queryStuff: newQuery });
    dispatch(vMakeTableRequests());
  };
};

const filterReducer = (state = defaultCurFilter, action) => {
  const i = action.index;
  const newFilter = {};
  switch (action.type) {
    case SET_DEFQUERY:
      const q = action.curQuery;
      if (
        'order_by' in q ||
        'limit' in q ||
        'offset' in q ||
        ('where' in q && '$and' in q.where)
      ) {
        const newCurFilterQ = {};
        newCurFilterQ.where =
          'where' in q && '$and' in q.where
            ? { $and: [...q.where.$and, { '': { '': '' } }] }
            : { ...defaultCurFilter.where };
        newCurFilterQ.order_by =
          'order_by' in q
            ? [...q.order_by, ...defaultCurFilter.order_by]
            : [...defaultCurFilter.order_by];
        newCurFilterQ.limit = 'limit' in q ? q.limit : defaultCurFilter.limit;