1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- import {createStore, Store, StoreDefinition} from 'reflux';
- import SidebarPanelActions from 'sentry/actions/sidebarPanelActions';
- import {SidebarPanelKey} from 'sentry/components/sidebar/types';
- import {makeSafeRefluxStore, SafeStoreDefinition} from 'sentry/utils/makeSafeRefluxStore';
- import {CommonStoreInterface} from './types';
- type ActivePanelType = SidebarPanelKey | '';
- type SidebarPanelStoreInterface = CommonStoreInterface<ActivePanelType> & {
- activePanel: ActivePanelType;
- onActivatePanel(panel: SidebarPanelKey): void;
- onHidePanel(): void;
- onTogglePanel(panel: SidebarPanelKey): void;
- };
- const storeConfig: StoreDefinition & SidebarPanelStoreInterface & SafeStoreDefinition = {
- activePanel: '',
- unsubscribeListeners: [],
- init() {
- this.unsubscribeListeners.push(
- this.listenTo(SidebarPanelActions.activatePanel, this.onActivatePanel)
- );
- this.unsubscribeListeners.push(
- this.listenTo(SidebarPanelActions.hidePanel, this.onHidePanel)
- );
- this.unsubscribeListeners.push(
- this.listenTo(SidebarPanelActions.togglePanel, this.onTogglePanel)
- );
- },
- onActivatePanel(panel: SidebarPanelKey) {
- this.activePanel = panel;
- this.trigger(this.activePanel);
- },
- onTogglePanel(panel: SidebarPanelKey) {
- if (this.activePanel === panel) {
- this.onHidePanel();
- } else {
- this.onActivatePanel(panel);
- }
- },
- onHidePanel() {
- this.activePanel = '';
- this.trigger(this.activePanel);
- },
- getState() {
- return this.activePanel;
- },
- };
- const SidebarPanelStore = createStore(makeSafeRefluxStore(storeConfig)) as Store &
- SidebarPanelStoreInterface;
- export default SidebarPanelStore;
|