Skip to content
This repository has been archived by the owner on Jul 3, 2023. It is now read-only.

[OODT-1001] Add initial code for OpsUI React Components by brenopolanski #93

Merged
merged 2 commits into from
May 14, 2019
Merged
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
17 changes: 17 additions & 0 deletions react-components/react-oodt-app/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# http://editorconfig.org

root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
max_line_length = 80

[*.md]
trim_trailing_whitespace = false
23 changes: 23 additions & 0 deletions react-components/react-oodt-app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

package-lock.json

npm-debug.log*
yarn-debug.log*
yarn-error.log*
33 changes: 33 additions & 0 deletions react-components/react-oodt-app/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# React OODT App Sample

---

> :warning: Not Official!

---

## Requirements

- [Node.js](https://nodejs.org/en/download/) v6.0.0 or higher
- NPM (v3.0.0+ recommended) (this comes with Node.js)

## Quick Start

```bash
# Install dependencies for server
npm install

# Install dependencies for client
npm run client-install

# Run the client & server with concurrently
npm run dev

# Run the Express server only
npm run server

# Run the React client only
npm run client

# Server runs on http://localhost:9999 and client on http://localhost:3000
```
23 changes: 23 additions & 0 deletions react-components/react-oodt-app/app-sample/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

package-lock.json

npm-debug.log*
yarn-debug.log*
yarn-error.log*
2,567 changes: 2,567 additions & 0 deletions react-components/react-oodt-app/app-sample/README.md

Large diffs are not rendered by default.

32 changes: 32 additions & 0 deletions react-components/react-oodt-app/app-sample/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "app-sample",
"version": "0.1.0",
"proxy": "http://localhost:9999",
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"precommit": "lint-staged"
},
"lint-staged": {
"src/**/*.{js,jsx,json}": [
"prettier --single-quote --write",
"git add"
]
},
"dependencies": {
"isomorphic-unfetch": "^3.0.0",
"react": "^16.2.0",
"react-dom": "^16.2.0",
"react-oodt-plugin-sample": "^0.1.4",
"ts-react-json-table": "^0.1.1",
"yup": "^0.26.6"
},
"devDependencies": {
"husky": "^0.14.3",
"lint-staged": "^7.1.2",
"prettier": "^1.12.1",
"react-scripts": "1.0.17"
}
}
Binary file not shown.
40 changes: 40 additions & 0 deletions react-components/react-oodt-app/app-sample/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="theme-color" content="#000000">
<!--
manifest.json provides metadata used when your web app is added to the
homescreen on Android. 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>
<noscript>
You need to enable JavaScript to run this app.
</noscript>
<div id="root"></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>
15 changes: 15 additions & 0 deletions react-components/react-oodt-app/app-sample/public/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"short_name": "React App",
"name": "Create React App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
44 changes: 44 additions & 0 deletions react-components/react-oodt-app/app-sample/src/App.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
.App {
text-align: center;
}

.App-logo {
height: 40vmin;
animation: App-logo-spin infinite 20s linear;
}

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

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

@keyframes App-logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}

table {
border-spacing: 0;
}

td {
padding: 2px 5px;
}

.jsonOdd {
background: #eee;
}
33 changes: 33 additions & 0 deletions react-components/react-oodt-app/app-sample/src/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import React, { Component } from 'react';
import OODTPluginSample from './components/react-oodt-plugin-sample';
// import OODTPluginSample from 'react-oodt-plugin-sample';
import './App.css';

class App extends Component {
render() {
return (
<div className="App">
<OODTPluginSample productId="ce4380c5-d0d2-11e8-89ca-971c29fc9f21" />
</div>
);
}
}

export default App;
26 changes: 26 additions & 0 deletions react-components/react-oodt-app/app-sample/src/App.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';

it('renders without crashing', () => {
const div = document.createElement('div');
ReactDOM.render(<App />, div);
ReactDOM.unmountComponentAtNode(div);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import React, { Component } from 'react';
import fetch from 'isomorphic-unfetch';
import { number, object, string } from 'yup';
import JsonTable from 'ts-react-json-table';

const schema = object().shape({
productId: string().required(),
interval: number()
});

export default class OODTSample extends Component {
static defaultProps = {
interval: 1000 * 60 * 5
};

state = {
product: {},
error: false,
loading: true
};

componentDidMount() {
schema
.validate(this.props)
.then(() => this.fetchData())
.catch(error => {
console.error(`${error.name} @ ${this.constructor.name}`, error.errors);
this.setState({ error: true, loading: false });
});
}

componentWillUnmount() {
clearTimeout(this.timeout);
}

async fetchData() {
const { productId, interval } = this.props;

try {
const res = await fetch(
// `http://46.4.26.22:8012/fmprod/jaxrs/product?productId=${productId}`
'http://localhost:9999/oodt' // fixed the cors
);
const json = await res.json();

this.setState({
product: json.product,
error: false,
loading: false
});
} catch (error) {
this.setState({ error: true, loading: false });
} finally {
this.timeout = setTimeout(() => this.fetchData(), interval);
}
}

render() {
const { product, error, loading } = this.state;

return loading ? (
<div>Loading...</div>
) : error ? (
<div>Error :(</div>
) : (
<JsonTable rows={[product]} />
);
}
}
14 changes: 14 additions & 0 deletions react-components/react-oodt-app/app-sample/src/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
body {
margin: 0;
padding: 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