navModel.ts 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import { NavModel, NavModelItem } from '@grafana/data';
  2. import { contextSrv } from 'app/core/services/context_srv';
  3. import { AccessControlAction, FolderDTO } from 'app/types';
  4. export function buildNavModel(folder: FolderDTO): NavModelItem {
  5. const model = {
  6. icon: 'folder',
  7. id: 'manage-folder',
  8. subTitle: 'Manage folder dashboards and permissions',
  9. url: '',
  10. text: folder.title,
  11. breadcrumbs: [{ title: 'Dashboards', url: 'dashboards' }],
  12. children: [
  13. {
  14. active: false,
  15. icon: 'apps',
  16. id: `folder-dashboards-${folder.uid}`,
  17. text: 'Dashboards',
  18. url: folder.url,
  19. },
  20. ],
  21. };
  22. model.children.push({
  23. active: false,
  24. icon: 'library-panel',
  25. id: `folder-library-panels-${folder.uid}`,
  26. text: 'Panels',
  27. url: `${folder.url}/library-panels`,
  28. });
  29. if (contextSrv.hasPermission(AccessControlAction.AlertingRuleRead)) {
  30. model.children.push({
  31. active: false,
  32. icon: 'bell',
  33. id: `folder-alerting-${folder.uid}`,
  34. text: 'Alert rules',
  35. url: `${folder.url}/alerting`,
  36. });
  37. }
  38. if (folder.canAdmin) {
  39. model.children.push({
  40. active: false,
  41. icon: 'lock',
  42. id: `folder-permissions-${folder.uid}`,
  43. text: 'Permissions',
  44. url: `${folder.url}/permissions`,
  45. });
  46. }
  47. if (folder.canSave) {
  48. model.children.push({
  49. active: false,
  50. icon: 'cog',
  51. id: `folder-settings-${folder.uid}`,
  52. text: 'Settings',
  53. url: `${folder.url}/settings`,
  54. });
  55. }
  56. return model;
  57. }
  58. export function getLoadingNav(tabIndex: number): NavModel {
  59. const main = buildNavModel({
  60. id: 1,
  61. uid: 'loading',
  62. title: 'Loading',
  63. url: 'url',
  64. canSave: true,
  65. canEdit: true,
  66. canAdmin: true,
  67. canDelete: true,
  68. version: 0,
  69. });
  70. main.children![tabIndex].active = true;
  71. return {
  72. main: main,
  73. node: main.children![tabIndex],
  74. };
  75. }