panel_editor_tab.ts 930 B

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