Skip to content

Commit d646c38

Browse files
committed
remembered choice logic
1 parent 22629e4 commit d646c38

File tree

3 files changed

+42
-15
lines changed

3 files changed

+42
-15
lines changed

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

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export type SchemaExportState = {
2626
abortController?: AbortController;
2727
isOpen: boolean;
2828
isLegacyBannerOpen: boolean;
29-
dontShowLegacyBanner: boolean;
29+
legacyBannerChoice?: 'legacy' | 'export';
3030
exportedSchema?: string;
3131
exportFormat: SchemaFormat;
3232
errorMessage?: string;
@@ -42,15 +42,15 @@ const getInitialState = (): SchemaExportState => ({
4242
exportedSchema: undefined,
4343
isOpen: false,
4444
isLegacyBannerOpen: false,
45-
dontShowLegacyBanner: localStorage.getItem('dontShowLegacyBanner') === 'true',
45+
legacyBannerChoice: undefined,
4646
});
4747

4848
export const enum SchemaExportActions {
4949
openExportSchema = 'schema-service/schema-export/openExportSchema',
5050
closeExportSchema = 'schema-service/schema-export/closeExportSchema',
5151
openLegacyBanner = 'schema-service/schema-export/openLegacyBanner',
5252
closeLegacyBanner = 'schema-service/schema-export/closeLegacyBanner',
53-
dontShowLegacyBanner = 'schema-service/schema-export/dontShowLegacyBanner',
53+
setLegacyBannerChoice = 'schema-service/schema-export/setLegacyBannerChoice',
5454
changeExportSchemaStatus = 'schema-service/schema-export/changeExportSchemaStatus',
5555
changeExportSchemaFormatStarted = 'schema-service/schema-export/changeExportSchemaFormatStarted',
5656
changeExportSchemaFormatComplete = 'schema-service/schema-export/changeExportSchemaFormatComplete',
@@ -300,14 +300,14 @@ export const schemaExportReducer: Reducer<SchemaExportState, Action> = (
300300
}
301301

302302
if (
303-
isAction<dontShowLegacyBannerAction>(
303+
isAction<setLegacyBannerChoiceAction>(
304304
action,
305-
SchemaExportActions.dontShowLegacyBanner
305+
SchemaExportActions.setLegacyBannerChoice
306306
)
307307
) {
308308
return {
309309
...state,
310-
isLegacyBannerOpen: false,
310+
legacyBannerChoice: action.choice,
311311
};
312312
}
313313

@@ -373,14 +373,41 @@ export type openLegacyBannerAction = {
373373
type: SchemaExportActions.openLegacyBanner;
374374
};
375375

376+
export const openLegacyBanner = (): SchemaThunkAction<void> => {
377+
return (dispatch, getState) => {
378+
const choiceInState = getState().schemaExport.legacyBannerChoice;
379+
const savedChoice = choiceInState || localStorage.getItem(localStorageId);
380+
if (savedChoice) {
381+
if (savedChoice !== choiceInState) {
382+
dispatch({
383+
type: SchemaExportActions.setLegacyBannerChoice,
384+
choice: savedChoice,
385+
});
386+
}
387+
if (savedChoice === 'legacy') {
388+
dispatch(confirmedLegacySchemaShare());
389+
return;
390+
}
391+
if (savedChoice === 'export') {
392+
dispatch(openExportSchema());
393+
return;
394+
}
395+
}
396+
dispatch({ type: SchemaExportActions.openLegacyBanner });
397+
};
398+
};
399+
376400
export type closeLegacyBannerAction = {
377401
type: SchemaExportActions.closeLegacyBanner;
378402
};
379403

380-
export type dontShowLegacyBannerAction = {
381-
type: SchemaExportActions.dontShowLegacyBanner;
404+
export type setLegacyBannerChoiceAction = {
405+
type: SchemaExportActions.setLegacyBannerChoice;
406+
choice: 'legacy' | 'export';
382407
};
383408

409+
const localStorageId = 'schemaExportLegacyBannerChoice';
410+
384411
export const switchToSchemaExport = (): SchemaThunkAction<void> => {
385412
return (dispatch) => {
386413
dispatch({ type: SchemaExportActions.closeLegacyBanner });
@@ -439,9 +466,11 @@ export const _trackSchemaShared = (
439466
};
440467
};
441468

442-
export const stopShowingLegacyBanner = (): SchemaThunkAction<void> => {
469+
export const stopShowingLegacyBanner = (
470+
choice: 'legacy' | 'export'
471+
): SchemaThunkAction<void> => {
443472
return (dispatch) => {
444-
localStorage.setItem('dontShowLegacyBanner', 'true');
445-
dispatch({ type: SchemaExportActions.dontShowLegacyBanner });
473+
localStorage.setItem(localStorageId, choice);
474+
dispatch({ type: SchemaExportActions.setLegacyBannerChoice, choice });
446475
};
447476
};

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { schemaAnalysisReducer, stopAnalysis } from './schema-analysis-reducer';
2121
import {
2222
cancelExportSchema,
2323
confirmedLegacySchemaShare,
24-
SchemaExportActions,
24+
openLegacyBanner,
2525
schemaExportReducer,
2626
} from './schema-export-reducer';
2727
import type { InternalLayer } from '../modules/geo';
@@ -79,7 +79,7 @@ export function activateSchemaPlugin(
7979
on(services.localAppRegistry, 'menu-share-schema-json', () => {
8080
const { enableExportSchema } = services.preferences.getPreferences();
8181
if (enableExportSchema) {
82-
store.dispatch({ type: SchemaExportActions.openLegacyBanner });
82+
store.dispatch(openLegacyBanner());
8383
return;
8484
}
8585
store.dispatch(confirmedLegacySchemaShare());

packages/compass-workspaces/src/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,7 @@ export function activateWorkspacePlugin(
157157

158158
on(globalAppRegistry, 'menu-share-schema-json', () => {
159159
const activeTab = getActiveTab(store.getState());
160-
console.log({ activeTab });
161160
if (activeTab?.type === 'Collection') {
162-
console.log('this is collection');
163161
getLocalAppRegistryForTab(activeTab.id).emit('menu-share-schema-json');
164162
}
165163
});

0 commit comments

Comments
 (0)