Skip to content

Commit

Permalink
fix(build, routerTypes): issues/34 dynamic routing baseName
Browse files Browse the repository at this point in the history
* build, dotenv path prefix
* build, html template add in lang attribute from dotenv
* routerTypes, create a dynamic routing baseName
  • Loading branch information
cdcabrera committed Aug 2, 2019
1 parent bd9239c commit 41d0364
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 45 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
REACT_APP_UI_VERSION=$npm_package_version
REACT_APP_UI_NAME=subscription-reporting
REACT_APP_UI_DISPLAY_NAME=Subscription Reporting
REACT_APP_UI_DEPLOY_PATH_PREFIX=${UI_DEPLOY_PATH_PREFIX}
PUBLIC_URL=${UI_DEPLOY_PATH_PREFIX}/apps/subscription-reporting/

REACT_APP_AJAX_TIMEOUT=60000
Expand Down
2 changes: 1 addition & 1 deletion public/index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="en">
<html lang="%REACT_APP_CONFIG_SERVICE_LOCALES_DEFAULT_LNG%">
<head>
<meta charset="utf-8" />
<title>%REACT_APP_UI_DISPLAY_NAME%</title>
Expand Down
1 change: 1 addition & 0 deletions src/common/__tests__/__snapshots__/helpers.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Object {
"PROD_MODE": false,
"REVIEW_MODE": false,
"TEST_MODE": true,
"UI_DEPLOY_PATH_PREFIX": "",
"UI_DISPLAY_NAME": "Subscription Reporting",
"UI_NAME": "subscription-reporting",
"UI_PATH": "/apps/subscription-reporting/",
Expand Down
3 changes: 3 additions & 0 deletions src/common/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ const TEST_MODE = process.env.REACT_APP_ENV === 'test';

const UI_NAME = process.env.REACT_APP_UI_NAME;

const UI_DEPLOY_PATH_PREFIX = process.env.REACT_APP_UI_DEPLOY_PATH_PREFIX;

const UI_DISPLAY_NAME = process.env.REACT_APP_UI_DISPLAY_NAME;

const UI_PATH = process.env.PUBLIC_URL || '/';
Expand All @@ -52,6 +54,7 @@ const helpers = {
REVIEW_MODE,
TEST_MODE,
UI_NAME,
UI_DEPLOY_PATH_PREFIX,
UI_DISPLAY_NAME,
UI_PATH,
UI_VERSION
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,8 @@ exports[`Authorization Component should render a non-connected component authori
Array [
Object {
"component": [Function],
"exact": true,
"id": "overview",
"title": "Subscription Reporting",
"to": "/",
},
Object {
"component": [Function],
"exact": true,
"id": "rhel",
"redirect": true,
"title": "Red Hat Enterprise Linux",
"to": "/rhel",
},
Expand Down Expand Up @@ -65,15 +58,8 @@ exports[`Authorization Component should render a non-connected component error:
Array [
Object {
"component": [Function],
"exact": true,
"id": "overview",
"title": "Subscription Reporting",
"to": "/",
},
Object {
"component": [Function],
"exact": true,
"id": "rhel",
"redirect": true,
"title": "Red Hat Enterprise Linux",
"to": "/rhel",
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,12 @@ exports[`Router Component should render a basic component: basic 1`] = `
<Switch>
<Route
component={[Function]}
exact={true}
key="/"
path="/"
/>
<Route
component={[Function]}
exact={true}
key="/rhel"
path="/rhel"
/>
<Redirect
to="/rhel"
/>
</Switch>
</div>
`;
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`RouterTypes should return specific properties: baseName 1`] = `"/apps/subscription-reporting/"`;
exports[`RouterTypes should return specific properties: baseName 1`] = `"/"`;

exports[`RouterTypes should return specific properties: routes 1`] = `
Array [
Object {
"component": [Function],
"exact": true,
"id": "overview",
"title": "Subscription Reporting",
"to": "/",
},
Object {
"component": [Function],
"exact": true,
"id": "rhel",
"redirect": true,
"title": "Red Hat Enterprise Linux",
"to": "/rhel",
},
Expand Down
26 changes: 15 additions & 11 deletions src/components/router/routerTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,33 @@ import { helpers } from '../../common/helpers';
import RhelView from '../rhelView/rhelView';

/**
* Return the application base directory.
* Return an assumed dynamic route baseName directory
* based on a predictable directory depth.
*
* @type {string}
*/
const baseName = helpers.UI_PATH;
const baseName = (() => {
const pathPrefix = helpers.UI_DEPLOY_PATH_PREFIX;
const pathName = window.location.pathname.split('/');

pathName.shift();

const pathSlice = pathPrefix && new RegExp(pathName[0]).test(pathPrefix) ? 2 : 1;

return `/${pathName.slice(0, pathSlice).join('/')}`;
})();

/**
* Return array of objects that describe navigation
* @return {array}
*/
const routes = [
{
title: 'Subscription Reporting',
id: 'overview',
to: '/',
component: RhelView,
exact: true
},
{
title: 'Red Hat Enterprise Linux',
id: 'rhel',
to: '/rhel',
component: RhelView,
exact: true
redirect: true,
component: RhelView
}
];

Expand Down
2 changes: 1 addition & 1 deletion tests/__snapshots__/html.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exports[`Index.HTML should have a specific html output: html output 1`] = `
"
<!doctype html>
<html lang=\\"en\\">
<html lang=\\"en-US\\">
<head>
<meta charset=\\"utf-8\\"/>
<title>Subscription Reporting
Expand Down

0 comments on commit 41d0364

Please sign in to comment.