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

Component registry - support both pure function component and class components #3941

Merged
merged 1 commit into from May 15, 2018
Merged

Component registry - support both pure function component and class components #3941

merged 1 commit into from May 15, 2018

Conversation

himdel
Copy link
Contributor

@himdel himdel commented May 15, 2018

previously, adding a class component had to be done via addReact('name', (props) => <Name {...props} />), otherwise, it would fail trying to "call" the class with props

this change makes it possible to treat both kinds of react components the same way, and register them directly as addReact('name', Name)

Cc @martinpovolny , @Hyperkid123

…omponents

previously, adding a class component had to be done via `addReact('name', (props) => <Name {...props} />)`, otherwise, it would fail trying to "call" the class with props

this change makes it possible to treat both kinds of react components the same way, and register them directly as `addReact('name', Name)`
@himdel
Copy link
Contributor Author

himdel commented May 15, 2018

Testing..

diff --git a/app/javascript/miq-component/helpers.js b/app/javascript/miq-component/helpers.js
index 709e9551b..e8c042e97 100644
--- a/app/javascript/miq-component/helpers.js
+++ b/app/javascript/miq-component/helpers.js
@@ -14,3 +14,27 @@ export function componentFactory(blueprintName, selector, props) {
   const allProps = { ...element.dataset, ...props };
   ManageIQ.component.newInstance(blueprintName, allProps, element);
 }
+
+import React from 'react';
+import ReactDOM from 'react-dom';
+
+class Contacts extends React.Component {
+  constructor(props) {
+    super(props);
+  }
+  render() {
+    return (
+      <div>Contacts</div>
+    );
+  }
+}
+
+let Magic = (props) => (<div>Magic</div>);
+
+window.magic = function() {
+  addReact('Contacts', Contacts);
+  addReact('Magic', Magic);
+
+  ManageIQ.component.componentFactory('Contacts', '#foo')
+  ManageIQ.component.componentFactory('Magic', '#bar')
+}
diff --git a/app/views/dashboard/show.html.haml b/app/views/dashboard/show.html.haml
index a07581316..81a445039 100644
--- a/app/views/dashboard/show.html.haml
+++ b/app/views/dashboard/show.html.haml
@@ -19,3 +19,9 @@
 - if WidgetPresenter.chart_data.present?
   :javascript
     ManageIQ.charts.chartData = #{{"widgetchart" => WidgetPresenter.chart_data}.to_json.html_safe};
+
+
+#foo
+#bar
+:javascript
+  magic()

(without this, Magic will work, but Contacts won't)

@miq-bot
Copy link
Member

miq-bot commented May 15, 2018

Checked commit https://github.com/himdel/manageiq-ui-classic/commit/574e8ca26bf20227c4b8cbdf05231c76727ca6cb with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0
0 files checked, 0 offenses detected
Everything looks fine. 🍰

@martinpovolny martinpovolny added this to the Sprint 86 Ending May 21, 2018 milestone May 15, 2018
@martinpovolny martinpovolny merged commit 6ae6bf2 into ManageIQ:master May 15, 2018
@himdel himdel deleted the registry-component-class branch May 15, 2018 15:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants