Typed enriched users

This commit is contained in:
Adria Navarro 2024-12-30 14:25:23 +01:00
parent 16fac7022d
commit 430431203b
2 changed files with 14 additions and 8 deletions

View File

@ -1,7 +1,7 @@
import { writable, get, derived, Writable, Readable } from "svelte/store"
import { helpers } from "@budibase/shared-core"
import { Store as StoreContext } from "."
import { UIUser } from "@budibase/types"
import { UIEnrichedUser, UIUser } from "@budibase/types"
interface UsersStore {
users: Writable<UIUser[]>
@ -12,21 +12,22 @@ interface DerivedUsersStore {
}
interface ActionUserStore {
users: UsersStore["users"] & {
actions: {
updateUser: (user: UIUser) => void
removeUser: (sessionId: string) => void
users: UsersStore["users"] &
Readable<UIEnrichedUser[]> & {
actions: {
updateUser: (user: UIUser) => void
removeUser: (sessionId: string) => void
}
}
}
}
export type Store = UsersStore & DerivedUsersStore
export type Store = DerivedUsersStore & ActionUserStore
export const createStores = (): UsersStore => {
const users = writable<UIUser[]>([])
const enrichedUsers = derived(users, $users => {
return $users.map(user => ({
return $users.map<UIEnrichedUser>(user => ({
...user,
color: helpers.getUserColor(user),
label: helpers.getUserLabel(user),

View File

@ -4,3 +4,8 @@ export interface UIUser extends User {
sessionId: string
gridMetadata?: { focusedCellId?: string }
}
export interface UIEnrichedUser extends UIUser {
color: string
label: string
}