sidebarPanelStore.tsx 1.2 KB

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