Skip to content

Commit b19205e

Browse files
committed
update archived item settings
1 parent 4df97c0 commit b19205e

File tree

7 files changed

+146
-98
lines changed

7 files changed

+146
-98
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,9 +315,9 @@ export class ConfigDetails extends BtrixElement {
315315
${this.renderSetting(
316316
html`<span class="mb-1 inline-block">${msg("Auto-Add")}</span>`,
317317
crawlConfig?.autoAddCollections.length
318-
? html`<btrix-linked-collections-list
318+
? html`<btrix-linked-collections
319319
.collectionIds=${crawlConfig.autoAddCollections}
320-
></btrix-linked-collections-list>`
320+
></btrix-linked-collections>`
321321
: undefined,
322322
)}
323323
`,

frontend/src/features/collections/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +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");
9+
import("./linked-collections");
1010
import("./select-collection-access");
1111
import("./select-collection-page");
1212
import("./share-collection");

frontend/src/features/collections/linked-collections-list.ts

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

frontend/src/pages/org/archived-item-detail/archived-item-detail.ts

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -403,13 +403,13 @@ export class ArchivedItemDetail extends BtrixElement {
403403
break;
404404
default:
405405
sectionContent = html`
406-
<div class="grid grid-cols-1 gap-5 lg:grid-cols-2">
407-
<div class="col-span-1 flex flex-col">
406+
<div class="grid grid-cols-1 gap-5 lg:grid-cols-2 lg:grid-rows-2">
407+
<div class="col-span-1 row-span-1 flex flex-col lg:row-span-2">
408408
${this.renderPanel(msg("Overview"), this.renderOverview(), [
409409
tw`rounded-lg border p-4`,
410410
])}
411411
</div>
412-
<div class="col-span-1 flex flex-col">
412+
<div class="col-span-1 row-span-1 flex flex-col">
413413
${this.renderPanel(
414414
html`
415415
${this.renderTitle(msg("Metadata"))}
@@ -429,6 +429,11 @@ export class ArchivedItemDetail extends BtrixElement {
429429
[tw`rounded-lg border p-4`],
430430
)}
431431
</div>
432+
<div class="col-span-1 row-span-1 flex flex-col">
433+
${this.renderPanel(msg("Collections"), this.renderCollections(), [
434+
tw`rounded-lg border p-4`,
435+
])}
436+
</div>
432437
</div>
433438
`;
434439
break;
@@ -959,26 +964,26 @@ export class ArchivedItemDetail extends BtrixElement {
959964
() => html`<sl-skeleton class="h-[16px] w-24"></sl-skeleton>`,
960965
)}
961966
</btrix-desc-list-item>
962-
<btrix-desc-list-item label=${msg("In Collections")}>
967+
</btrix-desc-list>
968+
`;
969+
}
970+
971+
private renderCollections() {
972+
const noneText = html`<span class="text-neutral-300">${msg("None")}</span>`;
973+
return html`
974+
<btrix-desc-list>
975+
<btrix-desc-list-item label=${msg("Included In")}>
963976
${when(
964977
this.item,
965-
() =>
978+
(item) =>
966979
when(
967-
this.item!.collections.length,
980+
item.collections.length,
968981
() => html`
969-
<ul>
970-
${this.item!.collections.map(
971-
({ id, name }) =>
972-
html`<li class="mt-1">
973-
<a
974-
class="text-primary hover:text-primary-400"
975-
href=${`${this.navigate.orgBasePath}/collections/view/${id}`}
976-
@click=${this.navigate.link}
977-
>${name}</a
978-
>
979-
</li>`,
980-
)}
981-
</ul>
982+
<btrix-linked-collections-list
983+
class="mt-1 block"
984+
.collections=${item.collections}
985+
baseUrl="${this.navigate.orgBasePath}/collections/view"
986+
></btrix-linked-collections-list>
982987
`,
983988
() => noneText,
984989
),

0 commit comments

Comments
 (0)