diff --git a/frontend/src/pages/archive/crawl-templates-list.ts b/frontend/src/pages/archive/crawl-templates-list.ts index 4817a329..9d419f68 100644 --- a/frontend/src/pages/archive/crawl-templates-list.ts +++ b/frontend/src/pages/archive/crawl-templates-list.ts @@ -1,4 +1,4 @@ -import type { HTMLTemplateResult } from "lit"; +import type { HTMLTemplateResult, PropertyValueMap } from "lit"; import { state, property } from "lit/decorators.js"; import { msg, localized, str } from "@lit/localize"; import { parseCron } from "@cheap-glitch/mi-cron"; @@ -18,6 +18,7 @@ import { humanizeSchedule, } from "../../utils/cron"; import "../../components/crawl-scheduler"; +import { SlCheckbox } from "@shoelace-style/shoelace"; type RunningCrawlsMap = { /** Map of configId: crawlId */ @@ -46,6 +47,9 @@ export class CrawlTemplatesList extends LiteElement { @property({ type: String }) archiveId!: string; + @property({ type: String }) + userId!: string; + @state() crawlTemplates?: CrawlConfig[]; @@ -67,6 +71,9 @@ export class CrawlTemplatesList extends LiteElement { direction: "desc", }; + @state() + private filterByCurrentUser = true; + @state() private searchBy: string = ""; @@ -80,18 +87,23 @@ export class CrawlTemplatesList extends LiteElement { threshold: 0.4, // stricter; default is 0.6 }); - async firstUpdated() { - try { - this.crawlTemplates = await this.getCrawlTemplates(); + protected async willUpdate(changedProperties: Map) { + if ( + changedProperties.has("archiveId") || + changedProperties.has("filterByCurrentUser") + ) { + try { + this.crawlTemplates = await this.getCrawlTemplates(); - // Update search/filter collection - this.fuse.setCollection(this.crawlTemplates as any); - } catch (e) { - this.notify({ - message: msg("Sorry, couldn't retrieve crawl configs at this time."), - variant: "danger", - icon: "exclamation-octagon", - }); + // Update search/filter collection + this.fuse.setCollection(this.crawlTemplates as any); + } catch (e) { + this.notify({ + message: msg("Sorry, couldn't retrieve crawl configs at this time."), + variant: "danger", + icon: "exclamation-octagon", + }); + } } } @@ -200,6 +212,21 @@ export class CrawlTemplatesList extends LiteElement {
+ ${this.userId + ? html`` + : ""} +
${msg("Sort By")}
@@ -553,8 +580,11 @@ export class CrawlTemplatesList extends LiteElement { * associated with the crawl configs **/ private async getCrawlTemplates(): Promise { + const params = + this.userId && this.filterByCurrentUser ? `?userid=${this.userId}` : ""; + const data: { crawlConfigs: CrawlConfig[] } = await this.apiFetch( - `/archives/${this.archiveId}/crawlconfigs`, + `/archives/${this.archiveId}/crawlconfigs${params}`, this.authState! ); diff --git a/frontend/src/pages/archive/crawls-list.ts b/frontend/src/pages/archive/crawls-list.ts index 8048dd3e..a4716f9f 100644 --- a/frontend/src/pages/archive/crawls-list.ts +++ b/frontend/src/pages/archive/crawls-list.ts @@ -12,6 +12,7 @@ import { RelativeDuration } from "../../components/relative-duration"; import type { AuthState } from "../../utils/AuthService"; import LiteElement, { html } from "../../utils/LiteElement"; import type { Crawl, CrawlConfig, InitialCrawlConfig } from "./types"; +import { SlCheckbox } from "@shoelace-style/shoelace"; type CrawlSearchResult = { item: Crawl; @@ -50,6 +51,9 @@ export class CrawlsList extends LiteElement { @property({ type: Object }) authState!: AuthState; + @property({ type: String }) + userId!: string; + // e.g. `/archive/${this.archiveId}/crawls` @property({ type: String }) crawlsBaseUrl!: string; @@ -80,6 +84,9 @@ export class CrawlsList extends LiteElement { direction: "desc", }; + @state() + private filterByCurrentUser = true; + @state() private filterBy: string = ""; @@ -104,7 +111,8 @@ export class CrawlsList extends LiteElement { if ( changedProperties.has("shouldFetch") || changedProperties.get("crawlsBaseUrl") || - changedProperties.get("crawlsAPIBaseUrl") + changedProperties.get("crawlsAPIBaseUrl") || + changedProperties.has("filterByCurrentUser") ) { if (this.shouldFetch) { if (!this.crawlsBaseUrl) { @@ -182,6 +190,21 @@ export class CrawlsList extends LiteElement {
+ ${this.userId + ? html`` + : ""} +
${msg("Sort By")}
@@ -554,13 +577,11 @@ export class CrawlsList extends LiteElement { } private async getCrawls(): Promise<{ crawls: Crawl[] }> { - // Mock to use in dev: - // return import("../../__mocks__/api/archives/[id]/crawls").then( - // (module) => module.default - // ); + const params = + this.userId && this.filterByCurrentUser ? `?userid=${this.userId}` : ""; const data = await this.apiFetch( - this.crawlsAPIBaseUrl || this.crawlsBaseUrl, + `${this.crawlsAPIBaseUrl || this.crawlsBaseUrl}${params}`, this.authState! ); diff --git a/frontend/src/pages/archive/index.ts b/frontend/src/pages/archive/index.ts index d5e0d82f..02e71b02 100644 --- a/frontend/src/pages/archive/index.ts +++ b/frontend/src/pages/archive/index.ts @@ -164,6 +164,7 @@ export class Archive extends LiteElement { return html``; @@ -196,6 +197,7 @@ export class Archive extends LiteElement { return html``; }