Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

frontend: fix to collection editor with crawls and uploads #971

Merged
merged 2 commits into from
Jul 10, 2023
Merged
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
48 changes: 21 additions & 27 deletions frontend/src/pages/org/collection-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1332,26 +1332,6 @@ export class CollectionEditor extends LiteElement {
}
}

private async getCrawlsAndUploads(
params: Partial<{
collectionId?: string;
state: CrawlState[];
}> &
APIPaginationQuery &
APISortQuery
): Promise<APIPaginatedList> {
const query = queryString.stringify({
state: "complete",
...params,
});
const data: APIPaginatedList = await this.apiFetch(
`/orgs/${this.orgId}/all-crawls?${query}`,
this.authState!
);

return data;
}

private async getUploads(
params: Partial<{
collectionId?: string;
Expand All @@ -1376,23 +1356,37 @@ export class CollectionEditor extends LiteElement {
if (!this.collectionId) return;

try {
const { items: crawls } = await this.getCrawlsAndUploads({
collectionId: this.collectionId,
sortBy: "finished",
pageSize: WORKFLOW_CRAWL_LIMIT,
});
const [crawlsRes, uploadsRes] = await Promise.allSettled([
this.getCrawls({
collectionId: this.collectionId,
sortBy: "finished",
pageSize: WORKFLOW_CRAWL_LIMIT,
}),
this.getUploads({
collectionId: this.collectionId,
sortBy: "finished",
pageSize: WORKFLOW_CRAWL_LIMIT,
}),
]);
const crawls =
crawlsRes.status === "fulfilled" ? crawlsRes.value.items : [];
const uploads =
uploadsRes.status === "fulfilled" ? uploadsRes.value.items : [];
const crawlsAndUploads = [...crawls, ...uploads];

this.selectedCrawls = mergeDeep(
this.selectedCrawls,
crawls.reduce(
crawlsAndUploads.reduce(
(acc, crawl) => ({
...acc,
[crawl.id]: crawl,
}),
{}
)
);

// TODO remove omit once API removes errors
this.collectionCrawls = crawls.map(omit("errors")) as Crawl[];
this.collectionCrawls = crawlsAndUploads.map(omit("errors")) as Crawl[];
// Store crawl IDs to compare later
this.savedCollectionCrawlIds = this.collectionCrawls.map(({ id }) => id);
} catch {
Expand Down