index.ts 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. import { config, featureEnabled, reportExperimentView } from '@grafana/runtime';
  2. import { contextSrv } from 'app/core/core';
  3. import { extraRoutes } from 'app/routes/routes';
  4. import { addRootReducer } from 'app/store/configureStore';
  5. import { AccessControlAction, DashboardRoutes } from 'app/types';
  6. import { initEnterpriseAdmin } from './admin';
  7. import { initPageBanners } from './banners';
  8. import DataSourceCache from './caching/DataSourceCache';
  9. import DataSourceCacheUpgradePage from './caching/UpgradePage';
  10. import dataSourceCacheReducers from './caching/state/reducers';
  11. import { initLicenseWarnings } from './licensing';
  12. import LicensePage from './licensing/LicensePage';
  13. import { initMetaAnalytics } from './meta-analytics';
  14. import DataSourceInsights from './meta-analytics/DataSourceInsights/DataSourceInsights';
  15. import DataSourceInsightsUpgradePage from './meta-analytics/DataSourceInsights/UpgradePage';
  16. import metaAnalyticsReducers from './meta-analytics/state/reducers';
  17. import DatasourcePermissions from './permissions/AccessControlDataSourcePermissions';
  18. import LegacyDataSourcePermissions from './permissions/DataSourcePermissions';
  19. import DatasourcePermissionsUpgradePage from './permissions/UpgradePage';
  20. import dataSourcePermissionReducers from './permissions/state/reducers';
  21. import { initRecordedQueries } from './recorded-queries';
  22. import { RecordedQueriesConfig } from './recorded-queries/RecordedQueriesConfig';
  23. import { WriteTargetConfig } from './recorded-queries/WriteTargetConfig';
  24. import { recordedQueryReducer } from './recorded-queries/state/reducers';
  25. import { initReporting, reportSteps } from './reports';
  26. import CSVExportPage from './reports/CSVExportPage';
  27. import Confirm from './reports/ReportForm/Confirm';
  28. import SelectDashboard from './reports/ReportForm/SelectDashboard';
  29. import ReportsList from './reports/ReportsListPage';
  30. import ReportsSettings from './reports/ReportsSettingsPage';
  31. import ReportsUpgrade from './reports/ReportsUpgradePage';
  32. import { BASE_URL as REPORTS_BASE } from './reports/constants';
  33. import reportsReducers from './reports/state/reducers';
  34. import { AccessControlAction as EnterpriseAccessControlAction } from './types';
  35. import { buildExperimentID, ExperimentGroup } from './utils/featureHighlights';
  36. import { initWhitelabeling } from './whitelabeling';
  37. export function addExtensionReducers() {
  38. if (featureEnabled('dspermissions')) {
  39. addRootReducer(dataSourcePermissionReducers);
  40. }
  41. if (featureEnabled('caching')) {
  42. addRootReducer(dataSourceCacheReducers);
  43. }
  44. if (featureEnabled('reports')) {
  45. addRootReducer(reportsReducers);
  46. }
  47. if (featureEnabled('analytics')) {
  48. addRootReducer(metaAnalyticsReducers);
  49. }
  50. if (featureEnabled('recordedqueries')) {
  51. addRootReducer(recordedQueryReducer);
  52. }
  53. }
  54. function initEnterprise() {
  55. const highlightsEnabled = config.featureToggles.featureHighlights;
  56. initLicenseWarnings();
  57. initReporting();
  58. initMetaAnalytics();
  59. if (featureEnabled('whitelabeling')) {
  60. initWhitelabeling();
  61. }
  62. if (featureEnabled('recordedqueries')) {
  63. initRecordedQueries();
  64. }
  65. if (featureEnabled('admin')) {
  66. initEnterpriseAdmin();
  67. }
  68. // DataSources components
  69. if (featureEnabled('caching')) {
  70. extraRoutes.push({
  71. path: '/datasources/edit/:uid/cache',
  72. component: DataSourceCache,
  73. });
  74. } else if (highlightsEnabled) {
  75. extraRoutes.push({
  76. path: '/datasources/edit/:uid/cache/upgrade',
  77. component: DataSourceCacheUpgradePage,
  78. });
  79. }
  80. if (featureEnabled('analytics')) {
  81. extraRoutes.push({
  82. path: '/datasources/edit/:uid/insights',
  83. component: DataSourceInsights as any,
  84. });
  85. } else if (highlightsEnabled) {
  86. extraRoutes.push({
  87. path: '/datasources/edit/:uid/insights/upgrade',
  88. component: DataSourceInsightsUpgradePage,
  89. });
  90. }
  91. const permissionsPath = '/datasources/edit/:uid/permissions';
  92. if (featureEnabled('dspermissions') && contextSrv.hasPermission(AccessControlAction.DataSourcesPermissionsRead)) {
  93. if (config.rbacEnabled) {
  94. extraRoutes.push({
  95. path: permissionsPath,
  96. component: DatasourcePermissions,
  97. });
  98. } else {
  99. extraRoutes.push({
  100. path: permissionsPath,
  101. component: LegacyDataSourcePermissions,
  102. });
  103. }
  104. } else if (highlightsEnabled) {
  105. extraRoutes.push({
  106. path: permissionsPath + '/upgrade',
  107. component: DatasourcePermissionsUpgradePage,
  108. });
  109. }
  110. if (config.reporting?.enabled) {
  111. if (featureEnabled('reports')) {
  112. extraRoutes.push(
  113. {
  114. path: REPORTS_BASE,
  115. component: ReportsList,
  116. },
  117. {
  118. path: `${REPORTS_BASE}/edit/:id`,
  119. component: Confirm,
  120. },
  121. {
  122. path: `${REPORTS_BASE}/settings`,
  123. component: ReportsSettings,
  124. },
  125. {
  126. path: '/d-csv/:uid',
  127. pageClass: 'dashboard-solo',
  128. routeName: DashboardRoutes.Normal,
  129. component: CSVExportPage,
  130. }
  131. );
  132. } else if (highlightsEnabled) {
  133. extraRoutes.push({
  134. path: REPORTS_BASE,
  135. component: ReportsUpgrade,
  136. });
  137. }
  138. if (featureEnabled('reports.creation')) {
  139. extraRoutes.push({
  140. path: `${REPORTS_BASE}/new`,
  141. component: SelectDashboard,
  142. });
  143. for (const step of reportSteps) {
  144. extraRoutes.push({ path: `${REPORTS_BASE}/${step.id}`, component: step.component });
  145. }
  146. }
  147. }
  148. const showRecordQuery = featureEnabled('recordedqueries') && config?.recordedQueries?.enabled;
  149. if (contextSrv.isEditor && showRecordQuery) {
  150. extraRoutes.push(
  151. ...[
  152. {
  153. path: '/recorded-queries',
  154. component: RecordedQueriesConfig,
  155. },
  156. {
  157. path: '/recorded-queries/write-target',
  158. component: WriteTargetConfig,
  159. },
  160. ]
  161. );
  162. }
  163. }
  164. // initUnlicensed initialized features which are defined in Enterprise but
  165. // should be available when running without a license.
  166. function initUnlicensed() {
  167. initPageBanners();
  168. extraRoutes.push({
  169. path: '/admin/licensing',
  170. roles: () =>
  171. contextSrv.evaluatePermission(
  172. () => ['ServerAdmin'],
  173. [EnterpriseAccessControlAction.LicensingRead, AccessControlAction.ActionServerStatsRead]
  174. ),
  175. component: LicensePage,
  176. });
  177. // Report experimentation views
  178. if (contextSrv.isSignedIn && config.licenseInfo.stateInfo !== 'Licensed') {
  179. reportExperimentView(
  180. buildExperimentID(),
  181. config.featureToggles.featureHighlights ? ExperimentGroup.Test : ExperimentGroup.Control,
  182. ''
  183. );
  184. }
  185. }
  186. export function init() {
  187. initUnlicensed();
  188. initEnterprise();
  189. }