Github integration (#6414)
Co-authored-by: Tom Moor <tom.moor@gmail.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { computed } from "mobx";
|
||||
import { IntegrationService, IntegrationType } from "@shared/types";
|
||||
import naturalSort from "@shared/utils/naturalSort";
|
||||
import RootStore from "~/stores/RootStore";
|
||||
import Store from "~/stores/base/Store";
|
||||
@@ -13,6 +14,13 @@ class IntegrationsStore extends Store<Integration> {
|
||||
get orderedData(): Integration[] {
|
||||
return naturalSort(Array.from(this.data.values()), "name");
|
||||
}
|
||||
|
||||
@computed
|
||||
get github(): Integration<IntegrationType.Embed>[] {
|
||||
return this.orderedData.filter(
|
||||
(integration) => integration.service === IntegrationService.GitHub
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default IntegrationsStore;
|
||||
|
||||
@@ -289,17 +289,28 @@ export default abstract class Store<T extends Model> {
|
||||
};
|
||||
|
||||
@action
|
||||
fetchAll = async (): Promise<T[]> => {
|
||||
fetchAll = async (params?: Record<string, any>): Promise<T[]> => {
|
||||
const limit = Pagination.defaultLimit;
|
||||
const response = await this.fetchPage({ limit });
|
||||
const response = await this.fetchPage({ ...params, limit });
|
||||
const pages = Math.ceil(response[PAGINATION_SYMBOL].total / limit);
|
||||
const fetchPages = [];
|
||||
for (let page = 1; page < pages; page++) {
|
||||
fetchPages.push(this.fetchPage({ offset: page * limit, limit }));
|
||||
fetchPages.push(
|
||||
this.fetchPage({ ...params, offset: page * limit, limit })
|
||||
);
|
||||
}
|
||||
|
||||
const results = await Promise.all(fetchPages);
|
||||
return flatten(results);
|
||||
const results = flatten(
|
||||
fetchPages.length ? await Promise.all(fetchPages) : [response]
|
||||
);
|
||||
|
||||
if (params?.withRelations) {
|
||||
await Promise.all(
|
||||
this.orderedData.map((integration) => integration.loadRelations())
|
||||
);
|
||||
}
|
||||
|
||||
return results;
|
||||
};
|
||||
|
||||
@computed
|
||||
|
||||
Reference in New Issue
Block a user