From c184d268d5f56b4b90018296233d7d25007e0eb5 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Thu, 23 Nov 2023 18:11:59 +0100 Subject: [PATCH] chore(compass-schema-validation): convert to TS and new-style plugin COMPASS-7476 (#5154) --- package-lock.json | 23 +- .../components/collection-tab-provider.tsx | 24 ++ .../src/components/collection-tab.tsx | 31 +- packages/compass-collection/src/index.ts | 2 + .../src/modules/collection-tab.ts | 21 +- .../compass-collection/src/modules/tabs.ts | 10 +- packages/compass-home/package.json | 4 + .../src/components/workspace-content.tsx | 8 +- .../compass-schema-validation/package.json | 17 +- .../compass-schema-validation.module.less | 6 - .../compass-schema-validation.spec.jsx | 30 -- .../compass-schema-validation.spec.tsx | 31 ++ ...tion.jsx => compass-schema-validation.tsx} | 44 ++- .../{index.js => index.ts} | 0 .../document-preview.module.less | 48 --- .../document-preview.spec.jsx | 58 --- .../document-preview.spec.tsx | 42 +++ ...ument-preview.jsx => document-preview.tsx} | 21 +- .../document-preview/{index.js => index.ts} | 5 +- .../sample-documents/{index.js => index.ts} | 0 .../sample-documents.module.less | 32 -- ...nts.spec.jsx => sample-documents.spec.tsx} | 15 +- ...ple-documents.jsx => sample-documents.tsx} | 14 +- .../validation-editor/{index.js => index.ts} | 0 ...or.spec.jsx => validation-editor.spec.tsx} | 34 +- ...ation-editor.jsx => validation-editor.tsx} | 100 ++--- .../src/components/validation-selectors.tsx | 16 +- .../validation-states/{index.js => index.ts} | 0 .../validation-states.module.less | 9 - ...es.spec.jsx => validation-states.spec.tsx} | 49 +-- ...ation-states.jsx => validation-states.tsx} | 42 ++- .../compass-schema-validation/src/index.js | 34 -- .../compass-schema-validation/src/index.ts | 41 +++ .../src/modules/data-service.js | 50 --- ...a-service.spec.js => data-service.spec.ts} | 15 +- .../src/modules/data-service.ts | 49 +++ .../{edit-mode.spec.js => edit-mode.spec.ts} | 2 +- .../modules/{edit-mode.js => edit-mode.ts} | 29 +- .../{fields.spec.js => fields.spec.ts} | 2 +- .../src/modules/{fields.js => fields.ts} | 44 ++- .../src/modules/index.js | 92 ----- .../src/modules/index.ts | 124 +++++++ .../src/modules/is-loaded.js | 16 - .../{is-loaded.spec.js => is-loaded.spec.ts} | 2 +- .../src/modules/is-loaded.ts | 29 ++ .../src/modules/namespace.js | 37 -- .../{namespace.spec.js => namespace.spec.ts} | 9 +- .../src/modules/namespace.ts | 53 +++ .../src/modules/sample-documents.js | 217 ----------- ...ments.spec.js => sample-documents.spec.ts} | 43 +-- .../src/modules/sample-documents.ts | 307 ++++++++++++++++ .../src/modules/server-version.js | 38 -- ...version.spec.js => server-version.spec.ts} | 2 +- .../src/modules/server-version.ts | 43 +++ ...{validation.spec.js => validation.spec.ts} | 28 +- .../modules/{validation.js => validation.ts} | 342 +++++++++++------- ...{zero-state.spec.js => zero-state.spec.ts} | 2 +- .../modules/{zero-state.js => zero-state.ts} | 38 +- .../compass-schema-validation/src/plugin.jsx | 29 -- .../src/plugin.spec.js | 17 - .../src/stores/index.js | 3 - .../src/stores/index.ts | 1 + .../src/stores/store.js | 105 ------ .../stores/{store.spec.js => store.spec.ts} | 71 ++-- .../src/stores/store.ts | 117 ++++++ .../src/typings.d.ts | 1 + 66 files changed, 1486 insertions(+), 1282 deletions(-) create mode 100644 packages/compass-collection/src/components/collection-tab-provider.tsx delete mode 100644 packages/compass-schema-validation/src/components/compass-schema-validation/compass-schema-validation.module.less delete mode 100644 packages/compass-schema-validation/src/components/compass-schema-validation/compass-schema-validation.spec.jsx create mode 100644 packages/compass-schema-validation/src/components/compass-schema-validation/compass-schema-validation.spec.tsx rename packages/compass-schema-validation/src/components/compass-schema-validation/{compass-schema-validation.jsx => compass-schema-validation.tsx} (58%) rename packages/compass-schema-validation/src/components/compass-schema-validation/{index.js => index.ts} (100%) delete mode 100644 packages/compass-schema-validation/src/components/document-preview/document-preview.module.less delete mode 100644 packages/compass-schema-validation/src/components/document-preview/document-preview.spec.jsx create mode 100644 packages/compass-schema-validation/src/components/document-preview/document-preview.spec.tsx rename packages/compass-schema-validation/src/components/document-preview/{document-preview.jsx => document-preview.tsx} (78%) rename packages/compass-schema-validation/src/components/document-preview/{index.js => index.ts} (88%) rename packages/compass-schema-validation/src/components/sample-documents/{index.js => index.ts} (100%) delete mode 100644 packages/compass-schema-validation/src/components/sample-documents/sample-documents.module.less rename packages/compass-schema-validation/src/components/sample-documents/{sample-documents.spec.jsx => sample-documents.spec.tsx} (51%) rename packages/compass-schema-validation/src/components/sample-documents/{sample-documents.jsx => sample-documents.tsx} (92%) rename packages/compass-schema-validation/src/components/validation-editor/{index.js => index.ts} (100%) rename packages/compass-schema-validation/src/components/validation-editor/{validation-editor.spec.jsx => validation-editor.spec.tsx} (79%) rename packages/compass-schema-validation/src/components/validation-editor/{validation-editor.jsx => validation-editor.tsx} (78%) rename packages/compass-schema-validation/src/components/validation-states/{index.js => index.ts} (100%) delete mode 100644 packages/compass-schema-validation/src/components/validation-states/validation-states.module.less rename packages/compass-schema-validation/src/components/validation-states/{validation-states.spec.jsx => validation-states.spec.tsx} (88%) rename packages/compass-schema-validation/src/components/validation-states/{validation-states.jsx => validation-states.tsx} (83%) delete mode 100644 packages/compass-schema-validation/src/index.js create mode 100644 packages/compass-schema-validation/src/index.ts delete mode 100644 packages/compass-schema-validation/src/modules/data-service.js rename packages/compass-schema-validation/src/modules/{data-service.spec.js => data-service.spec.ts} (65%) create mode 100644 packages/compass-schema-validation/src/modules/data-service.ts rename packages/compass-schema-validation/src/modules/{edit-mode.spec.js => edit-mode.spec.ts} (94%) rename packages/compass-schema-validation/src/modules/{edit-mode.js => edit-mode.ts} (50%) rename packages/compass-schema-validation/src/modules/{fields.spec.js => fields.spec.ts} (94%) rename packages/compass-schema-validation/src/modules/{fields.js => fields.ts} (53%) delete mode 100644 packages/compass-schema-validation/src/modules/index.js create mode 100644 packages/compass-schema-validation/src/modules/index.ts delete mode 100644 packages/compass-schema-validation/src/modules/is-loaded.js rename packages/compass-schema-validation/src/modules/{is-loaded.spec.js => is-loaded.spec.ts} (91%) create mode 100644 packages/compass-schema-validation/src/modules/is-loaded.ts delete mode 100644 packages/compass-schema-validation/src/modules/namespace.js rename packages/compass-schema-validation/src/modules/{namespace.spec.js => namespace.spec.ts} (71%) create mode 100644 packages/compass-schema-validation/src/modules/namespace.ts delete mode 100644 packages/compass-schema-validation/src/modules/sample-documents.js rename packages/compass-schema-validation/src/modules/{sample-documents.spec.js => sample-documents.spec.ts} (81%) create mode 100644 packages/compass-schema-validation/src/modules/sample-documents.ts delete mode 100644 packages/compass-schema-validation/src/modules/server-version.js rename packages/compass-schema-validation/src/modules/{server-version.spec.js => server-version.spec.ts} (91%) create mode 100644 packages/compass-schema-validation/src/modules/server-version.ts rename packages/compass-schema-validation/src/modules/{validation.spec.js => validation.spec.ts} (93%) rename packages/compass-schema-validation/src/modules/{validation.js => validation.ts} (51%) rename packages/compass-schema-validation/src/modules/{zero-state.spec.js => zero-state.spec.ts} (91%) rename packages/compass-schema-validation/src/modules/{zero-state.js => zero-state.ts} (50%) delete mode 100644 packages/compass-schema-validation/src/plugin.jsx delete mode 100644 packages/compass-schema-validation/src/plugin.spec.js delete mode 100644 packages/compass-schema-validation/src/stores/index.js create mode 100644 packages/compass-schema-validation/src/stores/index.ts delete mode 100644 packages/compass-schema-validation/src/stores/store.js rename packages/compass-schema-validation/src/stores/{store.spec.js => store.spec.ts} (86%) create mode 100644 packages/compass-schema-validation/src/stores/store.ts create mode 100644 packages/compass-schema-validation/src/typings.d.ts diff --git a/package-lock.json b/package-lock.json index ee518377cf4..6d0972ee953 100644 --- a/package-lock.json +++ b/package-lock.json @@ -46335,6 +46335,7 @@ "@mongodb-js/atlas-service": "^0.10.1", "@mongodb-js/compass-aggregations": "^9.20.0", "@mongodb-js/compass-app-stores": "^7.6.1", + "@mongodb-js/compass-collection": "^4.19.1", "@mongodb-js/compass-components": "^1.19.0", "@mongodb-js/compass-connections": "^1.20.1", "@mongodb-js/compass-database": "^3.19.1", @@ -46344,6 +46345,7 @@ "@mongodb-js/compass-instance": "^4.19.1", "@mongodb-js/compass-logging": "^1.2.6", "@mongodb-js/compass-saved-aggregations-queries": "^1.20.1", + "@mongodb-js/compass-schema-validation": "^6.20.0", "@mongodb-js/compass-serverstats": "^16.19.1", "@mongodb-js/compass-settings": "^0.21.1", "@mongodb-js/compass-shell": "^3.19.1", @@ -46384,6 +46386,7 @@ "@mongodb-js/atlas-service": "^0.10.1", "@mongodb-js/compass-aggregations": "^9.20.0", "@mongodb-js/compass-app-stores": "^7.6.1", + "@mongodb-js/compass-collection": "^4.19.1", "@mongodb-js/compass-components": "^1.19.0", "@mongodb-js/compass-connections": "^1.20.1", "@mongodb-js/compass-database": "^3.19.1", @@ -46393,6 +46396,7 @@ "@mongodb-js/compass-instance": "^4.19.1", "@mongodb-js/compass-logging": "^1.2.6", "@mongodb-js/compass-saved-aggregations-queries": "^1.20.1", + "@mongodb-js/compass-schema-validation": "^6.20.0", "@mongodb-js/compass-serverstats": "^16.19.1", "@mongodb-js/compass-settings": "^0.21.1", "@mongodb-js/compass-shell": "^3.19.1", @@ -47217,15 +47221,19 @@ "version": "6.20.0", "license": "SSPL", "dependencies": { + "@mongodb-js/compass-app-stores": "^7.6.1", "@mongodb-js/compass-components": "^1.19.0", "@mongodb-js/compass-crud": "^13.20.0", "@mongodb-js/compass-editor": "^0.18.0", "@mongodb-js/compass-logging": "^1.2.6", "@mongodb-js/mongodb-redux-common": "^2.0.15", "bson": "^6.2.0", - "compass-preferences-model": "^2.15.6" + "compass-preferences-model": "^2.15.6", + "hadron-app-registry": "^9.0.14", + "mongodb-data-service": "^22.15.1" }, "devDependencies": { + "@mongodb-js/compass-collection": "^4.19.1", "@mongodb-js/eslint-config-compass": "^1.0.11", "@mongodb-js/mocha-config-compass": "^1.3.2", "@mongodb-js/prettier-config-compass": "^1.0.1", @@ -47236,14 +47244,10 @@ "electron": "^25.9.5", "enzyme": "^3.11.0", "eslint": "^7.25.0", - "hadron-app": "^5.15.1", - "hadron-app-registry": "^9.0.14", "hadron-ipc": "^3.2.4", "javascript-stringify": "^2.0.1", - "less": "^3.11.1", "lodash": "^4.17.21", "mocha": "^10.2.0", - "mongodb-data-service": "^22.15.1", "mongodb-instance-model": "^12.15.1", "mongodb-ns": "^2.4.0", "mongodb-query-parser": "^4.0.0", @@ -47257,6 +47261,7 @@ "sinon": "^8.1.1" }, "peerDependencies": { + "@mongodb-js/compass-app-stores": "^7.6.1", "@mongodb-js/compass-components": "^1.19.0", "@mongodb-js/compass-crud": "^13.20.0", "@mongodb-js/compass-editor": "^0.18.0", @@ -47264,6 +47269,8 @@ "@mongodb-js/mongodb-redux-common": "^2.0.15", "bson": "^6.2.0", "compass-preferences-model": "^2.15.6", + "hadron-app-registry": "^9.0.14", + "mongodb-data-service": "^22.15.1", "react": "^17.0.2" } }, @@ -59658,6 +59665,7 @@ "@mongodb-js/atlas-service": "^0.10.1", "@mongodb-js/compass-aggregations": "^9.20.0", "@mongodb-js/compass-app-stores": "^7.6.1", + "@mongodb-js/compass-collection": "^4.19.1", "@mongodb-js/compass-components": "^1.19.0", "@mongodb-js/compass-connections": "^1.20.1", "@mongodb-js/compass-database": "^3.19.1", @@ -59667,6 +59675,7 @@ "@mongodb-js/compass-instance": "^4.19.1", "@mongodb-js/compass-logging": "^1.2.6", "@mongodb-js/compass-saved-aggregations-queries": "^1.20.1", + "@mongodb-js/compass-schema-validation": "^6.20.0", "@mongodb-js/compass-serverstats": "^16.19.1", "@mongodb-js/compass-settings": "^0.21.1", "@mongodb-js/compass-shell": "^3.19.1", @@ -60277,6 +60286,8 @@ "@mongodb-js/compass-schema-validation": { "version": "file:packages/compass-schema-validation", "requires": { + "@mongodb-js/compass-app-stores": "^7.6.1", + "@mongodb-js/compass-collection": "^4.19.1", "@mongodb-js/compass-components": "^1.19.0", "@mongodb-js/compass-crud": "^13.20.0", "@mongodb-js/compass-editor": "^0.18.0", @@ -60294,11 +60305,9 @@ "electron": "^25.9.5", "enzyme": "^3.11.0", "eslint": "^7.25.0", - "hadron-app": "^5.15.1", "hadron-app-registry": "^9.0.14", "hadron-ipc": "^3.2.4", "javascript-stringify": "^2.0.1", - "less": "^3.11.1", "lodash": "^4.17.21", "mocha": "^10.2.0", "mongodb-data-service": "^22.15.1", diff --git a/packages/compass-collection/src/components/collection-tab-provider.tsx b/packages/compass-collection/src/components/collection-tab-provider.tsx new file mode 100644 index 00000000000..00a657008f1 --- /dev/null +++ b/packages/compass-collection/src/components/collection-tab-provider.tsx @@ -0,0 +1,24 @@ +import React, { useContext, useRef } from 'react'; +import type { CollectionTabPluginMetadata } from '../modules/collection-tab'; + +export interface CollectionTabPlugin { + name: string; + component: React.ComponentType; +} + +const CollectionTabsContext = React.createContext([]); + +export const CollectionTabsProvider: React.FunctionComponent<{ + tabs: CollectionTabPlugin[]; +}> = ({ tabs, children }) => { + const tabsRef = useRef(tabs); + return ( + + {children} + + ); +}; + +export function useCollectionTabPlugins(): CollectionTabPlugin[] { + return useContext(CollectionTabsContext); +} diff --git a/packages/compass-collection/src/components/collection-tab.tsx b/packages/compass-collection/src/components/collection-tab.tsx index c2663e6662f..ada470f2f8d 100644 --- a/packages/compass-collection/src/components/collection-tab.tsx +++ b/packages/compass-collection/src/components/collection-tab.tsx @@ -1,6 +1,6 @@ import React, { useEffect } from 'react'; -import type { Store } from 'redux'; import { connect, Provider } from 'react-redux'; +import type { CollectionTabPluginMetadata } from '../modules/collection-tab'; import { returnToView, selectDatabase, @@ -9,10 +9,13 @@ import { selectTab, renderScopedModals, renderTabs, + createCollectionStoreMetadata, } from '../modules/collection-tab'; import { css, ErrorBoundary, TabNavBar } from '@mongodb-js/compass-components'; import CollectionHeader from './collection-header'; import { createLoggerAndTelemetry } from '@mongodb-js/compass-logging'; +import type { configureStore } from '../stores/collection-tab'; +import { useCollectionTabPlugins } from './collection-tab-provider'; const { log, mongoLogId, track } = createLoggerAndTelemetry( 'COMPASS-COLLECTION-TAB-UI' @@ -58,11 +61,26 @@ const collectionModalContainerStyles = css({ const CollectionTab: React.FunctionComponent<{ currentTab: string; + collectionTabPluginMetadata: CollectionTabPluginMetadata; renderScopedModals(): React.ReactElement[]; renderTabs(): { name: string; component: React.ReactElement }[]; onTabClick(name: string): void; -}> = ({ currentTab, renderScopedModals, renderTabs, onTabClick }) => { - const tabs = renderTabs(); +}> = ({ + currentTab, + collectionTabPluginMetadata, + renderScopedModals, + renderTabs, + onTabClick, +}) => { + const pluginTabs = useCollectionTabPlugins(); + const legacyTabs = renderTabs(); + const tabs = [ + ...legacyTabs, + ...pluginTabs.map(({ name, component: Component }) => ({ + name, + component: , + })), + ]; const activeTabIndex = tabs.findIndex((tab) => tab.name === currentTab); useEffect(() => { @@ -121,6 +139,7 @@ const ConnectedCollectionTab = connect( (state: CollectionState) => { return { currentTab: state.currentTab, + collectionTabPluginMetadata: createCollectionStoreMetadata(state), }; }, { @@ -130,9 +149,9 @@ const ConnectedCollectionTab = connect( } )(CollectionTab); -const CollectionTabPlugin: React.FunctionComponent<{ store: Store }> = ({ - store, -}) => { +const CollectionTabPlugin: React.FunctionComponent<{ + store: ReturnType; +}> = ({ store }) => { return ( diff --git a/packages/compass-collection/src/index.ts b/packages/compass-collection/src/index.ts index 5c91054af38..fbd62d7a1cf 100644 --- a/packages/compass-collection/src/index.ts +++ b/packages/compass-collection/src/index.ts @@ -33,3 +33,5 @@ function deactivate(appRegistry: AppRegistry): void { export default CollectionTabsPlugin; export { activate, deactivate }; export { default as metadata } from '../package.json'; +export type { CollectionTabPluginMetadata } from './modules/collection-tab'; +export { CollectionTabsProvider } from './components/collection-tab-provider'; diff --git a/packages/compass-collection/src/modules/collection-tab.ts b/packages/compass-collection/src/modules/collection-tab.ts index 1bc6479f008..cbf4a8a734d 100644 --- a/packages/compass-collection/src/modules/collection-tab.ts +++ b/packages/compass-collection/src/modules/collection-tab.ts @@ -137,7 +137,6 @@ export const selectTab = ( localAppRegistry.emit('subtab-changed', tabName); }; }; - export const selectDatabase = (): CollectionThunkAction => { return (dispatch, getState, { globalAppRegistry }) => { const { metadata } = getState(); @@ -164,6 +163,20 @@ export const returnToView = (): CollectionThunkAction => { }; }; +export function createCollectionStoreMetadata(state: CollectionState) { + return { + ...state.metadata, + query: state.initialQuery, + aggregation: state.initialAggregation, + pipelineText: state.initialPipelineText, + editViewName: state.editViewName, + }; +} + +export type CollectionTabPluginMetadata = ReturnType< + typeof createCollectionStoreMetadata +>; + const setupRole = ( roleName: string ): CollectionThunkAction<{ name: string; component: React.ReactElement }[]> => { @@ -187,7 +200,7 @@ const setupRole = ( } = role; const collectionStoreMetadata = { - ...getState().metadata, + ...createCollectionStoreMetadata(getState()), localAppRegistry, globalAppRegistry, dataProvider: { @@ -196,10 +209,6 @@ const setupRole = ( error: null, dataProvider: dataService, }, - query: getState().initialQuery, - aggregation: getState().initialAggregation, - pipelineText: getState().initialPipelineText, - editViewName: getState().editViewName, }; let actions; diff --git a/packages/compass-collection/src/modules/tabs.ts b/packages/compass-collection/src/modules/tabs.ts index a51363db8b6..ffe6d5dde9a 100644 --- a/packages/compass-collection/src/modules/tabs.ts +++ b/packages/compass-collection/src/modules/tabs.ts @@ -1,7 +1,7 @@ import React from 'react'; import type { AnyAction, Reducer } from 'redux'; import type { ThunkAction } from 'redux-thunk'; -import AppRegistry from 'hadron-app-registry'; +import AppRegistry, { AppRegistryProvider } from 'hadron-app-registry'; import { ObjectId } from 'bson'; import type { CollectionMetadata } from 'mongodb-collection-model'; import type { DataService } from 'mongodb-data-service'; @@ -213,8 +213,12 @@ const createNewTab = ( localAppRegistry, ...collectionMetadata, }); - const component = React.createElement(collectionTabRole.component, { - store, + const component = React.createElement(AppRegistryProvider, { + localAppRegistry: localAppRegistry, + deactivateOnUnmount: false, + children: React.createElement(collectionTabRole.component, { + store, + }), }); const tab: CollectionTab = { id: new ObjectId().toHexString(), diff --git a/packages/compass-home/package.json b/packages/compass-home/package.json index 8e3d83a5622..85bcee0095c 100644 --- a/packages/compass-home/package.json +++ b/packages/compass-home/package.json @@ -37,6 +37,7 @@ "@mongodb-js/atlas-service": "^0.10.1", "@mongodb-js/compass-aggregations": "^9.20.0", "@mongodb-js/compass-app-stores": "^7.6.1", + "@mongodb-js/compass-collection": "^4.19.1", "@mongodb-js/compass-components": "^1.19.0", "@mongodb-js/compass-connections": "^1.20.1", "@mongodb-js/compass-database": "^3.19.1", @@ -46,6 +47,7 @@ "@mongodb-js/compass-instance": "^4.19.1", "@mongodb-js/compass-logging": "^1.2.6", "@mongodb-js/compass-saved-aggregations-queries": "^1.20.1", + "@mongodb-js/compass-schema-validation": "^6.20.0", "@mongodb-js/compass-serverstats": "^16.19.1", "@mongodb-js/compass-settings": "^0.21.1", "@mongodb-js/compass-shell": "^3.19.1", @@ -61,6 +63,7 @@ "@mongodb-js/atlas-service": "^0.10.1", "@mongodb-js/compass-aggregations": "^9.20.0", "@mongodb-js/compass-app-stores": "^7.6.1", + "@mongodb-js/compass-collection": "^4.19.1", "@mongodb-js/compass-components": "^1.19.0", "@mongodb-js/compass-connections": "^1.20.1", "@mongodb-js/compass-database": "^3.19.1", @@ -70,6 +73,7 @@ "@mongodb-js/compass-instance": "^4.19.1", "@mongodb-js/compass-logging": "^1.2.6", "@mongodb-js/compass-saved-aggregations-queries": "^1.20.1", + "@mongodb-js/compass-schema-validation": "^6.20.0", "@mongodb-js/compass-serverstats": "^16.19.1", "@mongodb-js/compass-settings": "^0.21.1", "@mongodb-js/compass-shell": "^3.19.1", diff --git a/packages/compass-home/src/components/workspace-content.tsx b/packages/compass-home/src/components/workspace-content.tsx index 35dcb2e038b..dbb0367b329 100644 --- a/packages/compass-home/src/components/workspace-content.tsx +++ b/packages/compass-home/src/components/workspace-content.tsx @@ -11,10 +11,12 @@ import { CompassDatabasePlugin, DatabaseTabsProvider, } from '@mongodb-js/compass-database'; +import { CompassSchemaValidationPlugin } from '@mongodb-js/compass-schema-validation'; import CompassSavedAggregationsQueriesPlugin from '@mongodb-js/compass-saved-aggregations-queries'; import { InstanceTab as DatabasesTabPlugin } from '@mongodb-js/compass-databases-collections'; import { InstanceTab as PerformanceTabPlugin } from '@mongodb-js/compass-serverstats'; import type Namespace from '../types/namespace'; +import { CollectionTabsProvider } from '@mongodb-js/compass-collection'; const EmptyComponent: React.FunctionComponent = () => null; @@ -27,7 +29,11 @@ const WorkspaceContent: React.FunctionComponent<{ namespace: Namespace }> = ({ useAppRegistryComponent('Collection.Workspace') ?? EmptyComponent; if (namespace.collection) { - return ; + return ( + + + + ); } if (namespace.database) { diff --git a/packages/compass-schema-validation/package.json b/packages/compass-schema-validation/package.json index 50a3ffdb261..3232076d30b 100644 --- a/packages/compass-schema-validation/package.json +++ b/packages/compass-schema-validation/package.json @@ -24,14 +24,14 @@ "dist" ], "main": "dist/index.js", - "compass:main": "src/index.js", + "compass:main": "src/index.ts", "types": "dist/src/index.d.ts", "exports": { "browser": "./dist/browser.js", "require": "./dist/index.js" }, "compass:exports": { - ".": "./src/index.js" + ".": "./src/index.ts" }, "scripts": { "bootstrap": "npm run postcompile", @@ -56,6 +56,7 @@ "reformat": "npm run eslint . -- --fix && npm run prettier -- --write ." }, "peerDependencies": { + "@mongodb-js/compass-app-stores": "^7.6.1", "@mongodb-js/compass-components": "^1.19.0", "@mongodb-js/compass-crud": "^13.20.0", "@mongodb-js/compass-editor": "^0.18.0", @@ -63,9 +64,12 @@ "@mongodb-js/mongodb-redux-common": "^2.0.15", "bson": "^6.2.0", "compass-preferences-model": "^2.15.6", + "hadron-app-registry": "^9.0.14", + "mongodb-data-service": "^22.15.1", "react": "^17.0.2" }, "devDependencies": { + "@mongodb-js/compass-collection": "^4.19.1", "@mongodb-js/eslint-config-compass": "^1.0.11", "@mongodb-js/mocha-config-compass": "^1.3.2", "@mongodb-js/prettier-config-compass": "^1.0.1", @@ -76,14 +80,10 @@ "electron": "^25.9.5", "enzyme": "^3.11.0", "eslint": "^7.25.0", - "hadron-app": "^5.15.1", - "hadron-app-registry": "^9.0.14", "hadron-ipc": "^3.2.4", "javascript-stringify": "^2.0.1", - "less": "^3.11.1", "lodash": "^4.17.21", "mocha": "^10.2.0", - "mongodb-data-service": "^22.15.1", "mongodb-instance-model": "^12.15.1", "mongodb-ns": "^2.4.0", "mongodb-query-parser": "^4.0.0", @@ -97,12 +97,15 @@ "sinon": "^8.1.1" }, "dependencies": { + "@mongodb-js/compass-app-stores": "^7.6.1", "@mongodb-js/compass-components": "^1.19.0", "@mongodb-js/compass-crud": "^13.20.0", "@mongodb-js/compass-editor": "^0.18.0", "@mongodb-js/compass-logging": "^1.2.6", "@mongodb-js/mongodb-redux-common": "^2.0.15", "bson": "^6.2.0", - "compass-preferences-model": "^2.15.6" + "compass-preferences-model": "^2.15.6", + "hadron-app-registry": "^9.0.14", + "mongodb-data-service": "^22.15.1" } } diff --git a/packages/compass-schema-validation/src/components/compass-schema-validation/compass-schema-validation.module.less b/packages/compass-schema-validation/src/components/compass-schema-validation/compass-schema-validation.module.less deleted file mode 100644 index 5be432a4fc0..00000000000 --- a/packages/compass-schema-validation/src/components/compass-schema-validation/compass-schema-validation.module.less +++ /dev/null @@ -1,6 +0,0 @@ -.root { - display: flex; - flex-direction: column; - flex-grow: 1; - height: 100%; -} diff --git a/packages/compass-schema-validation/src/components/compass-schema-validation/compass-schema-validation.spec.jsx b/packages/compass-schema-validation/src/components/compass-schema-validation/compass-schema-validation.spec.jsx deleted file mode 100644 index 63d44a8c67d..00000000000 --- a/packages/compass-schema-validation/src/components/compass-schema-validation/compass-schema-validation.spec.jsx +++ /dev/null @@ -1,30 +0,0 @@ -import React from 'react'; -import { mount } from 'enzyme'; -import AppRegistry from 'hadron-app-registry'; -import { expect } from 'chai'; - -import CompassSchemaValidation from '../compass-schema-validation'; -import configureStore from '../../stores'; -import styles from './compass-schema-validation.module.less'; - -describe('CompassSchemaValidation [Component]', function () { - let component; - let store; - const appRegistry = new AppRegistry(); - - beforeEach(function () { - store = configureStore({ - localAppRegistry: appRegistry, - }); - component = mount(); - }); - - afterEach(function () { - store = null; - component = null; - }); - - it('renders the correct root classname', function () { - expect(component.find(`.${styles.root}`)).to.be.present(); - }); -}); diff --git a/packages/compass-schema-validation/src/components/compass-schema-validation/compass-schema-validation.spec.tsx b/packages/compass-schema-validation/src/components/compass-schema-validation/compass-schema-validation.spec.tsx new file mode 100644 index 00000000000..d44bb0a99d1 --- /dev/null +++ b/packages/compass-schema-validation/src/components/compass-schema-validation/compass-schema-validation.spec.tsx @@ -0,0 +1,31 @@ +import React from 'react'; +import { mount } from 'enzyme'; +import { expect } from 'chai'; + +import CompassSchemaValidation from '.'; +import { configureStore } from '../../stores/store'; +import { Provider } from 'react-redux'; + +describe('CompassSchemaValidation [Component]', function () { + let component: any; + let store: ReturnType | null; + + beforeEach(function () { + store = configureStore(); + component = mount( + + + + ); + }); + + afterEach(function () { + store = null; + component = null; + }); + + it('renders the correct root classname', function () { + expect(component.find(`[data-testid="compass-schema-validation"]`)).to + .exist; + }); +}); diff --git a/packages/compass-schema-validation/src/components/compass-schema-validation/compass-schema-validation.jsx b/packages/compass-schema-validation/src/components/compass-schema-validation/compass-schema-validation.tsx similarity index 58% rename from packages/compass-schema-validation/src/components/compass-schema-validation/compass-schema-validation.jsx rename to packages/compass-schema-validation/src/components/compass-schema-validation/compass-schema-validation.tsx index 3db3c24a4d3..50af835658f 100644 --- a/packages/compass-schema-validation/src/components/compass-schema-validation/compass-schema-validation.jsx +++ b/packages/compass-schema-validation/src/components/compass-schema-validation/compass-schema-validation.tsx @@ -10,25 +10,31 @@ import { } from '../../modules/validation'; import { namespaceChanged } from '../../modules/namespace'; import { clearSampleDocuments } from '../../modules/sample-documents'; -import { changeZeroState, zeroStateChanged } from '../../modules/zero-state'; +import { changeZeroState } from '../../modules/zero-state'; import { withPreferences } from 'compass-preferences-model'; +import { css } from '@mongodb-js/compass-components'; +import type { RootState } from '../../modules'; +import type { ValidationStatesProps } from '../validation-states/validation-states'; -import styles from './compass-schema-validation.module.less'; +const styles = css({ + display: 'flex', + flexDirection: 'column', + flexGrow: 1, + height: '100%', +}); /** * The core schema validation component. */ -class CompassSchemaValidation extends Component { +class CompassSchemaValidation extends Component { static displayName = 'CompassSchemaValidation'; /** * Renders the CompassSchemaValidation component. - * - * @returns {React.Component} The component. */ render() { return ( -
+
); @@ -42,7 +48,7 @@ class CompassSchemaValidation extends Component { * * @returns {Object} The mapped properties. */ -const mapStateToProps = (state) => ({ +const mapStateToProps = (state: RootState) => ({ serverVersion: state.serverVersion, validation: state.validation, fields: state.fields, @@ -55,17 +61,19 @@ const mapStateToProps = (state) => ({ /** * Connect the redux store to the component (dispatch). */ -const MappedCompassSchemaValidation = connect(mapStateToProps, { - clearSampleDocuments, - validatorChanged, - cancelValidation, - saveValidation, - namespaceChanged, - validationActionChanged, - validationLevelChanged, - zeroStateChanged, - changeZeroState, -})(withPreferences(CompassSchemaValidation, ['readOnly'], React)); +const MappedCompassSchemaValidation: React.FunctionComponent = connect( + mapStateToProps, + { + clearSampleDocuments, + validatorChanged, + cancelValidation, + saveValidation, + namespaceChanged, + validationActionChanged, + validationLevelChanged, + changeZeroState, + } +)(withPreferences(CompassSchemaValidation, ['readOnly'], React)); export default MappedCompassSchemaValidation; export { CompassSchemaValidation }; diff --git a/packages/compass-schema-validation/src/components/compass-schema-validation/index.js b/packages/compass-schema-validation/src/components/compass-schema-validation/index.ts similarity index 100% rename from packages/compass-schema-validation/src/components/compass-schema-validation/index.js rename to packages/compass-schema-validation/src/components/compass-schema-validation/index.ts diff --git a/packages/compass-schema-validation/src/components/document-preview/document-preview.module.less b/packages/compass-schema-validation/src/components/document-preview/document-preview.module.less deleted file mode 100644 index 948a6ad47c7..00000000000 --- a/packages/compass-schema-validation/src/components/document-preview/document-preview.module.less +++ /dev/null @@ -1,48 +0,0 @@ -@import (reference) 'mongodb-compass/src/app/styles/index.less'; - -.document-preview { - display: flex; - align-items: center; - overflow: auto; - width: 100%; - position: relative; - - &-documents { - display: flex; - align-items: flex-start; - margin-top: 15px; - width: 100%; - - .no-documents { - background-color: @palette__white; - border: 1px solid @palette__gray--light-2; - border-radius: 4px; - box-shadow: 1px 1px 4px fade(@palette__black, 10%); - width: 100%; - height: 150px; - display: flex; - justify-content: center; - align-items: center; - color: @palette__gray--dark-2; - font-style: italic; - } - } - - &-document-card { - flex: none; - border: 1px solid @palette__gray--light-2; - border-radius: 4px; - box-shadow: 1px 1px 4px fade(@palette__black, 10%); - width: 100%; - height: 150px; - overflow: scroll; - } - - &-document-card::-webkit-scrollbar { - display: none; - } -} - -.document-preview::-webkit-scrollbar { - display: none; -} diff --git a/packages/compass-schema-validation/src/components/document-preview/document-preview.spec.jsx b/packages/compass-schema-validation/src/components/document-preview/document-preview.spec.jsx deleted file mode 100644 index cf881fdd805..00000000000 --- a/packages/compass-schema-validation/src/components/document-preview/document-preview.spec.jsx +++ /dev/null @@ -1,58 +0,0 @@ -import React from 'react'; -import { mount, shallow } from 'enzyme'; -import { expect } from 'chai'; - -import DocumentPreview from '../document-preview'; -import { DOCUMENT_LOADING_STATES } from '../../modules/sample-documents'; - -describe('DocumentPreview [Component]', function () { - context('when document loading state is initial', function () { - it('renders a button to load a sample document', function () { - const component = mount( - - ); - expect( - component.find('[data-testid="load-sample-document"]') - ).to.be.present(); - }); - }); - - context('when document loading state is loading', function () { - it('renders a spinner', function () { - const component = mount( - - ); - expect( - component.find('[data-testid="load-sample-spinner"]') - ).to.be.present(); - }); - }); - - context('when document loading state is success', function () { - it('renders a document if there is one present', function () { - const component = shallow( - - ); - expect(component.find('Document')).to.be.present(); - }); - - it('renders a no preview text when there is no document', function () { - const component = mount( - - ); - expect(component).to.have.text('No Preview Documents'); - }); - }); - - context('when document loading state is error', function () { - it('renders a no preview text', function () { - const component = mount( - - ); - expect(component).to.have.text('No Preview Documents'); - }); - }); -}); diff --git a/packages/compass-schema-validation/src/components/document-preview/document-preview.spec.tsx b/packages/compass-schema-validation/src/components/document-preview/document-preview.spec.tsx new file mode 100644 index 00000000000..13503779965 --- /dev/null +++ b/packages/compass-schema-validation/src/components/document-preview/document-preview.spec.tsx @@ -0,0 +1,42 @@ +import React from 'react'; +import { mount, shallow } from 'enzyme'; +import { expect } from 'chai'; + +import DocumentPreview from '.'; + +describe('DocumentPreview [Component]', function () { + context('when document loading state is initial', function () { + it('renders a button to load a sample document', function () { + const component = mount(); + expect(component.find('[data-testid="load-sample-document"]')).to.exist; + }); + }); + + context('when document loading state is loading', function () { + it('renders a spinner', function () { + const component = mount(); + expect(component.find('[data-testid="load-sample-spinner"]')).to.exist; + }); + }); + + context('when document loading state is success', function () { + it('renders a document if there is one present', function () { + const component = shallow( + + ); + expect(component.find('Document')).to.exist; + }); + + it('renders a no preview text when there is no document', function () { + const component = mount(); + expect(component).to.have.text('No Preview Documents'); + }); + }); + + context('when document loading state is error', function () { + it('renders a no preview text', function () { + const component = mount(); + expect(component).to.have.text('No Preview Documents'); + }); + }); +}); diff --git a/packages/compass-schema-validation/src/components/document-preview/document-preview.jsx b/packages/compass-schema-validation/src/components/document-preview/document-preview.tsx similarity index 78% rename from packages/compass-schema-validation/src/components/document-preview/document-preview.jsx rename to packages/compass-schema-validation/src/components/document-preview/document-preview.tsx index 487e6b82f64..4be36b6fca3 100644 --- a/packages/compass-schema-validation/src/components/document-preview/document-preview.jsx +++ b/packages/compass-schema-validation/src/components/document-preview/document-preview.tsx @@ -1,5 +1,4 @@ import React, { Component } from 'react'; -import PropTypes from 'prop-types'; import { Body, @@ -12,7 +11,7 @@ import { import { Document } from '@mongodb-js/compass-crud'; import { LoadingOverlay } from '../loading-overlay'; -import { DOCUMENT_LOADING_STATES } from '../../modules/sample-documents'; +import type { DOCUMENT_LOADING_STATES } from '../../modules/sample-documents'; const previewStyles = css({ display: 'flex', @@ -38,18 +37,18 @@ const noPreviewTextStyles = css({ width: '100%', }); +export interface DocumentPreviewProps { + document?: Record; + loadingState: DOCUMENT_LOADING_STATES; + onLoadSampleClick?: () => void; +} + /** * The document preview component. */ -class DocumentPreview extends Component { +class DocumentPreview extends Component { static displayName = 'DocumentPreview'; - static propTypes = { - document: PropTypes.object, - loadingState: PropTypes.oneOf(Object.values(DOCUMENT_LOADING_STATES)), - onLoadSampleClick: PropTypes.func, - }; - /** * Renders the document preview. * @@ -64,7 +63,7 @@ class DocumentPreview extends Component { )} data-testid="document-preview" > - {this.props.loadingState === DOCUMENT_LOADING_STATES.INITIAL ? ( + {this.props.loadingState === 'initial' ? (