sidebarPanelStore.tsx 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import {createStore} from 'reflux';
  2. import type {SidebarPanelKey} from 'sentry/components/sidebar/types';
  3. import type {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. init() {
  14. // XXX: Do not use `this.listenTo` in this store. We avoid usage of reflux
  15. // listeners due to their leaky nature in tests.
  16. },
  17. activatePanel(panel: SidebarPanelKey) {
  18. this.activePanel = panel;
  19. this.trigger(this.activePanel);
  20. },
  21. togglePanel(panel: SidebarPanelKey) {
  22. if (this.activePanel === panel) {
  23. this.hidePanel();
  24. } else {
  25. this.activatePanel(panel);
  26. }
  27. },
  28. hidePanel() {
  29. this.activePanel = '';
  30. this.trigger(this.activePanel);
  31. },
  32. getState() {
  33. return this.activePanel;
  34. },
  35. };
  36. /**
  37. * This store is used to hold local user preferences
  38. * Side-effects (like reading/writing to cookies) are done in associated actionCreators
  39. */
  40. const SidebarPanelStore = createStore(storeConfig);
  41. export default SidebarPanelStore;