feat: lock documents while being edited (#7970)

## Description

Adds a new property to `collection` / `global` configs called
`lockDocuments`.

Set to `true` by default - the lock is automatically triggered when a
user begins editing a document within the Admin Panel and remains in
place until the user exits the editing view or the lock expires due to
inactivity.

Set to `false` to disable document locking entirely - i.e.
`lockDocuments: false`

You can pass an object to this property to configure the `duration` in
seconds, which defines how long the document remains locked without user
interaction. If no edits are made within the specified time (default:
300 seconds), the lock expires, allowing other users to edit / update or
delete the document.

```
lockDocuments: {
  duration: 180, // 180 seconds or 3 minutes
}
```

- [x] I have read and understand the
[CONTRIBUTING.md](https://github.com/payloadcms/payload/blob/main/CONTRIBUTING.md)
document in this repository.

## Type of change

- [x] New feature (non-breaking change which adds functionality)

## Checklist:

- [x] I have added tests that prove my fix is effective or that my
feature works
- [x] Existing test suite passes locally with my changes
- [x] I have made corresponding changes to the documentation
This commit is contained in:
Patrik
2024-09-17 14:04:48 -04:00
committed by GitHub
parent 05a3cc47a6
commit f98d032617
119 changed files with 10897 additions and 6575 deletions

View File

@@ -90,7 +90,7 @@ export const LinkButton: React.FC = () => {
text: editor.selection ? Editor.string(editor, editor.selection) : '',
}
const state = await getFormState({
const { state } = await getFormState({
apiRoute: config.routes.api,
body: {
data,

View File

@@ -100,7 +100,7 @@ export const LinkElement = () => {
url: element.url,
}
const state = await getFormState({
const { state } = await getFormState({
apiRoute: config.routes.api,
body: {
data,

View File

@@ -38,7 +38,7 @@ export const LinkDrawer: React.FC<Props> = ({
const onChange: FormProps['onChange'][0] = useCallback(
async ({ formState: prevFormState }) => {
return await getFormState({
const { state } = await getFormState({
apiRoute: config.routes.api,
body: {
id,
@@ -48,6 +48,8 @@ export const LinkDrawer: React.FC<Props> = ({
},
serverURL: config.serverURL,
})
return state
},
[config.routes.api, config.serverURL, fieldMapPath, id],

View File

@@ -71,7 +71,7 @@ export const UploadDrawer: React.FC<{
const data = deepCopyObject(element?.fields || {})
const awaitInitialState = async () => {
const state = await getFormState({
const { state } = await getFormState({
apiRoute: config.routes.api,
body: {
id,
@@ -101,7 +101,7 @@ export const UploadDrawer: React.FC<{
const onChange: FormProps['onChange'][0] = useCallback(
async ({ formState: prevFormState }) => {
return await getFormState({
const { state } = await getFormState({
apiRoute: config.routes.api,
body: {
id,
@@ -111,6 +111,8 @@ export const UploadDrawer: React.FC<{
},
serverURL: config.serverURL,
})
return state
},
[config.routes.api, config.serverURL, relatedCollection.slug, schemaPath, id],