serverSideSamplingStore.tsx 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. import {createStore} from 'reflux';
  2. import {SeriesApi} from 'sentry/types';
  3. import {SamplingDistribution, SamplingSdkVersion} from 'sentry/types/sampling';
  4. import {CommonStoreDefinition} from './types';
  5. type ProjectStats = {
  6. data: SeriesApi | undefined;
  7. error: string | undefined;
  8. loading: boolean;
  9. };
  10. type Distribution = {
  11. data: SamplingDistribution | undefined;
  12. error: string | undefined;
  13. loading: boolean;
  14. };
  15. type SdkVersions = {
  16. data: SamplingSdkVersion[] | undefined;
  17. error: string | undefined;
  18. loading: boolean;
  19. };
  20. type State = {
  21. distribution: Distribution;
  22. projectStats30d: ProjectStats;
  23. projectStats48h: ProjectStats;
  24. sdkVersions: SdkVersions;
  25. };
  26. const initialState: State = {
  27. projectStats48h: {
  28. error: undefined,
  29. loading: false,
  30. data: undefined,
  31. },
  32. projectStats30d: {
  33. error: undefined,
  34. loading: false,
  35. data: undefined,
  36. },
  37. distribution: {
  38. error: undefined,
  39. loading: false,
  40. data: undefined,
  41. },
  42. sdkVersions: {
  43. error: undefined,
  44. loading: false,
  45. data: undefined,
  46. },
  47. };
  48. interface ServerSideSamplingStoreDefinition extends CommonStoreDefinition<State> {
  49. distributionRequestError(error: string): void;
  50. distributionRequestLoading(): void;
  51. distributionRequestSuccess(data: SamplingDistribution): void;
  52. projectStats30dRequestError: (error: string) => void;
  53. projectStats30dRequestLoading(): void;
  54. projectStats30dRequestSuccess: (data: SeriesApi) => void;
  55. projectStats48hRequestError: (error: string) => void;
  56. projectStats48hRequestLoading(): void;
  57. projectStats48hRequestSuccess: (data: SeriesApi) => void;
  58. reset(): void;
  59. sdkVersionsRequestError(error: string): void;
  60. sdkVersionsRequestLoading(): void;
  61. sdkVersionsRequestSuccess(data: SamplingSdkVersion[]): void;
  62. }
  63. const storeConfig: ServerSideSamplingStoreDefinition = {
  64. state: initialState,
  65. reset() {
  66. this.state = initialState;
  67. this.trigger(this.state);
  68. },
  69. getState() {
  70. return this.state;
  71. },
  72. projectStats48hRequestLoading() {
  73. this.state = {
  74. ...this.state,
  75. projectStats48h: {
  76. error: undefined,
  77. loading: true,
  78. data: undefined,
  79. },
  80. };
  81. this.trigger(this.state);
  82. },
  83. projectStats48hRequestSuccess(data: SeriesApi) {
  84. this.state = {
  85. ...this.state,
  86. projectStats48h: {
  87. error: undefined,
  88. loading: false,
  89. data,
  90. },
  91. };
  92. this.trigger(this.state);
  93. },
  94. projectStats48hRequestError(error: string) {
  95. this.state = {
  96. ...this.state,
  97. projectStats48h: {
  98. error,
  99. loading: false,
  100. data: undefined,
  101. },
  102. };
  103. this.trigger(this.state);
  104. },
  105. projectStats30dRequestLoading() {
  106. this.state = {
  107. ...this.state,
  108. projectStats30d: {
  109. error: undefined,
  110. loading: true,
  111. data: undefined,
  112. },
  113. };
  114. this.trigger(this.state);
  115. },
  116. projectStats30dRequestSuccess(data: SeriesApi) {
  117. this.state = {
  118. ...this.state,
  119. projectStats30d: {
  120. error: undefined,
  121. loading: false,
  122. data,
  123. },
  124. };
  125. this.trigger(this.state);
  126. },
  127. projectStats30dRequestError(error: string) {
  128. this.state = {
  129. ...this.state,
  130. projectStats30d: {
  131. error,
  132. loading: false,
  133. data: undefined,
  134. },
  135. };
  136. this.trigger(this.state);
  137. },
  138. distributionRequestLoading() {
  139. this.state = {
  140. ...this.state,
  141. distribution: {
  142. error: undefined,
  143. loading: true,
  144. data: undefined,
  145. },
  146. };
  147. this.trigger(this.state);
  148. },
  149. distributionRequestSuccess(data: SamplingDistribution) {
  150. this.state = {
  151. ...this.state,
  152. distribution: {
  153. error: undefined,
  154. loading: false,
  155. data,
  156. },
  157. };
  158. this.trigger(this.state);
  159. },
  160. distributionRequestError(error: string) {
  161. this.state = {
  162. ...this.state,
  163. distribution: {
  164. error,
  165. loading: false,
  166. data: undefined,
  167. },
  168. };
  169. this.trigger(this.state);
  170. },
  171. sdkVersionsRequestLoading() {
  172. this.state = {
  173. ...this.state,
  174. sdkVersions: {
  175. error: undefined,
  176. loading: true,
  177. data: undefined,
  178. },
  179. };
  180. this.trigger(this.state);
  181. },
  182. sdkVersionsRequestSuccess(data: SamplingSdkVersion[]) {
  183. this.state = {
  184. ...this.state,
  185. sdkVersions: {
  186. error: undefined,
  187. loading: false,
  188. data,
  189. },
  190. };
  191. this.trigger(this.state);
  192. },
  193. sdkVersionsRequestError(error: string) {
  194. this.state = {
  195. ...this.state,
  196. sdkVersions: {
  197. error,
  198. loading: false,
  199. data: undefined,
  200. },
  201. };
  202. this.trigger(this.state);
  203. },
  204. };
  205. export const ServerSideSamplingStore = createStore(storeConfig);