Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/parallel coordinate #62 #69

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ yarn-error.log*

build/
lib/
.nyc_output
.nyc_output
venv/
32 changes: 17 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,14 @@ yarn install
cd backend && yarn install
```

## Running frontend, backend and plugins
The examples provided for client optimisers make use of Python 3.8.10. To run and test with the sample data provided, install the Python dependencies from the root of the project with the following (installing Python packages to user directory, optionally create a virtual environment and remove "--user" argument):

```bash
pip install --user -r requirements.txt

```

## Running frontend, backend and plugins

Once all the packages/dependencies have been installed for both the frontend and backend, the stack can be run in the following order:

Expand Down Expand Up @@ -82,16 +89,7 @@ yarn line

In order to feed in data to the database and see real-time visualisation, see the section below to run optimser clients.

## Running client scripts

The current examples provided make use of Python 3.8.10.

To run and test the sample data already provided, install the Python dependencies from the root of the project:

```bash
pip install --user -r requirements.txt

```
## Running client scripts

The optimiser client scripts are in the "/scripts" folder, you can run from them the root of the project with the following:

Expand All @@ -111,15 +109,15 @@ The frontend will show all active optmiser client runs once the script has been

## Development

### Creating Plugins
### Creating and configuring plugins

To create a plugin you can copy any of the existing plugins in the `packages` folder.
To create a plugin, begin by copying an existing plugin in the `packages` folder i.e. "pareto-front" plugin folder and rename appropriately.

To configure the plugin to work with the frontend, you will need to set its name and description through the files in the plugin folder:

1. `webpackConfig.output.library` in `craco.config.js` to the plugin name,

2. `settings.json/deploy-settings.json` to add the plugin details (look at examples already provided),
2. `settings.json/deploy-settings.json` to add the plugin details (look at examples already provided) (TODO: Clarify...),

3. `name` in `package.json` of the plugin project,

Expand All @@ -129,10 +127,14 @@ To configure the plugin to work with the frontend, you will need to set its name

6. `pluginName` in `src/index.tsx`,

7. `plugins` command in `package.json` to add the plugin to start with the command,
7. `plugins` command in `package.json` at project root to add the plugin to start with the command,

8. web dyno start in `Procfile` for plugin project (if you are using Heroku).

### Developing and testing plugins

TODO: Individually developing and testing plugins without having to serve it

### Deploying backend to Heroku

You will need to create a backend application on Heroku and add the GitHub repository to it.
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"frontend": "yarn workspace frontend start",
"pareto": "yarn workspace pareto-front serve:build",
"line": "yarn workspace line serve:build",
"parallel": "yarn workspace parallel serve:build",
"stack": "concurrently -n backend,pareto-plugin,frontend \"yarn --cwd backend start\" \"yarn pareto\" \"yarn workspace frontend serve:build\"",
"test:backend": "yarn --cwd backend test",
"test:frontend": "yarn workspace frontend test",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const updatePlugins = (
}

log.error(
`Duplicate plugin route identified: ${payload.link}. ${payload.plugin}: '${payload.displayName} not registered`
`Duplicate plugin route identified: ${payload.link}. ${payload.plugin}: '${payload.displayName} not registered'`
);
return existingPlugins;
};
Expand Down
2 changes: 2 additions & 0 deletions packages/frontend/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
<body>
<script crossorigin src="https://unpkg.com/react@16/umd/react.production.min.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.production.min.js"></script>
<!-- Add Plotly.js -->
<script crossorigin src="https://cdn.plot.ly/plotly-latest.min.js"></script>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
Expand Down
10 changes: 8 additions & 2 deletions packages/frontend/public/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"backendUrl": "http://localhost:9000",
"plugins":[
"plugins": [
{
"name": "pareto-front",
"src": "http://localhost:5000/main.js",
Expand All @@ -12,6 +12,12 @@
"src": "http://localhost:5001/main.js",
"enable": true,
"location": "main"
},
{
"name": "parallel",
"src": "http://localhost:5002/main.js",
"enable": true,
"location": "main"
}
]
}
}
26 changes: 14 additions & 12 deletions packages/frontend/src/pages/visualisationsPage.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,20 @@ const VisualisationsPage = (props: VisualisationsPageCombinedProps): React.React
<Grid container spacing={3}>
{selectedRun ? (
plugins.length > 0 ? (
plugins.map(
(p, i) =>
selectedRun.graphs.includes(p.plugin) && (
<Grid key={i} item xs={3}>
<VisualisationCard
runId={runId}
visualisationName={p.plugin}
displayName={p.displayName}
/>
</Grid>
),
)
plugins
.sort((a, b) => a.displayName.localeCompare(b.displayName))
.map(
(p, i) =>
selectedRun.graphs.includes(p.plugin) && (
<Grid key={i} item xs={3}>
<VisualisationCard
runId={runId}
visualisationName={p.plugin}
displayName={p.displayName}
/>
</Grid>
),
)
) : (
<Typography>No plugins have been loaded for visualisation</Typography>
)
Expand Down
7 changes: 4 additions & 3 deletions packages/frontend/src/utilities/loadMicroFrontends.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ async function loadApp(name: string, appURL: string, store: Store<unknown, AnyAc
singleSpa.registerApplication(
name,
() => loadReactApp(name),
// TODO: Investigate about making the application active at all times?
() => true,
customProps,
customProps, // Pass our state with data to plugins
);
}

Expand All @@ -56,13 +57,13 @@ async function init(plugins: Plugin[], store: Store<unknown, AnyAction>) {
log.debug(`Successfully loaded plugin ${p.name} from ${p.src}`);
})
.catch(() => {
log.error(`Failed to load plugin ${p.name} from ${p.src}`);
log.error(`Failed to load plugin "${p.name}" from ${p.src}`);
document.dispatchEvent(
new CustomEvent(microFrontendMessageId, {
detail: {
type: NotificationType,
payload: {
message: `Failed to load plugin ${p.name} from ${p.src}.
message: `Failed to load plugin "${p.name}" from ${p.src}.
Try reloading the page and if the error persists contact the support team.`,
severity: 'error',
},
Expand Down
1 change: 1 addition & 0 deletions packages/parallel/Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: yarn workspace parallel start
46 changes: 46 additions & 0 deletions packages/parallel/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Getting Started with Create React App

This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).

## Available Scripts

In the project directory, you can run:

### `yarn start`

Runs the app in the development mode.\
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.

The page will reload if you make edits.\
You will also see any lint errors in the console.

### `yarn test`

Launches the test runner in the interactive watch mode.\
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.

### `yarn build`

Builds the app for production to the `build` folder.\
It correctly bundles React in production mode and optimizes the build for the best performance.

The build is minified and the filenames include the hashes.\
Your app is ready to be deployed!

See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.

### `yarn eject`

**Note: this is a one-way operation. Once you `eject`, you can’t go back!**

If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.

Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.

You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.

## Learn More

You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).

To learn React, check out the [React documentation](https://reactjs.org/).
24 changes: 24 additions & 0 deletions packages/parallel/craco.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module.exports = {
webpack: {
configure: (webpackConfig, { env, paths }) => {
webpackConfig.externals = {
react: "React", // Case matters here
"react-dom": "ReactDOM", // Case matters here
};

if (env === "production") {
// && !process.env.REACT_APP_E2E_TESTING (we will need the redux state, so we must build it)
webpackConfig.output.library = "parallel";
webpackConfig.output.libraryTarget = "window";

webpackConfig.output.filename = "[name].js";
webpackConfig.output.chunkFilename = "[name].chunk.js";

delete webpackConfig.optimization.splitChunks;
webpackConfig.optimization.runtimeChunk = false;
}

return webpackConfig;
},
},
};
68 changes: 68 additions & 0 deletions packages/parallel/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"name": "parallel",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
"@types/jest": "^26.0.15",
"@types/loglevel": "^1.6.3",
"@types/node": "^12.0.0",
"@types/react": "^17.0.0",
"@types/react-dom": "^17.0.0",
"@types/react-plotly.js": "^2.5.0",
"@types/react-redux": "^7.1.16",
"@types/react-router": "^5.1.11",
"@types/redux-logger": "^3.0.8",
"connected-react-router": "^6.8.0",
"frontend-common": "0.1.0",
"loglevel": "^1.7.1",
"plotly.js": "^2.8.0",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-plotly.js": "^2.5.1",
"react-redux": "^7.2.2",
"react-router": "^5.2.0",
"react-router-dom": "^5.2.0",
"react-scripts": "4.0.2",
"redux": "^4.0.5",
"redux-logger": "^3.0.6",
"redux-thunk": "^2.3.0",
"serve": "^11.3.2",
"single-spa-react": "^3.0.0",
"typescript": "^4.1.2"
},
"scripts": {
"dev": "craco start",
"build": "craco build",
"start": "serve build",
"dev:start": "serve build -l 5002",
"serve:build": "yarn build && yarn dev:start",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"@craco/craco": "^6.1.1",
"@types/history": "^4.7.8",
"@types/single-spa-react": "2.8.3"
}
}
57 changes: 57 additions & 0 deletions packages/parallel/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.

Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
</head>
<body>
<script
crossorigin
src="https://unpkg.com/react@16/umd/react.production.min.js"
></script>
<script
crossorigin
src="https://unpkg.com/react-dom@16/umd/react-dom.production.min.js"
></script>
<!-- Add Plotly.js -->
<script
crossorigin
src="https://cdn.plot.ly/plotly-latest.min.js"
></script>
<noscript>You need to enable JavaScript to run this app.</noscript>

<div id="parallel"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.

You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.

To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>
8 changes: 8 additions & 0 deletions packages/parallel/public/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"short_name": "React App",
"name": "Create React App Sample",
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
Loading