blixify-ui-web 1.1.13 → 1.1.14

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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/data/dataTemplate/index.tsx"],"names":[],"mappings":"AAiCA,OAAO,KASN,MAAM,OAAO,CAAC;AA0Ef,OAAO,EACL,iBAAiB,EAKlB,MAAM,kBAAkB,CAAC;AAoB1B,eAAO,MAAM,YAAY,mFAknSvB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/data/dataTemplate/index.tsx"],"names":[],"mappings":"AAiCA,OAAO,KASN,MAAM,OAAO,CAAC;AA0Ef,OAAO,EACL,iBAAiB,EAKlB,MAAM,kBAAkB,CAAC;AAoB1B,eAAO,MAAM,YAAY,mFA4pSvB,CAAC"}
@@ -326,6 +326,11 @@ exports.DataTemplate = (0, react_1.forwardRef)(function (props, ref) {
326
326
  var _126 = (0, react_1.useState)(false), offlineModal = _126[0], setOfflineModal = _126[1];
327
327
  var previousType = (0, react_1.useRef)(null);
328
328
  var previousSelectedData = (0, react_1.useRef)(null);
329
+ // INFO: captures the doc exactly as loaded from the server — used by
330
+ // bareUpsertPartialUpdate to diff only the fields the user actually changed.
331
+ // Intentionally separate from previousSelectedData, which advances on every
332
+ // edit and therefore cannot serve as a stable submit baseline.
333
+ var loadedSelectedData = (0, react_1.useRef)(null);
329
334
  var formRef = (0, react_1.createRef)();
330
335
  var objectFormRef = (0, react_1.createRef)();
331
336
  var listAddressFromRef = (0, react_1.createRef)();
@@ -811,6 +816,9 @@ exports.DataTemplate = (0, react_1.forwardRef)(function (props, ref) {
811
816
  isCreatingRef.current = false;
812
817
  pendingDraftSaveRef.current = false;
813
818
  inflightIdRef.current = "";
819
+ // INFO: clear the load baseline so a subsequent load for a different id
820
+ // does not diff against a stale prior document.
821
+ loadedSelectedData.current = null;
814
822
  }
815
823
  }, [props.id]);
816
824
  var handleUpdateSelectedData = function (changeData) {
@@ -2991,13 +2999,13 @@ exports.DataTemplate = (0, react_1.forwardRef)(function (props, ref) {
2991
2999
  });
2992
3000
  }); };
2993
3001
  var handleSubmitData = function (type, rowId, columnId, data, offlineId, isOfflineUpdate, isDraft) { return __awaiter(void 0, void 0, void 0, function () {
2994
- var selectedId_2, id, createSelectedData_1, uniqueDataStructure, uniqueColumnId, res, offlineDataResp, offlineData, tempData, err_19, offlineDataResp, tempData, selectedIndex_3, offlineData, err_20, dataToSubmit_2, changedAttributeIds, operationType, selectedIndex_4, dataId, err_21;
3002
+ var selectedId_2, id, createSelectedData_1, uniqueDataStructure, uniqueColumnId, res, offlineDataResp, offlineData, tempData, err_19, isExistingDoc, newRecordData_1, changedAttributeIds, offlineDataResp, tempData, selectedIndex_3, offlineData, err_20, dataToSubmit_2, changedAttributeIds, operationType, selectedIndex_4, dataId, err_21;
2995
3003
  var _a, _b;
2996
- var _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
2997
- return __generator(this, function (_o) {
2998
- switch (_o.label) {
3004
+ var _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
3005
+ return __generator(this, function (_p) {
3006
+ switch (_p.label) {
2999
3007
  case 0:
3000
- _o.trys.push([0, 35, , 36]);
3008
+ _p.trys.push([0, 35, , 36]);
3001
3009
  selectedId_2 = "";
3002
3010
  if (type === "update")
3003
3011
  selectedId_2 = rowId !== null && rowId !== void 0 ? rowId : "";
@@ -3027,8 +3035,8 @@ exports.DataTemplate = (0, react_1.forwardRef)(function (props, ref) {
3027
3035
  return [3 /*break*/, 3];
3028
3036
  case 1: return [4 /*yield*/, handleUploadImage(id, data)];
3029
3037
  case 2:
3030
- createSelectedData_1 = _o.sent();
3031
- _o.label = 3;
3038
+ createSelectedData_1 = _p.sent();
3039
+ _p.label = 3;
3032
3040
  case 3:
3033
3041
  uniqueDataStructure = structure.filter(function (eachStructure) {
3034
3042
  return eachStructure.unique;
@@ -3048,12 +3056,12 @@ exports.DataTemplate = (0, react_1.forwardRef)(function (props, ref) {
3048
3056
  if (isDraft)
3049
3057
  createSelectedData_1["baseDraft"] = true;
3050
3058
  if (!isOffline) return [3 /*break*/, 9];
3051
- _o.label = 4;
3059
+ _p.label = 4;
3052
3060
  case 4:
3053
- _o.trys.push([4, 7, , 8]);
3061
+ _p.trys.push([4, 7, , 8]);
3054
3062
  return [4 /*yield*/, indexedDb_1.indexedDb.getValue("local", props.collectionId)];
3055
3063
  case 5:
3056
- offlineDataResp = _o.sent();
3064
+ offlineDataResp = _p.sent();
3057
3065
  offlineData = (_e = offlineDataResp === null || offlineDataResp === void 0 ? void 0 : offlineDataResp.data) !== null && _e !== void 0 ? _e : [];
3058
3066
  tempData = (0, updateModule_1.handleParseOfflineWrite)(selectedData, structure);
3059
3067
  offlineData.push(tempData);
@@ -3062,23 +3070,43 @@ exports.DataTemplate = (0, react_1.forwardRef)(function (props, ref) {
3062
3070
  type: props.collectionId,
3063
3071
  })];
3064
3072
  case 6:
3065
- _o.sent();
3073
+ _p.sent();
3066
3074
  res = true;
3067
3075
  return [3 /*break*/, 8];
3068
3076
  case 7:
3069
- err_19 = _o.sent();
3077
+ err_19 = _p.sent();
3070
3078
  return [3 /*break*/, 8];
3071
3079
  case 8: return [3 /*break*/, 15];
3072
3080
  case 9:
3073
3081
  if (!((idField && selectedData[idField]) ||
3074
3082
  ((_f = props.bareSettings) === null || _f === void 0 ? void 0 : _f.bareUpsertPartialUpdate))) return [3 /*break*/, 11];
3083
+ isExistingDoc = ((_g = props.bareSettings) === null || _g === void 0 ? void 0 : _g.bareUpsertPartialUpdate) &&
3084
+ loadedSelectedData.current != null;
3085
+ if (isExistingDoc) {
3086
+ changedAttributeIds = (0, updateModule_1.compareUpdatedFields)(loadedSelectedData.current, createSelectedData_1).changedAttributeIds;
3087
+ if (changedAttributeIds.length === 0)
3088
+ return [2 /*return*/, id];
3089
+ newRecordData_1 = {};
3090
+ changedAttributeIds.forEach(function (key) {
3091
+ newRecordData_1[key] = createSelectedData_1[key];
3092
+ });
3093
+ if (isDraft)
3094
+ newRecordData_1["baseDraft"] = true;
3095
+ else
3096
+ newRecordData_1["baseDraft"] = false;
3097
+ }
3098
+ else {
3099
+ // INFO: genuinely new record — no baseline to diff against,
3100
+ // send the full payload so no prefilled fields are silently dropped.
3101
+ newRecordData_1 = createSelectedData_1;
3102
+ }
3075
3103
  return [4 /*yield*/, writeServerQuery.call("update", {
3076
3104
  id: id,
3077
- data: createSelectedData_1,
3105
+ data: newRecordData_1,
3078
3106
  upsert: true,
3079
3107
  })];
3080
3108
  case 10:
3081
- res = _o.sent();
3109
+ res = _p.sent();
3082
3110
  return [3 /*break*/, 15];
3083
3111
  case 11:
3084
3112
  // INFO: stepper create guard — if a create is already in-flight, queue this
@@ -3098,7 +3126,7 @@ exports.DataTemplate = (0, react_1.forwardRef)(function (props, ref) {
3098
3126
  })];
3099
3127
  case 12:
3100
3128
  //INFO: [CREATE] Create new data
3101
- res = _o.sent();
3129
+ res = _p.sent();
3102
3130
  if (!(selectedId_2 === "new")) return [3 /*break*/, 15];
3103
3131
  isCreatingRef.current = false;
3104
3132
  if (!pendingDraftSaveRef.current) return [3 /*break*/, 14];
@@ -3110,25 +3138,25 @@ exports.DataTemplate = (0, react_1.forwardRef)(function (props, ref) {
3110
3138
  })];
3111
3139
  case 13:
3112
3140
  // INFO: replay as update — inflightIdRef.current holds the real _id
3113
- _o.sent();
3114
- _o.label = 14;
3141
+ _p.sent();
3142
+ _p.label = 14;
3115
3143
  case 14:
3116
3144
  inflightIdRef.current = "";
3117
- _o.label = 15;
3145
+ _p.label = 15;
3118
3146
  case 15: return [3 /*break*/, 24];
3119
3147
  case 16:
3120
3148
  if (!selectedId_2) return [3 /*break*/, 24];
3121
3149
  if (!(isOffline && !offlineId)) return [3 /*break*/, 22];
3122
- _o.label = 17;
3150
+ _p.label = 17;
3123
3151
  case 17:
3124
- _o.trys.push([17, 20, , 21]);
3152
+ _p.trys.push([17, 20, , 21]);
3125
3153
  return [4 /*yield*/, indexedDb_1.indexedDb.getValue("local", props.collectionId)];
3126
3154
  case 18:
3127
- offlineDataResp = _o.sent();
3155
+ offlineDataResp = _p.sent();
3128
3156
  tempData = (0, updateModule_1.handleParseOfflineWrite)(selectedData, structure);
3129
3157
  tempData[serverId] = selectedId_2;
3130
3158
  selectedIndex_3 = -1;
3131
- offlineData = (_g = offlineDataResp === null || offlineDataResp === void 0 ? void 0 : offlineDataResp.data) !== null && _g !== void 0 ? _g : [];
3159
+ offlineData = (_h = offlineDataResp === null || offlineDataResp === void 0 ? void 0 : offlineDataResp.data) !== null && _h !== void 0 ? _h : [];
3132
3160
  offlineData.map(function (eachOfflineData, index) {
3133
3161
  var offlineDataId = eachOfflineData[serverId];
3134
3162
  if (selectedId_2 === offlineDataId)
@@ -3142,11 +3170,11 @@ exports.DataTemplate = (0, react_1.forwardRef)(function (props, ref) {
3142
3170
  type: props.collectionId,
3143
3171
  })];
3144
3172
  case 19:
3145
- _o.sent();
3173
+ _p.sent();
3146
3174
  res = true;
3147
3175
  return [3 /*break*/, 21];
3148
3176
  case 20:
3149
- err_20 = _o.sent();
3177
+ err_20 = _p.sent();
3150
3178
  return [3 /*break*/, 21];
3151
3179
  case 21: return [3 /*break*/, 24];
3152
3180
  case 22:
@@ -3155,8 +3183,8 @@ exports.DataTemplate = (0, react_1.forwardRef)(function (props, ref) {
3155
3183
  _a[columnId] = createSelectedData_1[columnId],
3156
3184
  _a);
3157
3185
  }
3158
- else if ((_h = props.bareSettings) === null || _h === void 0 ? void 0 : _h.bareUpsertPartialUpdate) {
3159
- changedAttributeIds = (0, updateModule_1.compareUpdatedFields)((_j = previousSelectedData.current) !== null && _j !== void 0 ? _j : {}, createSelectedData_1).changedAttributeIds;
3186
+ else if ((_j = props.bareSettings) === null || _j === void 0 ? void 0 : _j.bareUpsertPartialUpdate) {
3187
+ changedAttributeIds = (0, updateModule_1.compareUpdatedFields)((_k = loadedSelectedData.current) !== null && _k !== void 0 ? _k : {}, createSelectedData_1).changedAttributeIds;
3160
3188
  // INFO: if nothing changed, skip the write entirely — sending an
3161
3189
  // empty payload would be a no-op at best and an error at worst.
3162
3190
  if (changedAttributeIds.length === 0)
@@ -3192,15 +3220,15 @@ exports.DataTemplate = (0, react_1.forwardRef)(function (props, ref) {
3192
3220
  // doesn't exist yet (covers deterministicId passed directly as props.id).
3193
3221
  // Scoped away from offline paths: offlineId uses operationType="create"
3194
3222
  // and isOfflineUpdate is a separate flow — upsert is not meaningful there.
3195
- upsert: ((_k = props.bareSettings) === null || _k === void 0 ? void 0 : _k.bareUpsertPartialUpdate) &&
3223
+ upsert: ((_l = props.bareSettings) === null || _l === void 0 ? void 0 : _l.bareUpsertPartialUpdate) &&
3196
3224
  !offlineId &&
3197
3225
  !isOfflineUpdate
3198
3226
  ? true
3199
3227
  : undefined,
3200
3228
  })];
3201
3229
  case 23:
3202
- res = _o.sent();
3203
- _o.label = 24;
3230
+ res = _p.sent();
3231
+ _p.label = 24;
3204
3232
  case 24:
3205
3233
  if (!(type === "update" || type === "create")) return [3 /*break*/, 32];
3206
3234
  if (!res) return [3 /*break*/, 31];
@@ -3216,25 +3244,25 @@ exports.DataTemplate = (0, react_1.forwardRef)(function (props, ref) {
3216
3244
  });
3217
3245
  return [4 /*yield*/, handleGetListData({ data: tableData[selectedIndex_4] }, "update", rowId)];
3218
3246
  case 25:
3219
- _o.sent();
3220
- _o.label = 26;
3247
+ _p.sent();
3248
+ _p.label = 26;
3221
3249
  case 26: return [3 /*break*/, 29];
3222
3250
  case 27: return [4 /*yield*/, handleGetListData({ data: [createSelectedData_1] }, "create")];
3223
3251
  case 28:
3224
- _o.sent();
3225
- _o.label = 29;
3252
+ _p.sent();
3253
+ _p.label = 29;
3226
3254
  case 29:
3227
- if (!((_l = props.bareSettings) === null || _l === void 0 ? void 0 : _l.bareUpdateHandlePostComplete)) return [3 /*break*/, 31];
3255
+ if (!((_m = props.bareSettings) === null || _m === void 0 ? void 0 : _m.bareUpdateHandlePostComplete)) return [3 /*break*/, 31];
3228
3256
  return [4 /*yield*/, props.bareSettings.bareUpdateHandlePostComplete(__assign((_b = {}, _b[serverId] = id, _b), createSelectedData_1))];
3229
3257
  case 30:
3230
- _o.sent();
3231
- _o.label = 31;
3258
+ _p.sent();
3259
+ _p.label = 31;
3232
3260
  case 31: return [3 /*break*/, 34];
3233
3261
  case 32:
3234
3262
  createSelectedData_1[serverId] = id;
3235
3263
  return [4 /*yield*/, handleGetListData({ data: [createSelectedData_1] }, selectedId_2 === "new" ? "create" : "update", id)];
3236
3264
  case 33:
3237
- _o.sent();
3265
+ _p.sent();
3238
3266
  setNotification({
3239
3267
  type: true,
3240
3268
  title: props.id === "new"
@@ -3244,12 +3272,12 @@ exports.DataTemplate = (0, react_1.forwardRef)(function (props, ref) {
3244
3272
  ? "Data sucessfully created"
3245
3273
  : "Data sucessfully updated",
3246
3274
  });
3247
- _o.label = 34;
3275
+ _p.label = 34;
3248
3276
  case 34:
3249
3277
  dataId = res ? id : "";
3250
3278
  return [2 /*return*/, dataId];
3251
3279
  case 35:
3252
- err_21 = _o.sent();
3280
+ err_21 = _p.sent();
3253
3281
  console.log("error", err_21);
3254
3282
  // INFO: clear in-flight guard on failure so the next save retries as a create
3255
3283
  if (isCreatingRef.current) {
@@ -3258,7 +3286,7 @@ exports.DataTemplate = (0, react_1.forwardRef)(function (props, ref) {
3258
3286
  inflightIdRef.current = "";
3259
3287
  }
3260
3288
  if (err_21.response && err_21.response.status === 400) {
3261
- if (typeof ((_m = err_21.response.data) === null || _m === void 0 ? void 0 : _m.err) === "string")
3289
+ if (typeof ((_o = err_21.response.data) === null || _o === void 0 ? void 0 : _o.err) === "string")
3262
3290
  setNotification({
3263
3291
  type: false,
3264
3292
  title: "Error",
@@ -3456,6 +3484,9 @@ exports.DataTemplate = (0, react_1.forwardRef)(function (props, ref) {
3456
3484
  if (!responseData.data) return [3 /*break*/, 6];
3457
3485
  if (!((_b = props.bareSettings) === null || _b === void 0 ? void 0 : _b.bareOffline)) return [3 /*break*/, 2];
3458
3486
  setSelectedData(responseData.data);
3487
+ // INFO: stamp the load baseline so bareUpsertPartialUpdate can diff
3488
+ // against the original doc rather than the post-edit state.
3489
+ loadedSelectedData.current = responseData.data;
3459
3490
  if ((_c = props.bareSettings) === null || _c === void 0 ? void 0 : _c.bareReadHandleData)
3460
3491
  props.bareSettings.bareReadHandleData(responseData.data);
3461
3492
  clonedReferencesOptions_1 = JSON.parse(JSON.stringify(referencesOptions));
@@ -3524,6 +3555,9 @@ exports.DataTemplate = (0, react_1.forwardRef)(function (props, ref) {
3524
3555
  case 5:
3525
3556
  newRespData = _a;
3526
3557
  setSelectedData(newRespData);
3558
+ // INFO: stamp the load baseline so bareUpsertPartialUpdate can diff
3559
+ // against the original doc rather than the post-edit state.
3560
+ loadedSelectedData.current = newRespData;
3527
3561
  if ((_g = props.bareSettings) === null || _g === void 0 ? void 0 : _g.bareReadHandleData)
3528
3562
  props.bareSettings.bareReadHandleData(newRespData);
3529
3563
  if ((props.type === "update" || props.type === "read") &&