panel_editor_tab.ts 948 B

1234567891011121314151617181920212223242526272829303132333435363738
  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. index: '=',
  11. },
  12. directive: scope => {
  13. const pluginId = scope.ctrl.pluginId;
  14. const tabName = scope.editorTab.title.toLowerCase().replace(' ', '-');
  15. if (directiveCache[pluginId]) {
  16. if (directiveCache[pluginId][tabName]) {
  17. return directiveCache[pluginId][tabName];
  18. }
  19. } else {
  20. directiveCache[pluginId] = [];
  21. }
  22. const result = {
  23. fn: () => scope.editorTab.directiveFn(),
  24. name: `panel-editor-tab-${pluginId}${tabName}`,
  25. };
  26. directiveCache[pluginId][tabName] = result;
  27. return result;
  28. },
  29. });
  30. }
  31. directiveModule.directive('panelEditorTab', panelEditorTab);