Typed enriched users
This commit is contained in:
parent
16fac7022d
commit
430431203b
|
@ -1,7 +1,7 @@
|
||||||
import { writable, get, derived, Writable, Readable } from "svelte/store"
|
import { writable, get, derived, Writable, Readable } from "svelte/store"
|
||||||
import { helpers } from "@budibase/shared-core"
|
import { helpers } from "@budibase/shared-core"
|
||||||
import { Store as StoreContext } from "."
|
import { Store as StoreContext } from "."
|
||||||
import { UIUser } from "@budibase/types"
|
import { UIEnrichedUser, UIUser } from "@budibase/types"
|
||||||
|
|
||||||
interface UsersStore {
|
interface UsersStore {
|
||||||
users: Writable<UIUser[]>
|
users: Writable<UIUser[]>
|
||||||
|
@ -12,21 +12,22 @@ interface DerivedUsersStore {
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ActionUserStore {
|
interface ActionUserStore {
|
||||||
users: UsersStore["users"] & {
|
users: UsersStore["users"] &
|
||||||
actions: {
|
Readable<UIEnrichedUser[]> & {
|
||||||
updateUser: (user: UIUser) => void
|
actions: {
|
||||||
removeUser: (sessionId: string) => void
|
updateUser: (user: UIUser) => void
|
||||||
|
removeUser: (sessionId: string) => void
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Store = UsersStore & DerivedUsersStore
|
export type Store = DerivedUsersStore & ActionUserStore
|
||||||
|
|
||||||
export const createStores = (): UsersStore => {
|
export const createStores = (): UsersStore => {
|
||||||
const users = writable<UIUser[]>([])
|
const users = writable<UIUser[]>([])
|
||||||
|
|
||||||
const enrichedUsers = derived(users, $users => {
|
const enrichedUsers = derived(users, $users => {
|
||||||
return $users.map(user => ({
|
return $users.map<UIEnrichedUser>(user => ({
|
||||||
...user,
|
...user,
|
||||||
color: helpers.getUserColor(user),
|
color: helpers.getUserColor(user),
|
||||||
label: helpers.getUserLabel(user),
|
label: helpers.getUserLabel(user),
|
||||||
|
|
|
@ -4,3 +4,8 @@ export interface UIUser extends User {
|
||||||
sessionId: string
|
sessionId: string
|
||||||
gridMetadata?: { focusedCellId?: string }
|
gridMetadata?: { focusedCellId?: string }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface UIEnrichedUser extends UIUser {
|
||||||
|
color: string
|
||||||
|
label: string
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue