Refactor archive tabs & navigation improvements (#123)

closes #112
This commit is contained in:
sua yoo 2022-01-31 15:45:36 -08:00 committed by GitHub
parent 9de1a3a003
commit d7c0877403
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 75 additions and 56 deletions

View File

@ -383,9 +383,7 @@ export class App extends LiteElement {
.userInfo=${this.userInfo} .userInfo=${this.userInfo}
.viewStateData=${this.viewState.data} .viewStateData=${this.viewState.data}
archiveId=${this.viewState.params.id} archiveId=${this.viewState.params.id}
archiveTab=${this.viewState.params.crawlConfigId archiveTab=${this.viewState.params.tab as ArchiveTab}
? "crawl-templates"
: (this.viewState.params.tab as ArchiveTab)}
crawlConfigId=${this.viewState.params.crawlConfigId} crawlConfigId=${this.viewState.params.crawlConfigId}
crawlId=${this.viewState.params.crawlId} crawlId=${this.viewState.params.crawlId}
?isAddingMember=${this.viewState.route === "archiveAddMember"} ?isAddingMember=${this.viewState.route === "archiveAddMember"}
@ -480,6 +478,9 @@ export class App extends LiteElement {
event.stopPropagation(); event.stopPropagation();
this.navigate(event.detail.url, event.detail.state); this.navigate(event.detail.url, event.detail.state);
// Scroll to top of page
window.scrollTo({ top: 0 });
} }
onUserInfoChange(event: CustomEvent<Partial<CurrentUser>>) { onUserInfoChange(event: CustomEvent<Partial<CurrentUser>>) {

View File

@ -153,7 +153,7 @@ export class CrawlDetail extends LiteElement {
? html` ? html`
<a <a
class="font-medium hover:underline" class="font-medium hover:underline"
href=${`/archives/${this.archiveId}/crawl-templates/${this.crawl.cid}`} href=${`/archives/${this.archiveId}/crawl-templates/config/${this.crawl.cid}`}
@click=${this.navLink} @click=${this.navLink}
>${this.crawl.configName}</a >${this.crawl.configName}</a
> >

View File

@ -218,9 +218,11 @@ export class CrawlTemplatesDetail extends LiteElement {
? html` ? html`
<sl-button <sl-button
size="small" size="small"
href=${`/archives/${this.archiveId}/crawl-templates/${ href=${`/archives/${
this.crawlTemplate.id this.archiveId
}${this.isEditing ? "" : "?edit=true"}`} }/crawl-templates/config/${this.crawlTemplate.id}${
this.isEditing ? "" : "?edit=true"
}`}
@click=${(e: any) => { @click=${(e: any) => {
const hasChanges = const hasChanges =
this.isEditing && this.editedSchedule; this.isEditing && this.editedSchedule;
@ -470,7 +472,9 @@ export class CrawlTemplatesDetail extends LiteElement {
}); });
this.navTo( this.navTo(
`/archives/${this.archiveId}/crawl-templates/${this.crawlTemplate!.id}` `/archives/${this.archiveId}/crawl-templates/config/${
this.crawlTemplate!.id
}`
); );
} catch (e: any) { } catch (e: any) {
console.error(e); console.error(e);

View File

@ -95,13 +95,13 @@ export class CrawlTemplatesList extends LiteElement {
role="button" role="button"
@click=${() => { @click=${() => {
this.navTo( this.navTo(
`/archives/${this.archiveId}/crawl-templates/${t.id}` `/archives/${this.archiveId}/crawl-templates/config/${t.id}`
); );
}} }}
> >
<header class="flex"> <header class="flex">
<a <a
href=${`/archives/${this.archiveId}/crawl-templates/${t.id}`} href=${`/archives/${this.archiveId}/crawl-templates/config/${t.id}`}
class="block flex-1 px-3 pt-3 font-medium whitespace-nowrap truncate mb-1" class="block flex-1 px-3 pt-3 font-medium whitespace-nowrap truncate mb-1"
title=${t.name} title=${t.name}
@click=${(e: any) => { @click=${(e: any) => {

View File

@ -412,7 +412,7 @@ export class CrawlsList extends LiteElement {
role="menuitem" role="menuitem"
@click=${(e: any) => { @click=${(e: any) => {
this.navTo( this.navTo(
`/archives/${this.archiveId}/crawl-templates/${crawl.cid}` `/archives/${this.archiveId}/crawl-templates/config/${crawl.cid}`
); );
}} }}
> >

View File

@ -89,6 +89,29 @@ export class Archive extends LiteElement {
const showMembersTab = Boolean(this.archive.users); const showMembersTab = Boolean(this.archive.users);
let tabPanelContent = "" as any;
switch (this.archiveTab) {
case "crawls":
tabPanelContent = this.renderCrawls();
break;
case "crawl-templates":
tabPanelContent = this.renderCrawlTemplates();
break;
case "members":
if (this.isAddingMember) {
tabPanelContent = this.renderAddMember();
} else {
tabPanelContent = this.renderMembers();
}
break;
default:
tabPanelContent = html`<btrix-not-found
class="flex items-center justify-center"
></btrix-not-found>`;
break;
}
return html`<article class="grid gap-4"> return html`<article class="grid gap-4">
<nav class="font-medium text-sm text-gray-500"> <nav class="font-medium text-sm text-gray-500">
<a <a
@ -102,56 +125,47 @@ export class Archive extends LiteElement {
</nav> </nav>
<main> <main>
<sl-tab-group @sl-tab-show=${this.updateUrl}> <nav class="flex items-end overflow-x-auto">
<sl-tab ${this.renderNavTab({ tabName: "crawls", label: msg("Crawls") })}
slot="nav" ${this.renderNavTab({
panel="crawls" tabName: "crawl-templates",
?active=${this.archiveTab === "crawls"} label: msg("Crawl Templates"),
@click=${() => this.navTo(`/archives/${this.archiveId}/crawls`)} })}
>${msg("Crawls")}
</sl-tab>
<sl-tab
slot="nav"
panel="crawl-templates"
?active=${this.archiveTab === "crawl-templates"}
@click=${() =>
this.navTo(`/archives/${this.archiveId}/crawl-templates`)}
>${msg("Crawl Templates")}
</sl-tab>
${showMembersTab ${showMembersTab
? html`<sl-tab ? this.renderNavTab({ tabName: "members", label: msg("Members") })
slot="nav"
panel="members"
?active=${this.archiveTab === "members"}
>${msg("Members")}</sl-tab
>`
: ""} : ""}
<hr class="flex-1 border-t-2" />
</nav>
<sl-tab-panel name="crawls" ?active=${this.archiveTab === "crawls"} <div class="my-5" aria-labelledby="${this.archiveTab}-tab">
>${this.renderCrawls()}</sl-tab-panel ${tabPanelContent}
> </div>
<sl-tab-panel
name="crawl-templates"
?active=${this.archiveTab === "crawl-templates"}
>${this.renderCrawlTemplates()}</sl-tab-panel
>
${showMembersTab
? html`<sl-tab-panel
name="members"
?active=${this.archiveTab === "members"}
>
${this.isAddingMember
? this.renderAddMember()
: this.renderMembers()}
</sl-tab-panel>`
: ""}
</sl-tab-group>
</main> </main>
</article>`; </article>`;
} }
private renderSettings() { private renderNavTab({
return html` TODO `; tabName,
label,
}: {
tabName: ArchiveTab;
label: string;
}) {
const isActive = this.archiveTab === tabName;
return html`
<a
id="${tabName}-tab"
class="block flex-shrink-0 text-sm font-medium p-3 md:px-5 border-b-2 transition-colors ${isActive
? "border-primary text-primary"
: "text-0-600"}"
href=${`/archives/${this.archiveId}/${tabName}`}
aria-selected=${isActive}
@click=${this.navLink}
>
${label}
</a>
`;
} }
private renderCrawls() { private renderCrawls() {

View File

@ -15,8 +15,8 @@ export const ROUTES = {
archiveNewResourceTab: "/archives/:id/:tab/new", archiveNewResourceTab: "/archives/:id/:tab/new",
archiveAddMember: "/archives/:id/:tab/add-member", archiveAddMember: "/archives/:id/:tab/add-member",
crawl: "/archives/:id/:tab/crawl/:crawlId", crawl: "/archives/:id/:tab/crawl/:crawlId",
crawlTemplate: "/archives/:id/crawl-templates/:crawlConfigId", crawlTemplate: "/archives/:id/:tab/config/:crawlConfigId",
crawlTemplateEdit: "/archives/:id/crawl-templates/:crawlConfigId?edit", crawlTemplateEdit: "/archives/:id/:tab/config/:crawlConfigId?edit",
users: "/users", users: "/users",
usersInvite: "/users/invite", usersInvite: "/users/invite",
} as const; } as const;