Skip to content

Commit 47983a3

Browse files
authored
chore(compass-web, crud, aggregations): make sure that all features are correctly toggled based on preference values (#5266)
* chore(compass-web, crud, aggregations): make sure that all features are correctly toggled based on preference values * chore: update lock after merge from main
1 parent eec9fb1 commit 47983a3

File tree

11 files changed

+187
-95
lines changed

11 files changed

+187
-95
lines changed

package-lock.json

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/compass-aggregations/src/components/pipeline-toolbar/pipeline-header/index.tsx

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import PipelineStages from './pipeline-stages';
1414
import PipelineActions from './pipeline-actions';
1515
import SavedPipelines from '../../saved-pipelines/saved-pipelines';
1616
import type { RootState } from '../../../modules';
17+
import { usePreference } from 'compass-preferences-model';
1718

1819
const containerStyles = css({
1920
display: 'flex',
@@ -116,18 +117,21 @@ export const PipelineHeader: React.FunctionComponent<PipelineHeaderProps> = ({
116117
isOptionsVisible,
117118
isOpenPipelineVisible,
118119
}) => {
120+
const isSavingAggregationsEnabled = usePreference(
121+
'enableSavedAggregationsQueries'
122+
);
119123
return (
120124
<div>
121125
<div className={containerStyles} data-testid="pipeline-header">
122-
{isOpenPipelineVisible && (
123-
<div
124-
data-testid="saved-pipelines-popover"
125-
className={pipelineTextAndOpenStyles}
126-
>
127-
<Body weight="medium">Pipeline</Body>
126+
<div
127+
data-testid="saved-pipelines-popover"
128+
className={pipelineTextAndOpenStyles}
129+
>
130+
<Body weight="medium">Pipeline</Body>
131+
{isOpenPipelineVisible && isSavingAggregationsEnabled && (
128132
<SavedPipelinesButton></SavedPipelinesButton>
129-
</div>
130-
)}
133+
)}
134+
</div>
131135
<div className={pipelineStagesStyles}>
132136
<PipelineStages />
133137
</div>

packages/compass-aggregations/src/components/pipeline-toolbar/pipeline-settings/index.tsx

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,16 @@ export const PipelineSettings: React.FunctionComponent<
5050
const enableSavedAggregationsQueries = usePreference(
5151
'enableSavedAggregationsQueries'
5252
);
53-
const isSavePipelineDisplayed =
54-
!editViewName && enableSavedAggregationsQueries;
53+
const isPipelineNameDisplayed =
54+
!editViewName && !!enableSavedAggregationsQueries;
55+
5556
const isCreatePipelineDisplayed = !editViewName;
5657

5758
return (
5859
<div className={containerStyles} data-testid="pipeline-settings">
5960
<div className={settingsStyles}>
60-
{isSavePipelineDisplayed && (
61-
<>
62-
<PipelineName />
63-
<SaveMenu />
64-
</>
65-
)}
61+
{isPipelineNameDisplayed && <PipelineName />}
62+
<SaveMenu isSaveEnabled={!!enableSavedAggregationsQueries}></SaveMenu>
6663
{isCreatePipelineDisplayed && (
6764
<Button
6865
size="xsmall"

packages/compass-aggregations/src/components/pipeline-toolbar/pipeline-settings/pipeline-menus.spec.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ describe('PipelineMenus', function () {
1919
onCreateViewSpy = spy();
2020
render(
2121
<SaveMenuComponent
22-
isCreateViewAvailable={true}
22+
isSaveEnabled={true}
23+
isCreateViewEnabled={true}
2324
pipelineName={'Name'}
2425
onSave={onSaveSpy}
2526
onSaveAs={onSaveAsSpy}
@@ -65,7 +66,8 @@ describe('PipelineMenus', function () {
6566
it('does not render createView menu option', function () {
6667
render(
6768
<SaveMenuComponent
68-
isCreateViewAvailable={false}
69+
isSaveEnabled={true}
70+
isCreateViewEnabled={false}
6971
pipelineName={'Name'}
7072
onSave={spy()}
7173
onSaveAs={spy()}

packages/compass-aggregations/src/components/pipeline-toolbar/pipeline-settings/pipeline-menus.tsx

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,22 @@ import {
1111
} from '../../../modules/saving-pipeline';
1212

1313
type SaveMenuActions = 'save' | 'saveAs' | 'createView';
14+
1415
type SaveMenuProps = {
1516
disabled?: boolean;
1617
pipelineName: string;
17-
isCreateViewAvailable: boolean;
18+
isSaveEnabled: boolean;
19+
isCreateViewEnabled: boolean;
1820
onSave: (name: string) => void;
1921
onSaveAs: (name: string) => void;
2022
onCreateView: () => void;
2123
};
22-
const saveMenuActions: MenuAction<SaveMenuActions>[] = [
23-
{ action: 'save', label: 'Save' },
24-
{ action: 'saveAs', label: 'Save as' },
25-
];
24+
2625
export const SaveMenuComponent: React.FunctionComponent<SaveMenuProps> = ({
2726
disabled,
2827
pipelineName,
29-
isCreateViewAvailable,
28+
isSaveEnabled,
29+
isCreateViewEnabled,
3030
onSave,
3131
onSaveAs,
3232
onCreateView,
@@ -41,24 +41,31 @@ export const SaveMenuComponent: React.FunctionComponent<SaveMenuProps> = ({
4141
return onCreateView();
4242
}
4343
};
44-
const actions = useMemo(
45-
() =>
46-
saveMenuActions.concat(
47-
isCreateViewAvailable
48-
? [
49-
{
50-
action: 'createView',
51-
label: 'Create view',
52-
},
53-
]
54-
: []
55-
),
56-
[isCreateViewAvailable]
57-
);
44+
const menuActions = useMemo(() => {
45+
const actions: MenuAction<SaveMenuActions>[] = [];
46+
if (isSaveEnabled) {
47+
actions.push(
48+
{ action: 'save' as const, label: 'Save' },
49+
{ action: 'saveAs' as const, label: 'Save as' }
50+
);
51+
}
52+
if (isCreateViewEnabled) {
53+
actions.push({
54+
action: 'createView',
55+
label: 'Create view',
56+
});
57+
}
58+
return actions;
59+
}, [isSaveEnabled, isCreateViewEnabled]);
60+
61+
if (menuActions.length === 0) {
62+
return null;
63+
}
64+
5865
return (
5966
<DropdownMenuButton<SaveMenuActions>
6067
data-testid="save-menu"
61-
actions={actions}
68+
actions={menuActions}
6269
onAction={onAction}
6370
buttonText="Save"
6471
buttonProps={{
@@ -76,7 +83,7 @@ const VIEWS_MIN_SERVER_VERSION = '3.4.0';
7683
const mapSaveMenuState = (state: RootState) => {
7784
return {
7885
pipelineName: state.name,
79-
isCreateViewAvailable: semver.gte(
86+
isCreateViewEnabled: semver.gte(
8087
state.serverVersion,
8188
VIEWS_MIN_SERVER_VERSION
8289
),
@@ -92,7 +99,7 @@ const mapSaveMenuDispatch = {
9299
? savingPipelineOpen()
93100
: savingPipelineOpen({ name, isSaveAs: true });
94101
},
95-
onCreateView: () => openCreateView(),
102+
onCreateView: openCreateView,
96103
};
97104
export const SaveMenu = connect(
98105
mapSaveMenuState,

packages/compass-crud/src/components/add-data-menu.tsx

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import React from 'react';
1+
import React, { useMemo } from 'react';
22
import {
33
Icon,
44
Tooltip,
55
DropdownMenuButton,
66
css,
77
} from '@mongodb-js/compass-components';
88
import type { MenuAction } from '@mongodb-js/compass-components';
9+
import { usePreference } from 'compass-preferences-model';
910

1011
const tooltipContainerStyles = css({
1112
display: 'flex',
@@ -25,6 +26,23 @@ function AddDataMenuButton({
2526
insertDataHandler: (openInsertKey: AddDataOption) => void;
2627
isDisabled?: boolean;
2728
}) {
29+
const isImportExportEnabled = usePreference('enableImportExport');
30+
31+
const addDataActions = useMemo(() => {
32+
const actions: MenuAction<AddDataOption>[] = [
33+
{ action: 'insert-document' as const, label: 'Insert document' },
34+
];
35+
36+
if (isImportExportEnabled) {
37+
actions.unshift({
38+
action: 'import-file' as const,
39+
label: 'Import JSON or CSV file',
40+
});
41+
}
42+
43+
return actions;
44+
}, [isImportExportEnabled]);
45+
2846
return (
2947
<DropdownMenuButton<AddDataOption>
3048
data-testid="crud-add-data"
@@ -42,10 +60,6 @@ function AddDataMenuButton({
4260
}
4361

4462
type AddDataOption = 'import-file' | 'insert-document';
45-
const addDataActions: MenuAction<AddDataOption>[] = [
46-
{ action: 'import-file', label: 'Import JSON or CSV file' },
47-
{ action: 'insert-document', label: 'Insert document' },
48-
];
4963

5064
const AddDataMenu: React.FunctionComponent<AddDataMenuProps> = ({
5165
instanceDescription,

packages/compass-crud/src/components/crud-toolbar.tsx

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ const CrudToolbar: React.FunctionComponent<CrudToolbarProps> = ({
142142
queryLimit,
143143
querySkip,
144144
}) => {
145+
const isImportExportEnabled = usePreference('enableImportExport');
146+
145147
const displayedDocumentCount = useMemo(
146148
() => (loadingCount ? '' : `${count ?? 'N/A'}`),
147149
[loadingCount, count]
@@ -187,19 +189,21 @@ const CrudToolbar: React.FunctionComponent<CrudToolbarProps> = ({
187189
instanceDescription={instanceDescription}
188190
/>
189191
)}
190-
<DropdownMenuButton<ExportDataOption>
191-
data-testid="crud-export-collection"
192-
actions={exportDataActions}
193-
onAction={(action: ExportDataOption) =>
194-
openExportFileDialog(action === 'export-full-collection')
195-
}
196-
buttonText="Export Data"
197-
buttonProps={{
198-
className: exportCollectionButtonStyles,
199-
size: 'xsmall',
200-
leftGlyph: <Icon glyph="Export" />,
201-
}}
202-
/>
192+
{isImportExportEnabled && (
193+
<DropdownMenuButton<ExportDataOption>
194+
data-testid="crud-export-collection"
195+
actions={exportDataActions}
196+
onAction={(action: ExportDataOption) =>
197+
openExportFileDialog(action === 'export-full-collection')
198+
}
199+
buttonText="Export Data"
200+
buttonProps={{
201+
className: exportCollectionButtonStyles,
202+
size: 'xsmall',
203+
leftGlyph: <Icon glyph="Export" />,
204+
}}
205+
/>
206+
)}
203207
{!readonly && (
204208
<UpdateMenu
205209
isWritable={isWritable && !shouldDisableBulkOp}

packages/compass-web/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
"@types/sinon-chai": "^3.2.5",
9090
"buffer": "^6.0.3",
9191
"chai": "^4.3.6",
92+
"compass-preferences-model": "^2.16.1",
9293
"depcheck": "^1.4.1",
9394
"dns-query": "^0.11.2",
9495
"eslint": "^7.25.0",

packages/compass-web/sandbox/index.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
rel="stylesheet"
1010
/>
1111
<style>
12+
body {
13+
margin: 0;
14+
}
1215
#sandbox-app {
1316
width: 100vw;
1417
height: 100vh;

0 commit comments

Comments
 (0)