sidebarPanelStore.tsx 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import {createStore} from 'reflux';
  2. import {SidebarPanelKey} from 'sentry/components/sidebar/types';
  3. import {CommonStoreDefinition} from './types';
  4. type ActivePanelType = SidebarPanelKey | '';
  5. interface SidebarPanelStoreDefinition extends CommonStoreDefinition<ActivePanelType> {
  6. activatePanel(panel: SidebarPanelKey): void;
  7. activePanel: ActivePanelType;
  8. hidePanel(): void;
  9. togglePanel(panel: SidebarPanelKey): void;
  10. }
  11. const storeConfig: SidebarPanelStoreDefinition = {
  12. activePanel: '',
  13. activatePanel(panel: SidebarPanelKey) {
  14. this.activePanel = panel;
  15. this.trigger(this.activePanel);
  16. },
  17. togglePanel(panel: SidebarPanelKey) {
  18. if (this.activePanel === panel) {
  19. this.hidePanel();
  20. } else {
  21. this.activatePanel(panel);
  22. }
  23. },
  24. hidePanel() {
  25. this.activePanel = '';
  26. this.trigger(this.activePanel);
  27. },
  28. getState() {
  29. return this.activePanel;
  30. },
  31. };
  32. /**
  33. * This store is used to hold local user preferences
  34. * Side-effects (like reading/writing to cookies) are done in associated actionCreators
  35. */
  36. const SidebarPanelStore = createStore(storeConfig);
  37. export default SidebarPanelStore;