Skip to content

Commit 4df97c0

Browse files
committed
update workflow settings
1 parent 35d299b commit 4df97c0

File tree

3 files changed

+93
-59
lines changed

3 files changed

+93
-59
lines changed

frontend/src/components/ui/config-details.ts

Lines changed: 16 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ import {
1616
import { labelFor } from "@/strings/crawl-workflows/labels";
1717
import scopeTypeLabel from "@/strings/crawl-workflows/scopeType";
1818
import sectionStrings from "@/strings/crawl-workflows/section";
19-
import type { Collection } from "@/types/collection";
2019
import { WorkflowScopeType, type StorageSeedFile } from "@/types/workflow";
21-
import { isApiError } from "@/utils/api";
2220
import { unescapeCustomPrefix } from "@/utils/crawl-workflows/unescapeCustomPrefix";
2321
import { DEPTH_SUPPORTED_SCOPES, isPageScopeType } from "@/utils/crawler";
2422
import { humanizeSchedule } from "@/utils/cron";
@@ -60,13 +58,9 @@ export class ConfigDetails extends BtrixElement {
6058
maxPagesPerCrawl?: number;
6159
};
6260

63-
@state()
64-
private collections: Collection[] = [];
65-
6661
async connectedCallback() {
6762
super.connectedCallback();
6863
void this.fetchOrgDefaults();
69-
await this.fetchCollections();
7064
}
7165

7266
render() {
@@ -313,6 +307,22 @@ export class ConfigDetails extends BtrixElement {
313307
)}
314308
`,
315309
})}
310+
${when(!this.hideMetadata, () =>
311+
this.renderSection({
312+
id: "collection",
313+
heading: sectionStrings.collection,
314+
renderDescItems: () => html`
315+
${this.renderSetting(
316+
html`<span class="mb-1 inline-block">${msg("Auto-Add")}</span>`,
317+
crawlConfig?.autoAddCollections.length
318+
? html`<btrix-linked-collections-list
319+
.collectionIds=${crawlConfig.autoAddCollections}
320+
></btrix-linked-collections-list>`
321+
: undefined,
322+
)}
323+
`,
324+
}),
325+
)}
316326
${when(!this.hideMetadata, () =>
317327
this.renderSection({
318328
id: "crawl-metadata",
@@ -338,21 +348,6 @@ export class ConfigDetails extends BtrixElement {
338348
)
339349
: [],
340350
)}
341-
${this.renderSetting(
342-
msg("Collections"),
343-
this.collections.length
344-
? this.collections.map(
345-
(coll) =>
346-
html`<sl-tag class="mr-2 mt-1" variant="neutral">
347-
${coll.name}
348-
<span class="font-monostyle pl-1 text-xs">
349-
(${this.localize.number(coll.crawlCount)}
350-
${pluralOf("items", coll.crawlCount)})
351-
</span>
352-
</sl-tag>`,
353-
)
354-
: undefined,
355-
)}
356351
`,
357352
}),
358353
)}
@@ -633,44 +628,6 @@ export class ConfigDetails extends BtrixElement {
633628
`;
634629
}
635630

636-
private async fetchCollections() {
637-
if (this.crawlConfig?.autoAddCollections) {
638-
try {
639-
await this.getCollections();
640-
} catch (e) {
641-
this.notify.toast({
642-
message:
643-
isApiError(e) && e.statusCode === 404
644-
? msg("Collections not found.")
645-
: msg(
646-
"Sorry, couldn't retrieve Collection details at this time.",
647-
),
648-
variant: "danger",
649-
icon: "exclamation-octagon",
650-
id: "collection-fetch-status",
651-
});
652-
}
653-
}
654-
}
655-
656-
private async getCollections() {
657-
const collections: Collection[] = [];
658-
const orgId = this.crawlConfig?.oid;
659-
660-
if (this.crawlConfig?.autoAddCollections && orgId) {
661-
for (const collectionId of this.crawlConfig.autoAddCollections) {
662-
const data = await this.api.fetch<Collection | undefined>(
663-
`/orgs/${orgId}/collections/${collectionId}`,
664-
);
665-
if (data) {
666-
collections.push(data);
667-
}
668-
}
669-
}
670-
this.collections = collections;
671-
this.requestUpdate();
672-
}
673-
674631
// TODO Consolidate with workflow-editor
675632
private async fetchOrgDefaults() {
676633
try {

frontend/src/features/collections/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import("./collection-edit-dialog");
66
import("./collection-create-dialog");
77
import("./collection-initial-view-dialog");
88
import("./collection-workflow-list");
9+
import("./linked-collections-list");
910
import("./select-collection-access");
1011
import("./select-collection-page");
1112
import("./share-collection");
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import { localized, msg } from "@lit/localize";
2+
import { Task } from "@lit/task";
3+
import { html } from "lit";
4+
import { customElement, property } from "lit/decorators.js";
5+
import isEqual from "lodash/fp/isEqual";
6+
7+
import { BtrixElement } from "@/classes/BtrixElement";
8+
import type { Collection } from "@/types/collection";
9+
import { pluralOf } from "@/utils/pluralize";
10+
11+
/**
12+
* Display list of collections that are linked to a workflow or archived item by ID.
13+
*/
14+
@customElement("btrix-linked-collections-list")
15+
@localized()
16+
export class LinkedCollectionsList extends BtrixElement {
17+
/**
18+
* List of collection IDs, checked against values so collection data is not
19+
* unnecessarily fetched if IDs have not changed
20+
*/
21+
@property({ type: Array, hasChanged: (a, b) => !isEqual(a, b) })
22+
collectionIds: string[] = [];
23+
24+
private readonly collectionsTask = new Task(this, {
25+
task: async ([ids], { signal }) => {
26+
return Promise.all(ids.map(async (id) => this.getCollection(id, signal)));
27+
},
28+
args: () => [this.collectionIds] as const,
29+
});
30+
31+
render() {
32+
return this.collectionsTask.render({
33+
complete: this.renderList,
34+
});
35+
}
36+
37+
private readonly renderList = (items: (Collection | undefined)[]) => {
38+
const collections = items.filter((v): v is Collection => v !== undefined);
39+
40+
if (!collections.length) {
41+
return;
42+
}
43+
44+
return html`<ul class="divide-y rounded border">
45+
${collections.map(
46+
(col) =>
47+
html`<li class="flex items-center">
48+
<div class="flex-1 p-1.5 leading-none">${col.name}</div>
49+
<div class="flex-none">
50+
<btrix-badge pill variant="cyan"
51+
>${col.crawlCount}
52+
${pluralOf("items", col.crawlCount)}</btrix-badge
53+
>
54+
</div>
55+
<div class="flex-none">
56+
<sl-tooltip placement="right" content=${msg("Open in New Tab")}>
57+
<sl-icon-button
58+
name="arrow-up-right"
59+
href="${this.navigate.orgBasePath}/collections/view/${col.id}"
60+
target="_blank"
61+
>
62+
</sl-icon-button>
63+
</sl-tooltip>
64+
</div>
65+
</li>`,
66+
)}
67+
</ul>`;
68+
};
69+
70+
private async getCollection(id: string, signal: AbortSignal) {
71+
return this.api.fetch<Collection | undefined>(
72+
`/orgs/${this.orgId}/collections/${id}`,
73+
{ signal },
74+
);
75+
}
76+
}

0 commit comments

Comments
 (0)