Skip to content

Commit

Permalink
fix(build): issues/296 npm updates for platform (#326)
Browse files Browse the repository at this point in the history
* build, platform specific npm resources
* chartArea, fix resize method, relates to left nav
* pageHeader, revert title to platform version
* redux, middleware, reducer, types, update notifications import
* styles, move css files to src/index.js to avoid breaking sass
  • Loading branch information
cdcabrera committed Jul 13, 2020
1 parent c210245 commit 96c459e
Show file tree
Hide file tree
Showing 17 changed files with 218 additions and 82 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@
"@patternfly/react-icons": "4.4.2",
"@patternfly/react-styles": "4.4.2",
"@patternfly/react-tokens": "4.5.2",
"@redhat-cloud-services/frontend-components": "1.0.29",
"@redhat-cloud-services/frontend-components-notifications": "1.0.4",
"@redhat-cloud-services/frontend-components-utilities": "1.0.4",
"@redhat-cloud-services/frontend-components": "2.1.1",
"@redhat-cloud-services/frontend-components-notifications": "2.1.0",
"@redhat-cloud-services/frontend-components-utilities": "2.1.0",
"axios": "^0.19.2",
"c3": "^0.7.15",
"classnames": "^2.2.6",
Expand Down
2 changes: 1 addition & 1 deletion src/components/app.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';
import { NotificationsPortal } from '@redhat-cloud-services/frontend-components-notifications';
import { NotificationsPortal } from '@redhat-cloud-services/frontend-components-notifications/cjs';
import { connectRouter, reduxActions } from '../redux';
import { helpers } from '../common/helpers';
import { I18n } from './i18n/i18n';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,25 @@ exports[`Authentication Component should render a non-connected component error:
className="pf-l-page-header pf-c-page-header pf-l-page__main-section pf-c-page__main-section pf-m-light"
widget-type="InsightsPageHeader"
>
<Title
headingLevel="h1"
<PageHeaderTitle
title="Subscription Watch"
>
<h1
className="pf-c-title pf-m-2xl"
<Title
className=""
headingLevel="h1"
size="2xl"
widget-type="InsightsPageHeaderTitle"
>
Subscription Watch
</h1>
</Title>
<h1
className="pf-c-title pf-m-2xl"
widget-type="InsightsPageHeaderTitle"
>
Subscription Watch
</h1>
</Title>
</PageHeaderTitle>
</section>
</PageHeader>
</PageHeader>
Expand Down
2 changes: 1 addition & 1 deletion src/components/c3GraphCard/c3GraphCard.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import { Card, CardTitle, CardHeader, CardActions, CardBody } from '@patternfly/react-core';
import { Skeleton, SkeletonSize } from '@redhat-cloud-services/frontend-components/components/Skeleton';
import { Skeleton, SkeletonSize } from '@redhat-cloud-services/frontend-components/components/cjs/Skeleton';
import _isEqual from 'lodash/isEqual';
import { Select } from '../form/select';
import { connectTranslate, reduxActions, reduxSelectors, reduxTypes, store } from '../../redux';
Expand Down
52 changes: 36 additions & 16 deletions src/components/chartArea/chartArea.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,32 +27,20 @@ class ChartArea extends React.Component {

dataSetsToggle = {};

resizeObserver = helpers.noop;

containerRef = React.createRef();

tooltipRef = React.createRef();

componentDidMount() {
this.onResizeContainer();
window.addEventListener('resize', this.onResizeContainer);
this.setResizeObserve();
}

componentWillUnmount() {
window.removeEventListener('resize', this.onResizeContainer);
this.resizeObserver();
}

/**
* On window resize adjust graph display.
*
* @event onResizeContainer
*/
onResizeContainer = () => {
const containerElement = this.containerRef.current;

if (containerElement && containerElement.clientWidth) {
this.setState({ chartWidth: containerElement.clientWidth });
}
};

/**
* Consumer exposed, hides chart layer.
*
Expand Down Expand Up @@ -89,6 +77,20 @@ class ChartArea extends React.Component {
return updatedToggle;
};

/**
* On resize adjust graph display.
*
* @event onResizeContainer
*/
onResizeContainer = () => {
const { chartWidth } = this.state;
const { clientWidth = 0 } = this.containerRef.current || {};

if (clientWidth !== chartWidth) {
this.setState({ chartWidth: clientWidth });
}
};

/**
* Consumer exposed, determine if chart layer on/off.
* Note: Using "setState" as related to this exposed check gives the appearance of a race condition.
Expand All @@ -99,6 +101,24 @@ class ChartArea extends React.Component {
*/
getIsToggled = id => this.dataSetsToggle[id] || false;

/**
* Set ResizeObserver for scenarios where the window.resize event doesn't fire.
*/
setResizeObserve() {
const containerElement = this.containerRef.current;
const { ResizeObserver } = window;

if (containerElement && ResizeObserver) {
const resizeObserver = new ResizeObserver(this.onResizeContainer);
resizeObserver.observe(containerElement);
this.resizeObserver = () => resizeObserver.unobserve(containerElement);
} else {
this.onResizeContainer();
window.addEventListener('resize', this.onResizeContainer);
this.resizeObserver = () => window.removeEventListener('resize', this.onResizeContainer);
}
}

/**
* Apply props, set x and y axis chart increments/ticks formatting.
*
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 @@ -2,7 +2,7 @@ import React from 'react';
import PropTypes from 'prop-types';
import { Card, CardTitle, CardHeader, CardActions, CardBody } from '@patternfly/react-core';
import { chart_color_green_300 as chartColorGreenDark } from '@patternfly/react-tokens';
import { Skeleton, SkeletonSize } from '@redhat-cloud-services/frontend-components/components/Skeleton';
import { Skeleton, SkeletonSize } from '@redhat-cloud-services/frontend-components/components/cjs/Skeleton';
import _isEqual from 'lodash/isEqual';
import { Select } from '../form/select';
import { connectTranslate, reduxActions, reduxSelectors, reduxTypes, store } from '../../redux';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,35 @@ exports[`PageHeader Component should render a basic component: basic 1`] = `
className="pf-l-page-header pf-c-page-header pf-l-page__main-section pf-c-page__main-section pf-m-light"
widget-type="InsightsPageHeader"
>
<Title
headingLevel="h1"
>
<h1
className="pf-c-title pf-m-2xl"
>
<PageHeaderTitle
title={
<span
className="test"
>
lorem
</span>
</h1>
</Title>
}
>
<Title
className=""
headingLevel="h1"
size="2xl"
widget-type="InsightsPageHeaderTitle"
>
<h1
className="pf-c-title pf-m-2xl"
widget-type="InsightsPageHeaderTitle"
>
<span
className="test"
>
lorem
</span>
</h1>
</Title>
</PageHeaderTitle>
</section>
</PageHeader>
</PageHeader>
Expand All @@ -32,15 +48,25 @@ exports[`PageHeader Component should render string node types: string 1`] = `
className="pf-l-page-header pf-c-page-header pf-l-page__main-section pf-c-page__main-section pf-m-light"
widget-type="InsightsPageHeader"
>
<Title
headingLevel="h1"
<PageHeaderTitle
title="dolor sit"
>
<h1
className="pf-c-title pf-m-2xl"
<Title
className=""
headingLevel="h1"
size="2xl"
widget-type="InsightsPageHeaderTitle"
>
dolor sit
</h1>
</Title>
<h1
className="pf-c-title pf-m-2xl"
widget-type="InsightsPageHeaderTitle"
>
dolor sit
</h1>
</Title>
</PageHeaderTitle>
</section>
</PageHeader>
</PageHeader>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,25 @@ exports[`PageLayout Component should render header and section children: multipl
className="pf-l-page-header pf-c-page-header pf-l-page__main-section pf-c-page__main-section pf-m-light"
widget-type="InsightsPageHeader"
>
<Title
headingLevel="h1"
<PageHeaderTitle
title="lorem"
>
<h1
className="pf-c-title pf-m-2xl"
<Title
className=""
headingLevel="h1"
size="2xl"
widget-type="InsightsPageHeaderTitle"
>
lorem
</h1>
</Title>
<h1
className="pf-c-title pf-m-2xl"
widget-type="InsightsPageHeaderTitle"
>
lorem
</h1>
</Title>
</PageHeaderTitle>
</section>
</PageHeader>
</PageHeader>
Expand Down
14 changes: 7 additions & 7 deletions src/components/pageLayout/pageHeader.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import React from 'react';
import PropTypes from 'prop-types';
import { Title } from '@patternfly/react-core';
import { PageHeader as RcsPageHeader } from '@redhat-cloud-services/frontend-components/components/PageHeader';
import {
PageHeader as RcsPageHeader,
PageHeaderTitle
} from '@redhat-cloud-services/frontend-components/components/cjs/PageHeader';

/**
* Render a platform page header.
Expand All @@ -12,7 +14,7 @@ import { PageHeader as RcsPageHeader } from '@redhat-cloud-services/frontend-com
*/
const PageHeader = ({ children }) => (
<RcsPageHeader>
<Title headingLevel="h1">{children}</Title>
<PageHeaderTitle title={children} />
</RcsPageHeader>
);

Expand All @@ -22,14 +24,12 @@ const PageHeader = ({ children }) => (
* @type {{children: Node}}
*/
PageHeader.propTypes = {
children: PropTypes.any
children: PropTypes.node.isRequired
};

/**
* Default props.
*/
PageHeader.defaultProps = {
children: null
};
PageHeader.defaultProps = {};

export { PageHeader as default, PageHeader };
2 changes: 1 addition & 1 deletion src/components/pageLayout/pageSection.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';
import { Section } from '@redhat-cloud-services/frontend-components/components/Section';
import { Section } from '@redhat-cloud-services/frontend-components/components/cjs/Section';

/**
* Render a platform page section.
Expand Down
2 changes: 1 addition & 1 deletion src/components/pageLayout/pageToolbar.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';
import { Section } from '@redhat-cloud-services/frontend-components/components/Section';
import { Section } from '@redhat-cloud-services/frontend-components/components/cjs/Section';

/**
* Render a platform toolbar section.
Expand Down
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { BrowserRouter } from 'react-router-dom';
import { baseName } from './components/router/routerHelpers';
import { store } from './redux';
import App from './components/app';
import '@redhat-cloud-services/frontend-components/index.css';
import '@redhat-cloud-services/frontend-components-notifications/index.css';
import './styles/index.scss';

render(
Expand Down
2 changes: 1 addition & 1 deletion src/redux/middleware/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createLogger } from 'redux-logger';
import promiseMiddleware from 'redux-promise-middleware';
import thunkMiddleware from 'redux-thunk';
import { notificationsMiddleware } from '@redhat-cloud-services/frontend-components-notifications';
import { notificationsMiddleware } from '@redhat-cloud-services/frontend-components-notifications/cjs';
import { statusMiddleware } from './statusMiddleware';
import { reduxHelpers } from '../common/reduxHelpers';

Expand Down
2 changes: 1 addition & 1 deletion src/redux/reducers/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { combineReducers } from 'redux';
import { notifications } from '@redhat-cloud-services/frontend-components-notifications';
import { notifications } from '@redhat-cloud-services/frontend-components-notifications/cjs';
import graphReducer from './graphReducer';
import inventoryReducer from './inventoryReducer';
import viewReducer from './viewReducer';
Expand Down
2 changes: 1 addition & 1 deletion src/redux/types/platformTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
ADD_NOTIFICATION,
REMOVE_NOTIFICATION,
CLEAR_NOTIFICATIONS
} from '@redhat-cloud-services/frontend-components-notifications';
} from '@redhat-cloud-services/frontend-components-notifications/cjs';

const PLATFORM_ADD_NOTIFICATION = ADD_NOTIFICATION;
const PLATFORM_REMOVE_NOTIFICATION = REMOVE_NOTIFICATION;
Expand Down
9 changes: 6 additions & 3 deletions src/styles/index.scss
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
// Framework
@import '~@redhat-cloud-services/frontend-components-utilities/files/Utilities/_all';
@import '~@redhat-cloud-services/frontend-components/index.css';
@import '~@redhat-cloud-services/frontend-components-notifications/index.css';
@import '~@patternfly/patternfly/sass-utilities/all';
/**
* FixMe: Variables break Sass compiler
* Sass compiler throws an error when coming across the following syntax in
* --BackgroundUrl:url("d...
* Workaround is to move the CSS files to ./src/index.js
*/

// App
@import 'app';
Expand Down
Loading

0 comments on commit 96c459e

Please sign in to comment.