1
1
import {
2
2
css ,
3
3
palette ,
4
+ Link ,
4
5
spacing ,
6
+ H3 ,
5
7
cx ,
6
8
SignalPopover ,
7
9
PerformanceSignals ,
8
10
useDarkMode ,
9
- Breadcrumbs ,
10
11
} from '@mongodb-js/compass-components' ;
11
12
import type { Signal } from '@mongodb-js/compass-components' ;
12
13
import React from 'react' ;
13
14
import toNS from 'mongodb-ns' ;
14
15
import { usePreference } from 'compass-preferences-model/provider' ;
15
16
import CollectionHeaderActions from '../collection-header-actions' ;
17
+ import CollectionStats from '../collection-stats' ;
16
18
import type { CollectionState } from '../../modules/collection-tab' ;
17
19
import { CollectionBadge } from './badges' ;
18
- import {
19
- useOpenWorkspace ,
20
- useWorkspaceBreadcrumbs ,
21
- } from '@mongodb-js/compass-workspaces/provider' ;
20
+ import { useOpenWorkspace } from '@mongodb-js/compass-workspaces/provider' ;
22
21
import { connect } from 'react-redux' ;
23
22
24
23
const collectionHeaderStyles = css ( {
25
- padding : spacing [ 3 ] ,
24
+ paddingTop : spacing [ 3 ] ,
25
+ paddingBottom : spacing [ 1 ] ,
26
+ height : + spacing [ 6 ] + + spacing [ 2 ] ,
26
27
flexShrink : 0 ,
27
28
display : 'flex' ,
28
29
alignItems : 'center' ,
29
30
justifyContent : 'space-between' ,
31
+ } ) ;
32
+
33
+ const collectionHeaderTitleStyles = css ( {
34
+ display : 'flex' ,
35
+ width : '100%' ,
36
+ alignItems : 'center' ,
37
+ padding : `0 ${ String ( spacing [ 3 ] ) } px` ,
38
+ margin : 0 ,
39
+ overflow : 'hidden' ,
30
40
gap : spacing [ 2 ] ,
31
41
} ) ;
32
42
43
+ const collectionHeaderDBLinkStyles = css ( {
44
+ whiteSpace : 'nowrap' ,
45
+ overflow : 'hidden' ,
46
+ textOverflow : 'ellipsis' ,
47
+ cursor : 'pointer' ,
48
+ textDecoration : 'none' ,
49
+ '&:hover,&:focus' : {
50
+ textDecoration : 'underline' ,
51
+ } ,
52
+ backgroundColor : 'transparent' ,
53
+ border : 'none' ,
54
+ display : 'inline-block' ,
55
+ padding : 0 ,
56
+ } ) ;
57
+
58
+ const collectionHeaderNamespaceStyles = css ( {
59
+ backgroundColor : 'transparent' ,
60
+ border : 'none' ,
61
+ display : 'flex' ,
62
+ whiteSpace : 'nowrap' ,
63
+ overflow : 'hidden' ,
64
+ } ) ;
65
+
66
+ const collectionHeaderDBNameStyles = css ( {
67
+ overflow : 'hidden' ,
68
+ textOverflow : 'ellipsis' ,
69
+ whiteSpace : 'nowrap' ,
70
+ } ) ;
71
+
72
+ const dbLinkLightStyles = css ( {
73
+ color : palette . green . dark2 ,
74
+ } ) ;
75
+
76
+ const dbLinkDarkStyles = css ( {
77
+ color : palette . green . base ,
78
+ } ) ;
79
+
80
+ const collectionHeaderCollectionStyles = css ( {
81
+ whiteSpace : 'nowrap' ,
82
+ overflow : 'hidden' ,
83
+ textOverflow : 'ellipsis' ,
84
+ } ) ;
85
+
33
86
const collectionHeaderLightStyles = css ( {
34
87
background : palette . white ,
35
88
} ) ;
@@ -38,6 +91,14 @@ const collectionHeaderDarkStyles = css({
38
91
backgroundColor : palette . black ,
39
92
} ) ;
40
93
94
+ const collectionHeaderTitleCollectionLightStyles = css ( {
95
+ color : palette . gray . dark1 ,
96
+ } ) ;
97
+
98
+ const collectionHeaderTitleCollectionDarkStyles = css ( {
99
+ color : palette . gray . light1 ,
100
+ } ) ;
101
+
41
102
type CollectionHeaderProps = {
42
103
namespace : string ;
43
104
isReadonly : boolean ;
@@ -48,6 +109,7 @@ type CollectionHeaderProps = {
48
109
sourceName ?: string ;
49
110
editViewName ?: string ;
50
111
sourcePipeline ?: unknown [ ] ;
112
+ stats : CollectionState [ 'stats' ] ;
51
113
} ;
52
114
53
115
const getInsightsForPipeline = ( pipeline : any [ ] , isAtlas : boolean ) => {
@@ -84,10 +146,15 @@ export const CollectionHeader: React.FunctionComponent<
84
146
sourceName,
85
147
editViewName,
86
148
sourcePipeline,
149
+ stats,
87
150
} ) => {
88
151
const darkMode = useDarkMode ( ) ;
89
152
const showInsights = usePreference ( 'showInsights' ) ;
90
- const { openCollectionWorkspace, openEditViewWorkspace } = useOpenWorkspace ( ) ;
153
+ const {
154
+ openCollectionsWorkspace,
155
+ openCollectionWorkspace,
156
+ openEditViewWorkspace,
157
+ } = useOpenWorkspace ( ) ;
91
158
92
159
const ns = toNS ( namespace ) ;
93
160
const database = ns . database ;
@@ -96,41 +163,85 @@ export const CollectionHeader: React.FunctionComponent<
96
163
showInsights && sourcePipeline ?. length
97
164
? getInsightsForPipeline ( sourcePipeline , isAtlas )
98
165
: [ ] ;
99
- const breadcrumbItems = useWorkspaceBreadcrumbs ( ) ;
166
+
100
167
return (
101
168
< div
102
- title = { `${ database } .${ collection } ` }
103
169
className = { cx (
104
170
collectionHeaderStyles ,
105
171
darkMode ? collectionHeaderDarkStyles : collectionHeaderLightStyles
106
172
) }
107
173
data-testid = "collection-header"
108
174
>
109
- < Breadcrumbs items = { breadcrumbItems } />
110
- { isReadonly && < CollectionBadge type = "readonly" /> }
111
- { isTimeSeries && < CollectionBadge type = "timeseries" /> }
112
- { isClustered && < CollectionBadge type = "clustered" /> }
113
- { isFLE && < CollectionBadge type = "fle" /> }
114
- { isReadonly && sourceName && < CollectionBadge type = "view" /> }
115
- { ! ! insights . length && < SignalPopover signals = { insights } /> }
116
- < CollectionHeaderActions
117
- editViewName = { editViewName }
118
- isReadonly = { isReadonly }
119
- onEditViewClicked = { ( ) => {
120
- if ( sourceName && sourcePipeline ) {
121
- openEditViewWorkspace ( namespace , {
122
- sourceName,
123
- sourcePipeline,
124
- } ) ;
125
- }
126
- } }
127
- onReturnToViewClicked = { ( ) => {
128
- if ( editViewName ) {
129
- openCollectionWorkspace ( editViewName , { sourceName : namespace } ) ;
130
- }
131
- } }
132
- sourceName = { sourceName }
133
- />
175
+ < div
176
+ title = { `${ database } .${ collection } ` }
177
+ className = { collectionHeaderTitleStyles }
178
+ data-testid = "collection-header-title"
179
+ >
180
+ < div
181
+ data-testid = "collection-header-namespace"
182
+ className = { collectionHeaderNamespaceStyles }
183
+ >
184
+ < Link
185
+ data-testid = "collection-header-title-db"
186
+ as = "button"
187
+ className = { cx (
188
+ collectionHeaderDBLinkStyles ,
189
+ darkMode ? dbLinkDarkStyles : dbLinkLightStyles
190
+ ) }
191
+ hideExternalIcon = { true }
192
+ onClick = { ( ) => {
193
+ openCollectionsWorkspace ( ns . database ) ;
194
+ } }
195
+ >
196
+ < H3
197
+ className = { cx (
198
+ collectionHeaderDBNameStyles ,
199
+ darkMode ? dbLinkDarkStyles : dbLinkLightStyles
200
+ ) }
201
+ >
202
+ { database }
203
+ </ H3 >
204
+ </ Link >
205
+ < H3
206
+ data-testid = "collection-header-title-collection"
207
+ className = { cx (
208
+ collectionHeaderCollectionStyles ,
209
+ darkMode
210
+ ? collectionHeaderTitleCollectionDarkStyles
211
+ : collectionHeaderTitleCollectionLightStyles
212
+ ) }
213
+ >
214
+ { `.${ collection } ` }
215
+ </ H3 >
216
+ </ div >
217
+ { isReadonly && < CollectionBadge type = "readonly" /> }
218
+ { isTimeSeries && < CollectionBadge type = "timeseries" /> }
219
+ { isClustered && < CollectionBadge type = "clustered" /> }
220
+ { isFLE && < CollectionBadge type = "fle" /> }
221
+ { isReadonly && sourceName && < CollectionBadge type = "view" /> }
222
+ { ! ! insights . length && < SignalPopover signals = { insights } /> }
223
+ < CollectionHeaderActions
224
+ editViewName = { editViewName }
225
+ isReadonly = { isReadonly }
226
+ onEditViewClicked = { ( ) => {
227
+ if ( sourceName && sourcePipeline ) {
228
+ openEditViewWorkspace ( namespace , {
229
+ sourceName,
230
+ sourcePipeline,
231
+ } ) ;
232
+ }
233
+ } }
234
+ onReturnToViewClicked = { ( ) => {
235
+ if ( editViewName ) {
236
+ openCollectionWorkspace ( editViewName ) ;
237
+ }
238
+ } }
239
+ sourceName = { sourceName }
240
+ />
241
+ </ div >
242
+ { ! isReadonly && ! editViewName && (
243
+ < CollectionStats isTimeSeries = { isTimeSeries } stats = { stats } />
244
+ ) }
134
245
</ div >
135
246
) ;
136
247
} ;
0 commit comments