|
@@ -5,16 +5,16 @@ import {Organization} from 'sentry/types';
|
|
|
import {makeSafeRefluxStore} from 'sentry/utils/makeSafeRefluxStore';
|
|
|
|
|
|
interface OrganizationsStoreDefinition extends StoreDefinition {
|
|
|
- add(item: Organization): void;
|
|
|
+ addOrReplace(item: Organization): void;
|
|
|
get(slug: string): Organization | undefined;
|
|
|
|
|
|
getAll(): Organization[];
|
|
|
getState(): Organization[];
|
|
|
load(items: Organization[]): void;
|
|
|
loaded: boolean;
|
|
|
- onChangeSlug(prev: Organization, next: Organization): void;
|
|
|
+ onChangeSlug(prev: Organization, next: Partial<Organization>): void;
|
|
|
onRemoveSuccess(slug: string): void;
|
|
|
- onUpdate(org: Organization): void;
|
|
|
+ onUpdate(org: Partial<Organization>): void;
|
|
|
remove(slug: string): void;
|
|
|
state: Organization[];
|
|
|
}
|
|
@@ -36,7 +36,19 @@ const storeConfig: OrganizationsStoreDefinition = {
|
|
|
},
|
|
|
|
|
|
onUpdate(org) {
|
|
|
- this.add(org);
|
|
|
+ let match = false;
|
|
|
+ this.state.forEach((existing, idx) => {
|
|
|
+ if (existing.id === org.id) {
|
|
|
+ this.state[idx] = {...existing, ...org};
|
|
|
+ match = true;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ if (!match) {
|
|
|
+ throw new Error(
|
|
|
+ 'Cannot update an organization that is not in the OrganizationsStore'
|
|
|
+ );
|
|
|
+ }
|
|
|
+ this.trigger(this.state);
|
|
|
},
|
|
|
|
|
|
onChangeSlug(prev, next) {
|
|
@@ -45,7 +57,7 @@ const storeConfig: OrganizationsStoreDefinition = {
|
|
|
}
|
|
|
|
|
|
this.remove(prev.slug);
|
|
|
- this.add(next);
|
|
|
+ this.addOrReplace({...prev, ...next});
|
|
|
},
|
|
|
|
|
|
onRemoveSuccess(slug) {
|
|
@@ -69,12 +81,11 @@ const storeConfig: OrganizationsStoreDefinition = {
|
|
|
this.trigger(this.state);
|
|
|
},
|
|
|
|
|
|
- add(item) {
|
|
|
+ addOrReplace(item) {
|
|
|
let match = false;
|
|
|
this.state.forEach((existing, idx) => {
|
|
|
if (existing.id === item.id) {
|
|
|
- item = {...existing, ...item};
|
|
|
- this.state[idx] = item;
|
|
|
+ this.state[idx] = {...existing, ...item};
|
|
|
match = true;
|
|
|
}
|
|
|
});
|