fix: Prevent browser profile selection overflow (#2029)

- Truncates selected browser profile description and refreshes style
- Order browser profiles by modified date
This commit is contained in:
sua yoo 2024-08-20 12:43:51 -07:00 committed by GitHub
parent 6ce565b5f7
commit 351e92ae2f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 51 additions and 44 deletions

View File

@ -29,6 +29,8 @@ export class Details extends LitElement {
// postcss-lit-disable-next-line // postcss-lit-disable-next-line
static styles = css` static styles = css`
:host { :host {
--margin-bottom: var(--sl-spacing-2x-small);
--border-bottom: 1px solid var(--sl-panel-border-color);
display: block; display: block;
} }
@ -46,8 +48,8 @@ export class Details extends LitElement {
} }
details[aria-disabled="false"] summary { details[aria-disabled="false"] summary {
border-bottom: 1px solid var(--sl-panel-border-color); border-bottom: var(--border-bottom);
margin-bottom: var(--sl-spacing-x-small); margin-bottom: var(--margin-bottom);
cursor: pointer; cursor: pointer;
user-select: none; user-select: none;
} }

View File

@ -1,6 +1,6 @@
import { localized, msg } from "@lit/localize"; import { localized, msg } from "@lit/localize";
import { type SlSelect } from "@shoelace-style/shoelace"; import { type SlSelect } from "@shoelace-style/shoelace";
import { html } from "lit"; import { html, nothing } from "lit";
import { customElement, property, state } from "lit/decorators.js"; import { customElement, property, state } from "lit/decorators.js";
import orderBy from "lodash/fp/orderBy"; import orderBy from "lodash/fp/orderBy";
@ -77,7 +77,7 @@ export class SelectBrowserProfile extends LiteElement {
<div class="text-xs"> <div class="text-xs">
<sl-format-date <sl-format-date
lang=${getLocale()} lang=${getLocale()}
date=${`${profile.created}Z` /** Z for UTC */} date=${`${profile.modified}Z` /** Z for UTC */}
month="2-digit" month="2-digit"
day="2-digit" day="2-digit"
year="2-digit" year="2-digit"
@ -89,6 +89,32 @@ export class SelectBrowserProfile extends LiteElement {
${this.browserProfiles && !this.browserProfiles.length ${this.browserProfiles && !this.browserProfiles.length
? this.renderNoProfiles() ? this.renderNoProfiles()
: ""} : ""}
${this.selectedProfile
? html`
<div slot="help-text" class="flex justify-between">
<span>
${msg("Last updated")}
<sl-format-date
lang=${getLocale()}
date=${`${this.selectedProfile.modified}Z` /** Z for UTC */}
month="2-digit"
day="2-digit"
year="2-digit"
hour="2-digit"
minute="2-digit"
></sl-format-date>
</span>
<a
class="flex items-center gap-1 text-blue-500 hover:text-blue-600"
href=${`${this.orgBasePath}/browser-profiles/profile/${this.selectedProfile.id}`}
target="_blank"
>
${msg("Check Profile")}
<sl-icon name="box-arrow-up-right"></sl-icon>
</a>
</div>
`
: nothing}
</sl-select> </sl-select>
${this.browserProfiles?.length ? this.renderSelectedProfileInfo() : ""} ${this.browserProfiles?.length ? this.renderSelectedProfileInfo() : ""}
@ -96,42 +122,19 @@ export class SelectBrowserProfile extends LiteElement {
} }
private renderSelectedProfileInfo() { private renderSelectedProfileInfo() {
if (!this.selectedProfile) return; if (!this.selectedProfile?.description) return;
return html` return html`<div class="my-2 rounded border pl-1">
<div <btrix-details style="--margin-bottom: 0; --border-bottom: 0;">
class="mt-2 flex justify-between rounded border bg-neutral-50 p-2 text-sm" <div slot="title" class="text-xs leading-normal text-neutral-600">
> ${msg("Description")}
${this.selectedProfile.description </div>
? html`<em class="text-slate-500" <!-- display: inline -->
>${this.selectedProfile.description}</em <div class="whitespace-pre-line p-3 text-xs leading-normal"
>` >${this.selectedProfile.description}</div
: ""}
<span>
${msg("Last edited:")}
<sl-format-date
lang=${getLocale()}
date=${`${this.selectedProfile.created}Z` /** Z for UTC */}
month="2-digit"
day="2-digit"
year="2-digit"
></sl-format-date>
</span>
<a
href=${`${this.orgBasePath}/browser-profiles/profile/${this.selectedProfile.id}`}
class="font-medium text-primary hover:text-indigo-500"
target="_blank"
> >
<span class="mr-1 inline-block align-middle" </btrix-details>
>${msg("Check profile")}</span </div>`;
>
<sl-icon
class="inline-block align-middle"
name="box-arrow-up-right"
></sl-icon>
</a>
</div>
`;
} }
private renderNoProfiles() { private renderNoProfiles() {
@ -188,7 +191,7 @@ export class SelectBrowserProfile extends LiteElement {
try { try {
const data = await this.getProfiles(); const data = await this.getProfiles();
this.browserProfiles = orderBy(["name", "created"])(["asc", "desc"])( this.browserProfiles = orderBy(["name", "modified"])(["asc", "desc"])(
data, data,
) as Profile[]; ) as Profile[];

View File

@ -264,16 +264,18 @@ export class BrowserProfilesDetail extends BtrixElement {
`, `,
)} )}
</header> </header>
<div class="rounded border p-5"> <!-- display: inline -->
${this.profile <div
class="leading whitespace-pre-line rounded border p-5 leading-relaxed first-line:leading-[0]"
>${this.profile
? this.profile.description || ? this.profile.description ||
html` html`
<div class="text-center text-neutral-400"> <div class="text-center text-neutral-400">
${msg("No description added.")} &nbsp;${msg("No description added.")}
</div> </div>
` `
: nothing} : nothing}</div
</div> >
</section> </section>
<section class="mb-7"> <section class="mb-7">