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

[POC] Use readux and extensible component together #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
52 changes: 52 additions & 0 deletions app/javascript/middleware-new-form/formUpdate.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import React from 'react';
import {connect} from 'react-redux';
import {bindActionCreators} from 'redux';

class FormUpdate extends React.Component {
constructor(props) {
super(props);
console.log(this);
}

componentDidMount() {
this.updateValue('');
};

updateValue(value) {
this.props.updateForm({reactThingy: value});
}

render(){
return (
<div>
<label className="col-md-2 control-label" htmlFor="react-thingy">React thingy</label>
<div className="col-md-8">
<input id="react-thingy"
type="text"
className="form-control"
value={this.props.formObject.reactThingy}
onChange={event => this.updateValue(event.target.value)}/>
</div>
</div>
)
}
}

function mapStateToProps(state, ownProps) {
return {
formObject: state.providers.middleware.hawkular.newProvider
}
}

function mapDispatchToProps(dispatch) {
return {
updateForm: (payload) => {
dispatch({type: 'UPDATE_FORM', payload: payload});
}
}
}

export default connect(
mapStateToProps,
mapDispatchToProps
)(FormUpdate);
16 changes: 16 additions & 0 deletions app/javascript/middleware-new-form/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import ReactDOM from 'react-dom';
import React from 'react';
import FormUpdate from './formUpdate';
import {Provider} from 'react-redux';

var subscriber = ManageIQ.extensions.subscribe('new-provider-hawkular');
subscriber.with(createNewFormFields);

function createNewFormFields(component: any) {
let element = component.render.newFieldsElement((element) => {
element && ReactDOM.render(
<Provider store={ManageIQ.redux.store}>
<FormUpdate/>
</Provider>, element);
});
}
1 change: 1 addition & 0 deletions app/javascript/packs/middleware-new-form-common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require('../middleware-new-form');
18 changes: 18 additions & 0 deletions bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "miq_plugin_example",
"homepage": "https://github.com/karelhala/miq_plugin_example",
"authors": [
"Karel Hala <[email protected]>"
],
"description": "",
"main": "",
"license": "MIT",
"private": true,
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"test",
"tests"
]
}
32 changes: 32 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "miq_plugin_example",
"version": "1.0.0",
"description": "Short description and motivation.",
"main": "index.js",
"directories": {
"test": "test"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/karelhala/miq_plugin_example.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/karelhala/miq_plugin_example/issues"
},
"homepage": "https://github.com/karelhala/miq_plugin_example#readme",
"dependencies": {
"@angular/platform-browser": "^4.3.3",
"@manageiq/ui-components": "0.0.20",
"react": "^15.6.1",
"react-dom": "^15.6.1",
"react-redux": "^5.0.6",
"redux": "^3.7.2",
"rxjs": "^5.4.2",
"zone.js": "^0.8.16"
}
}
10 changes: 10 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"outDir": "./dist/",
"sourceMap": true,
"noImplicitAny": true,
"module": "commonjs",
"target": "es5",
"jsx": "react"
}
}