Skip to content

Commit

Permalink
fix(redux): issues/10 expand rhsmTypes for filtering (#360)
Browse files Browse the repository at this point in the history
* rhsmTypes, add filter types, align naming
* rhsmServices, expand mock
* toolbar, rename SLA rhsmType
* viewReducer, apply filter types
  • Loading branch information
cdcabrera committed Jul 31, 2020
1 parent c0cc484 commit f2f8948
Show file tree
Hide file tree
Showing 9 changed files with 181 additions and 31 deletions.
2 changes: 1 addition & 1 deletion src/components/c3GraphCard/c3GraphCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class C3GraphCard extends React.Component {
const { viewId } = this.props;

store.dispatch({
type: reduxTypes.rhsm.SET_GRAPH_GRANULARITY_RHSM,
type: reduxTypes.rhsm.SET_FILTER_GRANULARITY_RHSM,
viewId,
[rhsmApiTypes.RHSM_API_QUERY_GRANULARITY]: value
});
Expand Down
2 changes: 1 addition & 1 deletion src/components/graphCard/graphCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class GraphCard extends React.Component {
const { viewId } = this.props;

store.dispatch({
type: reduxTypes.rhsm.SET_GRAPH_GRANULARITY_RHSM,
type: reduxTypes.rhsm.SET_FILTER_GRANULARITY_RHSM,
viewId,
[rhsmApiTypes.RHSM_API_QUERY_GRANULARITY]: value
});
Expand Down
4 changes: 2 additions & 2 deletions src/components/toolbar/toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Toolbar extends React.Component {
* @event onClear
*/
onClear = () => {
this.dispatchFilter(reduxTypes.rhsm.SET_GRAPH_SLA_RHSM, { [rhsmApiTypes.RHSM_API_QUERY_SLA]: null });
this.dispatchFilter(reduxTypes.rhsm.SET_FILTER_SLA_RHSM, { [rhsmApiTypes.RHSM_API_QUERY_SLA]: null });
};

/**
Expand All @@ -34,7 +34,7 @@ class Toolbar extends React.Component {
onSlaSelect = event => {
const { value } = event;

this.dispatchFilter(reduxTypes.rhsm.SET_GRAPH_SLA_RHSM, { [rhsmApiTypes.RHSM_API_QUERY_SLA]: value });
this.dispatchFilter(reduxTypes.rhsm.SET_FILTER_SLA_RHSM, { [rhsmApiTypes.RHSM_API_QUERY_SLA]: value });
};

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`ViewReducer should handle specific defined types: defined type SET_GRAPH_GRANULARITY_RHSM 1`] = `
exports[`ViewReducer should handle specific defined types: defined type SET_CLEAR_FILTERS 1`] = `
Object {
"result": Object {
"graphQuery": Object {
"test_id": Object {},
},
},
"type": "SET_CLEAR_FILTERS",
}
`;

exports[`ViewReducer should handle specific defined types: defined type SET_FILTER_GRANULARITY_RHSM 1`] = `
Object {
"result": Object {
"graphQuery": Object {
Expand All @@ -9,11 +20,11 @@ Object {
},
},
},
"type": "SET_GRAPH_GRANULARITY_RHSM",
"type": "SET_FILTER_GRANULARITY_RHSM",
}
`;

exports[`ViewReducer should handle specific defined types: defined type SET_GRAPH_SLA_RHSM 1`] = `
exports[`ViewReducer should handle specific defined types: defined type SET_FILTER_SLA_RHSM 1`] = `
Object {
"result": Object {
"graphQuery": Object {
Expand All @@ -22,6 +33,45 @@ Object {
},
},
},
"type": "SET_GRAPH_SLA_RHSM",
"type": "SET_FILTER_SLA_RHSM",
}
`;

exports[`ViewReducer should handle specific defined types: defined type SET_FILTER_USAGE_RHSM 1`] = `
Object {
"result": Object {
"graphQuery": Object {
"test_id": Object {
"usage": undefined,
},
},
},
"type": "SET_FILTER_USAGE_RHSM",
}
`;

exports[`ViewReducer should handle specific defined types: defined type SET_PAGE_LIMIT_RHSM 1`] = `
Object {
"result": Object {
"graphQuery": Object {
"test_id": Object {
"limit": undefined,
},
},
},
"type": "SET_PAGE_LIMIT_RHSM",
}
`;

exports[`ViewReducer should handle specific defined types: defined type SET_PAGE_OFFSET_RHSM 1`] = `
Object {
"result": Object {
"graphQuery": Object {
"test_id": Object {
"offset": undefined,
},
},
},
"type": "SET_PAGE_OFFSET_RHSM",
}
`;
9 changes: 8 additions & 1 deletion src/redux/reducers/__tests__/viewReducer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@ describe('ViewReducer', () => {
});

it('should handle specific defined types', () => {
const specificTypes = [types.SET_GRAPH_GRANULARITY_RHSM, types.SET_GRAPH_SLA_RHSM];
const specificTypes = [
types.SET_FILTER_GRANULARITY_RHSM,
types.SET_FILTER_SLA_RHSM,
types.SET_FILTER_USAGE_RHSM,
types.SET_CLEAR_FILTERS,
types.SET_PAGE_LIMIT_RHSM,
types.SET_PAGE_OFFSET_RHSM
];

specificTypes.forEach(value => {
const dispatched = {
Expand Down
68 changes: 65 additions & 3 deletions src/redux/reducers/viewReducer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { reduxTypes } from '../types';
import { reduxHelpers } from '../common/reduxHelpers';
import { RHSM_API_QUERY_GRANULARITY, RHSM_API_QUERY_SLA } from '../../types/rhsmApiTypes';
import {
RHSM_API_QUERY_GRANULARITY,
RHSM_API_QUERY_LIMIT,
RHSM_API_QUERY_OFFSET,
RHSM_API_QUERY_SLA,
RHSM_API_QUERY_USAGE
} from '../../types/rhsmApiTypes';

/**
* Initial state.
Expand All @@ -21,7 +27,7 @@ const initialState = {
*/
const viewReducer = (state = initialState, action) => {
switch (action.type) {
case reduxTypes.rhsm.SET_GRAPH_GRANULARITY_RHSM:
case reduxTypes.rhsm.SET_FILTER_GRANULARITY_RHSM:
return reduxHelpers.setStateProp(
'graphQuery',
{
Expand All @@ -35,7 +41,7 @@ const viewReducer = (state = initialState, action) => {
reset: false
}
);
case reduxTypes.rhsm.SET_GRAPH_SLA_RHSM:
case reduxTypes.rhsm.SET_FILTER_SLA_RHSM:
return reduxHelpers.setStateProp(
'graphQuery',
{
Expand All @@ -49,6 +55,62 @@ const viewReducer = (state = initialState, action) => {
reset: false
}
);
case reduxTypes.rhsm.SET_FILTER_USAGE_RHSM:
return reduxHelpers.setStateProp(
'graphQuery',
{
[action.viewId]: {
...state.graphQuery[action.viewId],
[RHSM_API_QUERY_USAGE]: action[RHSM_API_QUERY_USAGE]
}
},
{
state,
reset: false
}
);
case reduxTypes.rhsm.SET_CLEAR_FILTERS:
return reduxHelpers.setStateProp(
'graphQuery',
{
[action.viewId]: {
...state.graphQuery[action.viewId],
...action.clearFilters
}
},
{
state,
reset: false
}
);
case reduxTypes.rhsm.SET_PAGE_LIMIT_RHSM:
return reduxHelpers.setStateProp(
'graphQuery',
{
[action.viewId]: {
...state.graphQuery[action.viewId],
[RHSM_API_QUERY_LIMIT]: action[RHSM_API_QUERY_LIMIT]
}
},
{
state,
reset: false
}
);
case reduxTypes.rhsm.SET_PAGE_OFFSET_RHSM:
return reduxHelpers.setStateProp(
'graphQuery',
{
[action.viewId]: {
...state.graphQuery[action.viewId],
[RHSM_API_QUERY_OFFSET]: action[RHSM_API_QUERY_OFFSET]
}
},
{
state,
reset: false
}
);
default:
return state;
}
Expand Down
32 changes: 24 additions & 8 deletions src/redux/types/__tests__/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,12 @@ Object {
"GET_GRAPH_REPORT_RHSM": "GET_GRAPH_REPORT_RHSM",
"GET_HOSTS_INVENTORY_GUESTS_RHSM": "GET_HOSTS_INVENTORY_GUESTS_RHSM",
"GET_HOSTS_INVENTORY_RHSM": "GET_HOSTS_INVENTORY_RHSM",
"SET_GRAPH_GRANULARITY_RHSM": "SET_GRAPH_GRANULARITY_RHSM",
"SET_GRAPH_SLA_RHSM": "SET_GRAPH_SLA_RHSM",
"SET_CLEAR_FILTERS": "SET_CLEAR_FILTERS",
"SET_FILTER_GRANULARITY_RHSM": "SET_FILTER_GRANULARITY_RHSM",
"SET_FILTER_SLA_RHSM": "SET_FILTER_SLA_RHSM",
"SET_FILTER_USAGE_RHSM": "SET_FILTER_USAGE_RHSM",
"SET_PAGE_LIMIT_RHSM": "SET_PAGE_LIMIT_RHSM",
"SET_PAGE_OFFSET_RHSM": "SET_PAGE_OFFSET_RHSM",
},
"user": Object {
"DELETE_USER_OPTIN": "DELETE_USER_OPTIN",
Expand Down Expand Up @@ -76,8 +80,12 @@ Object {
"GET_GRAPH_REPORT_RHSM": "GET_GRAPH_REPORT_RHSM",
"GET_HOSTS_INVENTORY_GUESTS_RHSM": "GET_HOSTS_INVENTORY_GUESTS_RHSM",
"GET_HOSTS_INVENTORY_RHSM": "GET_HOSTS_INVENTORY_RHSM",
"SET_GRAPH_GRANULARITY_RHSM": "SET_GRAPH_GRANULARITY_RHSM",
"SET_GRAPH_SLA_RHSM": "SET_GRAPH_SLA_RHSM",
"SET_CLEAR_FILTERS": "SET_CLEAR_FILTERS",
"SET_FILTER_GRANULARITY_RHSM": "SET_FILTER_GRANULARITY_RHSM",
"SET_FILTER_SLA_RHSM": "SET_FILTER_SLA_RHSM",
"SET_FILTER_USAGE_RHSM": "SET_FILTER_USAGE_RHSM",
"SET_PAGE_LIMIT_RHSM": "SET_PAGE_LIMIT_RHSM",
"SET_PAGE_OFFSET_RHSM": "SET_PAGE_OFFSET_RHSM",
},
"user": Object {
"DELETE_USER_OPTIN": "DELETE_USER_OPTIN",
Expand All @@ -94,8 +102,12 @@ Object {
"GET_GRAPH_REPORT_RHSM": "GET_GRAPH_REPORT_RHSM",
"GET_HOSTS_INVENTORY_GUESTS_RHSM": "GET_HOSTS_INVENTORY_GUESTS_RHSM",
"GET_HOSTS_INVENTORY_RHSM": "GET_HOSTS_INVENTORY_RHSM",
"SET_GRAPH_GRANULARITY_RHSM": "SET_GRAPH_GRANULARITY_RHSM",
"SET_GRAPH_SLA_RHSM": "SET_GRAPH_SLA_RHSM",
"SET_CLEAR_FILTERS": "SET_CLEAR_FILTERS",
"SET_FILTER_GRANULARITY_RHSM": "SET_FILTER_GRANULARITY_RHSM",
"SET_FILTER_SLA_RHSM": "SET_FILTER_SLA_RHSM",
"SET_FILTER_USAGE_RHSM": "SET_FILTER_USAGE_RHSM",
"SET_PAGE_LIMIT_RHSM": "SET_PAGE_LIMIT_RHSM",
"SET_PAGE_OFFSET_RHSM": "SET_PAGE_OFFSET_RHSM",
},
"userTypes": Object {
"DELETE_USER_OPTIN": "DELETE_USER_OPTIN",
Expand Down Expand Up @@ -132,8 +144,12 @@ Object {
"GET_GRAPH_REPORT_RHSM": "GET_GRAPH_REPORT_RHSM",
"GET_HOSTS_INVENTORY_GUESTS_RHSM": "GET_HOSTS_INVENTORY_GUESTS_RHSM",
"GET_HOSTS_INVENTORY_RHSM": "GET_HOSTS_INVENTORY_RHSM",
"SET_GRAPH_GRANULARITY_RHSM": "SET_GRAPH_GRANULARITY_RHSM",
"SET_GRAPH_SLA_RHSM": "SET_GRAPH_SLA_RHSM",
"SET_CLEAR_FILTERS": "SET_CLEAR_FILTERS",
"SET_FILTER_GRANULARITY_RHSM": "SET_FILTER_GRANULARITY_RHSM",
"SET_FILTER_SLA_RHSM": "SET_FILTER_SLA_RHSM",
"SET_FILTER_USAGE_RHSM": "SET_FILTER_USAGE_RHSM",
"SET_PAGE_LIMIT_RHSM": "SET_PAGE_LIMIT_RHSM",
"SET_PAGE_OFFSET_RHSM": "SET_PAGE_OFFSET_RHSM",
},
"user": Object {
"DELETE_USER_OPTIN": "DELETE_USER_OPTIN",
Expand Down
32 changes: 23 additions & 9 deletions src/redux/types/rhsmTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,34 @@ const GET_GRAPH_REPORT_RHSM = 'GET_GRAPH_REPORT_RHSM';
const GET_GRAPH_REPORT_CAPACITY_RHSM = 'GET_GRAPH_REPORT_CAPACITY_RHSM';
const GET_HOSTS_INVENTORY_RHSM = 'GET_HOSTS_INVENTORY_RHSM';
const GET_HOSTS_INVENTORY_GUESTS_RHSM = 'GET_HOSTS_INVENTORY_GUESTS_RHSM';
const SET_GRAPH_GRANULARITY_RHSM = 'SET_GRAPH_GRANULARITY_RHSM';
const SET_GRAPH_SLA_RHSM = 'SET_GRAPH_SLA_RHSM';

const SET_PAGE_LIMIT_RHSM = 'SET_PAGE_LIMIT_RHSM';
const SET_PAGE_OFFSET_RHSM = 'SET_PAGE_OFFSET_RHSM';
const SET_CLEAR_FILTERS = 'SET_CLEAR_FILTERS';
const SET_FILTER_GRANULARITY_RHSM = 'SET_FILTER_GRANULARITY_RHSM';
const SET_FILTER_SLA_RHSM = 'SET_FILTER_SLA_RHSM';
const SET_FILTER_USAGE_RHSM = 'SET_FILTER_USAGE_RHSM';

/**
* RHSM API action, reducer types.
*
* @type {{GET_GRAPH_REPORT_CAPACITY_RHSM: string, SET_GRAPH_GRANULARITY_RHSM: string,
* GET_HOSTS_INVENTORY_GUESTS_RHSM: string, GET_GRAPH_CAPACITY_RHSM: string, SET_GRAPH_SLA_RHSM: string,
* GET_HOSTS_INVENTORY_RHSM: string, GET_GRAPH_REPORT_RHSM: string}}
* @type {{GET_GRAPH_REPORT_CAPACITY_RHSM: string, SET_FILTER_GRANULARITY_RHSM: string,
* GET_HOSTS_INVENTORY_GUESTS_RHSM: string, SET_FILTER_SLA_RHSM: string, GET_GRAPH_CAPACITY_RHSM: string,
* SET_PAGE_OFFSET_RHSM: string, SET_CLEAR_FILTERS: string, GET_HOSTS_INVENTORY_RHSM: string,
* SET_PAGE_LIMIT_RHSM: string, GET_GRAPH_REPORT_RHSM: string, SET_FILTER_USAGE_RHSM: string}}
*/
const rhsmTypes = {
GET_GRAPH_CAPACITY_RHSM,
GET_GRAPH_REPORT_RHSM,
GET_GRAPH_REPORT_CAPACITY_RHSM,
GET_HOSTS_INVENTORY_RHSM,
GET_HOSTS_INVENTORY_GUESTS_RHSM,
SET_GRAPH_GRANULARITY_RHSM,
SET_GRAPH_SLA_RHSM
SET_PAGE_LIMIT_RHSM,
SET_PAGE_OFFSET_RHSM,
SET_CLEAR_FILTERS,
SET_FILTER_GRANULARITY_RHSM,
SET_FILTER_SLA_RHSM,
SET_FILTER_USAGE_RHSM
};

export {
Expand All @@ -31,6 +41,10 @@ export {
GET_GRAPH_REPORT_CAPACITY_RHSM,
GET_HOSTS_INVENTORY_RHSM,
GET_HOSTS_INVENTORY_GUESTS_RHSM,
SET_GRAPH_GRANULARITY_RHSM,
SET_GRAPH_SLA_RHSM
SET_PAGE_LIMIT_RHSM,
SET_PAGE_OFFSET_RHSM,
SET_CLEAR_FILTERS,
SET_FILTER_GRANULARITY_RHSM,
SET_FILTER_SLA_RHSM,
SET_FILTER_USAGE_RHSM
};
5 changes: 3 additions & 2 deletions src/services/rhsmServices.js
Original file line number Diff line number Diff line change
Expand Up @@ -951,7 +951,7 @@ const getGraphCapacity = (id, params = {}) =>
* "cores": 4,
* "sockets": 2,
* "hardware_type": "physical",
* "number_of_guests": 4,
* "number_of_guests": 2,
* "last_seen": "2020-04-01T00:00:00Z"
* },
* {
Expand All @@ -961,6 +961,7 @@ const getGraphCapacity = (id, params = {}) =>
* "cores": 4,
* "sockets": 6,
* "hardware_type": "physical",
* "number_of_guests": 2,
* "last_seen": "2020-06-20T00:00:00Z"
* }
* ],
Expand Down Expand Up @@ -1004,7 +1005,7 @@ const getHostsInventory = (id, params = {}) =>
});

/**
* @apiMock {DelayResponse} 500
* @apiMock {DelayResponse} 2000
* @api {get} /api/rhsm-subscriptions/v1/hosts/:hypervisor_uuid/guests Get RHSM hosts/systems table/inventory guests data
* @apiDescription Retrieve hosts/systems table/inventory guests data.
*
Expand Down

0 comments on commit f2f8948

Please sign in to comment.