-
Notifications
You must be signed in to change notification settings - Fork 593
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(app-record-locking): ensure savedOn is updated on ACO cache updates
- Loading branch information
Showing
8 changed files
with
39 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
packages/app-record-locking/src/components/decorators/UseRecordsDecorator.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { useRecords } from "@webiny/app-aco"; | ||
|
||
/** | ||
* When record locking mechanism is checking for records equality, it compares record `id` and `savedOn`. | ||
* When you're updating ACO cache, you're just passing the new content entry value(s), and sometimes you might | ||
* be doing it without the `savedOn`, and that causes record locking to keep its old state. | ||
* | ||
* This decorator ensures that calls to `updateRecordInCache` always include a `savedOn` timestamp. | ||
*/ | ||
export const UseRecordsDecorator = useRecords.createDecorator(baseHook => { | ||
return (folderId?: string) => { | ||
const hook = baseHook(folderId); | ||
|
||
return { | ||
...hook, | ||
updateRecordInCache(record: any) { | ||
hook.updateRecordInCache({ | ||
...record, | ||
savedOn: new Date().toISOString() | ||
}); | ||
} | ||
}; | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters