Просмотр исходного кода

ref(stores): use interfaces (#33165)

* ref(stores): use interfaces

* ref(stores): fix types

* ref(stores): fix types

* fix(OrganizationEnvironmentsStore): use getState
Jonas 2 лет назад
Родитель
Сommit
3273a08b97

+ 4 - 3
static/app/actionCreators/group.tsx

@@ -134,7 +134,8 @@ export function assignToActor({id, actor, assignedBy}: AssignToActorParams) {
 export function deleteNote(api: Client, group: Group, id: string, _oldText: string) {
   const restore = group.activity.find(activity => activity.id === id);
   const index = GroupStore.removeActivity(group.id, id);
-  if (index === -1) {
+
+  if (index === -1 || restore === undefined) {
     // I dunno, the id wasn't found in the GroupStore
     return Promise.reject(new Error('Group was not found in store'));
   }
@@ -166,14 +167,14 @@ export function updateNote(
   id: string,
   oldText: string
 ) {
-  GroupStore.updateActivity(group.id, id, {text: note.text});
+  GroupStore.updateActivity(group.id, id, {data: {text: note.text}});
 
   const promise = api.requestPromise(`/issues/${group.id}/comments/${id}/`, {
     method: 'PUT',
     data: note,
   });
 
-  promise.catch(() => GroupStore.updateActivity(group.id, id, {text: oldText}));
+  promise.catch(() => GroupStore.updateActivity(group.id, id, {data: {text: oldText}}));
 
   return promise;
 }

+ 13 - 11
static/app/stores/alertStore.tsx

@@ -1,11 +1,11 @@
-import {createStore, Store, StoreDefinition} from 'reflux';
+import {createStore} from 'reflux';
 
 import AlertActions from 'sentry/actions/alertActions';
 import {defined} from 'sentry/utils';
 import localStorage from 'sentry/utils/localStorage';
 import {Theme} from 'sentry/utils/theme';
 
-import {CommonStoreInterface} from './types';
+import {CommonStoreDefinition} from './types';
 
 type Alert = {
   message: React.ReactNode;
@@ -20,18 +20,20 @@ type Alert = {
   url?: string;
 };
 
-type AlertStoreInterface = CommonStoreInterface<Alert[]> & {
+interface InternalAlertStoreDefinition {
+  alerts: Alert[];
+  count: number;
+}
+interface AlertStoreDefinition
+  extends CommonStoreDefinition<Alert[]>,
+    InternalAlertStoreDefinition {
   init(): void;
+
   onAddAlert(alert: Alert): void;
   onCloseAlert(alert: Alert, duration?: number): void;
-};
-
-type Internals = {
-  alerts: Alert[];
-  count: number;
-};
+}
 
-const storeConfig: StoreDefinition & Internals & AlertStoreInterface = {
+const storeConfig: AlertStoreDefinition = {
   listenables: AlertActions,
   alerts: [],
   count: 0,
@@ -109,6 +111,6 @@ const storeConfig: StoreDefinition & Internals & AlertStoreInterface = {
   },
 };
 
-const AlertStore = createStore(storeConfig) as Store & AlertStoreInterface;
+const AlertStore = createStore(storeConfig) as Reflux.Store & AlertStoreDefinition;
 
 export default AlertStore;

+ 5 - 5
static/app/stores/committerStore.tsx

@@ -1,4 +1,4 @@
-import {createStore, StoreDefinition} from 'reflux';
+import {createStore} from 'reflux';
 
 import CommitterActions from 'sentry/actions/committerActions';
 import {Committer} from 'sentry/types';
@@ -13,7 +13,7 @@ type State = {
   };
 };
 
-type CommitterStoreInterface = {
+interface CommitterStoreDefinition extends Reflux.StoreDefinition {
   get(
     orgSlug: string,
     projectSlug: string,
@@ -36,9 +36,9 @@ type CommitterStoreInterface = {
   ): void;
 
   state: State;
-};
+}
 
-export const storeConfig: StoreDefinition & CommitterStoreInterface = {
+export const storeConfig: CommitterStoreDefinition = {
   listenables: CommitterActions,
   state: {},
 
@@ -108,6 +108,6 @@ export function getCommitterStoreKey(
 }
 
 const CommitterStore = createStore(makeSafeRefluxStore(storeConfig)) as SafeRefluxStore &
-  CommitterStoreInterface;
+  CommitterStoreDefinition;
 
 export default CommitterStore;

+ 13 - 13
static/app/stores/configStore.tsx

@@ -1,25 +1,27 @@
 import moment from 'moment-timezone';
-import {createStore, StoreDefinition} from 'reflux';
+import {createStore} from 'reflux';
 
 import {Config} from 'sentry/types';
 import {makeSafeRefluxStore, SafeRefluxStore} from 'sentry/utils/makeSafeRefluxStore';
 
-import {CommonStoreInterface} from './types';
+import {CommonStoreDefinition} from './types';
 
-type ConfigStoreInterface = CommonStoreInterface<Config> & {
+interface InternalConfigStore {
+  config: Config;
+}
+
+interface ConfigStoreDefinition
+  extends CommonStoreDefinition<Config>,
+    InternalConfigStore {
   get<K extends keyof Config>(key: K): Config[K];
   getConfig(): Config;
   init(): void;
   loadInitialData(config: Config): void;
   set<K extends keyof Config>(key: K, value: Config[K]): void;
   updateTheme(theme: 'light' | 'dark'): void;
-};
+}
 
-type Internals = {
-  config: Config;
-};
-
-const storeConfig: StoreDefinition & Internals & ConfigStoreInterface = {
+const storeConfig: ConfigStoreDefinition = {
   // When the app is booted we will _immediately_ hydrate the config store,
   // effecively ensureing this is not empty.
   config: {} as Config,
@@ -79,7 +81,5 @@ const storeConfig: StoreDefinition & Internals & ConfigStoreInterface = {
   },
 };
 
-const ConfigStore = createStore(makeSafeRefluxStore(storeConfig)) as SafeRefluxStore &
-  ConfigStoreInterface;
-
-export default ConfigStore;
+export default createStore(makeSafeRefluxStore(storeConfig)) as SafeRefluxStore &
+  ConfigStoreDefinition;

+ 2 - 2
static/app/stores/debugMetaStore.tsx

@@ -12,12 +12,12 @@ type State = {
   filter: string | null;
 };
 
-type DebugMetaStoreInterface = {
+interface DebugMetaStoreInterface extends StoreDefinition {
   get(): State;
   init(): void;
   reset(): void;
   updateFilter(word: string): void;
-};
+}
 
 type Internals = {
   filter: string | null;

+ 5 - 5
static/app/stores/eventStore.tsx

@@ -5,12 +5,12 @@ import {createStore, StoreDefinition} from 'reflux';
 import {Event} from 'sentry/types/event';
 import {makeSafeRefluxStore, SafeRefluxStore} from 'sentry/utils/makeSafeRefluxStore';
 
-type Internals = {
+type InternalDefinition = {
   items: Event[];
   itemsById: Record<string, Event>;
 };
 
-type EventStoreInterface = {
+interface EventStoreDefinition extends StoreDefinition, InternalDefinition {
   add(items: Event[]): void;
   get(id: string): Event | undefined;
   getAllItemIds(): string[];
@@ -19,9 +19,9 @@ type EventStoreInterface = {
   loadInitialData(items: Event[]): void;
   remove(id: string): void;
   reset(): void;
-};
+}
 
-const storeConfig: StoreDefinition & Internals & EventStoreInterface = {
+const storeConfig: EventStoreDefinition = {
   items: [],
   itemsById: {},
 
@@ -100,6 +100,6 @@ const storeConfig: StoreDefinition & Internals & EventStoreInterface = {
 };
 
 const EventStore = createStore(makeSafeRefluxStore(storeConfig)) as SafeRefluxStore &
-  EventStoreInterface;
+  EventStoreDefinition;
 
 export default EventStore;

+ 4 - 4
static/app/stores/externalIssueStore.tsx

@@ -3,13 +3,13 @@ import {createStore, StoreDefinition} from 'reflux';
 import {PlatformExternalIssue} from 'sentry/types';
 import {makeSafeRefluxStore, SafeRefluxStore} from 'sentry/utils/makeSafeRefluxStore';
 
-type ExternalIssueStoreInterface = {
+interface ExternalIssueStoreDefinition extends StoreDefinition {
   add(issue: PlatformExternalIssue): void;
   getInitialState(): PlatformExternalIssue[];
   load(items: PlatformExternalIssue[]): void;
-};
+}
 
-const storeConfig: StoreDefinition & ExternalIssueStoreInterface = {
+const storeConfig: ExternalIssueStoreDefinition = {
   init() {
     this.items = [];
   },
@@ -41,6 +41,6 @@ const storeConfig: StoreDefinition & ExternalIssueStoreInterface = {
 
 const ExternalIssueStore = createStore(
   makeSafeRefluxStore(storeConfig)
-) as SafeRefluxStore & ExternalIssueStoreInterface;
+) as SafeRefluxStore & ExternalIssueStoreDefinition;
 
 export default ExternalIssueStore;

+ 6 - 4
static/app/stores/formSearchStore.tsx

@@ -1,4 +1,4 @@
-import {createStore, Store, StoreDefinition} from 'reflux';
+import {createStore, Store} from 'reflux';
 
 import FormSearchActions from 'sentry/actions/formSearchActions';
 import {FieldObject} from 'sentry/components/forms/type';
@@ -15,19 +15,21 @@ export type FormSearchField = {
 };
 
 type StoreInterface = {
-  get(): Internals['searchMap'];
+  get(): InternalDefinition['searchMap'];
   reset(): void;
 };
 
-type Internals = {
+type InternalDefinition = {
   onLoadSearchMap: (searchMap: null | FormSearchField[]) => void;
   searchMap: null | FormSearchField[];
 };
 
+interface ExternalIssuesDefinition extends SafeStoreDefinition, InternalDefinition {}
+
 /**
  * Store for "form" searches, but probably will include more
  */
-const storeConfig: StoreDefinition & Internals & StoreInterface & SafeStoreDefinition = {
+const storeConfig: ExternalIssuesDefinition = {
   searchMap: null,
   unsubscribeListeners: [],
 

+ 6 - 6
static/app/stores/groupStore.tsx

@@ -46,7 +46,7 @@ class PendingChangeQueue {
 
 type Item = BaseGroup | Group | GroupCollapseRelease;
 
-type Internals = {
+interface InternalDefinition {
   addActivity: (groupId: string, data: Activity, index?: number) => void;
   indexOfActivity: (groupId: string, id: string) => number;
   items: Item[];
@@ -55,9 +55,9 @@ type Internals = {
   removeActivity: (groupId: string, id: string) => number;
   statuses: Record<string, Record<string, boolean>>;
   updateActivity: (groupId: string, id: string, data: Partial<Activity>) => void;
-};
+}
 
-type GroupStoreInterface = StoreDefinition & {
+interface GroupStoreDefintion extends StoreDefinition, InternalDefinition {
   add: (items: Item[]) => void;
   addStatus: (id: string, status: string) => void;
   clearStatus: (id: string, status: string) => void;
@@ -95,9 +95,9 @@ type GroupStoreInterface = StoreDefinition & {
   ) => void;
   remove: (itemIds: string[]) => void;
   reset: () => void;
-};
+}
 
-const storeConfig: StoreDefinition & Internals & GroupStoreInterface = {
+const storeConfig: GroupStoreDefintion = {
   listenables: [GroupActions],
   pendingChanges: new PendingChangeQueue(),
   items: [],
@@ -520,6 +520,6 @@ const storeConfig: StoreDefinition & Internals & GroupStoreInterface = {
 };
 
 const GroupStore = createStore(makeSafeRefluxStore(storeConfig)) as SafeRefluxStore &
-  GroupStoreInterface;
+  GroupStoreDefintion;
 
 export default GroupStore;

+ 8 - 8
static/app/stores/groupingStore.tsx

@@ -110,7 +110,11 @@ type IdState = {
   collapsed?: boolean;
 };
 
-type GroupingStoreInterface = StoreDefinition & {
+type InternalDefinition = {
+  api: Client;
+};
+
+interface GroupingStoreDefinition extends StoreDefinition, InternalDefinition {
   getInitialState(): State;
   init(): void;
   isAllUnmergedSelected(): boolean;
@@ -166,13 +170,9 @@ type GroupingStoreInterface = StoreDefinition & {
     | 'enableFingerprintCompare'
     | 'unmergeLastCollapsed'
   >;
-};
-
-type Internals = {
-  api: Client;
-};
+}
 
-const storeConfig: StoreDefinition & Internals & GroupingStoreInterface = {
+const storeConfig: GroupingStoreDefinition = {
   listenables: [GroupingActions],
   api: new Client(),
 
@@ -618,6 +618,6 @@ const storeConfig: StoreDefinition & Internals & GroupingStoreInterface = {
 };
 
 const GroupingStore = createStore(makeSafeRefluxStore(storeConfig)) as SafeRefluxStore &
-  GroupingStoreInterface;
+  GroupingStoreDefinition;
 
 export default GroupingStore;

Некоторые файлы не были показаны из-за большого количества измененных файлов