Skip to content

Commit daeb744

Browse files
SuaYooShrinks99
andauthored
feat: Minor improvements to superadmin view (#1971)
Resolves #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 <[email protected]>
1 parent 94e985a commit daeb744

File tree

4 files changed

+44
-54
lines changed

4 files changed

+44
-54
lines changed

frontend/src/components/orgs-list.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { NavigateController } from "@/controllers/navigate";
1616
import { NotifyController } from "@/controllers/notify";
1717
import type { CurrentUser } from "@/types/user";
1818
import type { AuthState } from "@/utils/AuthService";
19-
import { formatNumber } from "@/utils/localization";
19+
import { formatNumber, getLocale } from "@/utils/localization";
2020
import type { OrgData } from "@/utils/orgs";
2121

2222
/**
@@ -27,7 +27,7 @@ import type { OrgData } from "@/utils/orgs";
2727
export class OrgsList extends TailwindElement {
2828
static styles = css`
2929
btrix-table {
30-
grid-template-columns: min-content [clickable-start] 50ch auto auto [clickable-end] min-content;
30+
grid-template-columns: min-content [clickable-start] 50ch auto auto auto [clickable-end] min-content;
3131
}
3232
`;
3333

@@ -76,6 +76,9 @@ export class OrgsList extends TailwindElement {
7676
<btrix-table-header-cell class="px-2">
7777
${msg("Name")}
7878
</btrix-table-header-cell>
79+
<btrix-table-header-cell class="px-2">
80+
${msg("Created")}
81+
</btrix-table-header-cell>
7982
<btrix-table-header-cell class="px-2">
8083
${msg("Members")}
8184
</btrix-table-header-cell>
@@ -500,17 +503,30 @@ export class OrgsList extends TailwindElement {
500503
</btrix-table-cell>
501504
<btrix-table-cell class="p-2" rowClickTarget="a">
502505
<a
503-
class=${org.readOnly ? "text-neutral-400" : "text-neutral-900"}
506+
class=${org.readOnly ? "text-neutral-500" : "text-neutral-900"}
504507
href="/orgs/${org.slug}"
505508
@click=${this.navigate.link}
506509
aria-disabled="${!isUserOrg}"
507510
>
508511
${org.default
509512
? html`<btrix-tag class="mr-1">${msg("Default")}</btrix-tag>`
510513
: nothing}
511-
${org.name}
514+
${org.name === org.id
515+
? html`<code class="text-neutral-400">${org.id}</code>`
516+
: org.name}
512517
</a>
513518
</btrix-table-cell>
519+
520+
<btrix-table-cell class="p-2">
521+
<sl-format-date
522+
lang=${getLocale()}
523+
class="truncate"
524+
date=${`${org.created}Z`}
525+
month="2-digit"
526+
day="2-digit"
527+
year="2-digit"
528+
></sl-format-date>
529+
</btrix-table-cell>
514530
<btrix-table-cell class="p-2">
515531
${memberCount ? formatNumber(memberCount) : none}
516532
</btrix-table-cell>

frontend/src/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ export class App extends LiteElement {
292292
class="mx-auto box-border flex h-12 items-center justify-between px-3 xl:pl-6"
293293
>
294294
<a
295+
class="items-between flex gap-2"
295296
aria-label="home"
296297
href=${homeHref}
297298
@click=${(e: MouseEvent) => {
@@ -302,6 +303,9 @@ export class App extends LiteElement {
302303
}}
303304
>
304305
<img class="h-6" alt="Browsertrix logo" src=${brandLockupColor} />
306+
${isSuperAdmin
307+
? html`<btrix-tag>${msg("Admin")}</btrix-tag>`
308+
: nothing}
305309
</a>
306310
${isSuperAdmin
307311
? html`

frontend/src/pages/home.ts

Lines changed: 19 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { localized, msg, str } from "@lit/localize";
22
import type { SlInput, SlInputEvent } from "@shoelace-style/shoelace";
33
import { serialize } from "@shoelace-style/shoelace/dist/utilities/form.js";
4-
import { type PropertyValues, type TemplateResult } from "lit";
4+
import { type PropertyValues } from "lit";
55
import { customElement, property, state } from "lit/decorators.js";
66

77
import type { InviteSuccessDetail } from "@/features/accounts/invite-form";
@@ -15,6 +15,11 @@ import type { OrgData } from "@/utils/orgs";
1515
import slugifyStrict from "@/utils/slugify";
1616

1717
/**
18+
* Home page when org is not selected.
19+
* Currently, only visible to superadmins--redirects to user's org, otherwise
20+
*
21+
* TODO Refactor out superadmin UI
22+
*
1823
* @fires btrix-update-user-info
1924
*/
2025
@localized()
@@ -62,57 +67,44 @@ export class Home extends LiteElement {
6267
this.navTo(`/orgs/${this.slug}`);
6368
} else if (changedProperties.has("userInfo") && this.userInfo) {
6469
if (this.userInfo.isSuperAdmin) {
65-
void this.fetchOrgs();
70+
if (this.userInfo.orgs.length) {
71+
void this.fetchOrgs();
72+
} else {
73+
this.isAddingOrg = true;
74+
this.isAddOrgFormVisible = true;
75+
}
6676
} else {
6777
this.navTo(`/account/settings`);
6878
}
6979
}
7080
}
7181

72-
async updated(
73-
changedProperties: PropertyValues<this> & Map<string, unknown>,
74-
) {
75-
const orgListUpdated = changedProperties.has("orgList") && this.orgList;
76-
const userInfoUpdated = changedProperties.has("userInfo") && this.userInfo;
77-
if (orgListUpdated || userInfoUpdated) {
78-
if (this.userInfo?.isSuperAdmin && this.orgList && !this.orgList.length) {
79-
this.isAddingOrg = true;
80-
}
82+
render() {
83+
if (!this.userInfo || !this.userInfo.isSuperAdmin) {
84+
return;
8185
}
82-
}
8386

84-
render() {
85-
if (!this.userInfo || !this.orgList) {
87+
if (this.userInfo.orgs.length && !this.orgList) {
8688
return html`
8789
<div class="my-24 flex items-center justify-center text-3xl">
8890
<sl-spinner></sl-spinner>
8991
</div>
9092
`;
9193
}
9294

93-
let title: string | undefined;
94-
let content: TemplateResult<1> | undefined;
95-
96-
if (this.userInfo.isSuperAdmin) {
97-
title = msg("Welcome");
98-
content = this.renderAdminOrgs();
99-
} else {
100-
title = msg("Organizations");
101-
content = this.renderLoggedInNonAdmin();
102-
}
103-
10495
return html`
10596
<div class="bg-white">
10697
<header
10798
class="mx-auto box-border w-full max-w-screen-desktop px-3 py-4 md:py-8"
10899
>
109-
<h1 class="text-xl font-medium">${title}</h1>
100+
<h1 class="text-xl font-medium">${msg("Welcome")}</h1>
110101
</header>
111102
<hr />
112103
</div>
113104
<main class="mx-auto box-border w-full max-w-screen-desktop px-3 py-4">
114-
${content}
105+
${this.renderAdminOrgs()}
115106
</main>
107+
${this.renderAddOrgDialog()}
116108
`;
117109
}
118110

@@ -182,8 +174,6 @@ export class Home extends LiteElement {
182174
</section>
183175
</div>
184176
</div>
185-
186-
${this.renderAddOrgDialog()}
187177
`;
188178
}
189179

@@ -277,24 +267,6 @@ export class Home extends LiteElement {
277267
`;
278268
}
279269

280-
private renderLoggedInNonAdmin() {
281-
if (this.orgList && !this.orgList.length) {
282-
return html`<div class="rounded-lg border bg-white p-4 md:p-8">
283-
<p class="text-center text-neutral-400">
284-
${msg("You don't have any organizations.")}
285-
</p>
286-
</div>`;
287-
}
288-
289-
return html`
290-
<btrix-orgs-list
291-
.userInfo=${this.userInfo}
292-
.orgList=${this.orgList}
293-
?skeleton=${!this.orgList}
294-
></btrix-orgs-list>
295-
`;
296-
}
297-
298270
private renderInvite() {
299271
return html`
300272
<btrix-invite-form
@@ -384,9 +356,6 @@ export class Home extends LiteElement {
384356
// Update user info since orgs are checked against userInfo.orgs
385357
this.dispatchEvent(new CustomEvent("btrix-update-user-info"));
386358

387-
await this.updateComplete;
388-
void this.fetchOrgs();
389-
390359
this.notify({
391360
message: msg(str`Created new org named "${params.name}".`),
392361
variant: "success",

frontend/src/types/org.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export type OrgQuotas = {
3131
export type OrgData = {
3232
id: string;
3333
name: string;
34+
created: string;
3435
slug: string;
3536
default: boolean;
3637
quotas: OrgQuotas;

0 commit comments

Comments
 (0)