-
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
Changes from 2 commits
ed107db
db1ee5d
7eb2cb9
657307b
5019960
743fa2a
7749a93
3e0c612
a1757f6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| 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 namespaceId = `${workspaceProps.connectionId}.${ns}`; | ||
| 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) => ({ | ||
| // TODO: Need to check the implications of moving this metadata here | ||
| // instead of having it passed from the workspaces store. | ||
| isTimeSeries: state.metadata?.isTimeSeries, | ||
| isReadonly: state.metadata?.isReadonly, | ||
| sourceName: state.metadata?.sourceName, | ||
| }))(_PluginTitle); | ||
|
|
||
| export const CollectionWorkspaceTitle = 'Collection' as const; | ||
| export function CollectionPluginTitle(workspaceProps: WorkspaceProps) { | ||
| return (tabProps: WorkspaceTabCoreProps) => { | ||
| return ( | ||
| <ConnectedPluginTitle | ||
| tabProps={tabProps} | ||
| workspaceProps={workspaceProps} | ||
| /> | ||
| ); | ||
| }; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -149,6 +149,11 @@ const draggingTabStyles = css({ | |
| cursor: 'grabbing !important', | ||
| }); | ||
|
|
||
| // TODO: Should this have a dark mode version? | ||
| const nonExistentStyles = css({ | ||
| color: palette.gray.base, | ||
| }); | ||
|
|
||
| const tabIconStyles = css({ | ||
| color: 'currentColor', | ||
| marginLeft: spacing[300], | ||
|
|
@@ -185,25 +190,34 @@ const workspaceTabTooltipStyles = css({ | |
| textWrap: 'wrap', | ||
| }); | ||
|
|
||
| type TabProps = { | ||
| // The plugins provide these essential props use to render the tab. | ||
| // The workspace-tabs component provides the other parts of TabProps. | ||
| export type WorkspaceTabPluginProps = { | ||
| connectionName?: string; | ||
| type: string; | ||
| title: string; | ||
| title: React.ReactNode; | ||
| isNonExistent?: boolean; | ||
| iconGlyph: GlyphName | 'Logo' | 'Server'; | ||
| tooltip?: [string, string][]; | ||
| tabTheme?: Partial<TabTheme>; | ||
|
Member
Author
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. We could get rid of this prop and instead use a provider.
Collaborator
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. 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 |
||
| }; | ||
|
|
||
| export type WorkspaceTabCoreProps = { | ||
| isSelected: boolean; | ||
| isDragging: boolean; | ||
| onSelect: () => void; | ||
| onClose: () => void; | ||
| iconGlyph: GlyphName | 'Logo' | 'Server'; | ||
| tabContentId: string; | ||
| tooltip?: [string, string][]; | ||
| tabTheme?: Partial<TabTheme>; | ||
| }; | ||
|
|
||
| type TabProps = WorkspaceTabCoreProps & WorkspaceTabPluginProps; | ||
|
|
||
| function Tab({ | ||
| connectionName, | ||
| type, | ||
| title, | ||
| tooltip, | ||
| isNonExistent, | ||
| isSelected, | ||
| isDragging, | ||
| onSelect, | ||
|
|
@@ -213,7 +227,7 @@ function Tab({ | |
| tabTheme, | ||
| className: tabClassName, | ||
| ...props | ||
| }: TabProps & React.HTMLProps<HTMLDivElement>) { | ||
| }: TabProps & Omit<React.HTMLProps<HTMLDivElement>, 'title'>) { | ||
| const darkMode = useDarkMode(); | ||
| const defaultActionProps = useDefaultAction(onSelect); | ||
| const { listeners, setNodeRef, transform, transition } = useSortable({ | ||
|
|
@@ -254,6 +268,7 @@ function Tab({ | |
| className={cx( | ||
| tabStyles, | ||
| themeClass, | ||
| isNonExistent && nonExistentStyles, | ||
| isSelected && selectedTabStyles, | ||
| isSelected && tabTheme && selectedThemedTabStyles, | ||
| isDragging && draggingTabStyles, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.