From dd580434038b1c334a1af6d6c550ea0e37c49b55 Mon Sep 17 00:00:00 2001 From: sua yoo Date: Tue, 19 Nov 2024 13:01:07 -0800 Subject: [PATCH] add frontend enum --- .../collections/collection-metadata-dialog.ts | 6 ++++-- frontend/src/pages/org/collection-detail.ts | 20 +++++++++++-------- frontend/src/pages/org/collections-list.ts | 14 +++++++++---- frontend/src/types/collection.ts | 8 +++++++- 4 files changed, 33 insertions(+), 15 deletions(-) diff --git a/frontend/src/features/collections/collection-metadata-dialog.ts b/frontend/src/features/collections/collection-metadata-dialog.ts index e19f0b2524..f83e8eaff2 100644 --- a/frontend/src/features/collections/collection-metadata-dialog.ts +++ b/frontend/src/features/collections/collection-metadata-dialog.ts @@ -14,7 +14,7 @@ import { when } from "lit/directives/when.js"; import { BtrixElement } from "@/classes/BtrixElement"; import type { Dialog } from "@/components/ui/dialog"; import type { MarkdownEditor } from "@/components/ui/markdown-editor"; -import type { Collection } from "@/types/collection"; +import { CollectionVisibility, type Collection } from "@/types/collection"; import { isApiError } from "@/utils/api"; import { maxLengthValidator } from "@/utils/form"; @@ -180,7 +180,9 @@ export class CollectionMetadataDialog extends BtrixElement { const body = JSON.stringify({ name, description, - visibility: !isPublic ? "private" : "unlisted", + visibility: !isPublic + ? CollectionVisibility.Private + : CollectionVisibility.Unlisted, }); let path = `/orgs/${this.orgId}/collections`; let method = "POST"; diff --git a/frontend/src/pages/org/collection-detail.ts b/frontend/src/pages/org/collection-detail.ts index 0814857d50..817e2e2e05 100644 --- a/frontend/src/pages/org/collection-detail.ts +++ b/frontend/src/pages/org/collection-detail.ts @@ -16,7 +16,7 @@ import type { APIPaginationQuery, APISortQuery, } from "@/types/api"; -import type { Collection } from "@/types/collection"; +import { CollectionVisibility, type Collection } from "@/types/collection"; import type { ArchivedItem, Crawl, Upload } from "@/types/crawler"; import type { CrawlState } from "@/types/crawlState"; import { formatNumber, getLocale } from "@/utils/localization"; @@ -100,7 +100,7 @@ export class CollectionDetail extends BtrixElement {
- ${this.collection?.visibility === "unlisted" + ${this.collection?.visibility === CollectionVisibility.Unlisted ? html`
${when( - this.isCrawler || this.collection?.visibility !== "private", + this.isCrawler || + this.collection?.visibility !== CollectionVisibility.Private, () => html` ${ - this.collection?.visibility === "unlisted" + this.collection?.visibility === CollectionVisibility.Unlisted ? "" : html`

${msg( @@ -253,7 +254,8 @@ export class CollectionDetail extends BtrixElement { () => html`

void this.onTogglePublic((e.target as SlCheckbox).checked)} >${msg("Collection is Shareable")} - ${when(this.collection?.visibility === "unlisted", this.renderShareInfo)} + ${when(this.collection?.visibility === CollectionVisibility.Unlisted, this.renderShareInfo)}
(this.showShareInfo = false)} >${msg("Done")} - ${this.collection?.visibility === "private" + ${this.collection?.visibility === CollectionVisibility.Private ? html` ( `/orgs/${this.orgId}/collections/${this.collectionId}`, { diff --git a/frontend/src/pages/org/collections-list.ts b/frontend/src/pages/org/collections-list.ts index adfa3db2e5..f111ac48b5 100644 --- a/frontend/src/pages/org/collections-list.ts +++ b/frontend/src/pages/org/collections-list.ts @@ -15,7 +15,11 @@ import type { PageChangeEvent } from "@/components/ui/pagination"; import type { CollectionSavedEvent } from "@/features/collections/collection-metadata-dialog"; import { pageHeader } from "@/layouts/pageHeader"; import type { APIPaginatedList, APIPaginationQuery } from "@/types/api"; -import type { Collection, CollectionSearchValues } from "@/types/collection"; +import { + CollectionVisibility, + type Collection, + type CollectionSearchValues, +} from "@/types/collection"; import type { UnderlyingFunction } from "@/types/utils"; import { isApiError } from "@/utils/api"; import { formatNumber, getLocale } from "@/utils/localization"; @@ -500,7 +504,7 @@ export class CollectionsList extends BtrixElement { class="cursor-pointer select-none rounded border shadow transition-all focus-within:bg-neutral-50 hover:bg-neutral-50 hover:shadow-none" > - ${col.visibility === "unlisted" + ${col.visibility === CollectionVisibility.Unlisted ? html` - ${col.visibility === "private" + ${col.visibility === CollectionVisibility.Private ? html`