Skip to content

Commit

Permalink
fix(ui): conditionally fetches versions based on read access
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobsfletch committed Apr 26, 2024
1 parent 5c816d9 commit 87f115f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
10 changes: 6 additions & 4 deletions packages/ui/src/providers/DocumentInfo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ export const DocumentInfoProvider: React.FC<
}

const isEditing = Boolean(id)
const shouldFetchVersions = Boolean(versionsConfig && docPermissions?.readVersions?.permission)

const getVersions = useCallback(async () => {
let versionFetchURL
let publishedFetchURL
const shouldFetchVersions = Boolean(versionsConfig)
let unpublishedVersionJSON = null
let versionJSON = null
let shouldFetch = true
Expand Down Expand Up @@ -209,7 +209,7 @@ export const DocumentInfoProvider: React.FC<
setVersions(versionJSON)
setUnpublishedVersions(unpublishedVersionJSON)
}
}, [i18n, globalSlug, collectionSlug, id, baseURL, locale, versionsConfig])
}, [i18n, globalSlug, collectionSlug, id, baseURL, locale, versionsConfig, shouldFetchVersions])

const getDocPermissions = React.useCallback(async () => {
let docAccessURL: string
Expand Down Expand Up @@ -364,8 +364,10 @@ export const DocumentInfoProvider: React.FC<
])

useEffect(() => {
void getVersions()
}, [getVersions])
if (shouldFetchVersions) {
void getVersions()
}
}, [getVersions, shouldFetchVersions])

useEffect(() => {
setDocumentTitle(
Expand Down
3 changes: 3 additions & 0 deletions test/_community/collections/Posts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ export const PostsCollection: CollectionConfig = {
admin: {
useAsTitle: 'text',
},
access: {
readVersions: () => false,
},
fields: [
{
name: 'text',
Expand Down

0 comments on commit 87f115f

Please sign in to comment.