@onehat/data 1.20.2 → 1.20.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onehat/data",
3
- "version": "1.20.2",
3
+ "version": "1.20.4",
4
4
  "description": "JS data modeling package with adapters for many storage mediums.",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -1036,7 +1036,10 @@ class AjaxRepository extends Repository {
1036
1036
  this.assembleTreeNodes();
1037
1037
  this.emit('changeData', this.entities);
1038
1038
  } else if (this.isRemotePhantomMode && (this._operations.add || this._operations.deletePhantom)) {
1039
- // Do nothing, as we don't want to immediately reload on add for a remote phantom mode record. It won't appear, and it will cause all kinds of trouble!
1039
+ if (this._operations.add) {
1040
+ // Do nothing, as we don't want to immediately reload on add for a remote phantom mode record.
1041
+ // The entity wouldn't appear, and it would cause all kinds of trouble!
1042
+ }
1040
1043
  if (this._operations.deletePhantom) {
1041
1044
  // sweep existing deleted records and remove them
1042
1045
  _.each(this.entities, (entity) => {
@@ -262,22 +262,31 @@ class OneBuildRepository extends AjaxRepository {
262
262
 
263
263
  /**
264
264
  * Integrates with RestTrait::reorder in OneBuild API
265
- * @param {entity} dragRecord - which entity was being dragged
265
+ * @param {entity|array} dragRecordOrIds - which entity or ids were being dragged
266
266
  * @param {entity} dropRecord - which entity it was dropped on to
267
267
  * @param {string} dropPosition - position in which it was dropped; could be 'before' or 'after'
268
268
  * @return {Promise}
269
269
  */
270
- reorder = (dragRecord, dropRecord, dropPosition) => {
270
+ reorder = (dragRecordOrIds, dropRecord, dropPosition) => {
271
271
 
272
272
  if (!this.isOnline) {
273
273
  this.throwError('Offline');
274
274
  return;
275
275
  }
276
-
276
+
277
+ let ids;
278
+ if (_.isArray(dragRecordOrIds)) {
279
+ ids = dragRecordOrIds;
280
+ } else if (dragRecordOrIds?.id) {
281
+ ids = [dragRecordOrIds.id];
282
+ } else {
283
+ throw Error('dragRecordOrIds must be an entity or array of ids')
284
+ }
285
+
277
286
  const data = {
278
287
  url: this.name + '/reorder',
279
288
  data: qs.stringify({
280
- ids: dragRecord.id,
289
+ ids,
281
290
  dropPosition,
282
291
  dropRecord_id: dropRecord.id,
283
292
  }),
@@ -340,6 +349,9 @@ class OneBuildRepository extends AjaxRepository {
340
349
 
341
350
 
342
351
  const duplicateEntity = await this.createStandaloneEntity(root, true, true);
352
+ if (entity.isRemotePhantomMode) {
353
+ entity.isRemotePhantom = true;
354
+ }
343
355
  this._insertBefore(duplicateEntity, entity);
344
356
 
345
357
  this.markLoading(false);
@@ -1716,6 +1716,10 @@ export default class Repository extends EventEmitter {
1716
1716
  break;
1717
1717
  case 'edit':
1718
1718
  entities = this.getDirty();
1719
+ if (_.isEmpty(entities) && this.isRemotePhantomMode) {
1720
+ // In remote phantom mode, we need to save phantoms even if they're not dirty
1721
+ entities = this.getPhantom();
1722
+ }
1719
1723
  if (useStaged) {
1720
1724
  entities = this.getStaged(entities);
1721
1725
  }