Skip to content

Commit 36715d4

Browse files
authored
fix(instance-model, compass-collection): Fetch collection info when active namepsace changes and don't show collStats when editing a view (#2610)
Hiding stats is a workaround for the issue with events not being emitted when we swith to the source collection that can be used to trigger the data fetch, this is a bigger issue to resolve so for now I'm just hiding the stats for these cases completely as they are not that imprtant anyway when editing and we don't consider them too important in general (new designs don't have as many shown there) so this feels to me like an alright compromise
1 parent b5f656d commit 36715d4

File tree

5 files changed

+21
-7
lines changed

5 files changed

+21
-7
lines changed

packages/compass-app-stores/src/stores/instance-store.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ store.fetchDatabaseDetails = async(dbName, { nameOnly = false } = {}) => {
6060
const { instance, dataService } = store.getState();
6161
const db = instance.databases.get(dbName);
6262

63-
if (db && db.collectionsStatus === 'initial') {
63+
if (db.collectionsStatus === 'initial') {
6464
await db.fetchCollections({ dataService, fetchInfo: !nameOnly });
6565
}
6666

@@ -162,6 +162,14 @@ store.onActivated = (appRegistry) => {
162162
store.fetchDatabaseDetails(dbName, { nameOnly: true });
163163
});
164164

165+
appRegistry.on('select-namespace', ({ namespace }) => {
166+
store.fetchCollectionDetails(namespace);
167+
});
168+
169+
appRegistry.on('open-namespace-in-new-tab', ({ namespace }) => {
170+
store.fetchCollectionDetails(namespace);
171+
});
172+
165173
appRegistry.on('refresh-data', () => {
166174
store.refreshInstance(appRegistry);
167175
});

packages/compass-collection-stats/src/components/collection-stats/collection-stats.jsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ class CollectionStats extends Component {
1717
totalIndexSize: PropTypes.string,
1818
avgIndexSize: PropTypes.string,
1919
isReadonly: PropTypes.bool,
20-
isTimeSeries: PropTypes.bool
20+
isTimeSeries: PropTypes.bool,
21+
isEditing: PropTypes.bool
2122
};
2223

2324
/**
@@ -26,7 +27,7 @@ class CollectionStats extends Component {
2627
* @returns {React.Component} The rendered component.
2728
*/
2829
render() {
29-
if (this.props.isReadonly === true) {
30+
if (this.props.isReadonly === true || this.props.isEditing === true) {
3031
return <div className={styles['collection-stats-empty']} />;
3132
}
3233

packages/compass-collection-stats/src/stores/store.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ const store = Reflux.createStore({
4444
getInitialState() {
4545
return {
4646
namespace: '',
47+
isEditing: false,
4748
isReadonly: false,
4849
isTimeSeries: false,
4950
documentCount: INVALID,
@@ -125,7 +126,7 @@ function onInstanceDestroyed() {
125126
/**
126127
* Collection Stats store.
127128
*/
128-
const configureStore = ({ namespace, globalAppRegistry } = {}) => {
129+
const configureStore = ({ namespace, globalAppRegistry, isEditing = false } = {}) => {
129130
if (!namespace) {
130131
throw new Error('Trying to render collection stats without namespace');
131132
}
@@ -151,7 +152,7 @@ const configureStore = ({ namespace, globalAppRegistry } = {}) => {
151152
instance.on('change:collections.status', onCollectionStatusChange);
152153
}
153154

154-
store.setState({ namespace });
155+
store.setState({ namespace, isEditing });
155156

156157
const { database, ns } = toNS(namespace);
157158

packages/compass-collection-stats/src/stores/store.spec.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ describe('CollectionStats [store]', function() {
5353
const store = configureStore({ globalAppRegistry, namespace: 'foo.bar' });
5454
expect(store.state).to.deep.eq({
5555
namespace: 'foo.bar',
56+
isEditing: false,
5657
isReadonly: false,
5758
isTimeSeries: false,
5859
documentCount: 'N/A',
@@ -71,6 +72,7 @@ describe('CollectionStats [store]', function() {
7172
});
7273
expect(store.state).to.deep.eq({
7374
namespace: 'bar.woof',
75+
isEditing: false,
7476
isReadonly: false,
7577
isTimeSeries: false,
7678
documentCount: '100',
@@ -90,6 +92,7 @@ describe('CollectionStats [store]', function() {
9092

9193
expect(store.state).to.deep.eq({
9294
namespace: 'baz.meow',
95+
isEditing: false,
9396
isReadonly: false,
9497
isTimeSeries: false,
9598
documentCount: 'N/A',
@@ -110,6 +113,7 @@ describe('CollectionStats [store]', function() {
110113

111114
expect(store.state).to.deep.eq({
112115
namespace: 'baz.meow',
116+
isEditing: false,
113117
isReadonly: false,
114118
isTimeSeries: false,
115119
documentCount: '5',

packages/compass-collection/src/modules/context.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,6 @@ const createContext = ({
263263
views.push(<UnsafeComponent component={role.component} key={i} store={store} actions={actions} />);
264264
});
265265

266-
// Setup the stats in the collection HUD
267266
const statsRole = globalAppRegistry.getRole('Collection.HUD')[0];
268267
const statsPlugin = statsRole.component;
269268
const statsStore = setupStore({
@@ -276,7 +275,8 @@ const createContext = ({
276275
isReadonly,
277276
isTimeSeries,
278277
actions: {},
279-
allowWrites: !isDataLake
278+
allowWrites: !isDataLake,
279+
isEditing: Boolean(editViewName)
280280
});
281281

282282
// Setup the scoped modals

0 commit comments

Comments
 (0)