@@ -650,69 +731,42 @@ export class CrawlsList extends LiteElement {
`;
}
- /**
- * Fetch archived items and update internal state
- */
- private async fetchArchivedItems(params?: APIPaginationQuery): Promise {
- this.cancelInProgressGetArchivedItems();
- try {
- this.archivedItems = await this.getArchivedItems(params);
- } catch (e) {
- if ((e as Error).name === "AbortError") {
- console.debug("Fetch archived items aborted to throttle");
- } else {
- this.notify({
- message: msg("Sorry, couldn't retrieve archived items at this time."),
- variant: "danger",
- icon: "exclamation-octagon",
- });
- }
- }
- }
-
- private cancelInProgressGetArchivedItems() {
- if (this.getArchivedItemsController) {
- this.getArchivedItemsController.abort(ABORT_REASON_THROTTLE);
- this.getArchivedItemsController = null;
- }
- }
-
private async getArchivedItems(
- queryParams?: APIPaginationQuery & { state?: CrawlState[] },
- ): Promise {
+ params: {
+ orgId: string;
+ authState: Auth;
+ userId: CrawlsList["userId"];
+ itemType: CrawlsList["itemType"];
+ pagination: CrawlsList["pagination"];
+ orderBy: CrawlsList["orderBy"];
+ filterBy: CrawlsList["filterBy"];
+ filterByCurrentUser: CrawlsList["filterByCurrentUser"];
+ },
+ signal: AbortSignal,
+ ) {
const query = queryString.stringify(
{
- ...this.filterBy,
- state: this.filterBy.state?.length
- ? this.filterBy.state
+ ...params.filterBy,
+ state: params.filterBy.state?.length
+ ? params.filterBy.state
: finishedCrawlStates,
- page: queryParams?.page || this.archivedItems?.page || 1,
- pageSize:
- queryParams?.pageSize ||
- this.archivedItems?.pageSize ||
- INITIAL_PAGE_SIZE,
- userid: this.filterByCurrentUser ? this.userId : undefined,
- sortBy: this.orderBy.field,
- sortDirection: this.orderBy.direction === "desc" ? -1 : 1,
- crawlType: this.itemType,
+ page: params.pagination.page,
+ pageSize: params.pagination.pageSize,
+ userid: params.filterByCurrentUser ? params.userId : undefined,
+ sortBy: params.orderBy.field,
+ sortDirection: params.orderBy.direction === "desc" ? -1 : 1,
+ crawlType: params.itemType,
},
{
arrayFormat: "comma",
},
);
- this.getArchivedItemsController = new AbortController();
- const data = await this.apiFetch(
- `/orgs/${this.orgId}/all-crawls?${query}`,
- this.authState!,
- {
- signal: this.getArchivedItemsController.signal,
- },
+ return this.api.fetch(
+ `/orgs/${params.orgId}/all-crawls?${query}`,
+ params.authState,
+ { signal },
);
-
- this.getArchivedItemsController = null;
-
- return data;
}
private async fetchConfigSearchValues() {
@@ -725,7 +779,7 @@ export class CrawlsList extends LiteElement {
names: string[];
descriptions: string[];
firstSeeds: string[];
- } = await this.apiFetch(
+ } = await this.api.fetch(
`/orgs/${this.orgId}/all-crawls/search-values?${query}`,
this.authState!,
);
@@ -764,7 +818,7 @@ export class CrawlsList extends LiteElement {
}
try {
- const _data = await this.apiFetch(
+ const _data = await this.api.fetch(
`/orgs/${item.oid}/${apiPath}/delete`,
this.authState!,
{
@@ -774,18 +828,19 @@ export class CrawlsList extends LiteElement {
}),
},
);
- const { items, ...crawlsData } = this.archivedItems!;
+ // TODO eager list update before server response
+ void this.archivedItemsTask.run();
+ // const { items, ...crawlsData } = this.archivedItems!;
this.itemToDelete = null;
- this.archivedItems = {
- ...crawlsData,
- items: items.filter((c) => c.id !== item.id),
- };
- this.notify({
+ // this.archivedItems = {
+ // ...crawlsData,
+ // items: items.filter((c) => c.id !== item.id),
+ // };
+ this.notify.toast({
message: msg(str`Successfully deleted archived item.`),
variant: "success",
icon: "check2-circle",
});
- void this.fetchArchivedItems();
} catch (e) {
if (this.itemToDelete) {
this.confirmDeleteItem(this.itemToDelete);
@@ -802,7 +857,7 @@ export class CrawlsList extends LiteElement {
message = e.message;
}
}
- this.notify({
+ this.notify.toast({
message: message,
variant: "danger",
icon: "exclamation-octagon",
@@ -811,7 +866,7 @@ export class CrawlsList extends LiteElement {
}
async getWorkflow(crawl: Crawl): Promise {
- const data: Workflow = await this.apiFetch(
+ const data: Workflow = await this.api.fetch(
`/orgs/${crawl.oid}/crawlconfigs/${crawl.cid}`,
this.authState!,
);