Skip to content

Commit

Permalink
chore: Refactor page headers (#2282)
Browse files Browse the repository at this point in the history
- Refactors all page headers to use new `pageHeader`
- Removes border under org name/title in the org dashboard
  • Loading branch information
SuaYoo committed Jan 9, 2025
1 parent 6614f05 commit 67eff18
Show file tree
Hide file tree
Showing 10 changed files with 119 additions and 142 deletions.
47 changes: 1 addition & 46 deletions frontend/src/layouts/page.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import clsx from "clsx";
import { html, nothing, type TemplateResult } from "lit";
import { ifDefined } from "lit/directives/if-defined.js";
import { html as staticHtml, unsafeStatic } from "lit/static-html.js";

import { pageNav, pageTitle } from "./pageHeader";
import { pageHeader, pageNav } from "./pageHeader";

import { tw } from "@/utils/tailwind";

type Content = string | TemplateResult | typeof nothing;

export function pageHeading({
content,
level = 2,
Expand All @@ -29,48 +26,6 @@ export function pageHeading({
`;
}

// TODO consolidate with pageHeader.ts https://github.com/webrecorder/browsertrix/issues/2197
export function pageHeader({
title,
prefix,
suffix,
secondary,
actions,
border = true,
classNames,
}: {
title?: Content;
prefix?: Content;
suffix?: Content;
secondary?: Content;
actions?: Content;
border?: boolean;
classNames?: typeof tw;
}) {
return html`
<header
class=${clsx(
tw`mt-5 flex flex-col gap-3 lg:flex-row`,
border && tw`border-b pb-3`,
classNames,
)}
>
<div class="flex flex-1 flex-col gap-2">
<div class="flex flex-wrap items-center gap-2.5">
${prefix}${pageTitle(title)}${suffix}
</div>
${secondary}
</div>
${actions
? html`<div class="ml-auto flex flex-shrink-0 items-center gap-2">
${actions}
</div>`
: nothing}
</header>
`;
}

export function page(
header: Parameters<typeof pageHeader>[0] & {
breadcrumbs?: Parameters<typeof pageNav>[0];
Expand Down
42 changes: 32 additions & 10 deletions frontend/src/layouts/pageHeader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { ifDefined } from "lit/directives/if-defined.js";
import { NavigateController } from "@/controllers/navigate";
import { tw } from "@/utils/tailwind";

type Content = string | TemplateResult | typeof nothing;

export type Breadcrumb = {
href?: string;
content?: string | TemplateResult;
Expand Down Expand Up @@ -101,22 +103,42 @@ export function pageNav(breadcrumbs: Breadcrumb[]) {
return pageBreadcrumbs(breadcrumbs);
}

// TODO consolidate with page.ts https://github.com/webrecorder/browsertrix/issues/2197
export function pageHeader(
title?: string | TemplateResult,
suffix?: TemplateResult<1>,
classNames?: string,
) {
export function pageHeader({
title,
prefix,
suffix,
secondary,
actions,
border = true,
classNames,
}: {
title?: Content;
prefix?: Content;
suffix?: Content;
secondary?: Content;
actions?: Content;
border?: boolean;
classNames?: typeof tw | string;
}) {
return html`
<header
class=${clsx(
"mt-5 flex items-end flex-wrap justify-between gap-2 border-b pb-3",
tw`mt-5 flex flex-col gap-3 lg:flex-row`,
border && tw`border-b pb-3`,
classNames,
)}
>
${pageTitle(title)}
${suffix
? html`<div class="ml-auto flex items-center gap-2">${suffix}</div>`
<div class="flex flex-1 flex-col gap-2">
<div class="flex flex-wrap items-center gap-2.5">
${prefix}${pageTitle(title)}${suffix}
</div>
${secondary}
</div>
${actions
? html`<div class="ml-auto flex flex-shrink-0 items-center gap-2">
${actions}
</div>`
: nothing}
</header>
`;
Expand Down
5 changes: 4 additions & 1 deletion frontend/src/pages/account-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,10 @@ export class AccountSettings extends BtrixElement {
title=${msg("Account Settings")}
></btrix-document-title>
${pageHeader(msg("Account Settings"), undefined, tw`mb-3 lg:mb-5`)}
${pageHeader({
title: msg("Account Settings"),
classNames: tw`mb-3 lg:mb-5`,
})}
<btrix-tab-list activePanel=${this.activeTab} hideIndicator>
<header slot="header" class="flex h-7 items-end justify-between">
Expand Down
43 changes: 21 additions & 22 deletions frontend/src/pages/org/archived-items.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,29 +264,28 @@ export class CrawlsList extends BtrixElement {
return html`
<main>
<div class="contents">
${pageHeader(
msg("Archived Items"),
when(
this.isCrawler,
() => html`
<sl-tooltip
content=${msg("Org Storage Full")}
?disabled=${!this.org?.storageQuotaReached}
>
<sl-button
size="small"
variant="primary"
@click=${() => (this.isUploadingArchive = true)}
?disabled=${isArchivingDisabled(this.org)}
${pageHeader({
title: msg("Archived Items"),
actions: this.isCrawler
? html`
<sl-tooltip
content=${msg("Org Storage Full")}
?disabled=${!this.org?.storageQuotaReached}
>
<sl-icon slot="prefix" name="upload"></sl-icon>
${msg("Upload WACZ")}
</sl-button>
</sl-tooltip>
`,
),
tw`mb-3`,
)}
<sl-button
size="small"
variant="primary"
@click=${() => (this.isUploadingArchive = true)}
?disabled=${isArchivingDisabled(this.org)}
>
<sl-icon slot="prefix" name="upload"></sl-icon>
${msg("Upload WACZ")}
</sl-button>
</sl-tooltip>
`
: nothing,
classNames: tw`mb-3`,
})}
<div class="mb-3 flex gap-2">
${listTypes.map(({ label, itemType, icon }) => {
const isSelected = itemType === this.itemType;
Expand Down
47 changes: 23 additions & 24 deletions frontend/src/pages/org/browser-profiles-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,30 +93,29 @@ export class BrowserProfilesList extends BtrixElement {
}

render() {
return html`${pageHeader(
msg("Browser Profiles"),
when(
this.isCrawler,
() => html`
<sl-button
variant="primary"
size="small"
?disabled=${isArchivingDisabled(this.org)}
@click=${() => {
this.dispatchEvent(
new CustomEvent("select-new-dialog", {
detail: "browser-profile",
}) as SelectNewDialogEvent,
);
}}
>
<sl-icon slot="prefix" name="plus-lg"></sl-icon>
${msg("New Browser Profile")}
</sl-button>
`,
),
tw`mb-3`,
)}
return html`${pageHeader({
title: msg("Browser Profiles"),
actions: this.isCrawler
? html`
<sl-button
variant="primary"
size="small"
?disabled=${isArchivingDisabled(this.org)}
@click=${() => {
this.dispatchEvent(
new CustomEvent("select-new-dialog", {
detail: "browser-profile",
}) as SelectNewDialogEvent,
);
}}
>
<sl-icon slot="prefix" name="plus-lg"></sl-icon>
${msg("New Browser Profile")}
</sl-button>
`
: undefined,
classNames: tw`mb-3`,
})}
<div class="pb-1">${this.renderTable()}</div>`;
}

Expand Down
3 changes: 1 addition & 2 deletions frontend/src/pages/org/collection-detail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ import type { MarkdownEditor } from "@/components/ui/markdown-editor";
import type { PageChangeEvent } from "@/components/ui/pagination";
import { SelectCollectionAccess } from "@/features/collections/select-collection-access";
import type { ShareCollection } from "@/features/collections/share-collection";
import { pageHeader } from "@/layouts/page";
import { pageNav, type Breadcrumb } from "@/layouts/pageHeader";
import { pageHeader, pageNav, type Breadcrumb } from "@/layouts/pageHeader";
import type {
APIPaginatedList,
APIPaginationQuery,
Expand Down
19 changes: 8 additions & 11 deletions frontend/src/pages/org/collections-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,24 +132,21 @@ export class CollectionsList extends BtrixElement {
render() {
return html`
<div class="contents">
${pageHeader(
msg("Collections"),
when(
this.isCrawler,
() => html`
<sl-button
${pageHeader({
title: msg("Collections"),
actions: this.isCrawler
? html` <sl-button
variant="primary"
size="small"
?disabled=${!this.org || this.org.readOnly}
@click=${() => (this.openDialogName = "create")}
>
<sl-icon slot="prefix" name="plus-lg"></sl-icon>
${msg("New Collection")}
</sl-button>
`,
),
tw`border-b-transparent`,
)}
</sl-button>`
: nothing,
classNames: tw`border-b-transparent`,
})}
</div>
<link rel="preload" as="image" href=${noCollectionsImg} />
Expand Down
11 changes: 6 additions & 5 deletions frontend/src/pages/org/dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { RouteNamespace } from "@/routes";
import type { PublicCollection } from "@/types/collection";
import type { PublicOrgCollections } from "@/types/org";
import { humanizeExecutionSeconds } from "@/utils/executionTimeFormatter";
import { tw } from "@/utils/tailwind";

type Metrics = {
storageUsedBytes: number;
Expand Down Expand Up @@ -84,9 +85,9 @@ export class Dashboard extends BtrixElement {
this.metrics.storageUsedBytes >= this.metrics.storageQuotaBytes;

return html`
${pageHeader(
this.userOrg?.name,
html`
${pageHeader({
title: this.userOrg?.name,
actions: html`
${when(
this.appState.isAdmin,
() =>
Expand Down Expand Up @@ -153,8 +154,8 @@ export class Dashboard extends BtrixElement {
</sl-dropdown>`,
)}
`,
"mb-6",
)}
classNames: tw`border-b-transparent lg:mb-2`,
})}
<main>
<div class="mb-10 flex flex-col gap-6 md:flex-row">
${this.renderCard(
Expand Down
34 changes: 18 additions & 16 deletions frontend/src/pages/org/settings/settings.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { localized, msg, str } from "@lit/localize";
import type { SlInput } from "@shoelace-style/shoelace";
import { serialize } from "@shoelace-style/shoelace/dist/utilities/form.js";
import { html, unsafeCSS, type PropertyValues } from "lit";
import { html, nothing, unsafeCSS, type PropertyValues } from "lit";
import { customElement, property, state } from "lit/decorators.js";
import { choose } from "lit/directives/choose.js";
import { ifDefined } from "lit/directives/if-defined.js";
Expand Down Expand Up @@ -136,21 +136,23 @@ export class OrgSettings extends BtrixElement {
}

render() {
return html` ${pageHeader(
msg("Org Settings"),
when(
this.userInfo?.orgs && this.userInfo.orgs.length > 1 && this.userOrg,
(userOrg) => html`
<div class="text-neutral-400">
${msg(
html`Viewing
<strong class="font-medium">${userOrg.name}</strong>`,
)}
</div>
`,
),
tw`mb-3 lg:mb-5`,
)}
return html` ${pageHeader({
title: msg("Org Settings"),
actions:
this.userInfo?.orgs && this.userInfo.orgs.length > 1 && this.userOrg
? html`
<div class="text-neutral-400">
${msg(
html`Viewing
<strong class="font-medium"
>${this.userOrg.name}</strong
>`,
)}
</div>
`
: nothing,
classNames: tw`mb-3 lg:mb-5`,
})}
<btrix-tab-list activePanel=${this.activePanel} hideIndicator>
<header slot="header" class="flex h-7 items-end justify-between">
Expand Down
10 changes: 5 additions & 5 deletions frontend/src/pages/org/workflows-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,9 @@ export class WorkflowsList extends BtrixElement {
render() {
return html`
<div class="contents">
${pageHeader(
msg("Crawl Workflows"),
html`
${pageHeader({
title: msg("Crawl Workflows"),
actions: html`
${when(
this.appState.isAdmin,
() =>
Expand Down Expand Up @@ -304,8 +304,8 @@ export class WorkflowsList extends BtrixElement {
`,
)}
`,
tw`border-b-transparent`,
)}
classNames: tw`border-b-transparent`,
})}
<div class="sticky top-2 z-10 mb-3 rounded-lg border bg-neutral-50 p-4">
${this.renderControls()}
</div>
Expand Down

0 comments on commit 67eff18

Please sign in to comment.