sidebarPanelStore.tsx 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import Reflux from 'reflux';
  2. import SidebarPanelActions from 'sentry/actions/sidebarPanelActions';
  3. import {SidebarPanelKey} from 'sentry/components/sidebar/types';
  4. import {CommonStoreInterface} from './types';
  5. type ActivePanelType = SidebarPanelKey | '';
  6. type SidebarPanelStoreInterface = CommonStoreInterface<ActivePanelType> & {
  7. activePanel: ActivePanelType;
  8. onActivatePanel(panel: SidebarPanelKey): void;
  9. onTogglePanel(panel: SidebarPanelKey): void;
  10. onHidePanel(): void;
  11. };
  12. const storeConfig: Reflux.StoreDefinition & SidebarPanelStoreInterface = {
  13. activePanel: '',
  14. init() {
  15. this.listenTo(SidebarPanelActions.activatePanel, this.onActivatePanel);
  16. this.listenTo(SidebarPanelActions.hidePanel, this.onHidePanel);
  17. this.listenTo(SidebarPanelActions.togglePanel, this.onTogglePanel);
  18. },
  19. onActivatePanel(panel: SidebarPanelKey) {
  20. this.activePanel = panel;
  21. this.trigger(this.activePanel);
  22. },
  23. onTogglePanel(panel: SidebarPanelKey) {
  24. if (this.activePanel === panel) {
  25. this.onHidePanel();
  26. } else {
  27. this.onActivatePanel(panel);
  28. }
  29. },
  30. onHidePanel() {
  31. this.activePanel = '';
  32. this.trigger(this.activePanel);
  33. },
  34. getState() {
  35. return this.activePanel;
  36. },
  37. };
  38. /**
  39. * This store is used to hold local user preferences
  40. * Side-effects (like reading/writing to cookies) are done in associated actionCreators
  41. */
  42. const SidebarPanelStore = Reflux.createStore(storeConfig) as Reflux.Store &
  43. SidebarPanelStoreInterface;
  44. export default SidebarPanelStore;