Skip to content

Commit

Permalink
fix(app-record-locking): ensure savedOn is updated on ACO cache updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel910 committed Jun 18, 2024
1 parent 4746eff commit 5dc413c
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 7 deletions.
4 changes: 2 additions & 2 deletions packages/api-headless-cms/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
{ "path": "../api-i18n/tsconfig.build.json" },
{ "path": "../api-security/tsconfig.build.json" },
{ "path": "../api-tenancy/tsconfig.build.json" },
{ "path": "../aws-sdk/tsconfig.build.json" },
{ "path": "../error/tsconfig.build.json" },
{ "path": "../handler/tsconfig.build.json" },
{ "path": "../handler-aws/tsconfig.build.json" },
Expand All @@ -17,7 +16,8 @@
{ "path": "../pubsub/tsconfig.build.json" },
{ "path": "../utils/tsconfig.build.json" },
{ "path": "../validation/tsconfig.build.json" },
{ "path": "../api-wcp/tsconfig.build.json" }
{ "path": "../api-wcp/tsconfig.build.json" },
{ "path": "../aws-sdk/tsconfig.build.json" }
],
"compilerOptions": {
"rootDir": "./src",
Expand Down
10 changes: 5 additions & 5 deletions packages/api-headless-cms/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
{ "path": "../api-i18n" },
{ "path": "../api-security" },
{ "path": "../api-tenancy" },
{ "path": "../aws-sdk" },
{ "path": "../error" },
{ "path": "../handler" },
{ "path": "../handler-aws" },
Expand All @@ -17,7 +16,8 @@
{ "path": "../pubsub" },
{ "path": "../utils" },
{ "path": "../validation" },
{ "path": "../api-wcp" }
{ "path": "../api-wcp" },
{ "path": "../aws-sdk" }
],
"compilerOptions": {
"rootDirs": ["./src", "./__tests__"],
Expand All @@ -34,8 +34,6 @@
"@webiny/api-security": ["../api-security/src"],
"@webiny/api-tenancy/*": ["../api-tenancy/src/*"],
"@webiny/api-tenancy": ["../api-tenancy/src"],
"@webiny/aws-sdk/*": ["../aws-sdk/src/*"],
"@webiny/aws-sdk": ["../aws-sdk/src"],
"@webiny/error/*": ["../error/src/*"],
"@webiny/error": ["../error/src"],
"@webiny/handler/*": ["../handler/src/*"],
Expand All @@ -57,7 +55,9 @@
"@webiny/validation/*": ["../validation/src/*"],
"@webiny/validation": ["../validation/src"],
"@webiny/api-wcp/*": ["../api-wcp/src/*"],
"@webiny/api-wcp": ["../api-wcp/src"]
"@webiny/api-wcp": ["../api-wcp/src"],
"@webiny/aws-sdk/*": ["../aws-sdk/src/*"],
"@webiny/aws-sdk": ["../aws-sdk/src"]
},
"baseUrl": "."
}
Expand Down
1 change: 1 addition & 0 deletions packages/app-record-locking/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"@emotion/styled": "^11.10.6",
"@material-design-icons/svg": "^0.14.3",
"@webiny/app": "0.0.0",
"@webiny/app-aco": "0.0.0",
"@webiny/app-admin": "0.0.0",
"@webiny/app-headless-cms": "0.0.0",
"@webiny/app-security": "0.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useRecordLocking } from "~/hooks";
import { UseContentEntriesListHookDecorator } from "./decorators/UseContentEntriesListHookDecorator";
import styled from "@emotion/styled";
import { UseSaveEntryDecorator } from "~/components/decorators/UseSaveEntryDecorator";
import { UseRecordsDecorator } from "./decorators/UseRecordsDecorator";

const CenterAlignment = styled.div`
display: block;
Expand Down Expand Up @@ -66,6 +67,7 @@ export const HeadlessCmsActionsAcoCell = () => {
<UseContentEntriesListHookDecorator />
<UseSaveEntryDecorator />
<RecordLockingCellActions />
<UseRecordsDecorator />
</>
);
};
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()
});
}
};
};
});
1 change: 1 addition & 0 deletions packages/app-record-locking/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"references": [
{ "path": "../app/tsconfig.build.json" },
{ "path": "../app-admin/tsconfig.build.json" },
{ "path": "../app-aco/tsconfig.build.json" },
{ "path": "../app-headless-cms/tsconfig.build.json" },
{ "path": "../app-security/tsconfig.build.json" },
{ "path": "../app-wcp/tsconfig.build.json" },
Expand Down
3 changes: 3 additions & 0 deletions packages/app-record-locking/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"references": [
{ "path": "../app" },
{ "path": "../app-admin" },
{ "path": "../app-aco" },
{ "path": "../app-headless-cms" },
{ "path": "../app-security" },
{ "path": "../app-wcp" },
Expand All @@ -24,6 +25,8 @@
"@webiny/app": ["../app/src"],
"@webiny/app-admin/*": ["../app-admin/src/*"],
"@webiny/app-admin": ["../app-admin/src"],
"@webiny/app-aco/*": ["../app-aco/src/*"],
"@webiny/app-aco": ["../app-aco/src"],
"@webiny/app-headless-cms/*": ["../app-headless-cms/src/*"],
"@webiny/app-headless-cms": ["../app-headless-cms/src"],
"@webiny/app-security/*": ["../app-security/src/*"],
Expand Down
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -17112,6 +17112,7 @@ __metadata:
"@emotion/styled": ^11.10.6
"@material-design-icons/svg": ^0.14.3
"@webiny/app": 0.0.0
"@webiny/app-aco": 0.0.0
"@webiny/app-admin": 0.0.0
"@webiny/app-headless-cms": 0.0.0
"@webiny/app-security": 0.0.0
Expand Down

0 comments on commit 5dc413c

Please sign in to comment.