summaryrefslogtreecommitdiffstats
path: root/src/app/configurableViews/ConfigurableViewManager.js
blob: 71cc6cfdcfdf5b04544901395c65f220b0984e98 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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;
}