panel_editor_tab.ts 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import angular from 'angular';
  2. const directiveModule = angular.module('grafana.directives');
  3. const directiveCache: any = {};
  4. /** @ngInject */
  5. function panelEditorTab(dynamicDirectiveSrv: any) {
  6. return dynamicDirectiveSrv.create({
  7. scope: {
  8. ctrl: '=',
  9. editorTab: '=',
  10. },
  11. directive: (scope: any) => {
  12. const pluginId = scope.ctrl.pluginId;
  13. const tabName = scope.editorTab.title
  14. .toLowerCase()
  15. .replace(' ', '-')
  16. .replace('&', '')
  17. .replace(' ', '')
  18. .replace(' ', '-');
  19. if (directiveCache[pluginId]) {
  20. if (directiveCache[pluginId][tabName]) {
  21. return directiveCache[pluginId][tabName];
  22. }
  23. } else {
  24. directiveCache[pluginId] = [];
  25. }
  26. const result = {
  27. fn: () => scope.editorTab.directiveFn(),
  28. name: `panel-editor-tab-${pluginId}${tabName}`,
  29. };
  30. directiveCache[pluginId][tabName] = result;
  31. return result;
  32. },
  33. });
  34. }
  35. directiveModule.directive('panelEditorTab', panelEditorTab);