123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234 |
- import {createStore} from 'reflux';
- import {SeriesApi} from 'sentry/types';
- import {SamplingDistribution, SamplingSdkVersion} from 'sentry/types/sampling';
- import {makeSafeRefluxStore} from 'sentry/utils/makeSafeRefluxStore';
- 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> {
- fetchDistribution(): void;
- fetchDistributionError(error: string): void;
- fetchDistributionSuccess(data: SamplingDistribution): void;
- fetchProjectStats30d(): void;
- fetchProjectStats30dError: (error: string) => void;
- fetchProjectStats30dSuccess: (data: SeriesApi) => void;
- fetchProjectStats48h(): void;
- fetchProjectStats48hError: (error: string) => void;
- fetchProjectStats48hSuccess: (data: SeriesApi) => void;
- fetchSdkVersions(): void;
- fetchSdkVersionsError(error: string): void;
- fetchSdkVersionsSuccess(data: SamplingSdkVersion[]): void;
- reset(): void;
- }
- const storeConfig: ServerSideSamplingStoreDefinition = {
- state: initialState,
- reset() {
- this.state = initialState;
- this.trigger(this.state);
- },
- getState() {
- return this.state;
- },
- fetchProjectStats48h() {
- this.state = {
- ...this.state,
- projectStats48h: {
- error: undefined,
- loading: true,
- data: undefined,
- },
- };
- this.trigger(this.state);
- },
- fetchProjectStats48hSuccess(data: SeriesApi) {
- this.state = {
- ...this.state,
- projectStats48h: {
- error: undefined,
- loading: false,
- data,
- },
- };
- this.trigger(this.state);
- },
- fetchProjectStats48hError(error: string) {
- this.state = {
- ...this.state,
- projectStats48h: {
- error,
- loading: false,
- data: undefined,
- },
- };
- this.trigger(this.state);
- },
- fetchProjectStats30d() {
- this.state = {
- ...this.state,
- projectStats30d: {
- error: undefined,
- loading: true,
- data: undefined,
- },
- };
- this.trigger(this.state);
- },
- fetchProjectStats30dSuccess(data: SeriesApi) {
- this.state = {
- ...this.state,
- projectStats30d: {
- error: undefined,
- loading: false,
- data,
- },
- };
- this.trigger(this.state);
- },
- fetchProjectStats30dError(error: string) {
- this.state = {
- ...this.state,
- projectStats30d: {
- error,
- loading: false,
- data: undefined,
- },
- };
- this.trigger(this.state);
- },
- fetchDistribution() {
- this.state = {
- ...this.state,
- distribution: {
- error: undefined,
- loading: true,
- data: undefined,
- },
- };
- this.trigger(this.state);
- },
- fetchDistributionSuccess(data: SamplingDistribution) {
- this.state = {
- ...this.state,
- distribution: {
- error: undefined,
- loading: false,
- data,
- },
- };
- this.trigger(this.state);
- },
- fetchDistributionError(error: string) {
- this.state = {
- ...this.state,
- distribution: {
- error,
- loading: false,
- data: undefined,
- },
- };
- this.trigger(this.state);
- },
- fetchSdkVersions() {
- this.state = {
- ...this.state,
- sdkVersions: {
- error: undefined,
- loading: true,
- data: undefined,
- },
- };
- this.trigger(this.state);
- },
- fetchSdkVersionsSuccess(data: SamplingSdkVersion[]) {
- this.state = {
- ...this.state,
- sdkVersions: {
- error: undefined,
- loading: false,
- data,
- },
- };
- this.trigger(this.state);
- },
- fetchSdkVersionsError(error: string) {
- this.state = {
- ...this.state,
- sdkVersions: {
- error,
- loading: false,
- data: undefined,
- },
- };
- this.trigger(this.state);
- },
- };
- export const ServerSideSamplingStore = createStore(makeSafeRefluxStore(storeConfig));
|