12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- import {createStore} from 'reflux';
- import {Environment} from 'sentry/types';
- import {getDisplayName, getUrlRoutingName} from 'sentry/utils/environment';
- import {CommonStoreDefinition} from './types';
- type EnhancedEnvironment = Environment & {
- displayName: string;
- urlRoutingName: string;
- };
- type State = {
- environments: EnhancedEnvironment[] | null;
- error: Error | null;
- };
- interface OrganizationEnvironmentsStoreDefinition extends CommonStoreDefinition<State> {
- init(): void;
- onFetchEnvironments(): void;
- onFetchEnvironmentsError(error: Error): void;
- onFetchEnvironmentsSuccess(environments: Environment[]): void;
- state: State;
- }
- const storeConfig: OrganizationEnvironmentsStoreDefinition = {
- state: {
- environments: null,
- error: null,
- },
- init() {
- this.state = {environments: null, error: null};
- },
- makeEnvironment(item: Environment): EnhancedEnvironment {
- return {
- id: item.id,
- name: item.name,
- get displayName() {
- return getDisplayName(item);
- },
- get urlRoutingName() {
- return getUrlRoutingName(item);
- },
- };
- },
- onFetchEnvironments() {
- this.state = {environments: null, error: null};
- this.trigger(this.state);
- },
- onFetchEnvironmentsSuccess(environments) {
- this.state = {error: null, environments: environments.map(this.makeEnvironment)};
- this.trigger(this.state);
- },
- onFetchEnvironmentsError(error) {
- this.state = {error, environments: null};
- this.trigger(this.state);
- },
- getState() {
- return this.state;
- },
- };
- const OrganizationEnvironmentsStore = createStore(storeConfig);
- export default OrganizationEnvironmentsStore;
|