-
Notifications
You must be signed in to change notification settings - Fork 247
feat(workspaces): move tab rendering to the plugins COMPASS-9413 #6997
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 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ed107db
feat(workspaces): move tab rendering to the plugins COMPASS-9413
Anemy db1ee5d
fixup: update comments
Anemy 7eb2cb9
fixup: improve header interface, update workspace context provider ty…
Anemy 657307b
fixup: update tests, improve typing
Anemy 5019960
fixup: naming, types, comments
Anemy 743fa2a
fixup: update types, move provider in workspace-tab-context-provider
Anemy 7749a93
Merge branch 'main' into COMPASS-9413-workspaces-plugins-have-titles
Anemy 3e0c612
fixup: useId for tab id for e2e test tab closing selector
Anemy a1757f6
fixup: move provider ordering, pass initial props to providers
Anemy 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| import React from 'react'; | ||
| import { connect } from 'react-redux'; | ||
| import toNS from 'mongodb-ns'; | ||
| import { | ||
| useConnectionsListRef, | ||
| useTabConnectionTheme, | ||
| } from '@mongodb-js/compass-connections/provider'; | ||
| import { | ||
| WorkspaceTab, | ||
| type WorkspaceTabCoreProps, | ||
| } from '@mongodb-js/compass-components'; | ||
| import type { CollectionSubtab } from '@mongodb-js/compass-workspaces'; | ||
|
|
||
| import { type CollectionState } from './modules/collection-tab'; | ||
|
|
||
| type WorkspaceProps = { | ||
| id: string; | ||
| connectionId: string; | ||
| namespace: string; | ||
| subTab: CollectionSubtab; | ||
| initialQuery?: unknown; | ||
| initialPipeline?: unknown[]; | ||
| initialPipelineText?: string; | ||
| initialAggregation?: unknown; | ||
| editViewName?: string; | ||
| isNonExistent: boolean; | ||
| }; | ||
|
|
||
| function _PluginTitle({ | ||
| isTimeSeries, | ||
| isReadonly, | ||
| sourceName, | ||
| tabProps, | ||
| workspaceProps, | ||
| }: { | ||
| isTimeSeries?: boolean; | ||
| isReadonly?: boolean; | ||
| sourceName?: string | null; | ||
| tabProps: WorkspaceTabCoreProps; | ||
| workspaceProps: WorkspaceProps; | ||
| }) { | ||
| const { getThemeOf } = useTabConnectionTheme(); | ||
| const { getConnectionById } = useConnectionsListRef(); | ||
|
|
||
| const { database, collection, ns } = toNS(workspaceProps.namespace); | ||
| const connectionName = | ||
| getConnectionById(workspaceProps.connectionId)?.title || ''; | ||
| const collectionType = isTimeSeries | ||
| ? 'timeseries' | ||
| : isReadonly | ||
| ? 'view' | ||
| : 'collection'; | ||
| // Similar to what we have in the collection breadcrumbs. | ||
| const tooltip: [string, string][] = [ | ||
| ['Connection', connectionName || ''], | ||
| ['Database', database], | ||
| ]; | ||
| if (sourceName) { | ||
| tooltip.push(['View', collection]); | ||
| tooltip.push(['Derived from', toNS(sourceName).collection]); | ||
| } else if (workspaceProps.editViewName) { | ||
| tooltip.push(['View', toNS(workspaceProps.editViewName).collection]); | ||
| tooltip.push(['Derived from', collection]); | ||
| } else { | ||
| tooltip.push(['Collection', collection]); | ||
| } | ||
|
|
||
| return ( | ||
| <WorkspaceTab | ||
| {...tabProps} | ||
| id={workspaceProps.id} | ||
| connectionName={connectionName} | ||
| type={CollectionWorkspaceTitle} | ||
| title={collection} | ||
| tooltip={tooltip} | ||
| iconGlyph={ | ||
| collectionType === 'view' | ||
| ? 'Visibility' | ||
| : collectionType === 'timeseries' | ||
| ? 'TimeSeries' | ||
| : workspaceProps.isNonExistent | ||
| ? 'EmptyFolder' | ||
| : 'Folder' | ||
| } | ||
| data-namespace={ns} | ||
| tabTheme={getThemeOf(workspaceProps.connectionId)} | ||
| isNonExistent={workspaceProps.isNonExistent} | ||
| /> | ||
| ); | ||
| } | ||
|
|
||
| const ConnectedPluginTitle = connect((state: CollectionState) => ({ | ||
| isTimeSeries: state.metadata?.isTimeSeries, | ||
| isReadonly: state.metadata?.isReadonly, | ||
| sourceName: state.metadata?.sourceName, | ||
| }))(_PluginTitle); | ||
|
|
||
| export const CollectionWorkspaceTitle = 'Collection' as const; | ||
| export function CollectionPluginTitleComponent({ | ||
| tabProps, | ||
| workspaceProps, | ||
| }: { | ||
| tabProps: WorkspaceTabCoreProps; | ||
| workspaceProps: WorkspaceProps; | ||
| }) { | ||
| return ( | ||
| <ConnectedPluginTitle tabProps={tabProps} workspaceProps={workspaceProps} /> | ||
| ); | ||
| } |
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
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could get rid of this prop and instead use a provider.
Here's a branch with that provider: main...tab-theme-context-provider-example
I didn't include it in these changes, as it is something we could do as a follow up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense to me, and then we can also add it to all the shared workspace providers. Then we can also use these colors inside the workspaces UI easily if we need to