hunk.code_window: -- | HGE's own representation of various JWKs
   data JWTConfig
     = JWTConfig
     { jcType :: !T.Text
     , jcKey  :: !JWK
     } deriving (Show, Eq)
   allowedRolesClaim :: T.Text
  
hunk.labels: keep keep keep replace replace keep keep keep
hunk.after_edit:   { jcType    :: !T.Text
     , jcKey     :: !JWK
     , jcClaimNs :: !(Maybe T.Text)
  
hunk.file_path: server/src-lib/Hasura/Server/Auth/JWT.hs
hunk.type: replace
file: import { defaultCurFilter } from '../EventState';
  import { vMakeRequest } from './ViewActions';
  
  const LOADING = 'PendingEvents/FilterQuery/LOADING';
  
  const SET_DEFQUERY = 'PendingEvents/FilterQuery/SET_DEFQUERY';
  const SET_FILTERCOL = 'PendingEvents/FilterQuery/SET_FILTERCOL';
  const SET_FILTEROP = 'PendingEvents/FilterQuery/SET_FILTEROP';
  const SET_FILTERVAL = 'PendingEvents/FilterQuery/SET_FILTERVAL';
  const ADD_FILTER = 'PendingEvents/FilterQuery/ADD_FILTER';
  const REMOVE_FILTER = 'PendingEvents/FilterQuery/REMOVE_FILTER';
  
  const SET_ORDERCOL = 'PendingEvents/FilterQuery/SET_ORDERCOL';
  const SET_ORDERTYPE = 'PendingEvents/FilterQuery/SET_ORDERTYPE';
  const ADD_ORDER = 'PendingEvents/FilterQuery/ADD_ORDER';
  const REMOVE_ORDER = 'PendingEvents/FilterQuery/REMOVE_ORDER';
  const SET_LIMIT = 'PendingEvents/FilterQuery/SET_LIMIT';
  const SET_OFFSET = 'PendingEvents/FilterQuery/SET_OFFSET';
  const SET_NEXTPAGE = 'PendingEvents/FilterQuery/SET_NEXTPAGE';
  const SET_PREVPAGE = 'PendingEvents/FilterQuery/SET_PREVPAGE';
  
  const setLoading = () => ({ type: LOADING, data: true });
  const unsetLoading = () => ({ type: LOADING, data: false });
  const setDefaultQuery = curQuery => ({ type: SET_DEFQUERY, curQuery });
  const setFilterCol = (name, index) => ({ type: SET_FILTERCOL, name, index });
  const setFilterOp = (opName, index) => ({ type: SET_FILTEROP, opName, index });
  const setFilterVal = (val, index) => ({ type: SET_FILTERVAL, val, index });
  const addFilter = () => ({ type: ADD_FILTER });
  const removeFilter = index => ({ type: REMOVE_FILTER, index });
  
  const setOrderCol = (name, index) => ({ type: SET_ORDERCOL, name, index });
  const setOrderType = (order, index) => ({ type: SET_ORDERTYPE, order, index });
  const addOrder = () => ({ type: ADD_ORDER });
  const removeOrder = index => ({ type: REMOVE_ORDER, index });
  
  const setLimit = limit => ({ type: SET_LIMIT, limit });
  const setOffset = offset => ({ type: SET_OFFSET, offset });
  const setNextPage = () => ({ type: SET_NEXTPAGE });
  const setPrevPage = () => ({ type: SET_PREVPAGE });
  
  const runQuery = triggerSchema => {
    return (dispatch, getState) => {
      const state = getState().triggers.view.curFilter;
      const finalWhereClauses = state.where.$and.filter(w => {
        const colName = Object.keys(w)[0].trim();
        if (colName === '') {
          return false;
        }
        const opName = Object.keys(w[colName])[0].trim();
        if (opName === '') {
          return false;
        }
        return true;
      });
      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: 'PendingEvents/V_SET_QUERY_OPTS', queryStuff: newQuery });
      dispatch(vMakeRequest());
    };
  };
  
  const pendingFilterReducer = (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;
          newCurFilterQ.offset =
            'offset' in q ? q.offset : defaultCurFilter.offset;
          return newCurFilterQ;
        }
        return defaultCurFilter;
      case SET_FILTERCOL:
        const oldColName = Object.keys(state.where.$and[i])[0];
        newFilter[action.name] = { ...state.where.$and[i][oldColName] };
        return {
          ...state,
          where: {
            $and: [
              ...state.where.$and.slice(0, i),
              newFilter,
              ...state.where.$and.slice(i + 1),
            ],
          },
        };
      case SET_FILTEROP:
        const colName = Object.keys(state.where.$and[i])[0];
        const oldOp = Object.keys(state.where.$and[i][colName])[0];
        newFilter[colName] = {};
        newFilter[colName][action.opName] = state.where.$and[i][colName][oldOp];
        return {
          ...state,
          where: {
            $and: [
              ...state.where.$and.slice(0, i),
              newFilter,
              ...state.where.$and.slice(i + 1),
            ],
          },
        };
      case SET_FILTERVAL:
        const colName1 = Object.keys(state.where.$and[i])[0];
        const opName = Object.keys(state.where.$and[i][colName1])[0];
        newFilter[colName1] = {};
        newFilter[colName1][opName] = action.val;
        return {
          ...state,
          where: {
            $and: [
              ...state.where.$and.slice(0, i),
              newFilter,
              ...state.where.$and.slice(i + 1),
            ],
          },
        };
      case ADD_FILTER:
        return {
          ...state,
          where: {
            $and: [...state.where.$and, { '': { '': '' } }],
          },
        };
      case REMOVE_FILTER:
        const newFilters = [
          ...state.where.$and.slice(0, i),
          ...state.where.$and.slice(i + 1),
        ];
        return {
          ...state,
          where: { $and: newFilters },
        };
  
      case SET_ORDERCOL:
        const oldOrder = state.order_by[i];
        return {
          ...state,
          order_by: [
            ...state.order_by.slice(0, i),
            { ...oldOrder, column: action.name },
            ...state.order_by.slice(i + 1),
          ],
        };
      case SET_ORDERTYPE:
        const oldOrder1 = state.order_by[i];
        return {
          ...state,
          order_by: [
            ...state.order_by.slice(0, i),
            { ...oldOrder1, type: action.order },
            ...state.order_by.slice(i + 1),
          ],
        };
      case REMOVE_ORDER:
        return {
          ...state,
          order_by: [
            ...state.order_by.slice(0, i),
            ...state.order_by.slice(i + 1),
          ],
        };
      case ADD_ORDER:
        return {
          ...state,
          order_by: [
            ...state.order_by,
            { column: '', type: 'asc', nulls: 'last' },
          ],
        };
  
      case SET_LIMIT:
        return {
          ...state,
          limit: action.limit,
        };
      case SET_OFFSET:
        return {
          ...state,
          offset: action.offset,
        };
      case SET_NEXTPAGE:
        return {
          ...state,
          offset: state.offset + state.limit,
        };
      case SET_PREVPAGE:
        const newOffset = state.offset - state.limit;
        return {
          ...state,
          offset: newOffset < 0 ? 0 : newOffset,
        };
      case LOADING:
        return {
          ...state,
          loading: action.data,
        };
      default:
        return state;
    }
  };
  
  export default pendingFilterReducer;
  export {
    setFilterCol,
    setFilterOp,
    setFilterVal,
    addFilter,
    removeFilter,
    setOrderCol,
    setOrderType,
    addOrder,
    removeOrder,
    setLimit,
    setOffset,
    setNextPage,
    setPrevPage,
    setDefaultQuery,
    setLoading,
    unsetLoading,
    runQuery,
  };
  