From 35469915a89c5c5ab04f284ae4a0c3c808e52525 Mon Sep 17 00:00:00 2001 From: sua yoo Date: Tue, 21 May 2024 14:45:38 -0700 Subject: [PATCH] refactor org list --- frontend/src/components/orgs-list.ts | 96 ++++++++++++---------------- frontend/src/types/org.ts | 1 + 2 files changed, 42 insertions(+), 55 deletions(-) diff --git a/frontend/src/components/orgs-list.ts b/frontend/src/components/orgs-list.ts index 344d0724..2f291ba8 100644 --- a/frontend/src/components/orgs-list.ts +++ b/frontend/src/components/orgs-list.ts @@ -1,6 +1,6 @@ import { localized, msg, str } from "@lit/localize"; import type { SlChangeEvent, SlInput } from "@shoelace-style/shoelace"; -import { html, type TemplateResult } from "lit"; +import { css, html, nothing } from "lit"; import { customElement, property, query, state } from "lit/decorators.js"; import { when } from "lit/directives/when.js"; @@ -8,12 +8,18 @@ import { TailwindElement } from "@/classes/TailwindElement"; import type { Dialog } from "@/components/ui/dialog"; import { APIController } from "@/controllers/api"; import { NavigateController } from "@/controllers/navigate"; -import type { CurrentUser, UserOrg } from "@/types/user"; +import type { CurrentUser } from "@/types/user"; +import { formatNumber } from "@/utils/localization"; import type { OrgData } from "@/utils/orgs"; @localized() @customElement("btrix-orgs-list") export class OrgsList extends TailwindElement { + static styles = css` + btrix-table { + grid-template-columns: [clickable-start] auto auto [clickable-end] min-content; + } + `; @property({ type: Object }) userInfo?: CurrentUser; @@ -43,14 +49,20 @@ export class OrgsList extends TailwindElement { return this.renderSkeleton(); } - const defaultOrg = this.userInfo?.orgs.find((org) => org.default === true); - return html` - + + + ${msg("Name")} + ${msg("Members")} + + ${msg("Actions")} + + + + ${this.orgList?.map(this.renderOrg)} + + + ${this.renderOrgDelete()} ${this.renderOrgQuotas()} `; } @@ -229,40 +241,31 @@ export class OrgsList extends TailwindElement { } } - private readonly renderOrg = (defaultOrg?: UserOrg) => (org: OrgData) => { + private readonly renderOrg = (org: OrgData) => { if (!this.userInfo) return; - // There shouldn't really be a case where an org is in the org list but - // not in user info, but disable clicking into the org just in case - const isUserOrg = this.userInfo.orgs.some(({ id }) => id === org.id); + // // There shouldn't really be a case where an org is in the org list but + // // not in user info, but disable clicking into the org just in case + // const isUserOrg = this.userInfo.orgs.some(({ id }) => id === org.id); - let defaultLabel: TemplateResult | undefined; - - if (defaultOrg && org.id === defaultOrg.id) { - defaultLabel = html`${msg("Default")}`; - } const memberCount = Object.keys(org.users || {}).length; return html` -
  • -
    - ${defaultLabel}${org.name} -
    -
    -
    - ${memberCount === 1 - ? msg(`1 member`) - : msg(str`${memberCount} members`)} -
    + + + ${org.default + ? html`${msg("Default")}` + : nothing} + ${org.name} + + + + ${formatNumber(memberCount)} + + e.stopPropagation()} > @@ -288,8 +291,8 @@ export class OrgsList extends TailwindElement { -
    -
  • + + `; }; @@ -302,21 +305,4 @@ export class OrgsList extends TailwindElement { `; } - - private makeOnOrgClick(org: OrgData) { - const navigate = () => this.navigate.to(`/orgs/${org.slug}`); - - if (typeof window.getSelection !== "undefined") { - return () => { - // Prevent navigation on user text selection - if (window.getSelection()?.type === "Range") { - return; - } - - navigate(); - }; - } - - return navigate; - } } diff --git a/frontend/src/types/org.ts b/frontend/src/types/org.ts index d3020d94..38a56cf4 100644 --- a/frontend/src/types/org.ts +++ b/frontend/src/types/org.ts @@ -17,6 +17,7 @@ export type OrgData = { id: string; name: string; slug: string; + default: boolean; quotas?: Record; bytesStored: number; bytesStoredCrawls: number;