-
Notifications
You must be signed in to change notification settings - Fork 245
feat: legacy to new schema export COMPASS-8798 #6713
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
4d79fba
wip
paula-stacho b19f578
feat: legacy to new schema export COMPASS-8798
paula-stacho ce7f4e9
checkbox
paula-stacho 22629e4
cleanup
paula-stacho d646c38
remembered choice logic
paula-stacho 4572725
fix
paula-stacho f031139
Update packages/compass-schema/src/components/export-schema-legacy-ba…
paula-stacho ae02133
Update packages/compass-schema/src/stores/schema-export-reducer.ts
paula-stacho 02561d9
PR suggestions
paula-stacho 0a94f95
cleanup
paula-stacho File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
547 changes: 547 additions & 0 deletions
547
packages/compass-schema/src/components/export-schema-legacy-banner.tsx
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,7 +9,12 @@ import type { | |
|
|
||
| import type { SchemaThunkAction } from './store'; | ||
| import { isAction } from '../utils'; | ||
| import type { SchemaAccessor } from '../modules/schema-analysis'; | ||
| import { | ||
| calculateSchemaDepth, | ||
| schemaContainsGeoData, | ||
| type SchemaAccessor, | ||
| } from '../modules/schema-analysis'; | ||
| import { openToast } from '@mongodb-js/compass-components'; | ||
|
|
||
| export type SchemaFormat = | ||
| | 'standardJSON' | ||
|
|
@@ -20,6 +25,8 @@ export type ExportStatus = 'inprogress' | 'complete' | 'error'; | |
| export type SchemaExportState = { | ||
| abortController?: AbortController; | ||
| isOpen: boolean; | ||
| isLegacyBannerOpen: boolean; | ||
| legacyBannerChoice?: 'legacy' | 'export'; | ||
| exportedSchema?: string; | ||
| exportFormat: SchemaFormat; | ||
| errorMessage?: string; | ||
|
|
@@ -34,11 +41,16 @@ const getInitialState = (): SchemaExportState => ({ | |
| exportStatus: 'inprogress', | ||
| exportedSchema: undefined, | ||
| isOpen: false, | ||
| isLegacyBannerOpen: false, | ||
| legacyBannerChoice: undefined, | ||
| }); | ||
|
|
||
| export const enum SchemaExportActions { | ||
| openExportSchema = 'schema-service/schema-export/openExportSchema', | ||
| closeExportSchema = 'schema-service/schema-export/closeExportSchema', | ||
| openLegacyBanner = 'schema-service/schema-export/openLegacyBanner', | ||
| closeLegacyBanner = 'schema-service/schema-export/closeLegacyBanner', | ||
| setLegacyBannerChoice = 'schema-service/schema-export/setLegacyBannerChoice', | ||
| changeExportSchemaStatus = 'schema-service/schema-export/changeExportSchemaStatus', | ||
| changeExportSchemaFormatStarted = 'schema-service/schema-export/changeExportSchemaFormatStarted', | ||
| changeExportSchemaFormatComplete = 'schema-service/schema-export/changeExportSchemaFormatComplete', | ||
|
|
@@ -263,6 +275,42 @@ export const schemaExportReducer: Reducer<SchemaExportState, Action> = ( | |
| }; | ||
| } | ||
|
|
||
| if ( | ||
| isAction<openLegacyBannerAction>( | ||
| action, | ||
| SchemaExportActions.openLegacyBanner | ||
| ) | ||
| ) { | ||
| return { | ||
| ...state, | ||
| isLegacyBannerOpen: true, | ||
| }; | ||
| } | ||
|
|
||
| if ( | ||
| isAction<closeLegacyBannerAction>( | ||
| action, | ||
| SchemaExportActions.closeLegacyBanner | ||
| ) | ||
| ) { | ||
| return { | ||
| ...state, | ||
| isLegacyBannerOpen: false, | ||
| }; | ||
| } | ||
|
|
||
| if ( | ||
| isAction<setLegacyBannerChoiceAction>( | ||
| action, | ||
| SchemaExportActions.setLegacyBannerChoice | ||
| ) | ||
| ) { | ||
| return { | ||
| ...state, | ||
| legacyBannerChoice: action.choice, | ||
| }; | ||
| } | ||
|
|
||
| if ( | ||
| isAction<ChangeExportSchemaFormatStartedAction>( | ||
| action, | ||
|
|
@@ -319,3 +367,110 @@ export const schemaExportReducer: Reducer<SchemaExportState, Action> = ( | |
|
|
||
| return state; | ||
| }; | ||
|
|
||
| // TODO clean out when phase out is confirmed COMPASS-8692 | ||
| export type openLegacyBannerAction = { | ||
| type: SchemaExportActions.openLegacyBanner; | ||
| }; | ||
|
|
||
| export const openLegacyBanner = (): SchemaThunkAction<void> => { | ||
| return (dispatch, getState) => { | ||
| const choiceInState = getState().schemaExport.legacyBannerChoice; | ||
| const savedChoice = choiceInState || localStorage.getItem(localStorageId); | ||
| if (savedChoice) { | ||
| if (savedChoice !== choiceInState) { | ||
| dispatch({ | ||
| type: SchemaExportActions.setLegacyBannerChoice, | ||
| choice: savedChoice, | ||
| }); | ||
| } | ||
| if (savedChoice === 'legacy') { | ||
| dispatch(confirmedLegacySchemaShare()); | ||
| return; | ||
| } | ||
| if (savedChoice === 'export') { | ||
| dispatch(openExportSchema()); | ||
| return; | ||
| } | ||
| } | ||
| dispatch({ type: SchemaExportActions.openLegacyBanner }); | ||
| }; | ||
| }; | ||
|
|
||
| export type closeLegacyBannerAction = { | ||
| type: SchemaExportActions.closeLegacyBanner; | ||
| }; | ||
|
|
||
| export type setLegacyBannerChoiceAction = { | ||
| type: SchemaExportActions.setLegacyBannerChoice; | ||
| choice: 'legacy' | 'export'; | ||
| }; | ||
|
|
||
| const localStorageId = 'schemaExportLegacyBannerChoice'; | ||
|
|
||
| export const switchToSchemaExport = (): SchemaThunkAction<void> => { | ||
| return (dispatch) => { | ||
| dispatch({ type: SchemaExportActions.closeLegacyBanner }); | ||
| dispatch(openExportSchema()); | ||
| }; | ||
| }; | ||
|
|
||
| export const confirmedLegacySchemaShare = (): SchemaThunkAction<void> => { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Calling out that in a branch I'm working on I've updated all the |
||
| return (dispatch, getState, { namespace }) => { | ||
| const { | ||
| schemaAnalysis: { schema }, | ||
| } = getState(); | ||
| const hasSchema = schema !== null; | ||
| if (hasSchema) { | ||
| void navigator.clipboard.writeText(JSON.stringify(schema, null, ' ')); | ||
| } | ||
| dispatch(_trackSchemaShared(hasSchema)); | ||
| dispatch({ type: SchemaExportActions.closeLegacyBanner }); | ||
| openToast( | ||
| 'share-schema', | ||
| hasSchema | ||
| ? { | ||
| variant: 'success', | ||
| title: 'Schema Copied', | ||
| description: `The schema definition of ${namespace} has been copied to your clipboard in JSON format.`, | ||
| timeout: 5_000, | ||
| } | ||
| : { | ||
| variant: 'warning', | ||
| title: 'Analyze Schema First', | ||
| description: | ||
| 'Please analyze the schema in the schema tab before sharing the schema.', | ||
| } | ||
| ); | ||
| }; | ||
| }; | ||
|
|
||
| export const _trackSchemaShared = ( | ||
| hasSchema: boolean | ||
| ): SchemaThunkAction<void> => { | ||
| return (dispatch, getState, { track, connectionInfoRef }) => { | ||
| const { | ||
| schemaAnalysis: { schema }, | ||
| } = getState(); | ||
| // Use a function here to a) ensure that the calculations here | ||
| // are only made when telemetry is enabled and b) that errors from | ||
| // those calculations are caught and logged rather than displayed to | ||
| // users as errors from the core schema sharing logic. | ||
| const trackEvent = () => ({ | ||
| has_schema: hasSchema, | ||
| schema_width: schema?.fields?.length ?? 0, | ||
| schema_depth: schema ? calculateSchemaDepth(schema) : 0, | ||
| geo_data: schema ? schemaContainsGeoData(schema) : false, | ||
| }); | ||
| track('Schema Exported', trackEvent, connectionInfoRef.current); | ||
| }; | ||
| }; | ||
|
|
||
| export const stopShowingLegacyBanner = ( | ||
| choice: 'legacy' | 'export' | ||
| ): SchemaThunkAction<void> => { | ||
| return (dispatch) => { | ||
| localStorage.setItem(localStorageId, choice); | ||
| dispatch({ type: SchemaExportActions.setLegacyBannerChoice, choice }); | ||
| }; | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.