Skip to content

Commit 1ff2033

Browse files
lerouxbCopilot
andauthored
feat: add inferNamespacesFromPrivileges, default to true COMPASS-9572 (#7153)
* add inferNamespacesFromPrivileges, default to true * Update packages/instance-model/lib/model.js Co-authored-by: Copilot <[email protected]> * cleanup * use methods rather so the timing of keeping these synced is not a thing * inferredFromPrivileges rather * unit tests * more might not * tweak comment --------- Co-authored-by: Copilot <[email protected]>
1 parent 2470d2d commit 1ff2033

File tree

34 files changed

+317
-198
lines changed

34 files changed

+317
-198
lines changed

package-lock.json

Lines changed: 19 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/collection-model/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ interface CollectionProps {
8383
sourceName: string | null;
8484
source: Collection;
8585
properties: { id: string; options?: Record<string, unknown> }[];
86-
is_non_existent: boolean;
86+
inferred_from_privileges: boolean;
8787
}
8888

8989
type CollectionDataService = Pick<

packages/collection-model/lib/model.js

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ function pickCollectionInfo({
102102
validation,
103103
clustered,
104104
fle2,
105-
is_non_existent,
105+
inferred_from_privileges,
106106
}) {
107107
return {
108108
type,
@@ -113,7 +113,7 @@ function pickCollectionInfo({
113113
validation,
114114
clustered,
115115
fle2,
116-
is_non_existent,
116+
inferred_from_privileges,
117117
};
118118
}
119119

@@ -134,8 +134,8 @@ const CollectionModel = AmpersandModel.extend(debounceActions(['fetch']), {
134134
status: { type: 'string', default: 'initial' },
135135
statusError: { type: 'string', default: null },
136136

137-
// Normalized values from collectionInfo command
138-
is_non_existent: 'boolean',
137+
// Normalized values from collectionInfo method
138+
inferred_from_privileges: 'boolean',
139139
readonly: 'boolean',
140140
clustered: 'boolean',
141141
fle2: 'boolean',
@@ -269,7 +269,7 @@ const CollectionModel = AmpersandModel.extend(debounceActions(['fetch']), {
269269
const shouldFetchDbAndCollStats = getParentByType(
270270
this,
271271
'Instance'
272-
).shouldFetchDbAndCollStats;
272+
).shouldFetchDbAndCollStats();
273273

274274
try {
275275
const newStatus = this.status === 'initial' ? 'fetching' : 'refreshing';
@@ -286,14 +286,14 @@ const CollectionModel = AmpersandModel.extend(debounceActions(['fetch']), {
286286
...collStats,
287287
...(collectionInfo && pickCollectionInfo(collectionInfo)),
288288
});
289-
// If the collection is not unprovisioned `is_non_existent` anymore,
290-
// let's update the parent database model to reflect the change.
291-
// This happens when a user tries to insert first document into a
292-
// collection that doesn't exist yet or creates a new collection
293-
// for an unprovisioned database.
294-
if (!this.is_non_existent) {
289+
// If the collection is not `inferred_from_privileges` anymore, let's
290+
// update the parent database model to reflect the change. This happens
291+
// when a user tries to insert first document into a collection that
292+
// doesn't exist yet or creates a new collection for an unprovisioned
293+
// database.
294+
if (!this.inferred_from_privileges) {
295295
getParentByType(this, 'Database').set({
296-
is_non_existent: false,
296+
inferred_from_privileges: false,
297297
});
298298
}
299299
} catch (err) {
@@ -385,6 +385,11 @@ const CollectionCollection = AmpersandCollection.extend(
385385
async fetch({ dataService }) {
386386
const databaseName = getParentByType(this, 'Database')?.getId();
387387

388+
const shouldFetchNamespacesFromPrivileges = getParentByType(
389+
this,
390+
'Instance'
391+
).shouldFetchNamespacesFromPrivileges();
392+
388393
if (!databaseName) {
389394
throw new Error(
390395
`Trying to fetch ${this.modelType} that doesn't have the Database parent model`
@@ -405,6 +410,7 @@ const CollectionCollection = AmpersandCollection.extend(
405410
{
406411
// Always fetch collections with info
407412
nameOnly: false,
413+
fetchNamespacesFromPrivileges: shouldFetchNamespacesFromPrivileges,
408414
privileges: instanceModel.auth.privileges,
409415
}
410416
);

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,15 @@ export function createInstancesStore(
286286
}
287287
);
288288

289+
preferences.onPreferenceValueChanged('inferNamespacesFromPrivileges', () => {
290+
const connectedConnectionIds = Array.from(
291+
instancesManager.listMongoDBInstances().keys()
292+
);
293+
for (const connectionId of connectedConnectionIds) {
294+
void refreshDatabases({ connectionId });
295+
}
296+
});
297+
289298
on(connections, 'disconnected', function (connectionInfoId: string) {
290299
try {
291300
const instance =

packages/compass-collection/src/plugin-tab-title.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ type PluginTitleProps = {
2424

2525
function PluginTitle({
2626
editViewName,
27-
isNonExistent,
27+
inferredFromPrivileges,
2828
isReadonly,
2929
isTimeSeries,
3030
sourceName,
@@ -68,12 +68,12 @@ function PluginTitle({
6868
? 'Visibility'
6969
: collectionType === 'timeseries'
7070
? 'TimeSeries'
71-
: isNonExistent
71+
: inferredFromPrivileges
7272
? 'EmptyFolder'
7373
: 'Folder'
7474
}
7575
data-namespace={ns}
76-
isNonExistent={isNonExistent}
76+
inferredFromPrivileges={inferredFromPrivileges}
7777
/>
7878
);
7979
}

packages/compass-components/src/components/workspace-tabs/tab.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ const draggingTabStyles = css({
138138
cursor: 'grabbing !important',
139139
});
140140

141-
const nonExistentStyles = css({
141+
const inferredFromPrivilegesStyles = css({
142142
color: palette.gray.base,
143143
});
144144

@@ -184,7 +184,7 @@ export type WorkspaceTabPluginProps = {
184184
connectionName?: string;
185185
type: string;
186186
title: React.ReactNode;
187-
isNonExistent?: boolean;
187+
inferredFromPrivileges?: boolean;
188188
iconGlyph: GlyphName | 'Logo' | 'Server';
189189
tooltip?: [string, string][];
190190
};
@@ -206,7 +206,7 @@ function Tab({
206206
type,
207207
title,
208208
tooltip,
209-
isNonExistent,
209+
inferredFromPrivileges,
210210
isSelected,
211211
isDragging,
212212
onSelect,
@@ -271,7 +271,7 @@ function Tab({
271271
className={cx(
272272
tabStyles,
273273
themeClass,
274-
isNonExistent && nonExistentStyles,
274+
inferredFromPrivileges && inferredFromPrivilegesStyles,
275275
isSelected && selectedTabStyles,
276276
isSelected && tabTheme && selectedThemedTabStyles,
277277
isDragging && draggingTabStyles,

packages/compass-connections-navigation/src/connections-navigation-tree.spec.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const connections: Connection[] = [
4343
collectionsStatus: 'initial',
4444
collectionsLength: 5,
4545
collections: [],
46-
isNonExistent: false,
46+
inferredFromPrivileges: false,
4747
},
4848
{
4949
_id: 'db_ready',
@@ -57,26 +57,26 @@ const connections: Connection[] = [
5757
type: 'collection',
5858
sourceName: '',
5959
pipeline: [],
60-
isNonExistent: false,
60+
inferredFromPrivileges: false,
6161
},
6262
{
6363
_id: 'db_ready.woof',
6464
name: 'woof',
6565
type: 'timeseries',
6666
sourceName: '',
6767
pipeline: [],
68-
isNonExistent: false,
68+
inferredFromPrivileges: false,
6969
},
7070
{
7171
_id: 'db_ready.bwok',
7272
name: 'bwok',
7373
type: 'view',
7474
sourceName: '',
7575
pipeline: [],
76-
isNonExistent: false,
76+
inferredFromPrivileges: false,
7777
},
7878
],
79-
isNonExistent: false,
79+
inferredFromPrivileges: false,
8080
},
8181
],
8282
isReady: true,

packages/compass-connections-navigation/src/navigation-item-icon.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import type { GlyphName } from '@mongodb-js/compass-components';
55
import { WithStatusMarker } from './with-status-marker';
66
import { isLocalhost } from 'mongodb-build-info';
77

8-
const NON_EXISTANT_NAMESPACE_TEXT =
9-
'Your privileges grant you access to this namespace, but it does not currently exist';
8+
const INFERRED_FROM_PRIVILEGES_TEXT =
9+
'Your privileges grant you access to this namespace, but it might not currently exist';
1010

1111
const tooltipTriggerStyles = css({
1212
display: 'flex',
@@ -35,21 +35,21 @@ const IconWithTooltip = ({
3535

3636
export const NavigationItemIcon = ({ item }: { item: SidebarTreeItem }) => {
3737
if (item.type === 'database') {
38-
if (item.isNonExistent) {
38+
if (item.inferredFromPrivileges) {
3939
return (
4040
<IconWithTooltip
41-
text={NON_EXISTANT_NAMESPACE_TEXT}
41+
text={INFERRED_FROM_PRIVILEGES_TEXT}
4242
glyph="EmptyDatabase"
4343
/>
4444
);
4545
}
4646
return <Icon glyph="Database" />;
4747
}
4848
if (item.type === 'collection') {
49-
if (item.isNonExistent) {
49+
if (item.inferredFromPrivileges) {
5050
return (
5151
<IconWithTooltip
52-
text={NON_EXISTANT_NAMESPACE_TEXT}
52+
text={INFERRED_FROM_PRIVILEGES_TEXT}
5353
glyph="EmptyFolder"
5454
/>
5555
);

0 commit comments

Comments
 (0)