-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(compass-database): convert to new plugin interface COMPASS-7401 (…
- Loading branch information
Showing
10 changed files
with
108 additions
and
72 deletions.
There are no files selected for viewing
This file contains 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
29 changes: 29 additions & 0 deletions
29
packages/compass-database/src/components/database-tabs-provider.tsx
This file contains 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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import React, { useContext, useMemo, useRef } from 'react'; | ||
|
||
export type DatabaseTab = { | ||
name: string; | ||
component: React.ComponentType; | ||
}; | ||
|
||
const DatabaseTabsContext = React.createContext<DatabaseTab[]>([]); | ||
|
||
export const DatabaseTabsProvider: React.FunctionComponent<{ | ||
tabs: DatabaseTab[]; | ||
}> = ({ tabs, children }) => { | ||
const tabsRef = useRef(tabs); | ||
return ( | ||
<DatabaseTabsContext.Provider value={tabsRef.current}> | ||
{children} | ||
</DatabaseTabsContext.Provider> | ||
); | ||
}; | ||
|
||
export function useDatabaseTabs( | ||
filterFn: (tab: DatabaseTab) => boolean = () => true | ||
): DatabaseTab[] { | ||
const tabs = useContext(DatabaseTabsContext); | ||
const filteredTabs = useMemo(() => { | ||
return tabs.filter(filterFn); | ||
}, [tabs, filterFn]); | ||
return filteredTabs; | ||
} |
This file contains 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 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 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 |
---|---|---|
@@ -1,22 +1,24 @@ | ||
import type AppRegistry from 'hadron-app-registry'; | ||
import DatabasePlugin from './plugin'; | ||
import type { LoggerAndTelemetry } from '@mongodb-js/compass-logging/provider'; | ||
import { registerHadronPlugin } from 'hadron-app-registry'; | ||
import { DatabasePlugin, onActivated } from './plugin'; | ||
|
||
/** | ||
* Activate all the components in the Database package. | ||
* @param {Object} appRegistry - The Hadron appRegisrty to activate this plugin with. | ||
**/ | ||
function activate(appRegistry: AppRegistry): void { | ||
appRegistry.registerComponent('Database.Workspace', DatabasePlugin); | ||
function activate(): void { | ||
// noop | ||
} | ||
|
||
/** | ||
* Deactivate all the components in the Database package. | ||
* @param {Object} appRegistry - The Hadron appRegisrty to deactivate this plugin with. | ||
**/ | ||
function deactivate(appRegistry: AppRegistry): void { | ||
appRegistry.deregisterComponent('Database.Workspace'); | ||
function deactivate(): void { | ||
// noop | ||
} | ||
|
||
export default DatabasePlugin; | ||
export const CompassDatabasePlugin = registerHadronPlugin< | ||
object, | ||
{ logger: () => LoggerAndTelemetry } | ||
>({ | ||
name: 'CompassDatabase', | ||
component: DatabasePlugin as React.FunctionComponent, | ||
activate: onActivated, | ||
}); | ||
|
||
export { DatabaseTabsProvider } from './components/database-tabs-provider'; | ||
export { activate, deactivate }; | ||
export { default as metadata } from '../package.json'; |
This file contains 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 |
---|---|---|
@@ -1,8 +1,17 @@ | ||
import React from 'react'; | ||
import { Database } from './components/database'; | ||
|
||
function Plugin() { | ||
export function DatabasePlugin() { | ||
return <Database />; | ||
} | ||
|
||
export default Plugin; | ||
export function onActivated() { | ||
return { | ||
store: { | ||
state: {}, | ||
}, | ||
deactivate() { | ||
/* nothing to do */ | ||
}, | ||
}; | ||
} |
This file contains 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 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 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 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