From c9c68fd3de92f09a7d773beb24a4a07729a445de Mon Sep 17 00:00:00 2001 From: Sergey Petushkov Date: Tue, 23 Nov 2021 13:09:36 +0100 Subject: [PATCH] fix(instance-model, compass-collection): Fetch collection info when active namepsace changes and don't show collStats when editing a view 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 --- .../compass-app-stores/src/stores/instance-store.js | 10 +++++++++- .../components/collection-stats/collection-stats.jsx | 5 +++-- packages/compass-collection-stats/src/stores/store.js | 5 +++-- .../compass-collection-stats/src/stores/store.spec.js | 4 ++++ packages/compass-collection/src/modules/context.js | 4 ++-- 5 files changed, 21 insertions(+), 7 deletions(-) diff --git a/packages/compass-app-stores/src/stores/instance-store.js b/packages/compass-app-stores/src/stores/instance-store.js index 75428e14b31..0d243e00703 100644 --- a/packages/compass-app-stores/src/stores/instance-store.js +++ b/packages/compass-app-stores/src/stores/instance-store.js @@ -60,7 +60,7 @@ store.fetchDatabaseDetails = async(dbName, { nameOnly = false } = {}) => { const { instance, dataService } = store.getState(); const db = instance.databases.get(dbName); - if (db && db.collectionsStatus === 'initial') { + if (db.collectionsStatus === 'initial') { await db.fetchCollections({ dataService, fetchInfo: !nameOnly }); } @@ -162,6 +162,14 @@ store.onActivated = (appRegistry) => { store.fetchDatabaseDetails(dbName, { nameOnly: true }); }); + appRegistry.on('select-namespace', ({ namespace }) => { + store.fetchCollectionDetails(namespace); + }); + + appRegistry.on('open-namespace-in-new-tab', ({ namespace }) => { + store.fetchCollectionDetails(namespace); + }); + appRegistry.on('refresh-data', () => { store.refreshInstance(appRegistry); }); diff --git a/packages/compass-collection-stats/src/components/collection-stats/collection-stats.jsx b/packages/compass-collection-stats/src/components/collection-stats/collection-stats.jsx index 39011da24f9..f9ac87c35e9 100644 --- a/packages/compass-collection-stats/src/components/collection-stats/collection-stats.jsx +++ b/packages/compass-collection-stats/src/components/collection-stats/collection-stats.jsx @@ -17,7 +17,8 @@ class CollectionStats extends Component { totalIndexSize: PropTypes.string, avgIndexSize: PropTypes.string, isReadonly: PropTypes.bool, - isTimeSeries: PropTypes.bool + isTimeSeries: PropTypes.bool, + isEditing: PropTypes.bool }; /** @@ -26,7 +27,7 @@ class CollectionStats extends Component { * @returns {React.Component} The rendered component. */ render() { - if (this.props.isReadonly === true) { + if (this.props.isReadonly === true || this.props.isEditing === true) { return
; } diff --git a/packages/compass-collection-stats/src/stores/store.js b/packages/compass-collection-stats/src/stores/store.js index 0456f1c6e61..4cc0cf9bd0f 100644 --- a/packages/compass-collection-stats/src/stores/store.js +++ b/packages/compass-collection-stats/src/stores/store.js @@ -44,6 +44,7 @@ const store = Reflux.createStore({ getInitialState() { return { namespace: '', + isEditing: false, isReadonly: false, isTimeSeries: false, documentCount: INVALID, @@ -125,7 +126,7 @@ function onInstanceDestroyed() { /** * Collection Stats store. */ -const configureStore = ({ namespace, globalAppRegistry } = {}) => { +const configureStore = ({ namespace, globalAppRegistry, isEditing = false } = {}) => { if (!namespace) { throw new Error('Trying to render collection stats without namespace'); } @@ -151,7 +152,7 @@ const configureStore = ({ namespace, globalAppRegistry } = {}) => { instance.on('change:collections.status', onCollectionStatusChange); } - store.setState({ namespace }); + store.setState({ namespace, isEditing }); const { database, ns } = toNS(namespace); diff --git a/packages/compass-collection-stats/src/stores/store.spec.js b/packages/compass-collection-stats/src/stores/store.spec.js index e87bfe2749b..b646aed7a95 100644 --- a/packages/compass-collection-stats/src/stores/store.spec.js +++ b/packages/compass-collection-stats/src/stores/store.spec.js @@ -53,6 +53,7 @@ describe('CollectionStats [store]', function() { const store = configureStore({ globalAppRegistry, namespace: 'foo.bar' }); expect(store.state).to.deep.eq({ namespace: 'foo.bar', + isEditing: false, isReadonly: false, isTimeSeries: false, documentCount: 'N/A', @@ -71,6 +72,7 @@ describe('CollectionStats [store]', function() { }); expect(store.state).to.deep.eq({ namespace: 'bar.woof', + isEditing: false, isReadonly: false, isTimeSeries: false, documentCount: '100', @@ -90,6 +92,7 @@ describe('CollectionStats [store]', function() { expect(store.state).to.deep.eq({ namespace: 'baz.meow', + isEditing: false, isReadonly: false, isTimeSeries: false, documentCount: 'N/A', @@ -110,6 +113,7 @@ describe('CollectionStats [store]', function() { expect(store.state).to.deep.eq({ namespace: 'baz.meow', + isEditing: false, isReadonly: false, isTimeSeries: false, documentCount: '5', diff --git a/packages/compass-collection/src/modules/context.js b/packages/compass-collection/src/modules/context.js index 5f33cad90a0..e67fb4c689a 100644 --- a/packages/compass-collection/src/modules/context.js +++ b/packages/compass-collection/src/modules/context.js @@ -263,7 +263,6 @@ const createContext = ({ views.push(); }); - // Setup the stats in the collection HUD const statsRole = globalAppRegistry.getRole('Collection.HUD')[0]; const statsPlugin = statsRole.component; const statsStore = setupStore({ @@ -276,7 +275,8 @@ const createContext = ({ isReadonly, isTimeSeries, actions: {}, - allowWrites: !isDataLake + allowWrites: !isDataLake, + isEditing: Boolean(editViewName) }); // Setup the scoped modals