Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions configs/testing-library-compass/src/index.tsx
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -109,8 +109,12 @@ export class MockDataService
implements implements
Pick< Pick<
DataService, DataService,
| 'getConnectionString'
| 'getConnectionOptions'
| 'getMongoClientConnectionOptions'
| 'addReauthenticationHandler' | 'addReauthenticationHandler'
| 'getCurrentTopologyType' | 'getCurrentTopologyType'
| 'getLastSeenTopology'
| 'getUpdatedSecrets' | 'getUpdatedSecrets'
| 'disconnect' | 'disconnect'
| 'instance' | 'instance'
Expand All @@ -126,6 +130,12 @@ export class MockDataService
getConnectionOptions() { getConnectionOptions() {
return this.connectionOptions; return this.connectionOptions;
} }
getMongoClientConnectionOptions() {
return {
url: this.connectionOptions.connectionString,
options: { productName: 'Test', productDocsLink: 'http://example.com' },
};
}
addReauthenticationHandler(): void { addReauthenticationHandler(): void {
// noop // noop
} }
Expand Down
2 changes: 0 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 3 additions & 14 deletions packages/compass-app-stores/src/stores/instance-store.ts
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -352,25 +352,14 @@ export function createInstancesStore(
} }
); );


on( on(globalAppRegistry, 'sidebar-filter-navigation-list', () => {
globalAppRegistry,
'sidebar-filter-navigation-list',
({ connectionId }: { connectionId?: string } = {}) => {
const connectedConnectionIds = Array.from( const connectedConnectionIds = Array.from(
instancesManager.listMongoDBInstances().keys() instancesManager.listMongoDBInstances().keys()
); );
// connectionId will be provided by the sidebar when in single connection for (const id of connectedConnectionIds) {
// mode. We don't derive that from the list of connected connections
// because there is a possibility for us to be fetching all collections on
// wrong connection that way
const connectionIds = connectionId
? [connectionId]
: connectedConnectionIds;
for (const id of connectionIds) {
void fetchAllCollections({ connectionId: id }); void fetchAllCollections({ connectionId: id });
} }
} });
);


on( on(
globalAppRegistry, globalAppRegistry,
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -55,21 +55,12 @@ const CollectionHeaderActions: React.FunctionComponent<
const { id: connectionId, atlasMetadata } = connectionInfo; const { id: connectionId, atlasMetadata } = connectionInfo;
const { openCollectionWorkspace, openEditViewWorkspace, openShellWorkspace } = const { openCollectionWorkspace, openEditViewWorkspace, openShellWorkspace } =
useOpenWorkspace(); useOpenWorkspace();
const { const { readOnly: preferencesReadOnly, enableShell: showOpenShellButton } =
readOnly: preferencesReadOnly, usePreferences(['readOnly', 'enableShell']);
enableShell,
enableMultipleConnectionSystem,
} = usePreferences([
'readOnly',
'enableShell',
'enableMultipleConnectionSystem',
]);
const track = useTelemetry(); const track = useTelemetry();


const { database, collection } = toNS(namespace); const { database, collection } = toNS(namespace);


const showOpenShellButton = enableShell && enableMultipleConnectionSystem;

return ( return (
<div <div
className={collectionHeaderActionsStyles} className={collectionHeaderActionsStyles}
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { SelectTable } from './select-table';
import type { ImportExportResult } from '../hooks/common'; import type { ImportExportResult } from '../hooks/common';
import { useOpenModalThroughIpc } from '../hooks/common'; import { useOpenModalThroughIpc } from '../hooks/common';
import { useImportConnections } from '../hooks/use-import-connections'; import { useImportConnections } from '../hooks/use-import-connections';
import { usePreference } from 'compass-preferences-model/provider';


const TOAST_TIMEOUT_MS = 5000; const TOAST_TIMEOUT_MS = 5000;


Expand All @@ -38,9 +37,6 @@ export function ImportConnectionsModal({
setOpen: (newOpen: boolean, trackingProps?: Record<string, unknown>) => void; setOpen: (newOpen: boolean, trackingProps?: Record<string, unknown>) => void;
trackingProps?: Record<string, unknown>; trackingProps?: Record<string, unknown>;
}): React.ReactElement { }): React.ReactElement {
const multipleConnectionsEnabled = usePreference(
'enableMultipleConnectionSystem'
);
const { openToast } = useToast('compass-connection-import-export'); const { openToast } = useToast('compass-connection-import-export');
const finish = useCallback( const finish = useCallback(
(result: ImportExportResult) => { (result: ImportExportResult) => {
Expand Down Expand Up @@ -100,16 +96,15 @@ export function ImportConnectionsModal({
variant={conn.selected ? 'yellow' : 'lightgray'} variant={conn.selected ? 'yellow' : 'lightgray'}
data-testid={`existing-favorite-badge-${conn.id}`} data-testid={`existing-favorite-badge-${conn.id}`}
> >
Existing{' '} Existing Connection
{multipleConnectionsEnabled ? 'Connection' : 'Favorite'}
</Badge> </Badge>
)} )}
</> </>
), ),
})), })),
connectionList.some((conn) => conn.isExistingConnection && conn.selected), connectionList.some((conn) => conn.isExistingConnection && conn.selected),
]; ];
}, [connectionList, multipleConnectionsEnabled]); }, [connectionList]);


return ( return (
<FormModal <FormModal
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -243,12 +243,10 @@ describe('useExportConnections', function () {
expect(result.current.state.error).to.equal(''); expect(result.current.state.error).to.equal('');
}); });


context('when multiple connections is enabled', function () {
it('includes also the non-favorites connections in the export list', function () { it('includes also the non-favorites connections in the export list', function () {
const { result } = renderUseExportConnectionsHook( const { result } = renderUseExportConnectionsHook(
{}, {},
{ {
preferences: { enableMultipleConnectionSystem: true },
connections: [ connections: [
{ {
id: 'id1', id: 'id1',
Expand All @@ -270,4 +268,3 @@ describe('useExportConnections', function () {
]); ]);
}); });
}); });
});
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -304,7 +304,6 @@ describe('useImportConnections', function () {
const { result, connectionStorage } = renderUseImportConnectionsHook( const { result, connectionStorage } = renderUseImportConnectionsHook(
{}, {},
{ {
preferences: { enableMultipleConnectionSystem: true },
connections: [ connections: [
{ {
id: 'id1', id: 'id1',
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ describe('ConnectionsNavigationTree', function () {
preferences = await createSandboxFromDefaultPreferences(); preferences = await createSandboxFromDefaultPreferences();
await preferences.savePreferences({ await preferences.savePreferences({
enableRenameCollectionModal: true, enableRenameCollectionModal: true,
enableMultipleConnectionSystem: true,
...preferencesOverrides, ...preferencesOverrides,
}); });
return render( return render(
Expand Down Expand Up @@ -661,7 +660,6 @@ describe('ConnectionsNavigationTree', function () {
preferences = await createSandboxFromDefaultPreferences(); preferences = await createSandboxFromDefaultPreferences();
await preferences.savePreferences({ await preferences.savePreferences({
enableRenameCollectionModal: true, enableRenameCollectionModal: true,
enableMultipleConnectionSystem: true,
}); });
}); });


Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -28,18 +28,11 @@ import {
notConnectedConnectionItemActions, notConnectedConnectionItemActions,
} from './item-actions'; } from './item-actions';


const MCContainer = css({ const ConnectionsNavigationContainerStyles = css({
display: 'flex', display: 'flex',
flex: '1 0 auto', flex: '1 0 auto',
height: `calc(100% - ${spacing[1600]}px - ${spacing[200]}px)`, height: `calc(100% - ${spacing[1600]}px - ${spacing[200]}px)`,
}); });

const SCContainer = css({
display: 'flex',
flex: '1 0 auto',
height: 0,
});

export interface ConnectionsNavigationTreeProps { export interface ConnectionsNavigationTreeProps {
connections: Connection[]; connections: Connection[];
activeWorkspace: WorkspaceTab | null; activeWorkspace: WorkspaceTab | null;
Expand All @@ -59,7 +52,6 @@ const ConnectionsNavigationTree: React.FunctionComponent<
}) => { }) => {
const preferencesShellEnabled = usePreference('enableShell'); const preferencesShellEnabled = usePreference('enableShell');
const preferencesReadOnly = usePreference('readOnly'); const preferencesReadOnly = usePreference('readOnly');
const isSingleConnection = !usePreference('enableMultipleConnectionSystem');
const isRenameCollectionEnabled = usePreference( const isRenameCollectionEnabled = usePreference(
'enableRenameCollectionModal' 'enableRenameCollectionModal'
); );
Expand All @@ -69,18 +61,11 @@ const ConnectionsNavigationTree: React.FunctionComponent<
const treeData = useMemo(() => { const treeData = useMemo(() => {
return getVirtualTreeItems({ return getVirtualTreeItems({
connections, connections,
isSingleConnection,
expandedItems: expanded, expandedItems: expanded,
preferencesReadOnly, preferencesReadOnly,
preferencesShellEnabled, preferencesShellEnabled,
}); });
}, [ }, [connections, expanded, preferencesReadOnly, preferencesShellEnabled]);
connections,
isSingleConnection,
expanded,
preferencesReadOnly,
preferencesShellEnabled,
]);


const onDefaultAction: OnDefaultAction<SidebarActionableItem> = useCallback( const onDefaultAction: OnDefaultAction<SidebarActionableItem> = useCallback(
(item, evt) => { (item, evt) => {
Expand Down Expand Up @@ -111,11 +96,11 @@ const ConnectionsNavigationTree: React.FunctionComponent<
return `${activeWorkspace.connectionId}.${activeWorkspace.namespace}`; return `${activeWorkspace.connectionId}.${activeWorkspace.namespace}`;
} }
// Database List (of a connection) // Database List (of a connection)
if (activeWorkspace.type === 'Databases' && !isSingleConnection) { if (activeWorkspace.type === 'Databases') {
return activeWorkspace.connectionId; return activeWorkspace.connectionId;
} }
} }
}, [activeWorkspace, isSingleConnection]); }, [activeWorkspace]);


const getCollapseAfterForConnectedItem = useCallback( const getCollapseAfterForConnectedItem = useCallback(
(actions: NavigationItemActions) => { (actions: NavigationItemActions) => {
Expand Down Expand Up @@ -213,7 +198,7 @@ const ConnectionsNavigationTree: React.FunctionComponent<
const isTestEnv = process.env.NODE_ENV === 'test'; const isTestEnv = process.env.NODE_ENV === 'test';


return ( return (
<div className={isSingleConnection ? SCContainer : MCContainer}> <div className={ConnectionsNavigationContainerStyles}>
<VisuallyHidden id={id}>Databases and Collections</VisuallyHidden> <VisuallyHidden id={id}>Databases and Collections</VisuallyHidden>
{/* AutoSizer types does not allow both width and height to be disabled {/* AutoSizer types does not allow both width and height to be disabled
considering that to be a pointless usecase and hence the type considering that to be a pointless usecase and hence the type
Expand Down
8 changes: 3 additions & 5 deletions packages/compass-connections-navigation/src/placeholder.tsx
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import type { CSSProperties } from 'react';
import { Placeholder, css } from '@mongodb-js/compass-components'; import { Placeholder, css } from '@mongodb-js/compass-components';
import { ROW_HEIGHT } from './constants'; import { ROW_HEIGHT } from './constants';
import { getTreeItemStyles } from './utils'; import { getTreeItemStyles } from './utils';
import { usePreference } from 'compass-preferences-model/provider';


const placeholderItem = css({ const placeholderItem = css({
display: 'flex', display: 'flex',
Expand All @@ -13,25 +12,24 @@ const placeholderItem = css({
color: 'var(--item-color)', color: 'var(--item-color)',
}); });


const MULTIPLE_CONNECTION_PROPS = { const PLACEHOLDER_PROPS = {
gradientStart: 'var(--item-bg-color-active)', gradientStart: 'var(--item-bg-color-active)',
gradientEnd: 'var(--item-bg-color)', gradientEnd: 'var(--item-bg-color)',
style: { filter: 'brightness(0.98)' }, style: { filter: 'brightness(0.98)' },
} as const; };


export const PlaceholderItem: React.FunctionComponent<{ export const PlaceholderItem: React.FunctionComponent<{
level: number; level: number;
style?: CSSProperties; style?: CSSProperties;
}> = ({ level, style }) => { }> = ({ level, style }) => {
const isSingleConnection = !usePreference('enableMultipleConnectionSystem');
const itemPaddingStyles = useMemo( const itemPaddingStyles = useMemo(
() => getTreeItemStyles({ level, isExpandable: false }), () => getTreeItemStyles({ level, isExpandable: false }),
[level] [level]
); );


return ( return (
<div className={placeholderItem} style={{ ...style, ...itemPaddingStyles }}> <div className={placeholderItem} style={{ ...style, ...itemPaddingStyles }}>
<Placeholder {...(isSingleConnection ? {} : MULTIPLE_CONNECTION_PROPS)} /> <Placeholder {...PLACEHOLDER_PROPS} />
</div> </div>
); );
}; };
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
useConnectionColor, useConnectionColor,
DefaultColorCode, DefaultColorCode,
} from '@mongodb-js/connection-form'; } from '@mongodb-js/connection-form';
import { usePreference } from 'compass-preferences-model/provider';
import { palette, useDarkMode } from '@mongodb-js/compass-components'; import { palette, useDarkMode } from '@mongodb-js/compass-components';
import type { SidebarTreeItem } from './tree-data'; import type { SidebarTreeItem } from './tree-data';
import { ConnectionStatus } from '@mongodb-js/compass-connections/provider'; import { ConnectionStatus } from '@mongodb-js/compass-connections/provider';
Expand All @@ -25,7 +24,6 @@ export default function StyledNavigationItem({
const isDarkMode = useDarkMode(); const isDarkMode = useDarkMode();
const { connectionColorToHex, connectionColorToHexActive } = const { connectionColorToHex, connectionColorToHexActive } =
useConnectionColor(); useConnectionColor();
const isSingleConnection = !usePreference('enableMultipleConnectionSystem');
const { colorCode } = item; const { colorCode } = item;
const isDisconnectedConnection = const isDisconnectedConnection =
item.type === 'connection' && item.type === 'connection' &&
Expand All @@ -34,7 +32,6 @@ export default function StyledNavigationItem({
const style: React.CSSProperties & AcceptedStyles = useMemo(() => { const style: React.CSSProperties & AcceptedStyles = useMemo(() => {
const style: AcceptedStyles = {}; const style: AcceptedStyles = {};


if (!isSingleConnection) {
if (colorCode && colorCode !== DefaultColorCode) { if (colorCode && colorCode !== DefaultColorCode) {
style['--item-bg-color'] = connectionColorToHex(colorCode); style['--item-bg-color'] = connectionColorToHex(colorCode);
style['--item-bg-color-hover'] = connectionColorToHexActive(colorCode); style['--item-bg-color-hover'] = connectionColorToHexActive(colorCode);
Expand All @@ -46,11 +43,9 @@ export default function StyledNavigationItem({
? palette.gray.light1 ? palette.gray.light1
: palette.gray.dark1; : palette.gray.dark1;
} }
}
return style; return style;
}, [ }, [
isDarkMode, isDarkMode,
isSingleConnection,
isDisconnectedConnection, isDisconnectedConnection,
colorCode, colorCode,
connectionColorToHex, connectionColorToHex,
Expand Down
29 changes: 0 additions & 29 deletions packages/compass-connections-navigation/src/tree-data.ts
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -323,30 +323,23 @@ const databaseToItems = ({
/** /**
* Converts a list connections to virtual tree items. * Converts a list connections to virtual tree items.
* *
* When isSingleConnection is true, the connections are treated as a single connection mode
* and only two levels of items are shown: databases and collections.
*
* The IDs of the items are just to be used by the tree to correctly identify the items and * The IDs of the items are just to be used by the tree to correctly identify the items and
* do not represent the actual IDs of the items. * do not represent the actual IDs of the items.
* *
* @param connections - The connections. * @param connections - The connections.
* @param isSingleConnection - Whether the connections are a single connection.
* @param expandedItems - The expanded items. * @param expandedItems - The expanded items.
*/ */
export function getVirtualTreeItems({ export function getVirtualTreeItems({
connections, connections,
isSingleConnection,
expandedItems = {}, expandedItems = {},
preferencesReadOnly, preferencesReadOnly,
preferencesShellEnabled, preferencesShellEnabled,
}: { }: {
connections: (NotConnectedConnection | ConnectedConnection)[]; connections: (NotConnectedConnection | ConnectedConnection)[];
isSingleConnection: boolean;
expandedItems: Record<string, false | Record<string, boolean>>; expandedItems: Record<string, false | Record<string, boolean>>;
preferencesReadOnly: boolean; preferencesReadOnly: boolean;
preferencesShellEnabled: boolean; preferencesShellEnabled: boolean;
}): SidebarTreeItem[] { }): SidebarTreeItem[] {
if (!isSingleConnection) {
return connections.flatMap((connection, connectionIndex) => { return connections.flatMap((connection, connectionIndex) => {
if (connection.connectionStatus === ConnectionStatus.Connected) { if (connection.connectionStatus === ConnectionStatus.Connected) {
return connectedConnectionToItems({ return connectedConnectionToItems({
Expand All @@ -366,25 +359,3 @@ export function getVirtualTreeItems({
} }
}); });
} }

const connection = connections[0];
// In single connection mode we expect the only connection to be connected
if (connection.connectionStatus !== ConnectionStatus.Connected) {
return [];
}

const dbExpandedItems = expandedItems[connection.connectionInfo.id] || {};
const hasWriteActionsDisabled =
preferencesReadOnly || connection.isDataLake || !connection.isWritable;
return connection.databases.flatMap((database, databaseIndex) => {
return databaseToItems({
connectionId: connection.connectionInfo.id,
database,
expandedItems: dbExpandedItems,
level: 1,
databasesLength: connection.databasesLength,
databaseIndex,
hasWriteActionsDisabled,
});
});
}
Loading
Loading