From 035e9e6191fea6a30a134952bdffa52251a02786 Mon Sep 17 00:00:00 2001 From: CD Cabrera Date: Thu, 14 Nov 2019 17:08:49 -0500 Subject: [PATCH] feat(rhelServices,rhelApiTypes): issues/77 allow passed id * rhelServices, allow product id to be passed * rhelApiTypes, key/value reference for product ids * rhelActions, open for product id --- .env | 4 +- .env.development | 4 +- .env.proxy | 4 +- .../__tests__/__snapshots__/i18n.test.js.snap | 12 ++--- src/components/rhelGraphCard/rhelGraphCard.js | 16 ++++--- src/redux/actions/rhelActions.js | 10 +++-- src/services/rhelServices.js | 8 ++-- .../__snapshots__/rhelApiTypes.test.js.snap | 44 +++++++++++++++++++ src/types/rhelApiTypes.js | 14 ++++++ 9 files changed, 90 insertions(+), 26 deletions(-) diff --git a/.env b/.env index d21e189ad..f6760bc71 100644 --- a/.env +++ b/.env @@ -20,5 +20,5 @@ REACT_APP_INCLUDE_CONTENT_HEADER= REACT_APP_SERVICES_RHSM_VERSION=/api/rhsm-subscriptions/v1/version -REACT_APP_SERVICES_RHSM_REPORT_RHEL=/api/rhsm-subscriptions/v1/tally/products/RHEL -REACT_APP_SERVICES_RHSM_CAPACITY_RHEL=/api/rhsm-subscriptions/v1/capacity/products/RHEL +REACT_APP_SERVICES_RHSM_REPORT=/api/rhsm-subscriptions/v1/tally/products/ +REACT_APP_SERVICES_RHSM_CAPACITY=/api/rhsm-subscriptions/v1/capacity/products/ diff --git a/.env.development b/.env.development index 13ae93985..0040f1a72 100644 --- a/.env.development +++ b/.env.development @@ -7,5 +7,5 @@ REACT_APP_CONFIG_SERVICE_LOCALES=./locales/locales.json REACT_APP_CONFIG_SERVICE_LOCALES_PATH=./locales/{{lng}}.json REACT_APP_SERVICES_RHSM_VERSION=http://localhost:5000/api/rhsm-subscriptions/v1/version -REACT_APP_SERVICES_RHSM_REPORT_RHEL=http://localhost:5000/api/rhsm-subscriptions/v1/tally/products/RHEL -REACT_APP_SERVICES_RHSM_CAPACITY_RHEL=http://localhost:5000/api/rhsm-subscriptions/v1/capacity/products/RHEL +REACT_APP_SERVICES_RHSM_REPORT=http://localhost:5000/api/rhsm-subscriptions/v1/tally/products/ +REACT_APP_SERVICES_RHSM_CAPACITY=http://localhost:5000/api/rhsm-subscriptions/v1/capacity/products/ diff --git a/.env.proxy b/.env.proxy index edf31d342..167c3fa0f 100644 --- a/.env.proxy +++ b/.env.proxy @@ -11,5 +11,5 @@ REACT_APP_CONFIG_SERVICE_LOCALES=/locales/locales.json REACT_APP_CONFIG_SERVICE_LOCALES_PATH=/locales/{{lng}}.json REACT_APP_SERVICES_RHSM_VERSION=/api/rhsm-subscriptions/v1/version -REACT_APP_SERVICES_RHSM_REPORT_RHEL=/api/rhsm-subscriptions/v1/tally/products/RHEL -REACT_APP_SERVICES_RHSM_CAPACITY_RHEL=/api/rhsm-subscriptions/v1/capacity/products/RHEL +REACT_APP_SERVICES_RHSM_REPORT=/api/rhsm-subscriptions/v1/tally/products/ +REACT_APP_SERVICES_RHSM_CAPACITY=/api/rhsm-subscriptions/v1/capacity/products/ diff --git a/src/components/i18n/__tests__/__snapshots__/i18n.test.js.snap b/src/components/i18n/__tests__/__snapshots__/i18n.test.js.snap index 1af21650f..8d12f68f8 100644 --- a/src/components/i18n/__tests__/__snapshots__/i18n.test.js.snap +++ b/src/components/i18n/__tests__/__snapshots__/i18n.test.js.snap @@ -12,15 +12,15 @@ exports[`I18n Component should generate a predictable pot output snapshot: pot o msgstr \\"\\" \\"Content-Type: text/plain; charset=UTF-8\\\\n\\" -#: src/components/rhelGraphCard/rhelGraphCard.js:107 +#: src/components/rhelGraphCard/rhelGraphCard.js:109 msgid \\"curiosity-graph.rhelLegendHypervisorLabel\\" msgstr \\"\\" -#: src/components/rhelGraphCard/rhelGraphCard.js:95 +#: src/components/rhelGraphCard/rhelGraphCard.js:97 msgid \\"curiosity-graph.rhelLegendSocketsLabel\\" msgstr \\"\\" -#: src/components/rhelGraphCard/rhelGraphCard.js:118 +#: src/components/rhelGraphCard/rhelGraphCard.js:120 msgid \\"curiosity-graph.rhelLegendThresholdLabel\\" msgstr \\"\\" @@ -44,7 +44,7 @@ msgstr \\"\\" msgid \\"curiosity-graph.tooltipNoData\\" msgstr \\"\\" -#: src/components/rhelGraphCard/rhelGraphCard.js:134 +#: src/components/rhelGraphCard/rhelGraphCard.js:136 msgctxt \\"CPU socket usage\\" msgid \\"curiosity-graph.heading\\" msgstr \\"\\" @@ -64,8 +64,8 @@ msgctxt \\"Quarterly\\" msgid \\"curiosity-graph.dropdownQuarterly\\" msgstr \\"\\" -#: src/components/rhelGraphCard/rhelGraphCard.js:137 -#: src/components/rhelGraphCard/rhelGraphCard.js:141 +#: src/components/rhelGraphCard/rhelGraphCard.js:139 +#: src/components/rhelGraphCard/rhelGraphCard.js:143 msgctxt \\"Select date range\\" msgid \\"curiosity-graph.dropdownPlaceholder\\" msgstr \\"\\" diff --git a/src/components/rhelGraphCard/rhelGraphCard.js b/src/components/rhelGraphCard/rhelGraphCard.js index d804e77a7..ac0f01e54 100644 --- a/src/components/rhelGraphCard/rhelGraphCard.js +++ b/src/components/rhelGraphCard/rhelGraphCard.js @@ -31,15 +31,17 @@ class RhelGraphCard extends React.Component { } onUpdateGraphData = () => { - const { getGraphCapacityRhel, getGraphReportsRhel, graphGranularity, startDate, endDate } = this.props; - const submit = { + const { getGraphCapacityRhel, getGraphReportsRhel, graphGranularity, startDate, endDate, productId } = this.props; + const query = { [rhelApiTypes.RHSM_API_QUERY_GRANULARITY]: graphGranularity, [rhelApiTypes.RHSM_API_QUERY_START_DATE]: startDate.toISOString(), [rhelApiTypes.RHSM_API_QUERY_END_DATE]: endDate.toISOString() }; - getGraphCapacityRhel(submit); - getGraphReportsRhel(submit); + if (productId) { + getGraphCapacityRhel(productId, query); + getGraphReportsRhel(productId, query); + } }; onSelect = event => { @@ -193,6 +195,7 @@ RhelGraphCard.propTypes = { GRANULARITY_TYPES.QUARTERLY ]), pending: PropTypes.bool, + productId: PropTypes.string, t: PropTypes.func, startDate: PropTypes.instanceOf(Date), endDate: PropTypes.instanceOf(Date) @@ -208,6 +211,7 @@ RhelGraphCard.defaultProps = { }, graphGranularity: GRANULARITY_TYPES.DAILY, pending: false, + productId: rhelApiTypes.RHSM_API_PATH_RHEL_ID_TYPES.RHEL, t: helpers.noopTranslate, startDate: dateHelpers.defaultDateTime.startDate, endDate: dateHelpers.defaultDateTime.endDate @@ -222,8 +226,8 @@ const makeMapStateToProps = () => { }; const mapDispatchToProps = dispatch => ({ - getGraphCapacityRhel: query => dispatch(reduxActions.rhel.getGraphCapacityRhel(query)), - getGraphReportsRhel: query => dispatch(reduxActions.rhel.getGraphReportsRhel(query)) + getGraphCapacityRhel: (id, query) => dispatch(reduxActions.rhel.getGraphCapacityRhel(id, query)), + getGraphReportsRhel: (id, query) => dispatch(reduxActions.rhel.getGraphReportsRhel(id, query)) }); const ConnectedRhelGraphCard = connectTranslate(makeMapStateToProps, mapDispatchToProps)(RhelGraphCard); diff --git a/src/redux/actions/rhelActions.js b/src/redux/actions/rhelActions.js index 67b0d8a41..c1c25dbc1 100644 --- a/src/redux/actions/rhelActions.js +++ b/src/redux/actions/rhelActions.js @@ -1,11 +1,12 @@ import { rhelTypes } from '../types'; import rhelServices from '../../services/rhelServices'; -const getGraphReportsRhel = (query = {}) => dispatch => +const getGraphReportsRhel = (id = null, query = {}) => dispatch => dispatch({ type: rhelTypes.GET_GRAPH_REPORT_RHEL, - payload: rhelServices.getGraphReportsRhel(query), + payload: rhelServices.getGraphReportsRhel(id, query), meta: { + productId: id, query, notifications: { rejected: { @@ -17,11 +18,12 @@ const getGraphReportsRhel = (query = {}) => dispatch => } }); -const getGraphCapacityRhel = (query = {}) => dispatch => +const getGraphCapacityRhel = (id = null, query = {}) => dispatch => dispatch({ type: rhelTypes.GET_GRAPH_CAPACITY_RHEL, - payload: rhelServices.getGraphCapacityRhel(query), + payload: rhelServices.getGraphCapacityRhel(id, query), meta: { + productId: id, query, notifications: { rejected: { diff --git a/src/services/rhelServices.js b/src/services/rhelServices.js index f4511b5ce..18adfbe86 100644 --- a/src/services/rhelServices.js +++ b/src/services/rhelServices.js @@ -378,10 +378,10 @@ import serviceConfig from './config'; * ] * } */ -const getGraphReportsRhel = (params = {}) => +const getGraphReportsRhel = (id, params = {}) => axios( serviceConfig({ - url: process.env.REACT_APP_SERVICES_RHSM_REPORT_RHEL, + url: `${process.env.REACT_APP_SERVICES_RHSM_REPORT}${id}`, params }) ); @@ -541,10 +541,10 @@ const getGraphReportsRhel = (params = {}) => * ] * } */ -const getGraphCapacityRhel = (params = {}) => +const getGraphCapacityRhel = (id, params = {}) => axios( serviceConfig({ - url: process.env.REACT_APP_SERVICES_RHSM_CAPACITY_RHEL, + url: `${process.env.REACT_APP_SERVICES_RHSM_CAPACITY}${id}`, params }) ); diff --git a/src/types/__tests__/__snapshots__/rhelApiTypes.test.js.snap b/src/types/__tests__/__snapshots__/rhelApiTypes.test.js.snap index e3e0fa4c6..01d3f1d49 100644 --- a/src/types/__tests__/__snapshots__/rhelApiTypes.test.js.snap +++ b/src/types/__tests__/__snapshots__/rhelApiTypes.test.js.snap @@ -2,6 +2,17 @@ exports[`RhelApiTypes Should have specific API properties: all exported api types 1`] = ` Object { + "RHSM_API_PATH_RHEL_ID_TYPES": Object { + "ARM": "RHEL for ARM", + "COMPUTE_NODE": "RHEL Compute Node", + "DESKTOP": "RHEL Desktop", + "IBM_POWER": "RHEL for IBM Power", + "IBM_Z": "RHEL for IBM z", + "RHEL": "RHEL", + "SERVER": "RHEL Server", + "WORKSTATION": "RHEL Workstation", + "X86": "RHEL for x86", + }, "RHSM_API_QUERY_END_DATE": "ending", "RHSM_API_QUERY_GRANULARITY": "granularity", "RHSM_API_QUERY_GRANULARITY_TYPES": Object { @@ -38,6 +49,17 @@ Object { "COUNT": "count", }, "default": Object { + "RHSM_API_PATH_RHEL_ID_TYPES": Object { + "ARM": "RHEL for ARM", + "COMPUTE_NODE": "RHEL Compute Node", + "DESKTOP": "RHEL Desktop", + "IBM_POWER": "RHEL for IBM Power", + "IBM_Z": "RHEL for IBM z", + "RHEL": "RHEL", + "SERVER": "RHEL Server", + "WORKSTATION": "RHEL Workstation", + "X86": "RHEL for x86", + }, "RHSM_API_QUERY_END_DATE": "ending", "RHSM_API_QUERY_GRANULARITY": "granularity", "RHSM_API_QUERY_GRANULARITY_TYPES": Object { @@ -75,6 +97,17 @@ Object { }, }, "rhelApiTypes": Object { + "RHSM_API_PATH_RHEL_ID_TYPES": Object { + "ARM": "RHEL for ARM", + "COMPUTE_NODE": "RHEL Compute Node", + "DESKTOP": "RHEL Desktop", + "IBM_POWER": "RHEL for IBM Power", + "IBM_Z": "RHEL for IBM z", + "RHEL": "RHEL", + "SERVER": "RHEL Server", + "WORKSTATION": "RHEL Workstation", + "X86": "RHEL for x86", + }, "RHSM_API_QUERY_END_DATE": "ending", "RHSM_API_QUERY_GRANULARITY": "granularity", "RHSM_API_QUERY_GRANULARITY_TYPES": Object { @@ -116,6 +149,17 @@ Object { exports[`RhelApiTypes Should have specific API properties: specific types 1`] = ` Object { + "RHSM_API_PATH_RHEL_ID_TYPES": Object { + "ARM": "RHEL for ARM", + "COMPUTE_NODE": "RHEL Compute Node", + "DESKTOP": "RHEL Desktop", + "IBM_POWER": "RHEL for IBM Power", + "IBM_Z": "RHEL for IBM z", + "RHEL": "RHEL", + "SERVER": "RHEL Server", + "WORKSTATION": "RHEL Workstation", + "X86": "RHEL for x86", + }, "RHSM_API_QUERY_END_DATE": "ending", "RHSM_API_QUERY_GRANULARITY": "granularity", "RHSM_API_QUERY_GRANULARITY_TYPES": Object { diff --git a/src/types/rhelApiTypes.js b/src/types/rhelApiTypes.js index bdb8f5892..aa712bb1a 100644 --- a/src/types/rhelApiTypes.js +++ b/src/types/rhelApiTypes.js @@ -24,6 +24,18 @@ const RHSM_API_RESPONSE_PRODUCTS_META_TYPES = { COUNT: 'count' }; +const RHSM_API_PATH_RHEL_ID_TYPES = { + RHEL: 'RHEL', + COMPUTE_NODE: 'RHEL Compute Node', + DESKTOP: 'RHEL Desktop', + SERVER: 'RHEL Server', + WORKSTATION: 'RHEL Workstation', + ARM: 'RHEL for ARM', + IBM_POWER: 'RHEL for IBM Power', + IBM_Z: 'RHEL for IBM z', + X86: 'RHEL for x86' +}; + const RHSM_API_QUERY_GRANULARITY = 'granularity'; const RHSM_API_QUERY_GRANULARITY_TYPES = { DAILY: 'daily', @@ -45,6 +57,7 @@ const rhelApiTypes = { RHSM_API_RESPONSE_PRODUCTS_DATA_TYPES, RHSM_API_RESPONSE_PRODUCTS_META, RHSM_API_RESPONSE_PRODUCTS_META_TYPES, + RHSM_API_PATH_RHEL_ID_TYPES, RHSM_API_QUERY_GRANULARITY, RHSM_API_QUERY_GRANULARITY_TYPES, RHSM_API_QUERY_LIMIT, @@ -64,6 +77,7 @@ export { RHSM_API_RESPONSE_PRODUCTS_DATA_TYPES, RHSM_API_RESPONSE_PRODUCTS_META, RHSM_API_RESPONSE_PRODUCTS_META_TYPES, + RHSM_API_PATH_RHEL_ID_TYPES, RHSM_API_QUERY_GRANULARITY, RHSM_API_QUERY_GRANULARITY_TYPES, RHSM_API_QUERY_LIMIT,