From daeb7448f5896121389b6d7411590a818f06940c Mon Sep 17 00:00:00 2001 From: sua yoo Date: Thu, 25 Jul 2024 18:47:40 -0400 Subject: [PATCH] feat: Minor improvements to superadmin view (#1971) Resolves https://github.com/webrecorder/browsertrix/issues/1951 ### Changes - Shows date org was created in superadmin org list - Visually differentiates unnamed org ID - Adds "Admin" badge to app header to make current login more apparent - Fixes logic to show "create org" dialog if there are no orgs in an instance - Refactors `btrix-home` to remove unused references to non-superadmin org list --------- Co-authored-by: Henry Wilkinson --- frontend/src/components/orgs-list.ts | 24 ++++++++-- frontend/src/index.ts | 4 ++ frontend/src/pages/home.ts | 71 ++++++++-------------------- frontend/src/types/org.ts | 1 + 4 files changed, 45 insertions(+), 55 deletions(-) diff --git a/frontend/src/components/orgs-list.ts b/frontend/src/components/orgs-list.ts index bb89774c..544704ea 100644 --- a/frontend/src/components/orgs-list.ts +++ b/frontend/src/components/orgs-list.ts @@ -16,7 +16,7 @@ import { NavigateController } from "@/controllers/navigate"; import { NotifyController } from "@/controllers/notify"; import type { CurrentUser } from "@/types/user"; import type { AuthState } from "@/utils/AuthService"; -import { formatNumber } from "@/utils/localization"; +import { formatNumber, getLocale } from "@/utils/localization"; import type { OrgData } from "@/utils/orgs"; /** @@ -27,7 +27,7 @@ import type { OrgData } from "@/utils/orgs"; export class OrgsList extends TailwindElement { static styles = css` btrix-table { - grid-template-columns: min-content [clickable-start] 50ch auto auto [clickable-end] min-content; + grid-template-columns: min-content [clickable-start] 50ch auto auto auto [clickable-end] min-content; } `; @@ -76,6 +76,9 @@ export class OrgsList extends TailwindElement { ${msg("Name")} + + ${msg("Created")} + ${msg("Members")} @@ -500,7 +503,7 @@ export class OrgsList extends TailwindElement { ${msg("Default")}` : nothing} - ${org.name} + ${org.name === org.id + ? html`${org.id}` + : org.name} + + + + ${memberCount ? formatNumber(memberCount) : none} diff --git a/frontend/src/index.ts b/frontend/src/index.ts index e25085e8..e37459a5 100644 --- a/frontend/src/index.ts +++ b/frontend/src/index.ts @@ -292,6 +292,7 @@ export class App extends LiteElement { class="mx-auto box-border flex h-12 items-center justify-between px-3 xl:pl-6" > { @@ -302,6 +303,9 @@ export class App extends LiteElement { }} > Browsertrix logo + ${isSuperAdmin + ? html`${msg("Admin")}` + : nothing} ${isSuperAdmin ? html` diff --git a/frontend/src/pages/home.ts b/frontend/src/pages/home.ts index a785a3ec..eca99dde 100644 --- a/frontend/src/pages/home.ts +++ b/frontend/src/pages/home.ts @@ -1,7 +1,7 @@ import { localized, msg, str } from "@lit/localize"; import type { SlInput, SlInputEvent } from "@shoelace-style/shoelace"; import { serialize } from "@shoelace-style/shoelace/dist/utilities/form.js"; -import { type PropertyValues, type TemplateResult } from "lit"; +import { type PropertyValues } from "lit"; import { customElement, property, state } from "lit/decorators.js"; import type { InviteSuccessDetail } from "@/features/accounts/invite-form"; @@ -15,6 +15,11 @@ import type { OrgData } from "@/utils/orgs"; import slugifyStrict from "@/utils/slugify"; /** + * Home page when org is not selected. + * Currently, only visible to superadmins--redirects to user's org, otherwise + * + * TODO Refactor out superadmin UI + * * @fires btrix-update-user-info */ @localized() @@ -62,27 +67,24 @@ export class Home extends LiteElement { this.navTo(`/orgs/${this.slug}`); } else if (changedProperties.has("userInfo") && this.userInfo) { if (this.userInfo.isSuperAdmin) { - void this.fetchOrgs(); + if (this.userInfo.orgs.length) { + void this.fetchOrgs(); + } else { + this.isAddingOrg = true; + this.isAddOrgFormVisible = true; + } } else { this.navTo(`/account/settings`); } } } - async updated( - changedProperties: PropertyValues & Map, - ) { - const orgListUpdated = changedProperties.has("orgList") && this.orgList; - const userInfoUpdated = changedProperties.has("userInfo") && this.userInfo; - if (orgListUpdated || userInfoUpdated) { - if (this.userInfo?.isSuperAdmin && this.orgList && !this.orgList.length) { - this.isAddingOrg = true; - } - } - } - render() { - if (!this.userInfo || !this.orgList) { + if (!this.userInfo || !this.userInfo.isSuperAdmin) { + return; + } + + if (this.userInfo.orgs.length && !this.orgList) { return html`
@@ -90,29 +92,19 @@ export class Home extends LiteElement { `; } - let title: string | undefined; - let content: TemplateResult<1> | undefined; - - if (this.userInfo.isSuperAdmin) { - title = msg("Welcome"); - content = this.renderAdminOrgs(); - } else { - title = msg("Organizations"); - content = this.renderLoggedInNonAdmin(); - } - return html`
-

${title}

+

${msg("Welcome")}


- ${content} + ${this.renderAdminOrgs()}
+ ${this.renderAddOrgDialog()} `; } @@ -182,8 +174,6 @@ export class Home extends LiteElement {
- - ${this.renderAddOrgDialog()} `; } @@ -277,24 +267,6 @@ export class Home extends LiteElement { `; } - private renderLoggedInNonAdmin() { - if (this.orgList && !this.orgList.length) { - return html`
-

- ${msg("You don't have any organizations.")} -

-
`; - } - - return html` - - `; - } - private renderInvite() { return html`