increasing test coverage to 20 percent
[aai/sparky-fe.git] / src / app / configurableViews / ConfigurableViewManager.js
diff --git a/src/app/configurableViews/ConfigurableViewManager.js b/src/app/configurableViews/ConfigurableViewManager.js
new file mode 100644 (file)
index 0000000..71cc6cf
--- /dev/null
@@ -0,0 +1,27 @@
+import React from 'react';
+import {
+  Route
+} from 'react-router-dom';
+import { fetchConfigurableViewRequest } from 'app/networking/NetworkCalls';
+
+export function getConfigurableRoutes(config, components) {
+  let routes = [];
+  if (config && Object.keys(config).length > 0 && components && Object.keys(components).length > 0) {
+    config.layouts.forEach( (viewConfig) => {
+      let ConfigurableView = components[viewConfig.viewType];
+      if (ConfigurableView) {
+        routes.push(
+          <Route key={viewConfig.id} path={`/${viewConfig.id}`} render={ () => {
+            return (
+              <ConfigurableView
+                config={ viewConfig }
+                networkAPI={ fetchConfigurableViewRequest }/>
+            );
+          }}/>
+        );
+      }
+    });
+  }
+
+  return routes;
+}