@stoker-platform/web-app 0.5.234 → 0.5.236
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/CHANGELOG.md +16 -0
- package/package.json +3 -3
- package/src/Calendar.tsx +1 -1
- package/src/Cards.tsx +9 -17
- package/src/Collection.tsx +1 -1
- package/src/Form.tsx +16 -17
- package/src/Map.tsx +1 -1
- package/src/utils/isOfflineDisabled.ts +8 -5
- package/src/utils/isServerWrite.ts +13 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @stoker-platform/web-app
|
|
2
2
|
|
|
3
|
+
## 0.5.236
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies
|
|
8
|
+
- @stoker-platform/node-client@0.5.95
|
|
9
|
+
|
|
10
|
+
## 0.5.235
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- fix: fix non-auth-field updates in auth collections
|
|
15
|
+
- Updated dependencies
|
|
16
|
+
- @stoker-platform/node-client@0.5.94
|
|
17
|
+
- @stoker-platform/web-client@0.5.99
|
|
18
|
+
|
|
3
19
|
## 0.5.234
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stoker-platform/web-app",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.236",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
6
6
|
"scripts": {
|
|
@@ -51,9 +51,9 @@
|
|
|
51
51
|
"@radix-ui/react-tooltip": "^1.2.8",
|
|
52
52
|
"@react-google-maps/api": "^2.20.8",
|
|
53
53
|
"@sentry/react": "^10.56.0",
|
|
54
|
-
"@stoker-platform/node-client": "0.5.
|
|
54
|
+
"@stoker-platform/node-client": "0.5.95",
|
|
55
55
|
"@stoker-platform/utils": "0.5.82",
|
|
56
|
-
"@stoker-platform/web-client": "0.5.
|
|
56
|
+
"@stoker-platform/web-client": "0.5.99",
|
|
57
57
|
"@tanstack/react-table": "^8.21.3",
|
|
58
58
|
"@types/react": "18.3.13",
|
|
59
59
|
"@types/react-dom": "18.3.1",
|
package/src/Calendar.tsx
CHANGED
|
@@ -1106,7 +1106,7 @@ export function Calendar({
|
|
|
1106
1106
|
return
|
|
1107
1107
|
}
|
|
1108
1108
|
|
|
1109
|
-
const serverWrite = isServerUpdate(eventCollectionSchema, record)
|
|
1109
|
+
const serverWrite = isServerUpdate(eventCollectionSchema, updatedFields, undefined, record)
|
|
1110
1110
|
const isServerReadOnly = serverReadOnly(eventCollectionSchema)
|
|
1111
1111
|
|
|
1112
1112
|
setGlobalLoading("+", record.id, serverWrite, !(serverWrite || isServerReadOnly))
|
package/src/Cards.tsx
CHANGED
|
@@ -603,14 +603,18 @@ function DropZone({
|
|
|
603
603
|
return
|
|
604
604
|
}
|
|
605
605
|
|
|
606
|
-
const
|
|
606
|
+
const updatedFields =
|
|
607
|
+
"values" in statusField && statusField.values
|
|
608
|
+
? { [statusField.name]: statusValue }
|
|
609
|
+
: { [statusField.name]: statusValue === statusValues[0] }
|
|
610
|
+
|
|
611
|
+
const serverWrite = isServerUpdate(collection, updatedFields, undefined, record)
|
|
607
612
|
|
|
608
613
|
setSettingOptimistic(true)
|
|
609
614
|
|
|
610
615
|
const optimisticUpdate = {
|
|
611
616
|
...record,
|
|
612
|
-
|
|
613
|
-
"values" in statusField && statusField.values ? statusValue : statusValue === statusValues[0],
|
|
617
|
+
...updatedFields,
|
|
614
618
|
}
|
|
615
619
|
setOptimisticUpdate(labels.collection, optimisticUpdate)
|
|
616
620
|
|
|
@@ -625,12 +629,7 @@ function DropZone({
|
|
|
625
629
|
}
|
|
626
630
|
|
|
627
631
|
if ("values" in statusField && statusField.values) {
|
|
628
|
-
updateRecord(
|
|
629
|
-
record.Collection_Path,
|
|
630
|
-
record.id,
|
|
631
|
-
{ [statusField.name]: statusValue },
|
|
632
|
-
{ originalRecord },
|
|
633
|
-
)
|
|
632
|
+
updateRecord(record.Collection_Path, record.id, updatedFields, { originalRecord })
|
|
634
633
|
.then(() => {
|
|
635
634
|
if (serverWrite || isServerReadOnly) {
|
|
636
635
|
toast({
|
|
@@ -658,14 +657,7 @@ function DropZone({
|
|
|
658
657
|
setGlobalLoading("-", record.id, undefined, !(serverWrite || isServerReadOnly))
|
|
659
658
|
})
|
|
660
659
|
} else if (statusField.type === "Boolean") {
|
|
661
|
-
updateRecord(
|
|
662
|
-
record.Collection_Path,
|
|
663
|
-
record.id,
|
|
664
|
-
{
|
|
665
|
-
[statusField.name]: statusValue === statusValues[0],
|
|
666
|
-
},
|
|
667
|
-
{ originalRecord },
|
|
668
|
-
)
|
|
660
|
+
updateRecord(record.Collection_Path, record.id, updatedFields, { originalRecord })
|
|
669
661
|
.then(() => {
|
|
670
662
|
if (serverWrite || isServerReadOnly) {
|
|
671
663
|
toast({
|
package/src/Collection.tsx
CHANGED
|
@@ -1987,7 +1987,6 @@ function Collection({
|
|
|
1987
1987
|
async (record: StokerRecord) => {
|
|
1988
1988
|
if (!relationList || !relationParent) return
|
|
1989
1989
|
const relationCollection = schema.collections[relationList.collection]
|
|
1990
|
-
const isRelationServerWrite = isServerUpdate(relationCollection, record)
|
|
1991
1990
|
const isRelationServerReadOnly = serverReadOnly(relationCollection)
|
|
1992
1991
|
const relationField = getField(relationCollection.fields, relationList.field) as RelationField
|
|
1993
1992
|
|
|
@@ -2004,6 +2003,7 @@ function Collection({
|
|
|
2004
2003
|
updatedFields[relationList.field][relationParent.id][includeField] = relationParent[includeField]
|
|
2005
2004
|
}
|
|
2006
2005
|
}
|
|
2006
|
+
const isRelationServerWrite = isServerUpdate(relationCollection, updatedFields, undefined, record)
|
|
2007
2007
|
|
|
2008
2008
|
const optimisticUpdate = {
|
|
2009
2009
|
...record,
|
package/src/Form.tsx
CHANGED
|
@@ -4224,17 +4224,6 @@ function RecordForm({
|
|
|
4224
4224
|
delete values.password
|
|
4225
4225
|
delete values.passwordConfirm
|
|
4226
4226
|
|
|
4227
|
-
const offlineDisabled = await isOfflineDisabledSync(
|
|
4228
|
-
operation === "update-many" ? "update" : operation,
|
|
4229
|
-
collection,
|
|
4230
|
-
values,
|
|
4231
|
-
userData,
|
|
4232
|
-
)
|
|
4233
|
-
if (offlineDisabled) {
|
|
4234
|
-
alert(`You are offline and cannot ${operation} this record.`)
|
|
4235
|
-
return
|
|
4236
|
-
}
|
|
4237
|
-
|
|
4238
4227
|
const recordToSave = cloneDeep(values) as Partial<StokerRecord>
|
|
4239
4228
|
const prevStateToSave = cloneDeep(prevState)
|
|
4240
4229
|
for (const key in recordToSave) {
|
|
@@ -4248,6 +4237,19 @@ function RecordForm({
|
|
|
4248
4237
|
}
|
|
4249
4238
|
}
|
|
4250
4239
|
|
|
4240
|
+
const offlineDisabled = await isOfflineDisabledSync(
|
|
4241
|
+
operation === "update-many" ? "update" : operation,
|
|
4242
|
+
collection,
|
|
4243
|
+
operation === "update" || operation === "update-many"
|
|
4244
|
+
? { ...recordToSave, User_ID: originalRecord?.User_ID ?? values.User_ID }
|
|
4245
|
+
: values,
|
|
4246
|
+
userData,
|
|
4247
|
+
)
|
|
4248
|
+
if (offlineDisabled) {
|
|
4249
|
+
alert(`You are offline and cannot ${operation} this record.`)
|
|
4250
|
+
return
|
|
4251
|
+
}
|
|
4252
|
+
|
|
4251
4253
|
if (operation === "create") {
|
|
4252
4254
|
const serverWrite = isServerCreate(collection, userData)
|
|
4253
4255
|
const docId = doc(dbCollection(db, "tenants", tenantId, labels.collection)).id
|
|
@@ -4352,7 +4354,7 @@ function RecordForm({
|
|
|
4352
4354
|
setError("No ID provided for update operation")
|
|
4353
4355
|
return
|
|
4354
4356
|
}
|
|
4355
|
-
const serverWrite = isServerUpdate(collection,
|
|
4357
|
+
const serverWrite = isServerUpdate(collection, recordToSave, userData, originalRecord)
|
|
4356
4358
|
const optimisticUpdate = {
|
|
4357
4359
|
...(originalRecord ?? record),
|
|
4358
4360
|
...cloneDeep(recordToSave),
|
|
@@ -4434,10 +4436,7 @@ function RecordForm({
|
|
|
4434
4436
|
for (let i = 0; i < recordsToUpdate.length; i += BATCH_SIZE) {
|
|
4435
4437
|
const batch = recordsToUpdate.slice(i, i + BATCH_SIZE)
|
|
4436
4438
|
const batchPromises = batch.map((selectedRecord) => {
|
|
4437
|
-
const serverWrite = isServerUpdate(collection,
|
|
4438
|
-
...recordToSave,
|
|
4439
|
-
id: selectedRecord.id,
|
|
4440
|
-
})
|
|
4439
|
+
const serverWrite = isServerUpdate(collection, recordToSave, undefined, selectedRecord)
|
|
4441
4440
|
setGlobalLoading("+", selectedRecord.id, serverWrite, !(serverWrite || isServerReadOnly))
|
|
4442
4441
|
|
|
4443
4442
|
return updateRecord(path, selectedRecord.id, recordToSave, {
|
|
@@ -4475,7 +4474,7 @@ function RecordForm({
|
|
|
4475
4474
|
}
|
|
4476
4475
|
|
|
4477
4476
|
rowSelection.forEach((selectedRecord) => {
|
|
4478
|
-
const serverWrite = isServerUpdate(collection,
|
|
4477
|
+
const serverWrite = isServerUpdate(collection, recordToSave, undefined, selectedRecord)
|
|
4479
4478
|
if (!serverWrite && !isServerReadOnly) {
|
|
4480
4479
|
if (selectedRecord.id) {
|
|
4481
4480
|
removeCacheOptimistic(collection, {
|
package/src/Map.tsx
CHANGED
|
@@ -56,17 +56,20 @@ export const isOfflineDisabled = async (
|
|
|
56
56
|
if (operation === "update") {
|
|
57
57
|
const createUserRequest = auth && userData?.operation === "create"
|
|
58
58
|
const deleteUserRequest = auth && userData?.operation === "delete"
|
|
59
|
+
const tokenFields = collection.fields.filter((field) => field.saveToAuthToken)
|
|
59
60
|
const updateUserRequest =
|
|
60
61
|
record &&
|
|
61
62
|
collection.auth &&
|
|
62
63
|
!createUserRequest &&
|
|
63
64
|
!deleteUserRequest &&
|
|
64
65
|
(userData?.operation === "update" ||
|
|
65
|
-
record.
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
66
|
+
(record.User_ID &&
|
|
67
|
+
(record.Role ||
|
|
68
|
+
record.Enabled !== undefined ||
|
|
69
|
+
record.Name ||
|
|
70
|
+
record.Email ||
|
|
71
|
+
record.Photo_URL ||
|
|
72
|
+
tokenFields.some((field) => record[field.name] !== undefined))))
|
|
70
73
|
if (createUserRequest || updateUserRequest || deleteUserRequest) {
|
|
71
74
|
return offline
|
|
72
75
|
}
|
|
@@ -6,7 +6,12 @@ export const isServerCreate = (collection: CollectionSchema, user?: UserData) =>
|
|
|
6
6
|
return !!(serverWriteOnly || (auth && user?.operation === "create"))
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
export const isServerUpdate = (
|
|
9
|
+
export const isServerUpdate = (
|
|
10
|
+
collection: CollectionSchema,
|
|
11
|
+
record: Partial<StokerRecord>,
|
|
12
|
+
user?: UserData,
|
|
13
|
+
originalRecord?: StokerRecord,
|
|
14
|
+
) => {
|
|
10
15
|
const { auth, access, fields } = collection
|
|
11
16
|
const { serverWriteOnly } = access
|
|
12
17
|
const tokenFields = fields.filter((field) => field.saveToAuthToken)
|
|
@@ -14,12 +19,13 @@ export const isServerUpdate = (collection: CollectionSchema, record: Partial<Sto
|
|
|
14
19
|
serverWriteOnly ||
|
|
15
20
|
(auth &&
|
|
16
21
|
(user?.operation ||
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
(originalRecord?.User_ID &&
|
|
23
|
+
(record.Role ||
|
|
24
|
+
record.Enabled !== undefined ||
|
|
25
|
+
record.Name ||
|
|
26
|
+
record.Email ||
|
|
27
|
+
record.Photo_URL ||
|
|
28
|
+
tokenFields.some((field) => record[field.name] !== undefined)))))
|
|
23
29
|
)
|
|
24
30
|
}
|
|
25
31
|
|