Skip to content

Commit 65b3cbe

Browse files
committed
suggested changes
1 parent d2914ab commit 65b3cbe

File tree

1 file changed

+16
-19
lines changed

1 file changed

+16
-19
lines changed

packages/ui/src/fields/Upload/Input.tsx

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,9 @@ export function UploadInput(props: UploadInputProps) {
133133
// This will be used by the bulk upload to allow you to select only collections you have create permissions for
134134
const collectionSlugsWithCreatePermission = useMemo(() => {
135135
if (Array.isArray(relationTo)) {
136-
return relationTo.filter((relation) => {
137-
if (permissions?.collections && permissions.collections?.[relation]?.create) {
138-
return true
139-
}
140-
return false
141-
})
136+
return relationTo.filter(
137+
(relation) => permissions?.collections && permissions.collections?.[relation]?.create,
138+
)
142139
}
143140
return []
144141
}, [relationTo, permissions])
@@ -537,12 +534,9 @@ export function UploadInput(props: UploadInputProps) {
537534
useEffect(() => {
538535
async function loadInitialDocs() {
539536
if (value) {
540-
const isPoly = Array.isArray(relationTo)
541-
const collectionSlug = relationTo as string
542-
543537
let itemsToLoad: ValueWithRelation[]
544538
if (
545-
isPoly &&
539+
Array.isArray(relationTo) &&
546540
((typeof value === 'object' && 'relationTo' in value) ||
547541
(Array.isArray(value) &&
548542
value.length > 0 &&
@@ -555,15 +549,18 @@ export function UploadInput(props: UploadInputProps) {
555549
(v): v is ValueWithRelation => typeof v === 'object' && 'relationTo' in v,
556550
)
557551
} else {
558-
// For single collection uploads, we need to wrap the IDs
559-
const ids = Array.isArray(value) ? value : [value]
560-
itemsToLoad = ids.map((id): ValueWithRelation => {
561-
const idValue = typeof id === 'object' && 'value' in id ? id.value : id
562-
return {
563-
relationTo: collectionSlug,
564-
value: idValue,
565-
}
566-
})
552+
// This check is here to satisfy TypeScript that relationTo is a string
553+
if (!Array.isArray(relationTo)) {
554+
// For single collection uploads, we need to wrap the IDs
555+
const ids = Array.isArray(value) ? value : [value]
556+
itemsToLoad = ids.map((id): ValueWithRelation => {
557+
const idValue = typeof id === 'object' && 'value' in id ? id.value : id
558+
return {
559+
relationTo,
560+
value: idValue,
561+
}
562+
})
563+
}
567564
}
568565

569566
const loadedDocs = await populateDocs(itemsToLoad)

0 commit comments

Comments
 (0)