123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233 |
- import {createStore} from 'reflux';
- import {SeriesApi} from 'sentry/types';
- import {SamplingDistribution, SamplingSdkVersion} from 'sentry/types/sampling';
- import {CommonStoreDefinition} from './types';
- type ProjectStats = {
- data: SeriesApi | undefined;
- error: string | undefined;
- loading: boolean;
- };
- type Distribution = {
- data: SamplingDistribution | undefined;
- error: string | undefined;
- loading: boolean;
- };
- type SdkVersions = {
- data: SamplingSdkVersion[] | undefined;
- error: string | undefined;
- loading: boolean;
- };
- type State = {
- distribution: Distribution;
- projectStats30d: ProjectStats;
- projectStats48h: ProjectStats;
- sdkVersions: SdkVersions;
- };
- const initialState: State = {
- projectStats48h: {
- error: undefined,
- loading: false,
- data: undefined,
- },
- projectStats30d: {
- error: undefined,
- loading: false,
- data: undefined,
- },
- distribution: {
- error: undefined,
- loading: false,
- data: undefined,
- },
- sdkVersions: {
- error: undefined,
- loading: false,
- data: undefined,
- },
- };
- interface ServerSideSamplingStoreDefinition extends CommonStoreDefinition<State> {
- distributionRequestError(error: string): void;
- distributionRequestLoading(): void;
- distributionRequestSuccess(data: SamplingDistribution): void;
- projectStats30dRequestError: (error: string) => void;
- projectStats30dRequestLoading(): void;
- projectStats30dRequestSuccess: (data: SeriesApi) => void;
- projectStats48hRequestError: (error: string) => void;
- projectStats48hRequestLoading(): void;
- projectStats48hRequestSuccess: (data: SeriesApi) => void;
- reset(): void;
- sdkVersionsRequestError(error: string): void;
- sdkVersionsRequestLoading(): void;
- sdkVersionsRequestSuccess(data: SamplingSdkVersion[]): void;
- }
- const storeConfig: ServerSideSamplingStoreDefinition = {
- state: initialState,
- reset() {
- this.state = initialState;
- this.trigger(this.state);
- },
- getState() {
- return this.state;
- },
- projectStats48hRequestLoading() {
- this.state = {
- ...this.state,
- projectStats48h: {
- error: undefined,
- loading: true,
- data: undefined,
- },
- };
- this.trigger(this.state);
- },
- projectStats48hRequestSuccess(data: SeriesApi) {
- this.state = {
- ...this.state,
- projectStats48h: {
- error: undefined,
- loading: false,
- data,
- },
- };
- this.trigger(this.state);
- },
- projectStats48hRequestError(error: string) {
- this.state = {
- ...this.state,
- projectStats48h: {
- error,
- loading: false,
- data: undefined,
- },
- };
- this.trigger(this.state);
- },
- projectStats30dRequestLoading() {
- this.state = {
- ...this.state,
- projectStats30d: {
- error: undefined,
- loading: true,
- data: undefined,
- },
- };
- this.trigger(this.state);
- },
- projectStats30dRequestSuccess(data: SeriesApi) {
- this.state = {
- ...this.state,
- projectStats30d: {
- error: undefined,
- loading: false,
- data,
- },
- };
- this.trigger(this.state);
- },
- projectStats30dRequestError(error: string) {
- this.state = {
- ...this.state,
- projectStats30d: {
- error,
- loading: false,
- data: undefined,
- },
- };
- this.trigger(this.state);
- },
- distributionRequestLoading() {
- this.state = {
- ...this.state,
- distribution: {
- error: undefined,
- loading: true,
- data: undefined,
- },
- };
- this.trigger(this.state);
- },
- distributionRequestSuccess(data: SamplingDistribution) {
- this.state = {
- ...this.state,
- distribution: {
- error: undefined,
- loading: false,
- data,
- },
- };
- this.trigger(this.state);
- },
- distributionRequestError(error: string) {
- this.state = {
- ...this.state,
- distribution: {
- error,
- loading: false,
- data: undefined,
- },
- };
- this.trigger(this.state);
- },
- sdkVersionsRequestLoading() {
- this.state = {
- ...this.state,
- sdkVersions: {
- error: undefined,
- loading: true,
- data: undefined,
- },
- };
- this.trigger(this.state);
- },
- sdkVersionsRequestSuccess(data: SamplingSdkVersion[]) {
- this.state = {
- ...this.state,
- sdkVersions: {
- error: undefined,
- loading: false,
- data,
- },
- };
- this.trigger(this.state);
- },
- sdkVersionsRequestError(error: string) {
- this.state = {
- ...this.state,
- sdkVersions: {
- error,
- loading: false,
- data: undefined,
- },
- };
- this.trigger(this.state);
- },
- };
- export const ServerSideSamplingStore = createStore(storeConfig);
|