@@ -2,49 +2,42 @@ import React from 'react';
22import { connect } from 'react-redux' ;
33import toNS from 'mongodb-ns' ;
44import {
5+ useConnectionInfo ,
56 useConnectionsListRef ,
67 useTabConnectionTheme ,
78} from '@mongodb-js/compass-connections/provider' ;
89import {
910 WorkspaceTab ,
1011 type WorkspaceTabCoreProps ,
1112} from '@mongodb-js/compass-components' ;
12- import type { CollectionSubtab } from '@mongodb-js/compass-workspaces' ;
13+ import type { WorkspacePluginProps } from '@mongodb-js/compass-workspaces' ;
1314
1415import { type CollectionState } from './modules/collection-tab' ;
1516
16- type WorkspaceProps = {
17- id : string ;
18- connectionId : string ;
19- namespace : string ;
20- subTab : CollectionSubtab ;
21- initialQuery ?: unknown ;
22- initialPipeline ?: unknown [ ] ;
23- initialPipelineText ?: string ;
24- initialAggregation ?: unknown ;
25- editViewName ?: string ;
26- isNonExistent : boolean ;
27- } ;
17+ export const CollectionWorkspaceTitle = 'Collection' as const ;
2818
29- function _PluginTitle ( {
30- isTimeSeries,
31- isReadonly,
32- sourceName,
33- tabProps,
34- workspaceProps,
35- } : {
19+ type PluginTitleProps = {
3620 isTimeSeries ?: boolean ;
3721 isReadonly ?: boolean ;
3822 sourceName ?: string | null ;
39- tabProps : WorkspaceTabCoreProps ;
40- workspaceProps : WorkspaceProps ;
41- } ) {
23+ } & WorkspaceTabCoreProps &
24+ WorkspacePluginProps < typeof CollectionWorkspaceTitle > ;
25+
26+ function _PluginTitle ( {
27+ editViewName,
28+ isNonExistent,
29+ isReadonly,
30+ isTimeSeries,
31+ sourceName,
32+ namespace,
33+ ...tabProps
34+ } : PluginTitleProps ) {
4235 const { getThemeOf } = useTabConnectionTheme ( ) ;
4336 const { getConnectionById } = useConnectionsListRef ( ) ;
37+ const { id : connectionId } = useConnectionInfo ( ) ;
4438
45- const { database, collection, ns } = toNS ( workspaceProps . namespace ) ;
46- const connectionName =
47- getConnectionById ( workspaceProps . connectionId ) ?. title || '' ;
39+ const { database, collection, ns } = toNS ( namespace ) ;
40+ const connectionName = getConnectionById ( connectionId ) ?. title || '' ;
4841 const collectionType = isTimeSeries
4942 ? 'timeseries'
5043 : isReadonly
@@ -58,8 +51,8 @@ function _PluginTitle({
5851 if ( sourceName ) {
5952 tooltip . push ( [ 'View' , collection ] ) ;
6053 tooltip . push ( [ 'Derived from' , toNS ( sourceName ) . collection ] ) ;
61- } else if ( workspaceProps . editViewName ) {
62- tooltip . push ( [ 'View' , toNS ( workspaceProps . editViewName ) . collection ] ) ;
54+ } else if ( editViewName ) {
55+ tooltip . push ( [ 'View' , toNS ( editViewName ) . collection ] ) ;
6356 tooltip . push ( [ 'Derived from' , collection ] ) ;
6457 } else {
6558 tooltip . push ( [ 'Collection' , collection ] ) ;
@@ -68,7 +61,6 @@ function _PluginTitle({
6861 return (
6962 < WorkspaceTab
7063 { ...tabProps }
71- id = { workspaceProps . id }
7264 connectionName = { connectionName }
7365 type = { CollectionWorkspaceTitle }
7466 title = { collection }
@@ -78,32 +70,21 @@ function _PluginTitle({
7870 ? 'Visibility'
7971 : collectionType === 'timeseries'
8072 ? 'TimeSeries'
81- : workspaceProps . isNonExistent
73+ : isNonExistent
8274 ? 'EmptyFolder'
8375 : 'Folder'
8476 }
8577 data-namespace = { ns }
86- tabTheme = { getThemeOf ( workspaceProps . connectionId ) }
87- isNonExistent = { workspaceProps . isNonExistent }
78+ tabTheme = { getThemeOf ( connectionId ) }
79+ isNonExistent = { isNonExistent }
8880 />
8981 ) ;
9082}
9183
92- const ConnectedPluginTitle = connect ( ( state : CollectionState ) => ( {
93- isTimeSeries : state . metadata ?. isTimeSeries ,
94- isReadonly : state . metadata ?. isReadonly ,
95- sourceName : state . metadata ?. sourceName ,
96- } ) ) ( _PluginTitle ) ;
97-
98- export const CollectionWorkspaceTitle = 'Collection' as const ;
99- export function CollectionPluginTitleComponent ( {
100- tabProps,
101- workspaceProps,
102- } : {
103- tabProps : WorkspaceTabCoreProps ;
104- workspaceProps : WorkspaceProps ;
105- } ) {
106- return (
107- < ConnectedPluginTitle tabProps = { tabProps } workspaceProps = { workspaceProps } />
108- ) ;
109- }
84+ export const CollectionPluginTitleComponent = connect (
85+ ( state : CollectionState ) => ( {
86+ isTimeSeries : state . metadata ?. isTimeSeries ,
87+ isReadonly : state . metadata ?. isReadonly ,
88+ sourceName : state . metadata ?. sourceName ,
89+ } )
90+ ) ( _PluginTitle ) ;
0 commit comments