Skip to content

Commit 8554a6a

Browse files
authored
feat(global-writes): open global writes tab when creating a collection COMPASS-8280 (#6405)
* open global writes tab * dont open tab for special namespaces
1 parent c301055 commit 8554a6a

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

packages/compass-workspaces/src/provider.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export type WorkspacesService = {
9292
options?: TabOptions &
9393
Omit<
9494
Extract<OpenWorkspaceOptions, { type: 'Collection' }>,
95-
'type' | 'namespace' | 'editViewName' | 'initialSubtab' | 'connectionId'
95+
'type' | 'namespace' | 'editViewName' | 'connectionId'
9696
>
9797
): void;
9898
/**

packages/compass-workspaces/src/stores/workspaces.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ export const getInitialTabState = (
220220
);
221221

222222
const subTab =
223-
initialSubtab ?? isAggregationsSubtab ? 'Aggregations' : 'Documents';
223+
initialSubtab ?? (isAggregationsSubtab ? 'Aggregations' : 'Documents');
224224

225225
return {
226226
id: tabId,

packages/databases-collections/src/modules/create-namespace.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import type { Action, AnyAction, Reducer } from 'redux';
22
import { parseFilter } from 'mongodb-query-parser';
33
import type { DataService } from '@mongodb-js/compass-connections/provider';
44
import type { CreateNamespaceThunkAction } from '../stores/create-namespace';
5+
import { connectionSupports } from '@mongodb-js/compass-connections';
6+
import toNS from 'mongodb-ns';
57

68
/**
79
* No dots in DB name error message.
@@ -402,17 +404,24 @@ export const createNamespace = (
402404
expires: !!data.options.expireAfterSeconds,
403405
};
404406

405-
track(
406-
`${kind} Created`,
407-
trackEvent,
408-
connectionRepository.getConnectionInfoById(connectionId)
409-
);
407+
const connectionInfo =
408+
connectionRepository.getConnectionInfoById(connectionId);
409+
410+
track(`${kind} Created`, trackEvent, connectionInfo);
410411

411412
globalAppRegistry.emit('collection-created', namespace, {
412413
connectionId,
413414
});
415+
416+
// For special namespaces (admin, local, config), we do not want
417+
// to navigate user to the global-writes tab if it's supported.
418+
const isSpecialNS = toNS(namespace).isSpecial;
419+
const isGlobalWritesSupported =
420+
connectionInfo && connectionSupports(connectionInfo, 'globalWrites');
414421
workspaces.openCollectionWorkspace(connectionId, namespace, {
415422
newTab: true,
423+
initialSubtab:
424+
!isSpecialNS && isGlobalWritesSupported ? 'GlobalWrites' : undefined,
416425
});
417426
dispatch(reset());
418427
} catch (e) {

0 commit comments

Comments
 (0)