Skip to content

Commit

Permalink
fix(databases-collections): fixes the visible "Create collection" but…
Browse files Browse the repository at this point in the history
…ton despite Compass being in readonly mode (#5842)
  • Loading branch information
himanshusinghs authored May 27, 2024
1 parent 82808f5 commit 38043f6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
4 changes: 2 additions & 2 deletions packages/compass-e2e-tests/tests/read-only.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ describe('readOnly: true / Read-Only Edition', function () {
await settingsModal.waitForDisplayed({ reverse: true });

databaseCreateCollectionButton = await browser.$(
Selectors.SidebarCreateDatabaseButton
Selectors.DatabaseCreateCollectionButton
);
isDatabaseCreateCollectionButtonExisting =
await databaseCreateCollectionButton.isExisting();
Expand Down Expand Up @@ -218,7 +218,7 @@ describe('readOnly: true / Read-Only Edition', function () {
// wait for the modal to go away
await settingsModal.waitForDisplayed({ reverse: true });

addDataButton = await browser.$(Selectors.SidebarCreateDatabaseButton);
addDataButton = await browser.$(Selectors.AddDataButton);
isAddDataButtonExisting = await addDataButton.isExisting();
expect(isAddDataButtonExisting).to.be.equal(false);
} finally {
Expand Down
9 changes: 7 additions & 2 deletions packages/databases-collections/src/components/collections.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useCallback } from 'react';
import React, { useCallback, useMemo } from 'react';
import { connect } from 'react-redux';
import { CollectionsList } from '@mongodb-js/databases-collections-list';
import {
Expand All @@ -19,6 +19,7 @@ import toNS from 'mongodb-ns';
import { useOpenWorkspace } from '@mongodb-js/compass-workspaces/provider';
import { useConnectionInfo } from '@mongodb-js/compass-connections/provider';
import { getConnectionTitle } from '@mongodb-js/connection-info';
import { usePreference } from 'compass-preferences-model/provider';

const ERROR_WARNING = 'An error occurred while loading collections';

Expand All @@ -42,11 +43,15 @@ const Collections: React.FunctionComponent<CollectionsListProps> = ({
collections,
collectionsLoadingStatus,
collectionsLoadingError,
isEditable,
isEditable: isInstanceWritable,
onDeleteCollectionClick: _onDeleteCollectionClick,
onCreateCollectionClick: _onCreateCollectionClick,
onRefreshClick,
}) => {
const isCompassInWritableMode = !usePreference('readOnly');
const isEditable = useMemo(() => {
return isCompassInWritableMode && isInstanceWritable;
}, [isCompassInWritableMode, isInstanceWritable]);
const connectionInfo = useConnectionInfo();
const { id: connectionId } = connectionInfo;
const { openDatabasesWorkspace, openCollectionWorkspace } =
Expand Down

0 comments on commit 38043f6

Please sign in to comment.