sort orgs alphabetically

This commit is contained in:
sua yoo 2024-05-21 14:24:47 -07:00
parent e7df805b51
commit 2664fd0f0e
No known key found for this signature in database
GPG Key ID: 5AD1B4C02D4F0567
2 changed files with 6 additions and 2 deletions

View File

@ -4,6 +4,7 @@ import { render, type TemplateResult } from "lit";
import { customElement, property, query, state } from "lit/decorators.js"; import { customElement, property, query, state } from "lit/decorators.js";
import { ifDefined } from "lit/directives/if-defined.js"; import { ifDefined } from "lit/directives/if-defined.js";
import { when } from "lit/directives/when.js"; import { when } from "lit/directives/when.js";
import { sortBy } from "lodash/fp";
import "broadcastchannel-polyfill"; import "broadcastchannel-polyfill";
import "./utils/polyfills"; import "./utils/polyfills";
@ -361,6 +362,8 @@ export class App extends LiteElement {
const orgs = this.appState.userInfo?.orgs; const orgs = this.appState.userInfo?.orgs;
if (!orgs || orgs.length < 2 || !this.appState.userInfo) return; if (!orgs || orgs.length < 2 || !this.appState.userInfo) return;
const sortedOrgs = sortBy<UserOrg>("name")(orgs);
const selectedOption = this.appState.orgSlug const selectedOption = this.appState.orgSlug
? orgs.find(({ slug }) => slug === this.appState.orgSlug) ? orgs.find(({ slug }) => slug === this.appState.orgSlug)
: { slug: "", name: msg("All Organizations") }; : { slug: "", name: msg("All Organizations") };
@ -405,7 +408,7 @@ export class App extends LiteElement {
<sl-divider></sl-divider> <sl-divider></sl-divider>
`, `,
)} )}
${this.appState.userInfo.orgs.map( ${sortedOrgs.map(
(org) => html` (org) => html`
<sl-menu-item <sl-menu-item
type="checkbox" type="checkbox"

View File

@ -2,6 +2,7 @@ import { localized, msg, str } from "@lit/localize";
import { serialize } from "@shoelace-style/shoelace/dist/utilities/form.js"; import { serialize } from "@shoelace-style/shoelace/dist/utilities/form.js";
import { type PropertyValues, type TemplateResult } from "lit"; import { type PropertyValues, type TemplateResult } from "lit";
import { customElement, property, state } from "lit/decorators.js"; import { customElement, property, state } from "lit/decorators.js";
import { sortBy } from "lodash/fp";
import type { InviteSuccessDetail } from "@/features/accounts/invite-form"; import type { InviteSuccessDetail } from "@/features/accounts/invite-form";
import type { APIPaginatedList } from "@/types/api"; import type { APIPaginatedList } from "@/types/api";
@ -276,7 +277,7 @@ export class Home extends LiteElement {
} }
private async fetchOrgs() { private async fetchOrgs() {
this.orgList = await this.getOrgs(); this.orgList = sortBy<OrgData>("name")(await this.getOrgs());
} }
private async getOrgs() { private async getOrgs() {