Skip to content

Commit 823f55a

Browse files
authored
chore: hide the disclaimer if networkTraffic is false COMPASS-6150 (#3548)
* hide the disclaimer if networkTraffic is false * set the defaults regardless if networkTraffic true/false * reformat
1 parent 9cd9989 commit 823f55a

File tree

7 files changed

+72
-37
lines changed

7 files changed

+72
-37
lines changed

packages/compass-home/src/components/home.spec.tsx

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,11 @@ describe('Home [Component]', function () {
6262
beforeEach(function () {
6363
render(
6464
<AppRegistryContext.Provider value={testAppRegistry}>
65-
<Home appName="home-testing" showWelcomeModal={false} />
65+
<Home
66+
appName="home-testing"
67+
showWelcomeModal={false}
68+
networkTraffic={true}
69+
/>
6670
</AppRegistryContext.Provider>
6771
);
6872
});
@@ -83,7 +87,11 @@ describe('Home [Component]', function () {
8387
) {
8488
render(
8589
<AppRegistryContext.Provider value={testAppRegistry}>
86-
<Home appName="home-testing" showWelcomeModal={false} />
90+
<Home
91+
appName="home-testing"
92+
showWelcomeModal={false}
93+
networkTraffic={true}
94+
/>
8795
</AppRegistryContext.Provider>
8896
);
8997
testAppRegistry.emit('data-service-connected', null, dataService, {
@@ -157,7 +165,11 @@ describe('Home [Component]', function () {
157165
beforeEach(function () {
158166
render(
159167
<AppRegistryContext.Provider value={testAppRegistry}>
160-
<Home appName="home-testing" showWelcomeModal={false} />
168+
<Home
169+
appName="home-testing"
170+
showWelcomeModal={false}
171+
networkTraffic={true}
172+
/>
161173
</AppRegistryContext.Provider>
162174
);
163175
});
@@ -185,7 +197,11 @@ describe('Home [Component]', function () {
185197
beforeEach(function () {
186198
const { unmount } = render(
187199
<AppRegistryContext.Provider value={testAppRegistry}>
188-
<Home appName="home-testing" showWelcomeModal={false} />
200+
<Home
201+
appName="home-testing"
202+
showWelcomeModal={false}
203+
networkTraffic={true}
204+
/>
189205
</AppRegistryContext.Provider>
190206
);
191207
unmount();

packages/compass-home/src/components/home.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -280,18 +280,19 @@ function Home({ appName }: { appName: string }): React.ReactElement | null {
280280
}
281281

282282
function ThemedHome(
283-
props: React.ComponentProps<typeof Home> & { showWelcomeModal: boolean }
283+
props: React.ComponentProps<typeof Home> & {
284+
showWelcomeModal: boolean;
285+
networkTraffic: boolean;
286+
}
284287
): ReturnType<typeof Home> {
285-
const { showWelcomeModal } = props;
288+
const { showWelcomeModal, networkTraffic } = props;
286289
const appRegistry = useAppRegistryContext();
287290

288291
const [theme, setTheme] = useState<ThemeState>({
289292
theme:
290293
process.env.COMPASS_LG_DARKMODE === 'true'
291294
? (global as any).hadronApp?.theme ?? Theme.Light
292295
: Theme.Light,
293-
// useful for quickly testing the new dark sidebar without rebuilding
294-
//theme: Theme.Dark, enabled: true
295296
});
296297

297298
function onDarkModeEnabled() {
@@ -368,7 +369,11 @@ function ThemedHome(
368369
<LeafyGreenProvider>
369370
<ThemeProvider theme={theme}>
370371
{showWelcomeModal && (
371-
<Welcome isOpen={isWelcomeOpen} closeModal={closeWelcomeModal} />
372+
<Welcome
373+
isOpen={isWelcomeOpen}
374+
closeModal={closeWelcomeModal}
375+
networkTraffic={networkTraffic}
376+
/>
372377
)}
373378
<Settings isOpen={isSettingsOpen} closeModal={closeSettingsModal} />
374379
<ToastArea>

packages/compass-home/src/plugin.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,20 @@ function Plugin({
99
appName,
1010
appRegistry,
1111
showWelcomeModal,
12+
networkTraffic,
1213
}: {
1314
appName: string;
1415
appRegistry: AppRegistry;
1516
showWelcomeModal: boolean;
17+
networkTraffic: boolean;
1618
}): React.ReactElement {
1719
return (
1820
<AppRegistryContext.Provider value={appRegistry}>
19-
<Home appName={appName} showWelcomeModal={showWelcomeModal} />
21+
<Home
22+
appName={appName}
23+
showWelcomeModal={showWelcomeModal}
24+
networkTraffic={networkTraffic}
25+
/>
2026
</AppRegistryContext.Provider>
2127
);
2228
}

packages/compass-preferences-model/src/preferences.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -633,9 +633,8 @@ export class Preferences {
633633
*/
634634
async ensureDefaultConfigurableUserPreferences(): Promise<void> {
635635
// Set the defaults and also update showedNetworkOptIn flag.
636-
const { showedNetworkOptIn, networkTraffic } =
637-
await this.fetchPreferences();
638-
if (!showedNetworkOptIn && networkTraffic) {
636+
const { showedNetworkOptIn } = await this.fetchPreferences();
637+
if (!showedNetworkOptIn) {
639638
await this.savePreferences({
640639
autoUpdates: true,
641640
enableMaps: true,

packages/compass-welcome/src/components/modal.spec.tsx

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@ describe('WelcomeModal', function () {
2121
props: Partial<ComponentProps<typeof WelcomeModal>> = {}
2222
) => {
2323
render(
24-
<WelcomeModal isOpen={false} closeModal={closeModalSpy} {...props} />
24+
<WelcomeModal
25+
networkTraffic={true}
26+
isOpen={false}
27+
closeModal={closeModalSpy}
28+
{...props}
29+
/>
2530
);
2631
};
2732
});
@@ -30,13 +35,13 @@ describe('WelcomeModal', function () {
3035
renderWelcomeModal({ isOpen: true });
3136

3237
const container = screen.queryByTestId('welcome-modal');
33-
expect(container).to.exist;
38+
expect(container).to.be.visible;
3439
});
3540

3641
it('closes when clicking the Start button', function () {
3742
renderWelcomeModal({ isOpen: true });
3843
const startButton = screen.getByText('Start').closest('button');
39-
expect(startButton).to.exist;
44+
expect(startButton).to.be.visible;
4045
userEvent.click(startButton as Element);
4146
expect(closeModalSpy.calledOnceWith()).to.be.true;
4247
});
@@ -54,4 +59,10 @@ describe('WelcomeModal', function () {
5459
userEvent.click(settingsLink);
5560
expect(closeModalSpy.calledOnceWith(true)).to.be.true;
5661
});
62+
63+
it('has no settings link when networkTraffic is false', function () {
64+
renderWelcomeModal({ isOpen: true, networkTraffic: false });
65+
const settingsLink = screen.queryByText('Settings');
66+
expect(settingsLink).to.not.exist;
67+
});
5768
});

packages/compass-welcome/src/components/modal.tsx

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@ const link = css({
2020
});
2121

2222
type WelcomeModalProps = {
23+
networkTraffic: boolean;
2324
isOpen: boolean;
2425
closeModal: (openSettings?: boolean) => void;
2526
};
2627

2728
const WelcomeModal: React.FunctionComponent<WelcomeModalProps> = ({
29+
networkTraffic,
2830
isOpen,
2931
closeModal,
3032
}) => {
@@ -53,16 +55,18 @@ const WelcomeModal: React.FunctionComponent<WelcomeModalProps> = ({
5355
Build aggregation pipelines, optimize queries, analyze schemas,
5456
and&nbsp;more. All with the GUI built by - and for - MongoDB.
5557
</Body>
56-
<Disclaimer className={disclaimer}>
57-
To help improve our products, anonymous usage data is collected and sent
58-
to MongoDB in accordance with MongoDB&apos;s privacy policy.
59-
<br />
60-
Manage this behaviour on the Compass{' '}
61-
<Link hideExternalIcon className={link} onClick={goToSettings}>
62-
Settings
63-
</Link>{' '}
64-
page.
65-
</Disclaimer>
58+
{networkTraffic && (
59+
<Disclaimer className={disclaimer}>
60+
To help improve our products, anonymous usage data is collected and
61+
sent to MongoDB in accordance with MongoDB&apos;s privacy policy.
62+
<br />
63+
Manage this behaviour on the Compass{' '}
64+
<Link hideExternalIcon className={link} onClick={goToSettings}>
65+
Settings
66+
</Link>{' '}
67+
page.
68+
</Disclaimer>
69+
)}
6670
</MarketingModal>
6771
);
6872
};

packages/compass/src/app/index.js

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,6 @@ const { log, mongoLogId, debug, track } =
7171
'COMPASS-APP'
7272
);
7373

74-
function shouldShowWelcomeModal(showedNetworkOptIn, networkTraffic) {
75-
if (!showedNetworkOptIn && networkTraffic) {
76-
return true;
77-
}
78-
79-
return false;
80-
}
81-
8274
/**
8375
* The top-level application singleton that brings everything together!
8476
*/
@@ -170,7 +162,7 @@ const Application = View.extend({
170162
* start showing status indicators as
171163
* quickly as possible.
172164
*/
173-
render: function ({ showWelcomeModal }) {
165+
render: function ({ showWelcomeModal, networkTraffic }) {
174166
log.info(
175167
mongoLogId(1_001_000_092),
176168
'Main Window',
@@ -193,7 +185,8 @@ const Application = View.extend({
193185
React.createElement(this.homeComponent, {
194186
appRegistry: app.appRegistry,
195187
appName: remote.app.getName(),
196-
showWelcomeModal
188+
showWelcomeModal,
189+
networkTraffic
197190
}),
198191
this.queryByHook('layout-container')
199192
);
@@ -299,7 +292,8 @@ app.extend({
299292
);
300293
// as soon as dom is ready, render and set up the rest
301294
state.render({
302-
showWelcomeModal: shouldShowWelcomeModal(showedNetworkOptIn, networkTraffic)
295+
showWelcomeModal: !showedNetworkOptIn,
296+
networkTraffic
303297
});
304298
marky.stop('Time to Connect rendered');
305299
state.postRender();

0 commit comments

Comments
 (0)