ui: Stop ember-data overwriting SyncTimes (#12315)

This commit is contained in:
John Cowen 2022-02-11 13:54:46 +00:00 committed by GitHub
parent c6342969c5
commit 72a10582d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 7 deletions

4
.changelog/12315.txt Normal file
View File

@ -0,0 +1,4 @@
```release-note:bug
ui: Fix up a problem where occasionally an intention can
visually disappear from the listing after saving
```

View File

@ -26,7 +26,7 @@ export const softDelete = (repo, item) => {
repo.getModelName() repo.getModelName()
); );
return res; return res;
} };
export default class RepositoryService extends Service { export default class RepositoryService extends Service {
@service('store') store; @service('store') store;
@service('env') env; @service('env') env;
@ -116,7 +116,12 @@ export default class RepositoryService extends Service {
if (typeof meta.date !== 'undefined') { if (typeof meta.date !== 'undefined') {
this.store.peekAll(this.getModelName()).forEach(item => { this.store.peekAll(this.getModelName()).forEach(item => {
const date = get(item, 'SyncTime'); const date = get(item, 'SyncTime');
if (!item.isDeleted && typeof date !== 'undefined' && date != meta.date && this.shouldReconcile(item, params)) { if (
!item.isDeleted &&
typeof date !== 'undefined' &&
date != meta.date &&
this.shouldReconcile(item, params)
) {
this.store.unloadRecord(item); this.store.unloadRecord(item);
} }
}); });
@ -156,12 +161,12 @@ export default class RepositoryService extends Service {
try { try {
res = await this.store.query(this.getModelName(), params); res = await this.store.query(this.getModelName(), params);
meta = res.meta; meta = res.meta;
} catch(e) { } catch (e) {
switch(get(e, 'errors.firstObject.status')) { switch (get(e, 'errors.firstObject.status')) {
case '404': case '404':
case '403': case '403':
meta = { meta = {
date: Number.POSITIVE_INFINITY date: Number.POSITIVE_INFINITY,
}; };
error = e; error = e;
break; break;
@ -169,10 +174,10 @@ export default class RepositoryService extends Service {
throw e; throw e;
} }
} }
if(typeof meta !== 'undefined') { if (typeof meta !== 'undefined') {
this.reconcile(meta, params, configuration); this.reconcile(meta, params, configuration);
} }
if(typeof error !== 'undefined') { if (typeof error !== 'undefined') {
throw error; throw error;
} }
return res; return res;
@ -210,6 +215,7 @@ export default class RepositoryService extends Service {
item.execute(); item.execute();
item = item.data; item = item.data;
} }
set(item, 'SyncTime', undefined);
return item.save(); return item.save();
} }