Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions static/app/stores/pluginsStore.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import {createStore} from 'reflux';

import type {Plugin} from 'sentry/types/integrations';

import type {StrictStoreDefinition} from './types';

type State = {
error: Error | null;
loading: boolean;
pageLinks: string | null;
plugins: Plugin[];
};

interface PluginsStoreDefinition extends StrictStoreDefinition<State> {
onFetchAllError(err: Error): void;
onFetchAllSuccess(data: Plugin[], options: {pageLinks?: string | null}): void;
onFetchAllStart(): void;

Check failure on line 17 in static/app/stores/pluginsStore.tsx

View workflow job for this annotation

GitHub Actions / eslint

Expected interface keys to be in required first ascending order. 'onFetchAllStart' should be before 'onFetchAllSuccess'
reset(): void;
triggerState(): void;
}

const storeConfig: PluginsStoreDefinition = {
plugins: new Map<string, Plugin>(),

Check failure on line 23 in static/app/stores/pluginsStore.tsx

View workflow job for this annotation

GitHub Actions / typescript

Object literal may only specify known properties, and 'plugins' does not exist in type 'PluginsStoreDefinition'.

state: {
plugins: [],
loading: true,
error: null,
pageLinks: null,
},

init() {
// XXX: Do not use `this.listenTo` in this store. We avoid usage of reflux
// listeners due to their leaky nature in tests.
this.reset();
},

reset() {
this.plugins = new Map();

Check failure on line 39 in static/app/stores/pluginsStore.tsx

View workflow job for this annotation

GitHub Actions / typescript

Property 'plugins' does not exist on type 'PluginsStoreDefinition'.
this.state = {
plugins: [],
loading: true,
error: null,
pageLinks: null,
};
},

triggerState() {
this.trigger({
...this.state,
plugins: this.plugins ? [...this.plugins.values()] : [],

Check failure on line 51 in static/app/stores/pluginsStore.tsx

View workflow job for this annotation

GitHub Actions / typescript

Property 'plugins' does not exist on type 'PluginsStoreDefinition'.

Check failure on line 51 in static/app/stores/pluginsStore.tsx

View workflow job for this annotation

GitHub Actions / typescript

Property 'plugins' does not exist on type 'PluginsStoreDefinition'.
});
},

onFetchAllStart() {
this.state.loading = true;

Check failure on line 56 in static/app/stores/pluginsStore.tsx

View workflow job for this annotation

GitHub Actions / typescript

Cannot assign to 'loading' because it is a read-only property.
this.state.error = null;

Check failure on line 57 in static/app/stores/pluginsStore.tsx

View workflow job for this annotation

GitHub Actions / typescript

Cannot assign to 'error' because it is a read-only property.
this.triggerState();
},

onFetchAllSuccess(data: Plugin[], {pageLinks}: {pageLinks?: string | null}) {
const dataArray = Array.isArray(data) ? data : [];
this.plugins = new Map(dataArray.map(plugin => [plugin.id, plugin]));

Check failure on line 63 in static/app/stores/pluginsStore.tsx

View workflow job for this annotation

GitHub Actions / typescript

Property 'plugins' does not exist on type 'PluginsStoreDefinition'.
this.state.pageLinks = pageLinks || null;

Check failure on line 64 in static/app/stores/pluginsStore.tsx

View workflow job for this annotation

GitHub Actions / typescript

Cannot assign to 'pageLinks' because it is a read-only property.
this.state.loading = false;

Check failure on line 65 in static/app/stores/pluginsStore.tsx

View workflow job for this annotation

GitHub Actions / typescript

Cannot assign to 'loading' because it is a read-only property.
this.triggerState();
},

onFetchAllError(err: Error) {
this.plugins = null;

Check failure on line 70 in static/app/stores/pluginsStore.tsx

View workflow job for this annotation

GitHub Actions / typescript

Property 'plugins' does not exist on type 'PluginsStoreDefinition'.
this.state.loading = false;
this.state.error = err;
this.triggerState();
},

getState() {
return {
...this.state,
plugins: this.plugins ? [...this.plugins.values()] : [],
};
},
};

const PluginsStore = createStore(storeConfig);
export default PluginsStore;

Check failure on line 85 in static/app/stores/pluginsStore.tsx

View workflow job for this annotation

GitHub Actions / eslint

We prefer named exports. Default exports are not allowed unless this file is lazy-imported
Loading