diff --git a/packages/compass-aggregations/src/components/pipeline-toolbar/pipeline-header/pipeline-actions.tsx b/packages/compass-aggregations/src/components/pipeline-toolbar/pipeline-header/pipeline-actions.tsx index 3126b22df41..556b20daa6b 100644 --- a/packages/compass-aggregations/src/components/pipeline-toolbar/pipeline-header/pipeline-actions.tsx +++ b/packages/compass-aggregations/src/components/pipeline-toolbar/pipeline-header/pipeline-actions.tsx @@ -23,8 +23,8 @@ import { import { isOutputStage } from '../../../utils/stage'; import { openCreateIndexModal } from '../../../modules/insights'; import { - usePreference, useIsAIFeatureEnabled, + usePreferences, } from 'compass-preferences-model/provider'; import { showInput as showAIInput } from '../../../modules/pipeline-builder/pipeline-ai'; import { useAssistantActions } from '@mongodb-js/compass-assistant'; @@ -85,10 +85,15 @@ export const PipelineActions: React.FunctionComponent = ({ onCollectionScanInsightActionButtonClick, stages, }) => { - const enableAggregationBuilderExtraOptions = usePreference( - 'enableAggregationBuilderExtraOptions' - ); - const showInsights = usePreference('showInsights'); + const { + readWrite: preferencesReadWrite, + enableAggregationBuilderExtraOptions, + showInsights, + } = usePreferences([ + 'readWrite', + 'enableAggregationBuilderExtraOptions', + 'showInsights', + ]); const isAIFeatureEnabled = useIsAIFeatureEnabled(); const { tellMoreAboutInsight } = useAssistantActions(); @@ -102,8 +107,15 @@ export const PipelineActions: React.FunctionComponent = ({ { diff --git a/packages/compass-collection/src/components/collection-header-actions/collection-header-actions.spec.tsx b/packages/compass-collection/src/components/collection-header-actions/collection-header-actions.spec.tsx index 05ddc16c916..1c55645717c 100644 --- a/packages/compass-collection/src/components/collection-header-actions/collection-header-actions.spec.tsx +++ b/packages/compass-collection/src/components/collection-header-actions/collection-header-actions.spec.tsx @@ -3,16 +3,12 @@ import React, { type ComponentProps } from 'react'; import { renderWithActiveConnection, screen, - cleanup, } from '@mongodb-js/testing-library-compass'; import sinon from 'sinon'; import { WorkspacesServiceProvider, type WorkspacesService, } from '@mongodb-js/compass-workspaces/provider'; -import type { PreferencesAccess } from 'compass-preferences-model'; -import { createSandboxFromDefaultPreferences } from 'compass-preferences-model'; -import { PreferencesProvider } from 'compass-preferences-model/provider'; import { ExperimentTestName } from '@mongodb-js/compass-telemetry/provider'; import { CompassExperimentationProvider } from '@mongodb-js/compass-telemetry'; import type { ConnectionInfo } from '@mongodb-js/compass-connections/provider'; @@ -20,11 +16,9 @@ import type { ConnectionInfo } from '@mongodb-js/compass-connections/provider'; import CollectionHeaderActions from '../collection-header-actions'; describe('CollectionHeaderActions [Component]', function () { - let preferences: PreferencesAccess; let mockUseAssignment: sinon.SinonStub; - beforeEach(async function () { - preferences = await createSandboxFromDefaultPreferences(); + beforeEach(function () { mockUseAssignment = sinon.stub(); mockUseAssignment.returns({ assignment: { @@ -42,7 +36,8 @@ describe('CollectionHeaderActions [Component]', function () { const renderCollectionHeaderActions = ( props: Partial> = {}, workspaceService: Partial = {}, - connectionInfo?: ConnectionInfo + connectionInfo?: ConnectionInfo, + preferences?: Record ) => { return renderWithActiveConnection( - - - + , - connectionInfo + connectionInfo, + { preferences } ); }; @@ -80,8 +74,6 @@ describe('CollectionHeaderActions [Component]', function () { }); }); - afterEach(cleanup); - it('does not render any buttons', function () { expect( screen.queryByTestId('collection-header-actions-edit-button') @@ -93,15 +85,18 @@ describe('CollectionHeaderActions [Component]', function () { }); context('Compass readonly mode', function () { - it('does not render edit view buttons when in readonly mode', async function () { - await preferences.savePreferences({ readOnly: true }); - - await renderCollectionHeaderActions({ - isReadonly: true, - namespace: 'db.coll2', - sourceName: 'db.someSource', - sourcePipeline: [{ $match: { a: 1 } }], - }); + it('does not render edit view buttons when in ReadWrite mode', async function () { + await renderCollectionHeaderActions( + { + isReadonly: true, + namespace: 'db.coll2', + sourceName: 'db.someSource', + sourcePipeline: [{ $match: { a: 1 } }], + }, + undefined, + undefined, + { readWrite: true } + ); expect( screen.queryByTestId('collection-header-actions-edit-button') @@ -142,8 +137,6 @@ describe('CollectionHeaderActions [Component]', function () { ); }); - afterEach(cleanup); - it('shows a button to edit the view pipeline', function () { expect( screen.getByTestId('collection-header-actions-edit-button') @@ -181,9 +174,6 @@ describe('CollectionHeaderActions [Component]', function () { } ); }); - - afterEach(cleanup); - it('shows a button to return to the view', function () { expect( screen.getByTestId('collection-header-actions-return-to-view-button') diff --git a/packages/compass-collection/src/components/collection-header-actions/collection-header-actions.tsx b/packages/compass-collection/src/components/collection-header-actions/collection-header-actions.tsx index 38ac74d9d84..613ab6375e0 100644 --- a/packages/compass-collection/src/components/collection-header-actions/collection-header-actions.tsx +++ b/packages/compass-collection/src/components/collection-header-actions/collection-header-actions.tsx @@ -89,8 +89,8 @@ const CollectionHeaderActions: React.FunctionComponent< const { id: connectionId, atlasMetadata } = connectionInfo; const { openCollectionWorkspace, openEditViewWorkspace, openShellWorkspace } = useOpenWorkspace(); - const { readOnly: preferencesReadOnly, enableShell: showOpenShellButton } = - usePreferences(['readOnly', 'enableShell']); + const { readWrite: preferencesReadWrite, enableShell: showOpenShellButton } = + usePreferences(['readWrite', 'enableShell']); const track = useTelemetry(); // Get experiment assignment for Mock Data Generator @@ -119,6 +119,10 @@ const CollectionHeaderActions: React.FunctionComponent< !hasSchemaAnalysisData && schemaAnalysisStatus !== SCHEMA_ANALYSIS_STATE_ANALYZING; + const isView = isReadonly && sourceName && !editViewName; + + const showViewEdit = isView && !preferencesReadWrite; + return (
)} - {isReadonly && sourceName && !editViewName && !preferencesReadOnly && ( + {showViewEdit && (