Skip to content

Commit

Permalink
fix(graphCard,rhelView,openshiftView): issues/10 query prop (#360)
Browse files Browse the repository at this point in the history
* graphCard, c3GraphCard, prop graphQuery to query
* rhelView, openshiftView, toolbar, graphQuery to query
* redux, viewReducer, selectors, graphQuery to query
  • Loading branch information
cdcabrera committed Jul 31, 2020
1 parent f2f8948 commit d20307b
Show file tree
Hide file tree
Showing 15 changed files with 131 additions and 131 deletions.
26 changes: 13 additions & 13 deletions src/components/c3GraphCard/c3GraphCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ class C3GraphCard extends React.Component {
}

componentDidUpdate(prevProps) {
const { graphQuery, productId } = this.props;
const { query, productId } = this.props;

if (productId !== prevProps.productId || !_isEqual(graphQuery, prevProps.graphQuery)) {
if (productId !== prevProps.productId || !_isEqual(query, prevProps.query)) {
this.onUpdateGraphData();
}
}
Expand All @@ -41,18 +41,18 @@ class C3GraphCard extends React.Component {
* @event onUpdateGraphData
*/
onUpdateGraphData = () => {
const { getGraphReportsCapacity, graphQuery, isDisabled, productId } = this.props;
const graphGranularity = graphQuery && graphQuery[rhsmApiTypes.RHSM_API_QUERY_GRANULARITY];
const { getGraphReportsCapacity, query, isDisabled, productId } = this.props;
const graphGranularity = query && query[rhsmApiTypes.RHSM_API_QUERY_GRANULARITY];

if (!isDisabled && graphGranularity && productId) {
const { startDate, endDate } = dateHelpers.getRangedDateTime(graphGranularity);
const query = {
const graphQuery = {
[rhsmApiTypes.RHSM_API_QUERY_START_DATE]: startDate.toISOString(),
[rhsmApiTypes.RHSM_API_QUERY_END_DATE]: endDate.toISOString(),
...graphQuery
...query
};

getGraphReportsCapacity(productId, query);
getGraphReportsCapacity(productId, graphQuery);
}
};

Expand Down Expand Up @@ -121,9 +121,9 @@ class C3GraphCard extends React.Component {
* @returns {Node}
*/
renderChart() {
const { filterGraphData, graphData, graphQuery, selectOptionsType, productId, productShortLabel } = this.props;
const { filterGraphData, graphData, query, selectOptionsType, productId, productShortLabel } = this.props;

const graphGranularity = graphQuery && graphQuery[rhsmApiTypes.RHSM_API_QUERY_GRANULARITY];
const graphGranularity = query && query[rhsmApiTypes.RHSM_API_QUERY_GRANULARITY];
const { selected } = graphCardTypes.getGranularityOptions(selectOptionsType);
const updatedGranularity = graphGranularity || selected;

Expand Down Expand Up @@ -171,14 +171,14 @@ class C3GraphCard extends React.Component {
* @returns {Node}
*/
render() {
const { cardTitle, children, error, graphQuery, isDisabled, selectOptionsType, pending, t } = this.props;
const { cardTitle, children, error, query, isDisabled, selectOptionsType, pending, t } = this.props;

if (isDisabled) {
return null;
}

const { options } = graphCardTypes.getGranularityOptions(selectOptionsType);
const graphGranularity = graphQuery && graphQuery[rhsmApiTypes.RHSM_API_QUERY_GRANULARITY];
const graphGranularity = query && query[rhsmApiTypes.RHSM_API_QUERY_GRANULARITY];

return (
<Card className="curiosity-usage-graph fadein">
Expand Down Expand Up @@ -216,7 +216,7 @@ class C3GraphCard extends React.Component {
/**
* Prop types.
*
* @type {{productId: string, pending: boolean, error: boolean, graphQuery: object, cardTitle: string,
* @type {{productId: string, pending: boolean, error: boolean, query: object, cardTitle: string,
* filterGraphData: Array, getGraphReportsCapacity: Function, productShortLabel: string, selectOptionsType: string,
* viewId: string, t: Function, children: Node, graphData: object, isDisabled: boolean}}
*/
Expand All @@ -232,7 +232,7 @@ C3GraphCard.propTypes = {
),
getGraphReportsCapacity: PropTypes.func,
graphData: PropTypes.object,
graphQuery: PropTypes.shape({
query: PropTypes.shape({
[rhsmApiTypes.RHSM_API_QUERY_GRANULARITY]: PropTypes.oneOf([...Object.values(GRANULARITY_TYPES)]).isRequired
}).isRequired,
isDisabled: PropTypes.bool,
Expand Down
10 changes: 5 additions & 5 deletions src/components/c3GraphCard/tests/c3GraphCard.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { RHSM_API_QUERY_GRANULARITY_TYPES as GRANULARITY_TYPES, rhsmApiTypes } f
describe('C3GraphCard Component', () => {
it('should render a non-connected component', () => {
const props = {
graphQuery: { [rhsmApiTypes.RHSM_API_QUERY_GRANULARITY]: GRANULARITY_TYPES.DAILY },
query: { [rhsmApiTypes.RHSM_API_QUERY_GRANULARITY]: GRANULARITY_TYPES.DAILY },
productId: 'lorem'
};
const component = shallow(<C3GraphCard {...props} />);
Expand All @@ -17,7 +17,7 @@ describe('C3GraphCard Component', () => {

it('should render multiple states', () => {
const props = {
graphQuery: { [rhsmApiTypes.RHSM_API_QUERY_GRANULARITY]: GRANULARITY_TYPES.DAILY },
query: { [rhsmApiTypes.RHSM_API_QUERY_GRANULARITY]: GRANULARITY_TYPES.DAILY },
productId: 'lorem',
graphData: {
physicalSockets: [
Expand Down Expand Up @@ -88,7 +88,7 @@ describe('C3GraphCard Component', () => {
id: 'thresholdLoremIpsumSockets'
}
],
graphQuery: { [rhsmApiTypes.RHSM_API_QUERY_GRANULARITY]: GRANULARITY_TYPES.DAILY },
query: { [rhsmApiTypes.RHSM_API_QUERY_GRANULARITY]: GRANULARITY_TYPES.DAILY },
productId: 'lorem',
graphData: {
loremIpsumSockets: [
Expand Down Expand Up @@ -151,7 +151,7 @@ describe('C3GraphCard Component', () => {

it('should render a custom legend', () => {
const props = {
graphQuery: { [rhsmApiTypes.RHSM_API_QUERY_GRANULARITY]: GRANULARITY_TYPES.DAILY },
query: { [rhsmApiTypes.RHSM_API_QUERY_GRANULARITY]: GRANULARITY_TYPES.DAILY },
productId: 'lorem'
};

Expand All @@ -171,7 +171,7 @@ describe('C3GraphCard Component', () => {

it('should return an empty render when disabled', () => {
const props = {
graphQuery: { [rhsmApiTypes.RHSM_API_QUERY_GRANULARITY]: GRANULARITY_TYPES.DAILY },
query: { [rhsmApiTypes.RHSM_API_QUERY_GRANULARITY]: GRANULARITY_TYPES.DAILY },
isDisabled: true,
productId: 'lorem'
};
Expand Down
8 changes: 4 additions & 4 deletions src/components/graphCard/__tests__/graphCard.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { RHSM_API_QUERY_GRANULARITY_TYPES as GRANULARITY_TYPES, rhsmApiTypes } f
describe('GraphCard Component', () => {
it('should render a non-connected component', () => {
const props = {
graphQuery: { [rhsmApiTypes.RHSM_API_QUERY_GRANULARITY]: GRANULARITY_TYPES.DAILY },
query: { [rhsmApiTypes.RHSM_API_QUERY_GRANULARITY]: GRANULARITY_TYPES.DAILY },
productId: 'lorem'
};
const component = shallow(<GraphCard {...props} />);
Expand All @@ -17,7 +17,7 @@ describe('GraphCard Component', () => {

it('should render multiple states', () => {
const props = {
graphQuery: { [rhsmApiTypes.RHSM_API_QUERY_GRANULARITY]: GRANULARITY_TYPES.DAILY },
query: { [rhsmApiTypes.RHSM_API_QUERY_GRANULARITY]: GRANULARITY_TYPES.DAILY },
productId: 'lorem',
graphData: {
physicalSockets: [
Expand Down Expand Up @@ -88,7 +88,7 @@ describe('GraphCard Component', () => {
id: 'thresholdLoremIpsumSockets'
}
],
graphQuery: { [rhsmApiTypes.RHSM_API_QUERY_GRANULARITY]: GRANULARITY_TYPES.DAILY },
query: { [rhsmApiTypes.RHSM_API_QUERY_GRANULARITY]: GRANULARITY_TYPES.DAILY },
productId: 'lorem',
graphData: {
loremIpsumSockets: [
Expand Down Expand Up @@ -152,7 +152,7 @@ describe('GraphCard Component', () => {

it('should return an empty render when disabled', () => {
const props = {
graphQuery: { [rhsmApiTypes.RHSM_API_QUERY_GRANULARITY]: GRANULARITY_TYPES.DAILY },
query: { [rhsmApiTypes.RHSM_API_QUERY_GRANULARITY]: GRANULARITY_TYPES.DAILY },
isDisabled: true,
productId: 'lorem'
};
Expand Down
26 changes: 13 additions & 13 deletions src/components/graphCard/graphCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ class GraphCard extends React.Component {
}

componentDidUpdate(prevProps) {
const { graphQuery, productId } = this.props;
const { query, productId } = this.props;

if (productId !== prevProps.productId || !_isEqual(graphQuery, prevProps.graphQuery)) {
if (productId !== prevProps.productId || !_isEqual(query, prevProps.query)) {
this.onUpdateGraphData();
}
}
Expand All @@ -41,18 +41,18 @@ class GraphCard extends React.Component {
* @event onUpdateGraphData
*/
onUpdateGraphData = () => {
const { getGraphReportsCapacity, graphQuery, isDisabled, productId } = this.props;
const graphGranularity = graphQuery && graphQuery[rhsmApiTypes.RHSM_API_QUERY_GRANULARITY];
const { getGraphReportsCapacity, query, isDisabled, productId } = this.props;
const graphGranularity = query && query[rhsmApiTypes.RHSM_API_QUERY_GRANULARITY];

if (!isDisabled && graphGranularity && productId) {
const { startDate, endDate } = dateHelpers.getRangedDateTime(graphGranularity);
const query = {
const graphQuery = {
[rhsmApiTypes.RHSM_API_QUERY_START_DATE]: startDate.toISOString(),
[rhsmApiTypes.RHSM_API_QUERY_END_DATE]: endDate.toISOString(),
...graphQuery
...query
};

getGraphReportsCapacity(productId, query);
getGraphReportsCapacity(productId, graphQuery);
}
};

Expand Down Expand Up @@ -84,8 +84,8 @@ class GraphCard extends React.Component {
* @returns {Node}
*/
renderChart() {
const { filterGraphData, graphData, graphQuery, selectOptionsType, productShortLabel, viewId } = this.props;
const graphGranularity = graphQuery && graphQuery[rhsmApiTypes.RHSM_API_QUERY_GRANULARITY];
const { filterGraphData, graphData, query, selectOptionsType, productShortLabel, viewId } = this.props;
const graphGranularity = query && query[rhsmApiTypes.RHSM_API_QUERY_GRANULARITY];
const { selected } = graphCardTypes.getGranularityOptions(selectOptionsType);
const updatedGranularity = graphGranularity || selected;

Expand Down Expand Up @@ -158,14 +158,14 @@ class GraphCard extends React.Component {
* @returns {Node}
*/
render() {
const { cardTitle, children, error, graphQuery, isDisabled, selectOptionsType, pending, t } = this.props;
const { cardTitle, children, error, query, isDisabled, selectOptionsType, pending, t } = this.props;

if (isDisabled) {
return null;
}

const { options } = graphCardTypes.getGranularityOptions(selectOptionsType);
const graphGranularity = graphQuery && graphQuery[rhsmApiTypes.RHSM_API_QUERY_GRANULARITY];
const graphGranularity = query && query[rhsmApiTypes.RHSM_API_QUERY_GRANULARITY];

return (
<Card className="curiosity-usage-graph fadein">
Expand Down Expand Up @@ -196,7 +196,7 @@ class GraphCard extends React.Component {
/**
* Prop types.
*
* @type {{productId: string, pending: boolean, error: boolean, graphQuery: object, cardTitle: string,
* @type {{productId: string, pending: boolean, error: boolean, query: object, cardTitle: string,
* filterGraphData: Array, getGraphReportsCapacity: Function, productShortLabel: string, selectOptionsType: string,
* viewId: string, t: Function, children: Node, graphData: object, isDisabled: boolean}}
*/
Expand All @@ -213,7 +213,7 @@ GraphCard.propTypes = {
),
getGraphReportsCapacity: PropTypes.func,
graphData: PropTypes.object,
graphQuery: PropTypes.shape({
query: PropTypes.shape({
[rhsmApiTypes.RHSM_API_QUERY_GRANULARITY]: PropTypes.oneOf([...Object.values(GRANULARITY_TYPES)]).isRequired
}).isRequired,
isDisabled: PropTypes.bool,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ exports[`OpenshiftView Component should display an alternate graph on query-stri
</PageHeader>
<PageToolbar>
<Toolbar
graphQuery={
isDisabled={false}
query={
Object {
"granularity": "daily",
}
}
isDisabled={false}
t={[Function]}
viewId="OpenShift"
/>
Expand All @@ -36,14 +36,14 @@ exports[`OpenshiftView Component should display an alternate graph on query-stri
},
]
}
graphQuery={
key="lorem ipsum"
productId="lorem ipsum"
productShortLabel="OpenShift"
query={
Object {
"granularity": "daily",
}
}
key="lorem ipsum"
productId="lorem ipsum"
productShortLabel="OpenShift"
viewId="OpenShift"
>
<Select
Expand Down Expand Up @@ -86,12 +86,12 @@ exports[`OpenshiftView Component should have a fallback title: title 1`] = `
</PageHeader>
<PageToolbar>
<Toolbar
graphQuery={
isDisabled={false}
query={
Object {
"granularity": "daily",
}
}
isDisabled={false}
t={[Function]}
viewId="OpenShift"
/>
Expand All @@ -112,14 +112,14 @@ exports[`OpenshiftView Component should have a fallback title: title 1`] = `
},
]
}
graphQuery={
key="lorem ipsum"
productId="lorem ipsum"
productShortLabel="OpenShift"
query={
Object {
"granularity": "daily",
}
}
key="lorem ipsum"
productId="lorem ipsum"
productShortLabel="OpenShift"
viewId="OpenShift"
>
<Select
Expand Down Expand Up @@ -162,12 +162,12 @@ exports[`OpenshiftView Component should render a non-connected component: non-co
</PageHeader>
<PageToolbar>
<Toolbar
graphQuery={
isDisabled={false}
query={
Object {
"granularity": "daily",
}
}
isDisabled={false}
t={[Function]}
viewId="OpenShift"
/>
Expand All @@ -188,14 +188,14 @@ exports[`OpenshiftView Component should render a non-connected component: non-co
},
]
}
graphQuery={
key="lorem ipsum"
productId="lorem ipsum"
productShortLabel="OpenShift"
query={
Object {
"granularity": "daily",
}
}
key="lorem ipsum"
productId="lorem ipsum"
productShortLabel="OpenShift"
viewId="OpenShift"
>
<Select
Expand Down
Loading

0 comments on commit d20307b

Please sign in to comment.