@webiny/app-record-locking 5.43.2 → 6.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/HeadlessCmsActionsAcoCell.js +46 -57
- package/components/HeadlessCmsActionsAcoCell.js.map +1 -1
- package/components/HeadlessCmsContentEntry/ContentEntryGuard.js +22 -29
- package/components/HeadlessCmsContentEntry/ContentEntryGuard.js.map +1 -1
- package/components/HeadlessCmsContentEntry/ContentEntryLocker.js +43 -60
- package/components/HeadlessCmsContentEntry/ContentEntryLocker.js.map +1 -1
- package/components/HeadlessCmsContentEntry/HeadlessCmsContentEntry.js +54 -67
- package/components/HeadlessCmsContentEntry/HeadlessCmsContentEntry.js.map +1 -1
- package/components/HeadlessCmsContentEntry/index.js +1 -16
- package/components/HeadlessCmsContentEntry/index.js.map +1 -1
- package/components/LockedRecord/LockedRecord.js +49 -144
- package/components/LockedRecord/LockedRecord.js.map +1 -1
- package/components/LockedRecord/LockedRecordForceUnlock.js +51 -93
- package/components/LockedRecord/LockedRecordForceUnlock.js.map +1 -1
- package/components/LockedRecord/index.js +1 -16
- package/components/LockedRecord/index.js.map +1 -1
- package/components/RecordLockingProvider.js +47 -67
- package/components/RecordLockingProvider.js.map +1 -1
- package/components/decorators/UseContentEntriesListHookDecorator.js +10 -17
- package/components/decorators/UseContentEntriesListHookDecorator.js.map +1 -1
- package/components/decorators/UseRecordsDecorator.js +11 -16
- package/components/decorators/UseRecordsDecorator.js.map +1 -1
- package/components/decorators/UseSaveEntryDecorator.js +34 -32
- package/components/decorators/UseSaveEntryDecorator.js.map +1 -1
- package/components/permissionRenderer/RecordLockingPermissions.js +39 -53
- package/components/permissionRenderer/RecordLockingPermissions.js.map +1 -1
- package/components/permissionRenderer/index.js +13 -17
- package/components/permissionRenderer/index.js.map +1 -1
- package/domain/RecordLocking.js +271 -311
- package/domain/RecordLocking.js.map +1 -1
- package/domain/RecordLockingClient.js +15 -29
- package/domain/RecordLockingClient.js.map +1 -1
- package/domain/RecordLockingGetLockRecord.js +16 -29
- package/domain/RecordLockingGetLockRecord.js.map +1 -1
- package/domain/RecordLockingGetLockedEntryLockRecord.js +14 -27
- package/domain/RecordLockingGetLockedEntryLockRecord.js.map +1 -1
- package/domain/RecordLockingIsEntryLocked.js +14 -27
- package/domain/RecordLockingIsEntryLocked.js.map +1 -1
- package/domain/RecordLockingListLockRecords.js +26 -37
- package/domain/RecordLockingListLockRecords.js.map +1 -1
- package/domain/RecordLockingLockEntry.js +9 -22
- package/domain/RecordLockingLockEntry.js.map +1 -1
- package/domain/RecordLockingUnlockEntry.js +14 -27
- package/domain/RecordLockingUnlockEntry.js.map +1 -1
- package/domain/RecordLockingUpdateEntryLock.js +14 -27
- package/domain/RecordLockingUpdateEntryLock.js.map +1 -1
- package/domain/abstractions/IRecordLocking.js +1 -5
- package/domain/abstractions/IRecordLockingClient.js +1 -5
- package/domain/abstractions/IRecordLockingGetLockRecord.js +1 -5
- package/domain/abstractions/IRecordLockingGetLockedEntryLockRecord.js +1 -5
- package/domain/abstractions/IRecordLockingIsEntryLocked.js +1 -5
- package/domain/abstractions/IRecordLockingListLockRecords.js +1 -5
- package/domain/abstractions/IRecordLockingLockEntry.js +1 -5
- package/domain/abstractions/IRecordLockingUnlockEntry.js +1 -5
- package/domain/abstractions/IRecordLockingUpdateEntryLock.js +1 -5
- package/domain/graphql/fields.js +28 -8
- package/domain/graphql/fields.js.map +1 -1
- package/domain/graphql/getLockRecord.js +16 -12
- package/domain/graphql/getLockRecord.js.map +1 -1
- package/domain/graphql/getLockedEntryLockRecord.js +16 -12
- package/domain/graphql/getLockedEntryLockRecord.js.map +1 -1
- package/domain/graphql/isEntryLocked.js +14 -12
- package/domain/graphql/isEntryLocked.js.map +1 -1
- package/domain/graphql/listLockRecords.js +23 -14
- package/domain/graphql/listLockRecords.js.map +1 -1
- package/domain/graphql/lockEntry.js +17 -13
- package/domain/graphql/lockEntry.js.map +1 -1
- package/domain/graphql/unlockEntry.js +16 -12
- package/domain/graphql/unlockEntry.js.map +1 -1
- package/domain/graphql/updateEntryLock.js +16 -12
- package/domain/graphql/updateEntryLock.js.map +1 -1
- package/domain/utils/createRecordLockingClient.js +6 -12
- package/domain/utils/createRecordLockingClient.js.map +1 -1
- package/domain/utils/createRecordLockingError.js +1 -7
- package/domain/utils/createRecordLockingError.js.map +1 -1
- package/hooks/index.js +2 -27
- package/hooks/index.js.map +1 -1
- package/hooks/usePermission.js +11 -16
- package/hooks/usePermission.js.map +1 -1
- package/hooks/useRecordLocking.js +6 -12
- package/hooks/useRecordLocking.js.map +1 -1
- package/index.js +20 -50
- package/index.js.map +1 -1
- package/package.json +17 -18
- package/types.js +1 -5
- package/utils/createCacheKey.js +5 -11
- package/utils/createCacheKey.js.map +1 -1
- package/components/assets/lock.svg +0 -13
package/domain/RecordLocking.js
CHANGED
|
@@ -1,32 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
var _RecordLockingUnlockEntry = require("./RecordLockingUnlockEntry");
|
|
18
|
-
var _RecordLockingClient = require("./RecordLockingClient");
|
|
19
|
-
var _createRecordLockingError = require("./utils/createRecordLockingError");
|
|
20
|
-
var _parseIdentifier9 = require("@webiny/utils/parseIdentifier");
|
|
21
|
-
var _createCacheKey = require("../utils/createCacheKey");
|
|
22
|
-
var _RecordLockingUpdateEntryLock = require("./RecordLockingUpdateEntryLock");
|
|
23
|
-
var _RecordLockingGetLockedEntryLockRecord = require("./RecordLockingGetLockedEntryLockRecord");
|
|
24
|
-
var RecordLocking = /*#__PURE__*/function () {
|
|
25
|
-
function RecordLocking(params) {
|
|
26
|
-
(0, _classCallCheck2.default)(this, RecordLocking);
|
|
27
|
-
(0, _defineProperty2.default)(this, "loading", false);
|
|
28
|
-
(0, _defineProperty2.default)(this, "records", []);
|
|
29
|
-
(0, _defineProperty2.default)(this, "onErrorCb", null);
|
|
1
|
+
import { RecordLockingGetLockRecord } from "./RecordLockingGetLockRecord";
|
|
2
|
+
import { RecordLockingIsEntryLocked } from "./RecordLockingIsEntryLocked";
|
|
3
|
+
import { RecordLockingListLockRecords } from "./RecordLockingListLockRecords";
|
|
4
|
+
import { RecordLockingLockEntry } from "./RecordLockingLockEntry";
|
|
5
|
+
import { RecordLockingUnlockEntry } from "./RecordLockingUnlockEntry";
|
|
6
|
+
import { RecordLockingClient } from "./RecordLockingClient";
|
|
7
|
+
import { createRecordLockingError } from "./utils/createRecordLockingError";
|
|
8
|
+
import { parseIdentifier } from "@webiny/utils/parseIdentifier";
|
|
9
|
+
import { createCacheKey } from "../utils/createCacheKey";
|
|
10
|
+
import { RecordLockingUpdateEntryLock } from "./RecordLockingUpdateEntryLock";
|
|
11
|
+
import { RecordLockingGetLockedEntryLockRecord } from "./RecordLockingGetLockedEntryLockRecord";
|
|
12
|
+
class RecordLocking {
|
|
13
|
+
loading = false;
|
|
14
|
+
records = [];
|
|
15
|
+
onErrorCb = null;
|
|
16
|
+
constructor(params) {
|
|
30
17
|
this._setLoading = params.setLoading;
|
|
31
18
|
this._getLockRecord = params.getLockRecord;
|
|
32
19
|
this._getLockedEntryLockRecord = params.getLockedEntryLockRecord;
|
|
@@ -34,326 +21,299 @@ var RecordLocking = /*#__PURE__*/function () {
|
|
|
34
21
|
this._unlockEntry = params.unlockEntry;
|
|
35
22
|
this._updateEntryLock = params.updateEntryLock;
|
|
36
23
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
if (!result) {
|
|
42
|
-
return undefined;
|
|
43
|
-
}
|
|
44
|
-
return result.map(function (record) {
|
|
45
|
-
var _parseIdentifier = (0, _parseIdentifier9.parseIdentifier)(record.id),
|
|
46
|
-
entryId = _parseIdentifier.id;
|
|
47
|
-
return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, record), {}, {
|
|
48
|
-
$lockingType: type,
|
|
49
|
-
$locked: record.$locked,
|
|
50
|
-
$selectable: record.$locked ? false : record.$selectable,
|
|
51
|
-
entryId: entryId
|
|
52
|
-
});
|
|
53
|
-
});
|
|
24
|
+
async setRecords(folderId, type, records) {
|
|
25
|
+
const result = await this.fetchAndAssignRecords(folderId, type, records);
|
|
26
|
+
if (!result) {
|
|
27
|
+
return undefined;
|
|
54
28
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}, {
|
|
79
|
-
key: "fetchLockedEntryLockRecord",
|
|
80
|
-
value: async function fetchLockedEntryLockRecord(params) {
|
|
81
|
-
var id = params.id,
|
|
82
|
-
$lockingType = params.$lockingType;
|
|
83
|
-
var _parseIdentifier3 = (0, _parseIdentifier9.parseIdentifier)(id),
|
|
84
|
-
entryId = _parseIdentifier3.id;
|
|
85
|
-
var result = await this._getLockedEntryLockRecord.execute({
|
|
29
|
+
return result.map(record => {
|
|
30
|
+
const {
|
|
31
|
+
id: entryId
|
|
32
|
+
} = parseIdentifier(record.id);
|
|
33
|
+
return {
|
|
34
|
+
...record,
|
|
35
|
+
$lockingType: type,
|
|
36
|
+
$locked: record.$locked,
|
|
37
|
+
$selectable: record.$locked ? false : record.$selectable,
|
|
38
|
+
entryId
|
|
39
|
+
};
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
async fetchLockRecord(params) {
|
|
43
|
+
const {
|
|
44
|
+
id,
|
|
45
|
+
$lockingType
|
|
46
|
+
} = params;
|
|
47
|
+
const {
|
|
48
|
+
id: entryId
|
|
49
|
+
} = parseIdentifier(id);
|
|
50
|
+
try {
|
|
51
|
+
const result = await this._getLockRecord.execute({
|
|
86
52
|
id: entryId,
|
|
87
53
|
type: $lockingType
|
|
88
54
|
});
|
|
89
|
-
return
|
|
55
|
+
return {
|
|
56
|
+
data: result.data,
|
|
57
|
+
error: result.error
|
|
58
|
+
};
|
|
59
|
+
} catch (ex) {
|
|
60
|
+
return {
|
|
61
|
+
data: null,
|
|
62
|
+
error: ex
|
|
63
|
+
};
|
|
90
64
|
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
65
|
+
}
|
|
66
|
+
async fetchLockedEntryLockRecord(params) {
|
|
67
|
+
const {
|
|
68
|
+
id,
|
|
69
|
+
$lockingType
|
|
70
|
+
} = params;
|
|
71
|
+
const {
|
|
72
|
+
id: entryId
|
|
73
|
+
} = parseIdentifier(id);
|
|
74
|
+
const result = await this._getLockedEntryLockRecord.execute({
|
|
75
|
+
id: entryId,
|
|
76
|
+
type: $lockingType
|
|
77
|
+
});
|
|
78
|
+
return result.data;
|
|
79
|
+
}
|
|
80
|
+
getLockRecordEntry(id) {
|
|
81
|
+
return this.records.find(record => {
|
|
82
|
+
const {
|
|
83
|
+
id: entryId
|
|
84
|
+
} = parseIdentifier(id);
|
|
85
|
+
return record.entryId === entryId;
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
isRecordLocked(record) {
|
|
89
|
+
const result = this.records.find(r => {
|
|
90
|
+
const {
|
|
91
|
+
id: entryId
|
|
92
|
+
} = parseIdentifier(record.id);
|
|
93
|
+
return r.entryId === entryId && !!r.$locked && r.$lockingType === record.$lockingType;
|
|
94
|
+
});
|
|
95
|
+
if (!result?.$locked?.expiresOn) {
|
|
96
|
+
return false;
|
|
99
97
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
98
|
+
const isExpired = this.isLockExpired(result.$locked.expiresOn);
|
|
99
|
+
return !isExpired;
|
|
100
|
+
}
|
|
101
|
+
async updateEntryLock(params) {
|
|
102
|
+
try {
|
|
103
|
+
return await this._updateEntryLock.execute({
|
|
104
|
+
id: params.id,
|
|
105
|
+
type: params.$lockingType
|
|
107
106
|
});
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
107
|
+
} catch (ex) {
|
|
108
|
+
this.triggerOnError(ex);
|
|
109
|
+
return {
|
|
110
|
+
data: null,
|
|
111
|
+
error: ex
|
|
112
|
+
};
|
|
113
113
|
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
});
|
|
122
|
-
} catch (ex) {
|
|
123
|
-
this.triggerOnError(ex);
|
|
124
|
-
return {
|
|
125
|
-
data: null,
|
|
126
|
-
error: ex
|
|
127
|
-
};
|
|
128
|
-
}
|
|
114
|
+
}
|
|
115
|
+
removeEntryLock(params) {
|
|
116
|
+
const index = this.records.findIndex(record => {
|
|
117
|
+
return record.entryId === params.id && record.$lockingType === params.$lockingType;
|
|
118
|
+
});
|
|
119
|
+
if (index === -1) {
|
|
120
|
+
return;
|
|
129
121
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
122
|
+
this.records[index] = {
|
|
123
|
+
...this.records[index],
|
|
124
|
+
$locked: null,
|
|
125
|
+
$selectable: true
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
async unlockEntry(params, force) {
|
|
129
|
+
try {
|
|
130
|
+
const result = await this._unlockEntry.execute({
|
|
131
|
+
id: params.id,
|
|
132
|
+
type: params.$lockingType,
|
|
133
|
+
force
|
|
135
134
|
});
|
|
136
|
-
|
|
137
|
-
|
|
135
|
+
const id = result.data?.id;
|
|
136
|
+
if (!id) {
|
|
137
|
+
return result;
|
|
138
138
|
}
|
|
139
|
-
this.
|
|
140
|
-
|
|
141
|
-
$selectable: true
|
|
139
|
+
this.removeEntryLock({
|
|
140
|
+
...params
|
|
142
141
|
});
|
|
142
|
+
return result;
|
|
143
|
+
} catch (ex) {
|
|
144
|
+
this.triggerOnError(ex);
|
|
145
|
+
return {
|
|
146
|
+
data: null,
|
|
147
|
+
error: ex
|
|
148
|
+
};
|
|
143
149
|
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
});
|
|
153
|
-
var id = result.data?.id;
|
|
154
|
-
if (!id) {
|
|
155
|
-
return result;
|
|
156
|
-
}
|
|
157
|
-
this.removeEntryLock((0, _objectSpread2.default)({}, params));
|
|
158
|
-
return result;
|
|
159
|
-
} catch (ex) {
|
|
160
|
-
this.triggerOnError(ex);
|
|
161
|
-
return {
|
|
162
|
-
data: null,
|
|
163
|
-
error: ex
|
|
164
|
-
};
|
|
165
|
-
}
|
|
150
|
+
}
|
|
151
|
+
onError(cb) {
|
|
152
|
+
this.onErrorCb = cb;
|
|
153
|
+
}
|
|
154
|
+
triggerOnError(error) {
|
|
155
|
+
this.setIsLoading(false);
|
|
156
|
+
if (!this.onErrorCb) {
|
|
157
|
+
return;
|
|
166
158
|
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
159
|
+
this.onErrorCb(error);
|
|
160
|
+
}
|
|
161
|
+
isLockExpired(input) {
|
|
162
|
+
const expiresOn = new Date(input);
|
|
163
|
+
return expiresOn <= new Date();
|
|
164
|
+
}
|
|
165
|
+
setIsLoading(loading) {
|
|
166
|
+
this._setLoading(loading);
|
|
167
|
+
this.loading = loading;
|
|
168
|
+
}
|
|
169
|
+
async fetchAndAssignRecords(folderId, type, records) {
|
|
170
|
+
if (records.length === 0) {
|
|
171
|
+
return;
|
|
172
|
+
} else if (this.loading) {
|
|
173
|
+
return;
|
|
171
174
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
this.setIsLoading(false);
|
|
176
|
-
if (!this.onErrorCb) {
|
|
177
|
-
return;
|
|
178
|
-
}
|
|
179
|
-
this.onErrorCb(error);
|
|
175
|
+
const assignedIdList = await this.assignRecords(folderId, type, records);
|
|
176
|
+
if (assignedIdList.length === 0) {
|
|
177
|
+
return;
|
|
180
178
|
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
179
|
+
this.setIsLoading(true);
|
|
180
|
+
let result;
|
|
181
|
+
try {
|
|
182
|
+
result = await this._listLockRecords.execute({
|
|
183
|
+
where: {
|
|
184
|
+
id_in: assignedIdList,
|
|
185
|
+
type
|
|
186
|
+
},
|
|
187
|
+
limit: 10000
|
|
188
|
+
});
|
|
189
|
+
} catch (ex) {
|
|
190
|
+
console.error(ex);
|
|
191
|
+
this.triggerOnError(ex);
|
|
192
|
+
return;
|
|
193
|
+
} finally {
|
|
194
|
+
this.setIsLoading(false);
|
|
186
195
|
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
this.
|
|
196
|
+
if (result.error) {
|
|
197
|
+
this.triggerOnError(result.error);
|
|
198
|
+
return;
|
|
199
|
+
} else if (!result.data) {
|
|
200
|
+
this.triggerOnError(createRecordLockingError({
|
|
201
|
+
message: `There is no data in the result and there is no error. Please check the network tab for more info.`,
|
|
202
|
+
code: "NO_DATA_IN_RESULT"
|
|
203
|
+
}));
|
|
204
|
+
return;
|
|
205
|
+
} else if (result.data.length === 0) {
|
|
206
|
+
return;
|
|
192
207
|
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
return;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
if (assignedIdList.length === 0) {
|
|
204
|
-
return;
|
|
205
|
-
}
|
|
206
|
-
this.setIsLoading(true);
|
|
207
|
-
var result;
|
|
208
|
-
try {
|
|
209
|
-
result = await this._listLockRecords.execute({
|
|
210
|
-
where: {
|
|
211
|
-
id_in: assignedIdList,
|
|
212
|
-
type: type
|
|
213
|
-
},
|
|
214
|
-
limit: 10000
|
|
215
|
-
});
|
|
216
|
-
} catch (ex) {
|
|
217
|
-
console.error(ex);
|
|
218
|
-
this.triggerOnError(ex);
|
|
219
|
-
return;
|
|
220
|
-
} finally {
|
|
221
|
-
this.setIsLoading(false);
|
|
222
|
-
}
|
|
223
|
-
if (result.error) {
|
|
224
|
-
this.triggerOnError(result.error);
|
|
225
|
-
return;
|
|
226
|
-
} else if (!result.data) {
|
|
227
|
-
this.triggerOnError((0, _createRecordLockingError.createRecordLockingError)({
|
|
228
|
-
message: "There is no data in the result and there is no error. Please check the network tab for more info.",
|
|
229
|
-
code: "NO_DATA_IN_RESULT"
|
|
230
|
-
}));
|
|
231
|
-
return;
|
|
232
|
-
} else if (result.data.length === 0) {
|
|
233
|
-
return;
|
|
208
|
+
for (const record of result.data) {
|
|
209
|
+
const index = this.records.findIndex(r => {
|
|
210
|
+
const {
|
|
211
|
+
id: entryId
|
|
212
|
+
} = parseIdentifier(record.id);
|
|
213
|
+
return r.entryId === entryId;
|
|
214
|
+
});
|
|
215
|
+
if (index < 0) {
|
|
216
|
+
console.error(`There is no record with id ${record.id} in the records array.`);
|
|
217
|
+
continue;
|
|
234
218
|
}
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
entryId = _parseIdentifier6.id;
|
|
243
|
-
return r.entryId === entryId;
|
|
244
|
-
});
|
|
245
|
-
if (index < 0) {
|
|
246
|
-
console.error("There is no record with id ".concat(record.id, " in the records array."));
|
|
247
|
-
return 1; // continue
|
|
248
|
-
}
|
|
249
|
-
_this.records[index] = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, _this.records[index]), {}, {
|
|
250
|
-
$locked: {
|
|
251
|
-
lockedBy: record.lockedBy,
|
|
252
|
-
expiresOn: record.expiresOn,
|
|
253
|
-
lockedOn: record.lockedOn,
|
|
254
|
-
actions: record.actions
|
|
255
|
-
}
|
|
256
|
-
});
|
|
257
|
-
};
|
|
258
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
259
|
-
if (await _loop()) continue;
|
|
219
|
+
this.records[index] = {
|
|
220
|
+
...this.records[index],
|
|
221
|
+
$locked: {
|
|
222
|
+
lockedBy: record.lockedBy,
|
|
223
|
+
expiresOn: record.expiresOn,
|
|
224
|
+
lockedOn: record.lockedOn,
|
|
225
|
+
actions: record.actions
|
|
260
226
|
}
|
|
261
|
-
}
|
|
262
|
-
_iterator.e(err);
|
|
263
|
-
} finally {
|
|
264
|
-
_iterator.f();
|
|
265
|
-
}
|
|
266
|
-
return this.records;
|
|
227
|
+
};
|
|
267
228
|
}
|
|
229
|
+
return this.records;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Assign records and return the assigned ID list.
|
|
233
|
+
*/
|
|
234
|
+
async assignRecords(folderId, type, records) {
|
|
268
235
|
/**
|
|
269
|
-
*
|
|
236
|
+
* First we check the record keys against ones in the local cache.
|
|
270
237
|
*/
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
var _this2 = this;
|
|
275
|
-
/**
|
|
276
|
-
* First we check the record keys against ones in the local cache.
|
|
277
|
-
*/
|
|
278
|
-
var keys = records.map(function (record) {
|
|
279
|
-
if (record.entryId) {
|
|
280
|
-
return record.entryId;
|
|
281
|
-
}
|
|
282
|
-
var _parseIdentifier7 = (0, _parseIdentifier9.parseIdentifier)(record.id),
|
|
283
|
-
entryId = _parseIdentifier7.id;
|
|
284
|
-
return entryId;
|
|
285
|
-
});
|
|
286
|
-
var cacheKey = await (0, _createCacheKey.createCacheKey)(keys);
|
|
287
|
-
if (this.currentRecordsCacheKey === cacheKey) {
|
|
288
|
-
return [];
|
|
238
|
+
const keys = records.map(record => {
|
|
239
|
+
if (record.entryId) {
|
|
240
|
+
return record.entryId;
|
|
289
241
|
}
|
|
290
|
-
|
|
242
|
+
const {
|
|
243
|
+
id: entryId
|
|
244
|
+
} = parseIdentifier(record.id);
|
|
245
|
+
return entryId;
|
|
246
|
+
});
|
|
247
|
+
const cacheKey = await createCacheKey(keys);
|
|
248
|
+
if (this.currentRecordsCacheKey === cacheKey) {
|
|
249
|
+
return [];
|
|
250
|
+
}
|
|
251
|
+
this.currentRecordsCacheKey = cacheKey;
|
|
291
252
|
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
253
|
+
/**
|
|
254
|
+
* Reset records if new type is not as same as the old type / folderId.
|
|
255
|
+
*/
|
|
256
|
+
if (this.currentRecordType !== type || this.currentFolderId !== folderId) {
|
|
257
|
+
this.records = [];
|
|
258
|
+
this.currentRecordType = type;
|
|
259
|
+
this.currentFolderId = folderId;
|
|
260
|
+
}
|
|
261
|
+
return records.reduce((collection, record) => {
|
|
262
|
+
const {
|
|
263
|
+
id: entryId
|
|
264
|
+
} = parseIdentifier(record.id);
|
|
265
|
+
const index = this.records.findIndex(r => r.entryId === entryId);
|
|
266
|
+
if (index >= 0) {
|
|
267
|
+
return collection;
|
|
299
268
|
}
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
return collection;
|
|
308
|
-
}
|
|
309
|
-
_this2.records.push((0, _objectSpread2.default)((0, _objectSpread2.default)({}, record), {}, {
|
|
310
|
-
entryId: entryId,
|
|
311
|
-
$lockingType: type,
|
|
312
|
-
$locked: undefined
|
|
313
|
-
}));
|
|
314
|
-
if (record.$type !== "RECORD") {
|
|
315
|
-
return collection;
|
|
316
|
-
}
|
|
317
|
-
collection.push(entryId);
|
|
269
|
+
this.records.push({
|
|
270
|
+
...record,
|
|
271
|
+
entryId,
|
|
272
|
+
$lockingType: type,
|
|
273
|
+
$locked: undefined
|
|
274
|
+
});
|
|
275
|
+
if (record.$type !== "RECORD") {
|
|
318
276
|
return collection;
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
|
|
277
|
+
}
|
|
278
|
+
collection.push(entryId);
|
|
279
|
+
return collection;
|
|
280
|
+
}, []);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
export const createRecordLocking = config => {
|
|
284
|
+
const client = new RecordLockingClient({
|
|
325
285
|
client: config.client
|
|
326
286
|
});
|
|
327
|
-
|
|
328
|
-
client
|
|
287
|
+
const getLockRecord = new RecordLockingGetLockRecord({
|
|
288
|
+
client
|
|
329
289
|
});
|
|
330
|
-
|
|
331
|
-
client
|
|
290
|
+
const getLockedEntryLockRecord = new RecordLockingGetLockedEntryLockRecord({
|
|
291
|
+
client
|
|
332
292
|
});
|
|
333
|
-
|
|
334
|
-
client
|
|
293
|
+
const isEntryLocked = new RecordLockingIsEntryLocked({
|
|
294
|
+
client
|
|
335
295
|
});
|
|
336
|
-
|
|
337
|
-
client
|
|
296
|
+
const listLockRecords = new RecordLockingListLockRecords({
|
|
297
|
+
client
|
|
338
298
|
});
|
|
339
|
-
|
|
340
|
-
client
|
|
299
|
+
const lockEntry = new RecordLockingLockEntry({
|
|
300
|
+
client
|
|
341
301
|
});
|
|
342
|
-
|
|
343
|
-
client
|
|
302
|
+
const unlockEntry = new RecordLockingUnlockEntry({
|
|
303
|
+
client
|
|
344
304
|
});
|
|
345
|
-
|
|
346
|
-
client
|
|
305
|
+
const updateEntryLock = new RecordLockingUpdateEntryLock({
|
|
306
|
+
client
|
|
347
307
|
});
|
|
348
308
|
return new RecordLocking({
|
|
349
309
|
setLoading: config.setLoading,
|
|
350
|
-
getLockRecord
|
|
351
|
-
getLockedEntryLockRecord
|
|
352
|
-
isEntryLocked
|
|
353
|
-
listLockRecords
|
|
354
|
-
updateEntryLock
|
|
355
|
-
lockEntry
|
|
356
|
-
unlockEntry
|
|
310
|
+
getLockRecord,
|
|
311
|
+
getLockedEntryLockRecord,
|
|
312
|
+
isEntryLocked,
|
|
313
|
+
listLockRecords,
|
|
314
|
+
updateEntryLock,
|
|
315
|
+
lockEntry,
|
|
316
|
+
unlockEntry
|
|
357
317
|
});
|
|
358
318
|
};
|
|
359
319
|
|