navModel.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import _ from 'lodash';
  2. import { DataSource, PluginMeta, NavModel } from 'app/types';
  3. export function buildNavModel(ds: DataSource, plugin: PluginMeta, currentPage: string): NavModel {
  4. let title = 'New';
  5. const subTitle = `Type: ${plugin.name}`;
  6. if (ds.id) {
  7. title = ds.name;
  8. }
  9. const main = {
  10. img: plugin.info.logos.large,
  11. id: 'ds-edit-' + plugin.id,
  12. subTitle: subTitle,
  13. url: '',
  14. text: title,
  15. breadcrumbs: [{ title: 'Data Sources', url: 'datasources' }],
  16. children: [
  17. {
  18. active: currentPage === 'datasource-settings',
  19. icon: 'fa fa-fw fa-sliders',
  20. id: 'datasource-settings',
  21. text: 'Settings',
  22. url: `datasources/edit/${ds.id}`,
  23. },
  24. ],
  25. };
  26. const hasDashboards = _.find(plugin.includes, { type: 'dashboard' }) !== undefined;
  27. if (hasDashboards && ds.id) {
  28. main.children.push({
  29. active: currentPage === 'datasource-dashboards',
  30. icon: 'fa fa-fw fa-th-large',
  31. id: 'datasource-dashboards',
  32. text: 'Dashboards',
  33. url: `datasources/edit/${ds.id}/dashboards`,
  34. });
  35. }
  36. return {
  37. main: main,
  38. node: _.find(main.children, { active: true }),
  39. };
  40. }