Skip to content

Commit 909ee05

Browse files
authored
Merge pull request #3707 from bjester/topics-are-folders
Resolve issues with editing and browsing newly added topics
2 parents 514acc0 + 982fc02 commit 909ee05

3 files changed

Lines changed: 47 additions & 17 deletions

File tree

contentcuration/contentcuration/frontend/channelEdit/components/ContentNodeOptions.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
<script>
3939
4040
import { mapActions, mapGetters } from 'vuex';
41-
import { RouteNames } from '../constants';
41+
import { RouteNames, TabNames } from '../constants';
4242
import MoveModal from './move/MoveModal';
4343
import { ContentNode } from 'shared/data/resources';
4444
import { withChangeTracker } from 'shared/data/changes';
@@ -119,6 +119,7 @@
119119
params: {
120120
...this.$route.params,
121121
detailNodeIds: newId,
122+
tab: TabNames.DETAILS,
122123
},
123124
});
124125
});

contentcuration/contentcuration/frontend/shared/data/constants.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@ export const CHANGE_TYPES = {
77
PUBLISHED: 6,
88
SYNCED: 7,
99
};
10+
/**
11+
* An array of change types that directly result in the creation of nodes
12+
* @type {(number)[]}
13+
*/
14+
export const CREATION_CHANGE_TYPES = [CHANGE_TYPES.CREATED, CHANGE_TYPES.COPIED];
15+
/**
16+
* An array of change types that directly result in changes to tree structure
17+
* @type {(number)[]}
18+
*/
19+
export const TREE_CHANGE_TYPES = [CHANGE_TYPES.CREATED, CHANGE_TYPES.COPIED, CHANGE_TYPES.MOVED];
1020

1121
// Tables
1222
export const CHANGES_TABLE = 'changesForSyncing';

contentcuration/contentcuration/frontend/shared/data/resources.js

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import {
2626
CHANNEL_SYNC_KEEP_ALIVE_INTERVAL,
2727
MAX_REV_KEY,
2828
LAST_FETCHED,
29+
CREATION_CHANGE_TYPES,
30+
TREE_CHANGE_TYPES,
2931
} from './constants';
3032
import applyChanges, { applyMods, collectChanges } from './applyRemoteChanges';
3133
import mergeAllChanges from './mergeChanges';
@@ -685,28 +687,45 @@ class Resource extends mix(APIResource, IndexedDBResource) {
685687
if (objs === EMPTY_ARRAY) {
686688
return [];
687689
}
688-
if (!objs.length && !objs.count) {
689-
return this.fetchCollection(params);
690-
}
691-
if (doRefresh) {
692-
// Only fetch new updates if we've finished syncing the changes table
693-
db[CHANGES_TABLE].where('table')
694-
.equals(this.tableName)
695-
.filter(c => !c.synced)
696-
.limit(1)
697-
.toArray()
698-
.then(pendingChanges => {
699-
if (pendingChanges.length === 0) {
700-
this.fetchCollection(params);
701-
}
702-
});
690+
// if there are no objects, and it's also not an empty paginated response (objs.count),
691+
// or we mean to refresh
692+
if ((!objs.length && !objs.count) || doRefresh) {
693+
let refresh = Promise.resolve(true);
694+
// ContentNode tree operations are the troublemakers causing the logic below
695+
if (this.tableName === TABLE_NAMES.CONTENTNODE) {
696+
// Only fetch new updates if we don't have pending changes to ContentNode that
697+
// affect tree structure
698+
refresh = db[CHANGES_TABLE].where('table')
699+
.equals(TABLE_NAMES.CONTENTNODE)
700+
.filter(c => TREE_CHANGE_TYPES.includes(c.type))
701+
.count()
702+
.then(pendingCount => pendingCount === 0);
703+
}
704+
705+
const fetch = refresh.then(shouldFetch => {
706+
return shouldFetch ? this.fetchCollection(params) : [];
707+
});
708+
// Be sure to return the fetch promise to relay fetched objects in this condition
709+
if (!objs.length && !objs.count) {
710+
return fetch;
711+
}
703712
}
704713
return objs;
705714
});
706715
}
707716

708717
headModel(id) {
709-
return client.head(this.modelUrl(id));
718+
// If the resource identified by `id` has just been created, but we haven't verified
719+
// the server has applied the change yet, we skip making the HEAD request for it
720+
return db[CHANGES_TABLE].where('[table+key]')
721+
.equals([this.tableName, id])
722+
.filter(c => CREATION_CHANGE_TYPES.includes(c.type))
723+
.count()
724+
.then(pendingCount => {
725+
if (pendingCount === 0) {
726+
return client.head(this.modelUrl(id));
727+
}
728+
});
710729
}
711730

712731
fetchModel(id) {

0 commit comments

Comments
 (0)