fix(ui): document drawer permissions (#5296)
This commit is contained in:
@@ -14,6 +14,7 @@ import { FieldPathProvider, useFieldPath } from '../../forms/FieldPathProvider/i
|
|||||||
import { useRelatedCollections } from '../../forms/fields/Relationship/AddNew/useRelatedCollections.js'
|
import { useRelatedCollections } from '../../forms/fields/Relationship/AddNew/useRelatedCollections.js'
|
||||||
import usePayloadAPI from '../../hooks/usePayloadAPI.js'
|
import usePayloadAPI from '../../hooks/usePayloadAPI.js'
|
||||||
import { X } from '../../icons/X/index.js'
|
import { X } from '../../icons/X/index.js'
|
||||||
|
import { useAuth } from '../../index.js'
|
||||||
import { useComponentMap } from '../../providers/ComponentMapProvider/index.js'
|
import { useComponentMap } from '../../providers/ComponentMapProvider/index.js'
|
||||||
import { useConfig } from '../../providers/Config/index.js'
|
import { useConfig } from '../../providers/Config/index.js'
|
||||||
import { DocumentInfoProvider } from '../../providers/DocumentInfo/index.js'
|
import { DocumentInfoProvider } from '../../providers/DocumentInfo/index.js'
|
||||||
@@ -52,7 +53,7 @@ const Content: React.FC<DocumentDrawerProps> = ({
|
|||||||
const { formQueryParams } = useFormQueryParams()
|
const { formQueryParams } = useFormQueryParams()
|
||||||
const formattedQueryParams = queryString.stringify(formQueryParams)
|
const formattedQueryParams = queryString.stringify(formQueryParams)
|
||||||
|
|
||||||
const { fields: fieldsFromConfig } = collectionConfig
|
const { permissions } = useAuth()
|
||||||
|
|
||||||
const { schemaPath } = useFieldPath()
|
const { schemaPath } = useFieldPath()
|
||||||
|
|
||||||
@@ -120,6 +121,8 @@ const Content: React.FC<DocumentDrawerProps> = ({
|
|||||||
return <LoadingOverlay />
|
return <LoadingOverlay />
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const docPermissions = permissions?.collections[collectionSlug]
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DocumentInfoProvider
|
<DocumentInfoProvider
|
||||||
BeforeDocument={
|
BeforeDocument={
|
||||||
@@ -151,11 +154,12 @@ const Content: React.FC<DocumentDrawerProps> = ({
|
|||||||
collectionSlug={collectionConfig.slug}
|
collectionSlug={collectionConfig.slug}
|
||||||
disableActions
|
disableActions
|
||||||
disableLeaveWithoutSaving
|
disableLeaveWithoutSaving
|
||||||
|
docPermissions={docPermissions}
|
||||||
|
hasSavePermission={docPermissions?.update?.permission}
|
||||||
// isLoading,
|
// isLoading,
|
||||||
id={id}
|
id={id}
|
||||||
initialData={data}
|
initialData={data}
|
||||||
initialState={initialState}
|
initialState={initialState}
|
||||||
// hasSavePermission={hasSavePermission}
|
|
||||||
isEditing={isEditing}
|
isEditing={isEditing}
|
||||||
// me: true,
|
// me: true,
|
||||||
onSave={onSave}
|
onSave={onSave}
|
||||||
@@ -175,7 +179,7 @@ export const DocumentDrawerContent: React.FC<DocumentDrawerProps> = (props) => {
|
|||||||
const [id, setId] = useState<null | number | string>(idFromProps)
|
const [id, setId] = useState<null | number | string>(idFromProps)
|
||||||
|
|
||||||
const onSave = useCallback<DocumentDrawerProps['onSave']>(
|
const onSave = useCallback<DocumentDrawerProps['onSave']>(
|
||||||
async (args) => {
|
(args) => {
|
||||||
setId(args.doc.id)
|
setId(args.doc.id)
|
||||||
|
|
||||||
if (typeof onSaveFromProps === 'function') {
|
if (typeof onSaveFromProps === 'function') {
|
||||||
|
|||||||
@@ -10,12 +10,11 @@ import type { Props } from './types.js'
|
|||||||
|
|
||||||
import { Button } from '../../../../elements/Button/index.js'
|
import { Button } from '../../../../elements/Button/index.js'
|
||||||
import { useDocumentDrawer } from '../../../../elements/DocumentDrawer/index.js'
|
import { useDocumentDrawer } from '../../../../elements/DocumentDrawer/index.js'
|
||||||
import Popup from '../../../../elements/Popup/index.js'
|
|
||||||
import * as PopupList from '../../../../elements/Popup/PopupButtonList/index.js'
|
import * as PopupList from '../../../../elements/Popup/PopupButtonList/index.js'
|
||||||
|
import Popup from '../../../../elements/Popup/index.js'
|
||||||
import { Tooltip } from '../../../../elements/Tooltip/index.js'
|
import { Tooltip } from '../../../../elements/Tooltip/index.js'
|
||||||
import { Plus } from '../../../../icons/Plus/index.js'
|
import { Plus } from '../../../../icons/Plus/index.js'
|
||||||
import { useAuth } from '../../../../providers/Auth/index.js'
|
import { useAuth } from '../../../../providers/Auth/index.js'
|
||||||
import { useConfig } from '../../../../providers/Config/index.js'
|
|
||||||
import { useTranslation } from '../../../../providers/Translation/index.js'
|
import { useTranslation } from '../../../../providers/Translation/index.js'
|
||||||
import './index.scss'
|
import './index.scss'
|
||||||
import { useRelatedCollections } from './useRelatedCollections.js'
|
import { useRelatedCollections } from './useRelatedCollections.js'
|
||||||
@@ -23,7 +22,7 @@ import { useRelatedCollections } from './useRelatedCollections.js'
|
|||||||
const baseClass = 'relationship-add-new'
|
const baseClass = 'relationship-add-new'
|
||||||
|
|
||||||
export const AddNewRelation: React.FC<Props> = ({
|
export const AddNewRelation: React.FC<Props> = ({
|
||||||
dispatchOptions,
|
// dispatchOptions,
|
||||||
hasMany,
|
hasMany,
|
||||||
path,
|
path,
|
||||||
relationTo,
|
relationTo,
|
||||||
@@ -41,7 +40,6 @@ export const AddNewRelation: React.FC<Props> = ({
|
|||||||
const [popupOpen, setPopupOpen] = useState(false)
|
const [popupOpen, setPopupOpen] = useState(false)
|
||||||
const { i18n, t } = useTranslation()
|
const { i18n, t } = useTranslation()
|
||||||
const [showTooltip, setShowTooltip] = useState(false)
|
const [showTooltip, setShowTooltip] = useState(false)
|
||||||
const config = useConfig()
|
|
||||||
|
|
||||||
const [DocumentDrawer, DocumentDrawerToggler, { isDrawerOpen, toggleDrawer }] = useDocumentDrawer(
|
const [DocumentDrawer, DocumentDrawerToggler, { isDrawerOpen, toggleDrawer }] = useDocumentDrawer(
|
||||||
{
|
{
|
||||||
@@ -87,7 +85,7 @@ export const AddNewRelation: React.FC<Props> = ({
|
|||||||
setSelectedCollection(undefined)
|
setSelectedCollection(undefined)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[relationTo, collectionConfig, dispatchOptions, i18n, hasMany, setValue, value, config],
|
[relationTo, collectionConfig, hasMany, setValue, value],
|
||||||
)
|
)
|
||||||
|
|
||||||
const onPopupToggle = useCallback((state) => {
|
const onPopupToggle = useCallback((state) => {
|
||||||
|
|||||||
@@ -20,6 +20,11 @@ export const PostsCollection: CollectionConfig = {
|
|||||||
name: 'richText',
|
name: 'richText',
|
||||||
type: 'richText',
|
type: 'richText',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: 'relationship',
|
||||||
|
type: 'relationship',
|
||||||
|
relationTo: ['posts'],
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: 'associatedMedia',
|
name: 'associatedMedia',
|
||||||
access: {
|
access: {
|
||||||
|
|||||||
Reference in New Issue
Block a user