Skip to content
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
1 change: 1 addition & 0 deletions packages/three-obj/Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: yarn workspace three-obj start
46 changes: 46 additions & 0 deletions packages/three-obj/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/three-obj/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 = "three-obj";
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/three-obj/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"name": "three-obj",
"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.3.1",
"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 5001",
"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"
}
}
55 changes: 55 additions & 0 deletions packages/three-obj/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<!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>
<noscript>You need to enable JavaScript to run this app.</noscript>

<!-- Add Plotly.js -->
<script crossorigin src="https://cdn.plot.ly/plotly-latest.min.js"></script>

<div id="three-obj"></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/three-obj/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"
}
38 changes: 38 additions & 0 deletions packages/three-obj/src/App.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
.App {
text-align: center;
}

.App-logo {
height: 40vmin;
pointer-events: none;
}

@media (prefers-reduced-motion: no-preference) {
.App-logo {
animation: App-logo-spin infinite 20s linear;
}
}

.App-header {
background-color: #282c34;
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: calc(10px + 2vmin);
color: white;
}

.App-link {
color: #61dafb;
}

@keyframes App-logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
9 changes: 9 additions & 0 deletions packages/three-obj/src/App.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import App from './App';

test('renders learn react link', () => {
render(<App />);
const linkElement = screen.getByText(/learn react/i);
expect(linkElement).toBeInTheDocument();
});
104 changes: 104 additions & 0 deletions packages/three-obj/src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import { routerMiddleware } from "connected-react-router";
// import AppReducer from "./state/reducers/App.reducer";
import { microFrontendMessageId } from "frontend-common";
import { createBrowserHistory } from "history";
import * as log from "loglevel";
import React from "react";
import { Provider } from "react-redux";
import { AnyAction, Store } from "redux";
// import { applyMiddleware, compose, createStore } from "redux";
import { createLogger } from "redux-logger";
import thunk from "redux-thunk";
import "./App.css";
import VisualisationComponent from "./visualisation.component";

//
// const VisualisationComponent = React.lazy(
// () => import("./visualisation.component")
// );

const history = createBrowserHistory();
const middleware = [thunk, routerMiddleware(history)];
if (process.env.NODE_ENV === "development") {
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
const logger = (createLogger as any)();
middleware.push(logger);
log.setDefaultLevel(log.levels.DEBUG);
} else {
log.setDefaultLevel(log.levels.ERROR);
}

// /* eslint-disable no-underscore-dangle, @typescript-eslint/no-explicit-any */
// const composeEnhancers =
// (window as any).__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
// /* eslint-enable */

// Create the store
// const store = createStore(
// AppReducer(history),
// composeEnhancers(applyMiddleware(...middleware))
// );

const registerRouteAction = {
type: "frontend:api:register_route",
payload: {
section: "Test",
// TODO: Remove this, this should be declared from parent
link: "/runs/:runId/visualisations/three-obj/data",
plugin: "three-obj",
displayName: "3D Graph",
},
};

// Dispatch the register route event.
document.dispatchEvent(
new CustomEvent(microFrontendMessageId, {
detail: registerRouteAction,
})
);

interface AppState {
hasError: boolean;
store: Store<any, AnyAction>;
}

/* eslint-disable @typescript-eslint/no-explicit-any */
class App extends React.Component<{ dev?: boolean }, AppState> {
/* eslint-disable @typescript-eslint/no-explicit-any */
public constructor(props: { dev?: boolean } & AppState) {
super(props);
this.state = { hasError: false, store: props.store };
console.log("Props: ", props);
}

public componentDidCatch(error: Error | null): void {
this.setState({ ...this.state, hasError: true });
log.error(`three-obj failed with error: ${error}`);
}

public render(): React.ReactNode {
if (!this.props.dev) {
if (this.state.hasError) {
return (
<div className="error">
An error occurred when loading the plugin.
</div>
);
} else if (!this.state.store) {
return (
<div className="error">Did not receive a store from the parent.</div>
);
} else {
return (
<Provider store={this.state.store}>
<VisualisationComponent />
</Provider>
);
}
} else {
return <VisualisationComponent />;
}
}
}

export default App;
13 changes: 13 additions & 0 deletions packages/three-obj/src/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
body {
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}

code {
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
monospace;
}
Loading