Skip to content

Commit

Permalink
fix(build,routing): issues/77 naming, routing, views (#132)
Browse files Browse the repository at this point in the history
* build, npm script proxy run, remove staging path
* build, dotenv, expand app brand, rename expand
* helpers, app brand, rename expand
* authentication, correct history routing
* rhelView, expand routing params to display title
* tourView, initial view, routing params to display title
* routerTypes, dynamic base name, staging to beta move
* router, pass additional routing details to rendered components
  • Loading branch information
cdcabrera committed Nov 19, 2019
1 parent 60a1a5c commit 400ee1d
Show file tree
Hide file tree
Showing 18 changed files with 241 additions and 116 deletions.
4 changes: 3 additions & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
REACT_APP_UI_VERSION=$npm_package_version
REACT_APP_UI_NAME=subscriptions
REACT_APP_UI_DISPLAY_NAME=Subscription Reporting
REACT_APP_UI_DISPLAY_NAME=subscription watch
REACT_APP_UI_DISPLAY_CONFIG_NAME=Subscription Watch
REACT_APP_UI_DISPLAY_START_NAME=Subscription watch
REACT_APP_UI_DEPLOY_PATH_PREFIX=${UI_DEPLOY_PATH_PREFIX}
PUBLIC_URL=${UI_DEPLOY_PATH_PREFIX}/apps/subscriptions/

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"release": "standard-version",
"start": "run-s dev:chrome; run-p -l api:dev start:js",
"start:js": "react-scripts start",
"start:proxy": "sh -ac '. ./.env.proxy; open https://ci.foo.redhat.com:1337/beta/staging/subscriptions/; run-s api:proxy-hosts; run-p -l start:js api:proxy'",
"start:proxy": "sh -ac '. ./.env.proxy; open https://ci.foo.redhat.com:1337/beta/subscriptions/; run-s api:proxy-hosts; run-p -l start:js api:proxy'",
"start:standalone": "rm ./.env.development.local; run-p -l api:dev start:js",
"test": "run-s test:lint test:ci",
"test:ci": "export CI=true; react-scripts test --env=jsdom --roots=./src --coverage",
Expand Down
4 changes: 3 additions & 1 deletion src/common/__tests__/__snapshots__/helpers.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ Object {
"TEST_MODE": true,
"UI_DEPLOY_PATH_PREFIX": "",
"UI_DISABLED": false,
"UI_DISPLAY_NAME": "Subscription Reporting",
"UI_DISPLAY_CONFIG_NAME": "Subscription Watch",
"UI_DISPLAY_NAME": "subscription watch",
"UI_DISPLAY_START_NAME": "Subscription watch",
"UI_LOGGER_ID": "curiosity",
"UI_NAME": "subscriptions",
"UI_PATH": "/",
Expand Down
6 changes: 6 additions & 0 deletions src/common/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ const UI_DISABLED = process.env.REACT_APP_UI_DISABLED === 'true';

const UI_DISPLAY_NAME = process.env.REACT_APP_UI_DISPLAY_NAME;

const UI_DISPLAY_CONFIG_NAME = process.env.REACT_APP_UI_DISPLAY_CONFIG_NAME;

const UI_DISPLAY_START_NAME = process.env.REACT_APP_UI_DISPLAY_START_NAME;

const UI_LOGGER_ID = process.env.REACT_APP_UI_LOGGER_ID || 'GUI';

const UI_NAME = process.env.REACT_APP_UI_NAME;
Expand All @@ -41,6 +45,8 @@ const helpers = {
UI_DEPLOY_PATH_PREFIX,
UI_DISABLED,
UI_DISPLAY_NAME,
UI_DISPLAY_CONFIG_NAME,
UI_DISPLAY_START_NAME,
UI_LOGGER_ID,
UI_NAME,
UI_PATH,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,6 @@ exports[`Authorization Component should render a non-connected component authori
"pathParameter": "RHEL",
"title": "Red Hat Enterprise Linux",
},
Object {
"id": "computenode",
"pathParameter": "RHEL Compute Node",
"title": "Compute Node",
},
Object {
"id": "desktop",
"pathParameter": "RHEL Desktop",
"title": "Desktop",
},
Object {
"id": "server",
"pathParameter": "RHEL Server",
"title": "Server",
},
Object {
"id": "workstation",
"pathParameter": "RHEL Workstation",
"title": "Workstation",
},
Object {
"id": "arm",
"pathParameter": "RHEL for ARM",
Expand Down Expand Up @@ -101,26 +81,6 @@ exports[`Authorization Component should render a non-connected component error:
"pathParameter": "RHEL",
"title": "Red Hat Enterprise Linux",
},
Object {
"id": "computenode",
"pathParameter": "RHEL Compute Node",
"title": "Compute Node",
},
Object {
"id": "desktop",
"pathParameter": "RHEL Desktop",
"title": "Desktop",
},
Object {
"id": "server",
"pathParameter": "RHEL Server",
"title": "Server",
},
Object {
"id": "workstation",
"pathParameter": "RHEL Workstation",
"title": "Workstation",
},
Object {
"id": "arm",
"pathParameter": "RHEL for ARM",
Expand Down
5 changes: 1 addition & 4 deletions src/components/authentication/authentication.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,10 @@ class Authentication extends Component {
try {
if (helpers.PROD_MODE || helpers.REVIEW_MODE) {
insights.chrome.init();
}

if (helpers.PROD_MODE) {
insights.chrome.identifyApp(appName);
insights.chrome.navigation(this.buildNavigation());

this.appNav = insights.chrome.on('APP_NAVIGATION', event => history.push(`/${event.navId}`));
this.appNav = insights.chrome.on('APP_NAVIGATION', event => history.push(`${event.navId}`));
this.buildNav = history.listen(() => insights.chrome.navigation(this.buildNavigation()));
}

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

exports[`RhelView Component should have a fallback title: title 1`] = `
<Fragment>
<PageHeader>
<PageHeaderTitle
title="Subscription watch"
/>
</PageHeader>
<PageSection>
<Connect(RhelGraphCard)
key="lorem ipsum"
productId="lorem ipsum"
/>
</PageSection>
</Fragment>
`;

exports[`RhelView Component should render a non-connected component: non-connected 1`] = `
<Fragment>
<PageHeader>
<PageHeaderTitle
title="Red Hat Enterprise Linux"
title="Dolor sit"
/>
</PageHeader>
<PageSection>
<Connect(RhelGraphCard)
key="lorem ipsum"
productId="lorem ipsum"
/>
</PageSection>
Expand Down
16 changes: 15 additions & 1 deletion src/components/rhelView/__tests__/rhelView.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,25 @@ describe('RhelView Component', () => {
it('should render a non-connected component', () => {
const props = {
routeDetail: {
pathParameter: 'lorem ipsum'
pathParameter: 'lorem ipsum',
routeItem: {
title: 'Dolor sit'
}
}
};

const component = shallow(<RhelView {...props} />);
expect(component).toMatchSnapshot('non-connected');
});

it('should have a fallback title', () => {
const props = {
routeDetail: {
pathParameter: 'lorem ipsum'
}
};

const component = shallow(<RhelView {...props} />);
expect(component).toMatchSnapshot('title');
});
});
18 changes: 13 additions & 5 deletions src/components/rhelView/rhelView.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { PageHeader, PageHeaderTitle } from '@redhat-cloud-services/frontend-com
import { PageSection } from '@patternfly/react-core';
import { connectRouter } from '../../redux';
import RhelGraphCard from '../rhelGraphCard/rhelGraphCard';
import { helpers } from '../../common';

class RhelView extends React.Component {
componentDidMount() {}
Expand All @@ -14,10 +15,12 @@ class RhelView extends React.Component {
return (
<React.Fragment>
<PageHeader>
<PageHeaderTitle title="Red Hat Enterprise Linux" />
<PageHeaderTitle
title={(routeDetail.routeItem && routeDetail.routeItem.title) || helpers.UI_DISPLAY_START_NAME}
/>
</PageHeader>
<PageSection>
<RhelGraphCard productId={routeDetail.pathParameter} />
<RhelGraphCard key={routeDetail.pathParameter} productId={routeDetail.pathParameter} />
</PageSection>
</React.Fragment>
);
Expand All @@ -26,11 +29,16 @@ class RhelView extends React.Component {

RhelView.propTypes = {
routeDetail: PropTypes.shape({
pathParameter: PropTypes.string.isRequired
}).isRequired
pathParameter: PropTypes.string.isRequired,
routeItem: PropTypes.shape({
title: PropTypes.string
})
})
};

RhelView.defaultProps = {};
RhelView.defaultProps = {
routeDetail: {}
};

const mapStateToProps = () => ({});

Expand Down
24 changes: 21 additions & 3 deletions src/components/router/__tests__/__snapshots__/router.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,30 @@ exports[`Router Component should render a basic component: basic 1`] = `
<Switch>
<Route
exact={true}
key="/rhel/:variant?"
path="/rhel/:variant?"
key="/rhel-sw/all"
path="/rhel-sw/all"
render={[Function]}
/>
<Route
exact={true}
key="/rhel-sw/:variant"
path="/rhel-sw/:variant"
render={[Function]}
/>
<Route
exact={true}
key="/soon"
path="/soon"
render={[Function]}
/>
<Route
exact={true}
key="/tour"
path="/tour"
render={[Function]}
/>
<Redirect
to="/rhel/:variant?"
to="/rhel-sw/all"
/>
</Switch>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`RouterTypes should return a generated baseName: app base lorem base name 1`] = `"/apps/lorem"`;
exports[`RouterTypes should return a generated baseName: app base lorem base name 1`] = `"/beta/appName"`;

exports[`RouterTypes should return a generated baseName: app base name 1`] = `"/apps/appName"`;
exports[`RouterTypes should return a generated baseName: app base name 1`] = `"/appName"`;

exports[`RouterTypes should return a generated baseName: beta app base name 1`] = `"/beta/apps/appName"`;
exports[`RouterTypes should return a generated baseName: beta app base name 1`] = `"/beta/appName"`;

exports[`RouterTypes should return a generated baseName: beta app lorem base name 1`] = `"/beta/apps/lorem"`;
exports[`RouterTypes should return a generated baseName: beta app lorem route name 1`] = `"/beta/appName"`;

exports[`RouterTypes should return route details that match navigation: route detail: computenode 1`] = `
Object {
"id": "computenode",
"pathParameter": "RHEL Compute Node",
"title": "Compute Node",
"default": true,
"id": "all",
"pathParameter": "RHEL",
"title": "Red Hat Enterprise Linux",
}
`;

Expand Down Expand Up @@ -42,26 +43,6 @@ Array [
"pathParameter": "RHEL",
"title": "Red Hat Enterprise Linux",
},
Object {
"id": "computenode",
"pathParameter": "RHEL Compute Node",
"title": "Compute Node",
},
Object {
"id": "desktop",
"pathParameter": "RHEL Desktop",
"title": "Desktop",
},
Object {
"id": "server",
"pathParameter": "RHEL Server",
"title": "Server",
},
Object {
"id": "workstation",
"pathParameter": "RHEL Workstation",
"title": "Workstation",
},
Object {
"id": "arm",
"pathParameter": "RHEL for ARM",
Expand Down Expand Up @@ -91,11 +72,37 @@ Array [
"component": [Function],
"disabled": false,
"exact": true,
"id": "rhel",
"redirect": true,
"render": true,
"title": "Red Hat Enterprise Linux",
"to": "/rhel/:variant?",
"to": "/rhel-sw/all",
},
Object {
"component": [Function],
"disabled": false,
"exact": true,
"id": "rhel-sw",
"render": true,
"title": "Red Hat Enterprise Linux",
"to": "/rhel-sw/:variant",
},
Object {
"component": [Function],
"disabled": false,
"exact": true,
"id": "soon",
"render": true,
"title": "Tour",
"to": "/soon",
},
Object {
"component": [Function],
"disabled": false,
"exact": true,
"id": "tour",
"render": true,
"title": "Tour",
"to": "/tour",
},
]
`;
10 changes: 5 additions & 5 deletions src/components/router/__tests__/routerTypes.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,31 @@ describe('RouterTypes', () => {
it('should return a generated baseName', () => {
expect(
dynamicBaseName({
pathName: '/apps/appName',
pathName: '/appName',
pathPrefix: '/beta'
})
).toMatchSnapshot('app base name');

expect(
dynamicBaseName({
pathName: '/apps/lorem/appName',
pathName: '/beta/appName',
pathPrefix: '/beta'
})
).toMatchSnapshot('app base lorem base name');

expect(
dynamicBaseName({
pathName: '/beta/apps/appName',
pathName: '/beta/appName',
pathPrefix: '/beta'
})
).toMatchSnapshot('beta app base name');

expect(
dynamicBaseName({
pathName: '/beta/apps/lorem/appName',
pathName: '/beta/appName/loremRoute',
pathPrefix: '/beta'
})
).toMatchSnapshot('beta app lorem base name');
).toMatchSnapshot('beta app lorem route name');
});

it('should return route details that match navigation', () => {
Expand Down
3 changes: 2 additions & 1 deletion src/components/router/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ class Router extends React.Component {
<item.component
routeDetail={{
baseName,
navigation,
routes,
routeItem: { ...item },
...routeDetail
}}
{...routeProps}
Expand Down
Loading

0 comments on commit 400ee1d

Please sign in to comment.