NavStore.ts 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. import _ from 'lodash';
  2. import { types, getEnv } from 'mobx-state-tree';
  3. import { NavItem } from './NavItem';
  4. import { ITeam } from '../TeamsStore/TeamsStore';
  5. export const NavStore = types
  6. .model('NavStore', {
  7. main: types.maybe(NavItem),
  8. node: types.maybe(NavItem),
  9. })
  10. .actions(self => ({
  11. load(...args) {
  12. let children = getEnv(self).navTree;
  13. let main, node;
  14. let parents = [];
  15. for (let id of args) {
  16. node = children.find(el => el.id === id);
  17. if (!node) {
  18. throw new Error(`NavItem with id ${id} not found`);
  19. }
  20. children = node.children;
  21. parents.push(node);
  22. }
  23. main = parents[parents.length - 2];
  24. if (main.children) {
  25. for (let item of main.children) {
  26. item.active = false;
  27. if (item.url === node.url) {
  28. item.active = true;
  29. }
  30. }
  31. }
  32. self.main = NavItem.create(main);
  33. self.node = NavItem.create(node);
  34. },
  35. initFolderNav(folder: any, activeChildId: string) {
  36. let main = {
  37. icon: 'fa fa-folder-open',
  38. id: 'manage-folder',
  39. subTitle: 'Manage folder dashboards & permissions',
  40. url: '',
  41. text: folder.title,
  42. breadcrumbs: [{ title: 'Dashboards', url: 'dashboards' }],
  43. children: [
  44. {
  45. active: activeChildId === 'manage-folder-dashboards',
  46. icon: 'fa fa-fw fa-th-large',
  47. id: 'manage-folder-dashboards',
  48. text: 'Dashboards',
  49. url: folder.url,
  50. },
  51. {
  52. active: activeChildId === 'manage-folder-permissions',
  53. icon: 'fa fa-fw fa-lock',
  54. id: 'manage-folder-permissions',
  55. text: 'Permissions',
  56. url: `${folder.url}/permissions`,
  57. },
  58. {
  59. active: activeChildId === 'manage-folder-settings',
  60. icon: 'fa fa-fw fa-cog',
  61. id: 'manage-folder-settings',
  62. text: 'Settings',
  63. url: `${folder.url}/settings`,
  64. },
  65. ],
  66. };
  67. self.main = NavItem.create(main);
  68. },
  69. initDatasourceEditNav(ds: any, plugin: any, currentPage: string) {
  70. let title = 'New';
  71. let subTitle = `Type: ${plugin.name}`;
  72. if (ds.id) {
  73. title = ds.name;
  74. }
  75. let main = {
  76. img: plugin.info.logos.large,
  77. id: 'ds-edit-' + plugin.id,
  78. subTitle: subTitle,
  79. url: '',
  80. text: title,
  81. breadcrumbs: [{ title: 'Data Sources', url: 'datasources' }],
  82. children: [
  83. {
  84. active: currentPage === 'datasource-settings',
  85. icon: 'fa fa-fw fa-sliders',
  86. id: 'datasource-settings',
  87. text: 'Settings',
  88. url: `datasources/edit/${ds.id}`,
  89. },
  90. ],
  91. };
  92. const hasDashboards = _.find(plugin.includes, { type: 'dashboard' }) !== undefined;
  93. if (hasDashboards && ds.id) {
  94. main.children.push({
  95. active: currentPage === 'datasource-dashboards',
  96. icon: 'fa fa-fw fa-th-large',
  97. id: 'datasource-dashboards',
  98. text: 'Dashboards',
  99. url: `datasources/edit/${ds.id}/dashboards`,
  100. });
  101. }
  102. self.main = NavItem.create(main);
  103. },
  104. initTeamPage(team: ITeam, tab: string, isSyncEnabled: boolean) {
  105. let main = {
  106. img: team.avatarUrl,
  107. id: 'team-' + team.id,
  108. subTitle: 'Manage members & settings',
  109. url: '',
  110. text: team.name,
  111. breadcrumbs: [{ title: 'Teams', url: 'org/teams' }],
  112. children: [
  113. {
  114. active: tab === 'members',
  115. icon: 'gicon gicon-team',
  116. id: 'team-members',
  117. text: 'Members',
  118. url: `org/teams/edit/${team.id}/members`,
  119. },
  120. {
  121. active: tab === 'settings',
  122. icon: 'fa fa-fw fa-sliders',
  123. id: 'team-settings',
  124. text: 'Settings',
  125. url: `org/teams/edit/${team.id}/settings`,
  126. },
  127. ],
  128. };
  129. if (isSyncEnabled) {
  130. main.children.splice(1, 0, {
  131. active: tab === 'groupsync',
  132. icon: 'fa fa-fw fa-refresh',
  133. id: 'team-settings',
  134. text: 'External group sync',
  135. url: `org/teams/edit/${team.id}/groupsync`,
  136. });
  137. }
  138. self.main = NavItem.create(main);
  139. },
  140. }));