Skip to content

Commit ce7f4e9

Browse files
committed
checkbox
1 parent b19f578 commit ce7f4e9

File tree

4 files changed

+67
-12
lines changed

4 files changed

+67
-12
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,7 @@ const Schema: React.FunctionComponent<{
376376
schema: MongodbSchema | null;
377377
count?: number;
378378
resultId?: string;
379+
dontShowLegacyBanner?: boolean;
379380
onExportSchemaClicked: () => void;
380381
onStartAnalysis: () => Promise<void>;
381382
onStopAnalysis: () => void;
@@ -384,6 +385,7 @@ const Schema: React.FunctionComponent<{
384385
errorMessage,
385386
schema,
386387
resultId,
388+
dontShowLegacyBanner,
387389
onExportSchemaClicked,
388390
onStartAnalysis,
389391
onStopAnalysis,
@@ -432,7 +434,9 @@ const Schema: React.FunctionComponent<{
432434
</WorkspaceContainer>
433435
</div>
434436
{enableExportSchema && <ExportSchemaModal />}
435-
{enableExportSchema && <ExportSchemaLegacyBanner />}
437+
{enableExportSchema && !dontShowLegacyBanner && (
438+
<ExportSchemaLegacyBanner />
439+
)}
436440
</>
437441
);
438442
};
@@ -443,6 +447,7 @@ export default connect(
443447
errorMessage: state.schemaAnalysis.errorMessage,
444448
schema: state.schemaAnalysis.schema,
445449
resultId: state.schemaAnalysis.resultId,
450+
dontShowLegacyBanner: state.schemaExport.dontShowLegacyBanner,
446451
}),
447452
{
448453
onStartAnalysis: startAnalysis,

packages/compass-schema/src/components/export-schema-legacy-banner.tsx

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import React, { useCallback, useState } from 'react';
22
import { connect } from 'react-redux';
33
import {
44
ModalBody,
@@ -8,13 +8,15 @@ import {
88
spacing,
99
Badge,
1010
Button,
11+
Checkbox,
1112
} from '@mongodb-js/compass-components';
1213

1314
import type { RootState, SchemaThunkDispatch } from '../stores/store';
1415
import {
1516
confirmedLegacySchemaShare,
1617
switchToSchemaExport,
1718
SchemaExportActions,
19+
stopShowingLegacyBanner,
1820
} from '../stores/schema-export-reducer';
1921

2022
const Image = () => (
@@ -462,7 +464,23 @@ const ExportSchemaLegacyBanner: React.FunctionComponent<{
462464
onClose: () => void;
463465
onLegacyShare: () => void;
464466
onSwitchToSchemaExport: () => void;
465-
}> = ({ isOpen, onClose, onLegacyShare, onSwitchToSchemaExport }) => {
467+
stopShowingLegacyBanner: () => void;
468+
}> = ({
469+
isOpen,
470+
onClose,
471+
onLegacyShare,
472+
onSwitchToSchemaExport,
473+
stopShowingLegacyBanner,
474+
}) => {
475+
const [dontShowAgainChecked, setDontShowAgainChecked] = useState(false);
476+
const handleLegacyShare = useCallback(() => {
477+
if (dontShowAgainChecked) stopShowingLegacyBanner();
478+
onLegacyShare();
479+
}, [onLegacyShare, dontShowAgainChecked, stopShowingLegacyBanner]);
480+
const handleSwitchToNew = useCallback(() => {
481+
if (dontShowAgainChecked) stopShowingLegacyBanner();
482+
onSwitchToSchemaExport();
483+
}, [onSwitchToSchemaExport, dontShowAgainChecked, stopShowingLegacyBanner]);
466484
return (
467485
<Modal open={isOpen} setOpen={onClose} contentClassName={containerStyles}>
468486
<ModalHeader
@@ -492,17 +510,20 @@ const ExportSchemaLegacyBanner: React.FunctionComponent<{
492510
3 standardized schema formats designed for schema validation and
493511
analysis use cases.
494512
</div>
495-
<Button variant="default" size="small" onClick={onLegacyShare}>
513+
<Button variant="default" size="small" onClick={handleLegacyShare}>
496514
Continue with legacy Share
497515
</Button>
498-
<Button
499-
variant="primary"
500-
size="small"
501-
onClick={onSwitchToSchemaExport}
502-
>
516+
<Button variant="primary" size="small" onClick={handleSwitchToNew}>
503517
Try new Export
504518
</Button>
505519
</div>
520+
<div>
521+
<Checkbox
522+
label="Do not show me this message again"
523+
checked={dontShowAgainChecked}
524+
onChange={(e) => setDontShowAgainChecked(e.currentTarget.checked)}
525+
/>
526+
</div>
506527
</ModalBody>
507528
</Modal>
508529
);
@@ -516,5 +537,6 @@ export default connect(
516537
onClose: () => dispatch({ type: SchemaExportActions.closeLegacyBanner }),
517538
onLegacyShare: () => dispatch(confirmedLegacySchemaShare()),
518539
onSwitchToSchemaExport: () => dispatch(switchToSchemaExport()),
540+
stopShowingLegacyBanner: () => dispatch(stopShowingLegacyBanner()),
519541
})
520542
)(ExportSchemaLegacyBanner);

packages/compass-schema/src/stores/schema-export-reducer.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export type SchemaExportState = {
2626
abortController?: AbortController;
2727
isOpen: boolean;
2828
isLegacyBannerOpen: boolean;
29+
dontShowLegacyBanner: boolean;
2930
exportedSchema?: string;
3031
exportFormat: SchemaFormat;
3132
errorMessage?: string;
@@ -41,13 +42,15 @@ const getInitialState = (): SchemaExportState => ({
4142
exportedSchema: undefined,
4243
isOpen: false,
4344
isLegacyBannerOpen: false,
45+
dontShowLegacyBanner: localStorage.getItem('dontShowLegacyBanner') === 'true',
4446
});
4547

4648
export const enum SchemaExportActions {
4749
openExportSchema = 'schema-service/schema-export/openExportSchema',
4850
closeExportSchema = 'schema-service/schema-export/closeExportSchema',
4951
openLegacyBanner = 'schema-service/schema-export/openLegacyBanner',
5052
closeLegacyBanner = 'schema-service/schema-export/closeLegacyBanner',
53+
dontShowLegacyBanner = 'schema-service/schema-export/dontShowLegacyBanner',
5154
changeExportSchemaStatus = 'schema-service/schema-export/changeExportSchemaStatus',
5255
changeExportSchemaFormatStarted = 'schema-service/schema-export/changeExportSchemaFormatStarted',
5356
changeExportSchemaFormatComplete = 'schema-service/schema-export/changeExportSchemaFormatComplete',
@@ -278,6 +281,7 @@ export const schemaExportReducer: Reducer<SchemaExportState, Action> = (
278281
SchemaExportActions.openLegacyBanner
279282
)
280283
) {
284+
console.log('opening the banner');
281285
return {
282286
...state,
283287
isLegacyBannerOpen: true,
@@ -296,6 +300,18 @@ export const schemaExportReducer: Reducer<SchemaExportState, Action> = (
296300
};
297301
}
298302

303+
if (
304+
isAction<dontShowLegacyBannerAction>(
305+
action,
306+
SchemaExportActions.dontShowLegacyBanner
307+
)
308+
) {
309+
return {
310+
...state,
311+
isLegacyBannerOpen: false,
312+
};
313+
}
314+
299315
if (
300316
isAction<ChangeExportSchemaFormatStartedAction>(
301317
action,
@@ -362,6 +378,10 @@ export type closeLegacyBannerAction = {
362378
type: SchemaExportActions.closeLegacyBanner;
363379
};
364380

381+
export type dontShowLegacyBannerAction = {
382+
type: SchemaExportActions.dontShowLegacyBanner;
383+
};
384+
365385
export const switchToSchemaExport = (): SchemaThunkAction<void> => {
366386
return (dispatch) => {
367387
dispatch({ type: SchemaExportActions.closeLegacyBanner });
@@ -419,3 +439,10 @@ export const _trackSchemaShared = (
419439
track('Schema Exported', trackEvent, connectionInfoRef.current);
420440
};
421441
};
442+
443+
export const stopShowingLegacyBanner = (): SchemaThunkAction<void> => {
444+
return (dispatch) => {
445+
localStorage.setItem('dontShowLegacyBanner', 'true');
446+
dispatch({ type: SchemaExportActions.dontShowLegacyBanner });
447+
};
448+
};

packages/compass-schema/src/stores/store.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,10 @@ export function activateSchemaPlugin(
7575
* When `Share Schema as JSON` clicked in menu show a dialog message.
7676
*/
7777

78-
on(services.localAppRegistry, 'menu-share-schema-json', () =>
79-
store.dispatch({ type: SchemaExportActions.openLegacyBanner })
80-
);
78+
on(services.localAppRegistry, 'menu-share-schema-json', () => {
79+
console.log('I am here');
80+
store.dispatch({ type: SchemaExportActions.openLegacyBanner });
81+
});
8182

8283
addCleanup(() => store.dispatch(stopAnalysis()));
8384
addCleanup(() => store.dispatch(cancelExportSchema()));

0 commit comments

Comments
 (0)