sanity-plugin-utils 1.8.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +10 -36
- package/dist/index.d.ts +94 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +343 -0
- package/dist/index.js.map +1 -0
- package/package.json +35 -74
- package/lib/index.cjs +0 -650
- package/lib/index.cjs.map +0 -1
- package/lib/index.d.cts +0 -130
- package/lib/index.d.ts +0 -130
- package/lib/index.js +0 -655
- package/lib/index.js.map +0 -1
- package/sanity.json +0 -8
- package/src/components/Feedback.tsx +0 -48
- package/src/components/Table.tsx +0 -83
- package/src/components/UserSelectMenu/index.tsx +0 -162
- package/src/hooks/useImageUrlBuilder.tsx +0 -13
- package/src/hooks/useImageUrlBuilderImage.tsx +0 -18
- package/src/hooks/useListeningQuery.tsx +0 -98
- package/src/hooks/useOpenInNewPane.tsx +0 -27
- package/src/hooks/useProjectUsers.tsx +0 -99
- package/src/index.ts +0 -9
- package/v2-incompatible.js +0 -11
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import {useEffect, useState} from 'react'
|
|
2
|
-
import {useClient, useWorkspace} from 'sanity'
|
|
3
|
-
|
|
4
|
-
export type UserExtended = {
|
|
5
|
-
createdAt: string
|
|
6
|
-
displayName: string
|
|
7
|
-
email: string
|
|
8
|
-
familyName: string
|
|
9
|
-
givenName: string
|
|
10
|
-
id: string
|
|
11
|
-
imageUrl: string
|
|
12
|
-
isCurrentUser: boolean
|
|
13
|
-
middleName: string
|
|
14
|
-
projectId: string
|
|
15
|
-
provider: string
|
|
16
|
-
sanityUserId: string
|
|
17
|
-
updatedAt: string
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
type UserRole = {
|
|
21
|
-
name: string
|
|
22
|
-
title: string
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
type UserResponse = {
|
|
26
|
-
isRobot: boolean
|
|
27
|
-
projectUserId: string
|
|
28
|
-
roles: UserRole[]
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
type HookConfig = {
|
|
32
|
-
apiVersion?: string
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function chunkArray<T>(array: T[], size: number): T[][] {
|
|
36
|
-
const chunks: T[][] = []
|
|
37
|
-
for (let i = 0; i < array.length; i += size) {
|
|
38
|
-
chunks.push(array.slice(i, i + size))
|
|
39
|
-
}
|
|
40
|
-
return chunks
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// Custom hook to fetch user details and roles in batches
|
|
44
|
-
export function useProjectUsers({apiVersion}: HookConfig): UserExtended[] {
|
|
45
|
-
const {currentUser} = useWorkspace()
|
|
46
|
-
const client = useClient({apiVersion: apiVersion ?? '2023-01-01'})
|
|
47
|
-
const [users, setUsers] = useState<UserExtended[]>([])
|
|
48
|
-
|
|
49
|
-
useEffect(() => {
|
|
50
|
-
const {projectId} = client.config()
|
|
51
|
-
|
|
52
|
-
async function getUsersWithRoles() {
|
|
53
|
-
try {
|
|
54
|
-
const aclData = await client.request({
|
|
55
|
-
url: `/projects/${projectId}/acl`,
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
const userIds = aclData.map((user: UserResponse) => user.projectUserId)
|
|
59
|
-
|
|
60
|
-
const userIdChunks = chunkArray(userIds, 200)
|
|
61
|
-
|
|
62
|
-
let usersData: UserExtended[] = []
|
|
63
|
-
|
|
64
|
-
// Fetch users in batches of 200
|
|
65
|
-
for (const chunk of userIdChunks) {
|
|
66
|
-
const chunkedUserIds = chunk.join(',')
|
|
67
|
-
const response = await client.request({
|
|
68
|
-
url: `/projects/${projectId}/users/${chunkedUserIds}`,
|
|
69
|
-
})
|
|
70
|
-
usersData = [...usersData, ...response]
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// Combine user details with roles
|
|
74
|
-
const usersWithRoles = usersData.map((user: UserExtended) => {
|
|
75
|
-
const userRoles =
|
|
76
|
-
aclData.find(
|
|
77
|
-
(aclUser: UserResponse) => aclUser.projectUserId === user.id
|
|
78
|
-
)?.roles || []
|
|
79
|
-
|
|
80
|
-
return {
|
|
81
|
-
...user,
|
|
82
|
-
isCurrentUser: user.id === currentUser?.id,
|
|
83
|
-
roles: userRoles,
|
|
84
|
-
}
|
|
85
|
-
})
|
|
86
|
-
|
|
87
|
-
setUsers(usersWithRoles)
|
|
88
|
-
} catch (err) {
|
|
89
|
-
console.error('Failed to fetch users:', err)
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
if (!users.length) {
|
|
94
|
-
getUsersWithRoles()
|
|
95
|
-
}
|
|
96
|
-
}, [client, currentUser?.id, users.length])
|
|
97
|
-
|
|
98
|
-
return users
|
|
99
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export {Feedback} from './components/Feedback'
|
|
2
|
-
export {Cell, Row, Table} from './components/Table'
|
|
3
|
-
export {UserSelectMenu} from './components/UserSelectMenu/index'
|
|
4
|
-
export {useImageUrlBuilder} from './hooks/useImageUrlBuilder'
|
|
5
|
-
export {useImageUrlBuilderImage} from './hooks/useImageUrlBuilderImage'
|
|
6
|
-
export {useListeningQuery} from './hooks/useListeningQuery'
|
|
7
|
-
export {useOpenInNewPane} from './hooks/useOpenInNewPane'
|
|
8
|
-
export type {UserExtended} from './hooks/useProjectUsers'
|
|
9
|
-
export {useProjectUsers} from './hooks/useProjectUsers'
|
package/v2-incompatible.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
const {showIncompatiblePluginDialog} = require('@sanity/incompatible-plugin')
|
|
2
|
-
const {name, version, sanityExchangeUrl} = require('./package.json')
|
|
3
|
-
|
|
4
|
-
export default showIncompatiblePluginDialog({
|
|
5
|
-
name: name,
|
|
6
|
-
versions: {
|
|
7
|
-
v3: version,
|
|
8
|
-
v2: undefined,
|
|
9
|
-
},
|
|
10
|
-
sanityExchangeUrl,
|
|
11
|
-
})
|