persist app sort method selection by saving it against the user
This commit is contained in:
parent
ca8a827e3d
commit
696b2c38db
|
@ -26,6 +26,7 @@
|
||||||
licensing,
|
licensing,
|
||||||
environment,
|
environment,
|
||||||
enrichedApps,
|
enrichedApps,
|
||||||
|
sortBy,
|
||||||
} from "stores/portal"
|
} from "stores/portal"
|
||||||
import { goto } from "@roxi/routify"
|
import { goto } from "@roxi/routify"
|
||||||
import AppRow from "components/start/AppRow.svelte"
|
import AppRow from "components/start/AppRow.svelte"
|
||||||
|
@ -247,7 +248,7 @@
|
||||||
<div class="app-actions">
|
<div class="app-actions">
|
||||||
<Select
|
<Select
|
||||||
autoWidth
|
autoWidth
|
||||||
value={$appsStore.sortBy}
|
value={$sortBy}
|
||||||
on:change={e => {
|
on:change={e => {
|
||||||
appsStore.updateSort(e.detail)
|
appsStore.updateSort(e.detail)
|
||||||
}}
|
}}
|
||||||
|
|
|
@ -9,7 +9,6 @@ const DEV_PROPS = ["updatedBy", "updatedAt"]
|
||||||
|
|
||||||
export const INITIAL_APPS_STATE = {
|
export const INITIAL_APPS_STATE = {
|
||||||
apps: [],
|
apps: [],
|
||||||
sortBy: "name",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export class AppsStore extends BudiStore {
|
export class AppsStore extends BudiStore {
|
||||||
|
@ -53,6 +52,15 @@ export class AppsStore extends BudiStore {
|
||||||
...state,
|
...state,
|
||||||
sortBy,
|
sortBy,
|
||||||
}))
|
}))
|
||||||
|
this.updateUserSort(sortBy)
|
||||||
|
}
|
||||||
|
|
||||||
|
async updateUserSort(sortBy) {
|
||||||
|
try {
|
||||||
|
await auth.updateSelf({ appSort: sortBy })
|
||||||
|
} catch (err) {
|
||||||
|
console.error("couldn't save user sort: ", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async load() {
|
async load() {
|
||||||
|
@ -140,8 +148,14 @@ export class AppsStore extends BudiStore {
|
||||||
|
|
||||||
export const appsStore = new AppsStore()
|
export const appsStore = new AppsStore()
|
||||||
|
|
||||||
|
export const sortBy = derived([appsStore, auth], ([$store, $auth]) => {
|
||||||
|
return $store.sortBy || $auth.user?.appSort || "name"
|
||||||
|
})
|
||||||
|
|
||||||
// Centralise any logic that enriches the apps list
|
// Centralise any logic that enriches the apps list
|
||||||
export const enrichedApps = derived([appsStore, auth], ([$store, $auth]) => {
|
export const enrichedApps = derived(
|
||||||
|
[appsStore, auth, sortBy],
|
||||||
|
([$store, $auth, $sortBy]) => {
|
||||||
const enrichedApps = $store.apps
|
const enrichedApps = $store.apps
|
||||||
? $store.apps.map(app => ({
|
? $store.apps.map(app => ({
|
||||||
...app,
|
...app,
|
||||||
|
@ -152,7 +166,7 @@ export const enrichedApps = derived([appsStore, auth], ([$store, $auth]) => {
|
||||||
}))
|
}))
|
||||||
: []
|
: []
|
||||||
|
|
||||||
if ($store.sortBy === "status") {
|
if ($sortBy === "status") {
|
||||||
return enrichedApps.sort((a, b) => {
|
return enrichedApps.sort((a, b) => {
|
||||||
if (a.favourite === b.favourite) {
|
if (a.favourite === b.favourite) {
|
||||||
if (a.status === b.status) {
|
if (a.status === b.status) {
|
||||||
|
@ -162,7 +176,7 @@ export const enrichedApps = derived([appsStore, auth], ([$store, $auth]) => {
|
||||||
}
|
}
|
||||||
return a.favourite ? -1 : 1
|
return a.favourite ? -1 : 1
|
||||||
})
|
})
|
||||||
} else if ($store.sortBy === "updated") {
|
} else if ($sortBy === "updated") {
|
||||||
return enrichedApps?.sort((a, b) => {
|
return enrichedApps?.sort((a, b) => {
|
||||||
if (a.favourite === b.favourite) {
|
if (a.favourite === b.favourite) {
|
||||||
const aUpdated = a.updatedAt || "9999"
|
const aUpdated = a.updatedAt || "9999"
|
||||||
|
@ -179,4 +193,5 @@ export const enrichedApps = derived([appsStore, auth], ([$store, $auth]) => {
|
||||||
return a.favourite ? -1 : 1
|
return a.favourite ? -1 : 1
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
)
|
||||||
|
|
|
@ -3,7 +3,7 @@ import { writable } from "svelte/store"
|
||||||
export { organisation } from "./organisation"
|
export { organisation } from "./organisation"
|
||||||
export { users } from "./users"
|
export { users } from "./users"
|
||||||
export { admin } from "./admin"
|
export { admin } from "./admin"
|
||||||
export { appsStore, enrichedApps } from "./apps"
|
export { appsStore, enrichedApps, sortBy } from "./apps"
|
||||||
export { email } from "./email"
|
export { email } from "./email"
|
||||||
export { auth } from "./auth"
|
export { auth } from "./auth"
|
||||||
export { oidc } from "./oidc"
|
export { oidc } from "./oidc"
|
||||||
|
|
|
@ -21,6 +21,7 @@ export interface UpdateSelfRequest {
|
||||||
freeTrialConfirmedAt?: string
|
freeTrialConfirmedAt?: string
|
||||||
appFavourites?: string[]
|
appFavourites?: string[]
|
||||||
tours?: Record<string, Date>
|
tours?: Record<string, Date>
|
||||||
|
appSort?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface UpdateSelfResponse {
|
export interface UpdateSelfResponse {
|
||||||
|
|
|
@ -67,6 +67,7 @@ export interface User extends Document {
|
||||||
scimInfo?: { isSync: true } & Record<string, any>
|
scimInfo?: { isSync: true } & Record<string, any>
|
||||||
appFavourites?: string[]
|
appFavourites?: string[]
|
||||||
ssoId?: string
|
ssoId?: string
|
||||||
|
appSort?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum UserStatus {
|
export enum UserStatus {
|
||||||
|
|
|
@ -29,6 +29,7 @@ export const buildSelfSaveValidation = () => {
|
||||||
freeTrialConfirmedAt: Joi.string().optional(),
|
freeTrialConfirmedAt: Joi.string().optional(),
|
||||||
appFavourites: Joi.array().optional(),
|
appFavourites: Joi.array().optional(),
|
||||||
tours: Joi.object().optional(),
|
tours: Joi.object().optional(),
|
||||||
|
appSort: Joi.string().optional(),
|
||||||
}
|
}
|
||||||
return auth.joiValidator.body(Joi.object(schema).required().unknown(false))
|
return auth.joiValidator.body(Joi.object(schema).required().unknown(false))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue