Skip to content

Commit cbddf11

Browse files
committed
add inferNamespacesFromPrivileges, default to true
1 parent ec74f26 commit cbddf11

File tree

33 files changed

+252
-161
lines changed

33 files changed

+252
-161
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+
is_ghost_namespace: boolean;
8787
}
8888

8989
type CollectionDataService = Pick<

packages/collection-model/lib/model.js

Lines changed: 12 additions & 6 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+
is_ghost_namespace,
106106
}) {
107107
return {
108108
type,
@@ -113,7 +113,7 @@ function pickCollectionInfo({
113113
validation,
114114
clustered,
115115
fle2,
116-
is_non_existent,
116+
is_ghost_namespace,
117117
};
118118
}
119119

@@ -135,7 +135,7 @@ const CollectionModel = AmpersandModel.extend(debounceActions(['fetch']), {
135135
statusError: { type: 'string', default: null },
136136

137137
// Normalized values from collectionInfo command
138-
is_non_existent: 'boolean',
138+
is_ghost_namespace: 'boolean',
139139
readonly: 'boolean',
140140
clustered: 'boolean',
141141
fle2: 'boolean',
@@ -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,
289+
// If the collection is not unprovisioned `is_ghost_namespace` anymore,
290290
// let's update the parent database model to reflect the change.
291291
// This happens when a user tries to insert first document into a
292292
// collection that doesn't exist yet or creates a new collection
293293
// for an unprovisioned database.
294-
if (!this.is_non_existent) {
294+
if (!this.is_ghost_namespace) {
295295
getParentByType(this, 'Database').set({
296-
is_non_existent: false,
296+
is_ghost_namespace: 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: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,16 @@ export function createInstancesStore(
286286
}
287287
);
288288

289+
preferences.onPreferenceValueChanged('inferNamespacesFromPrivileges', () => {
290+
const connectedConnectionIds = Array.from(
291+
instancesManager.listMongoDBInstances().keys()
292+
);
293+
294+
for (const connectionId of connectedConnectionIds) {
295+
void refreshDatabases({ connectionId });
296+
}
297+
});
298+
289299
on(connections, 'disconnected', function (connectionInfoId: string) {
290300
try {
291301
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+
isGhostNamespace,
2828
isReadonly,
2929
isTimeSeries,
3030
sourceName,
@@ -68,12 +68,12 @@ function PluginTitle({
6868
? 'Visibility'
6969
: collectionType === 'timeseries'
7070
? 'TimeSeries'
71-
: isNonExistent
71+
: isGhostNamespace
7272
? 'EmptyFolder'
7373
: 'Folder'
7474
}
7575
data-namespace={ns}
76-
isNonExistent={isNonExistent}
76+
isGhostNamespace={isGhostNamespace}
7777
/>
7878
);
7979
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ export type WorkspaceTabPluginProps = {
184184
connectionName?: string;
185185
type: string;
186186
title: React.ReactNode;
187-
isNonExistent?: boolean;
187+
isGhostNamespace?: 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+
isGhostNamespace,
210210
isSelected,
211211
isDragging,
212212
onSelect,
@@ -271,7 +271,7 @@ function Tab({
271271
className={cx(
272272
tabStyles,
273273
themeClass,
274-
isNonExistent && nonExistentStyles,
274+
isGhostNamespace && nonExistentStyles,
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+
isGhostNamespace: 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+
isGhostNamespace: false,
6161
},
6262
{
6363
_id: 'db_ready.woof',
6464
name: 'woof',
6565
type: 'timeseries',
6666
sourceName: '',
6767
pipeline: [],
68-
isNonExistent: false,
68+
isGhostNamespace: false,
6969
},
7070
{
7171
_id: 'db_ready.bwok',
7272
name: 'bwok',
7373
type: 'view',
7474
sourceName: '',
7575
pipeline: [],
76-
isNonExistent: false,
76+
isGhostNamespace: false,
7777
},
7878
],
79-
isNonExistent: false,
79+
isGhostNamespace: false,
8080
},
8181
],
8282
isReady: true,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const IconWithTooltip = ({
3535

3636
export const NavigationItemIcon = ({ item }: { item: SidebarTreeItem }) => {
3737
if (item.type === 'database') {
38-
if (item.isNonExistent) {
38+
if (item.isGhostNamespace) {
3939
return (
4040
<IconWithTooltip
4141
text={NON_EXISTANT_NAMESPACE_TEXT}
@@ -46,7 +46,7 @@ export const NavigationItemIcon = ({ item }: { item: SidebarTreeItem }) => {
4646
return <Icon glyph="Database" />;
4747
}
4848
if (item.type === 'collection') {
49-
if (item.isNonExistent) {
49+
if (item.isGhostNamespace) {
5050
return (
5151
<IconWithTooltip
5252
text={NON_EXISTANT_NAMESPACE_TEXT}

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,26 @@ export default function StyledNavigationItem({
4141
!showDisabledConnections || getConnectable(connectionId);
4242
const isDisconnectedConnection =
4343
item.type === 'connection' && item.connectionStatus !== 'connected';
44-
const isNonExistentNamespace =
44+
const isGhostNamespaceNamespace =
4545
(item.type === 'database' || item.type === 'collection') &&
46-
item.isNonExistent;
46+
item.isGhostNamespace;
4747

4848
if (colorCode && colorCode !== DefaultColorCode) {
4949
style['--item-bg-color'] = connectionColorToHex(colorCode);
5050
style['--item-bg-color-hover'] = connectionColorToHexActive(colorCode);
5151
style['--item-bg-color-active'] = connectionColorToHexActive(colorCode);
5252
}
5353

54-
if (isDisconnectedConnection || isNonExistentNamespace || !isConnectable) {
54+
if (
55+
isDisconnectedConnection ||
56+
isGhostNamespaceNamespace ||
57+
!isConnectable
58+
) {
5559
style['--item-color'] = inactiveColor;
5660
}
5761

5862
// We always show these as inactive
59-
if (isNonExistentNamespace || !isConnectable) {
63+
if (isGhostNamespaceNamespace || !isConnectable) {
6064
style['--item-color-active'] = inactiveColor;
6165
}
6266
return style;

0 commit comments

Comments
 (0)