11import * as vscode from 'vscode' ;
2- import numeral from 'numeral' ;
3- import path from 'path' ;
42
53import { createLogger } from '../logging' ;
64import DocumentTreeItem from './documentTreeItem' ;
75import formatError from '../utils/formatError' ;
8- import { getImagesPath } from '../extensionConstants' ;
96import type TreeItemParent from './treeItemParentInterface' ;
107import type { DataService } from 'mongodb-data-service' ;
8+ import {
9+ CollectionType ,
10+ formatDocCount ,
11+ getDocumentsIconPath ,
12+ getDocumentsTooltip ,
13+ } from './documentListUtils' ;
14+
15+ export {
16+ CollectionType ,
17+ formatDocCount ,
18+ getDocumentsIconPath ,
19+ getDocumentsTooltip ,
20+ } from './documentListUtils' ;
1121
1222const log = createLogger ( 'documents tree item' ) ;
1323
@@ -17,14 +27,6 @@ const log = createLogger('documents tree item');
1727export const MAX_DOCUMENTS_VISIBLE = 10 ;
1828
1929export const DOCUMENT_LIST_ITEM = 'documentListTreeItem' ;
20- export const CollectionType = {
21- collection : 'collection' ,
22- view : 'view' ,
23- timeseries : 'timeseries' ,
24- } as const ;
25-
26- export type CollectionType =
27- ( typeof CollectionType ) [ keyof typeof CollectionType ] ;
2830
2931const ITEM_LABEL = 'Documents' ;
3032
@@ -65,29 +67,6 @@ const getCollapsableStateForDocumentList = (
6567 : vscode . TreeItemCollapsibleState . Collapsed ;
6668} ;
6769
68- export const formatDocCount = ( count : number ) : string => {
69- // We format the count (30000 -> 30k) and then display it uppercase (30K).
70- return `${ numeral ( count ) . format ( '0a' ) as string } ` . toUpperCase ( ) ;
71- } ;
72-
73- function getIconPath ( ) : { light : vscode . Uri ; dark : vscode . Uri } {
74- const LIGHT = path . join ( getImagesPath ( ) , 'light' ) ;
75- const DARK = path . join ( getImagesPath ( ) , 'dark' ) ;
76-
77- return {
78- light : vscode . Uri . file ( path . join ( LIGHT , 'documents.svg' ) ) ,
79- dark : vscode . Uri . file ( path . join ( DARK , 'documents.svg' ) ) ,
80- } ;
81- }
82-
83- function getTooltip ( type : string , documentCount : number | null ) : string {
84- const typeString = type === CollectionType . view ? 'View' : 'Collection' ;
85- if ( documentCount !== null ) {
86- return `${ typeString } Documents - ${ documentCount } ` ;
87- }
88- return `${ typeString } Documents` ;
89- }
90-
9170export default class DocumentListTreeItem
9271 extends vscode . TreeItem
9372 implements TreeItemParent , vscode . TreeDataProvider < DocumentListTreeItem >
@@ -164,8 +143,8 @@ export default class DocumentListTreeItem
164143 this . description = formatDocCount ( this . _documentCount ) ;
165144 }
166145
167- this . iconPath = getIconPath ( ) ;
168- this . tooltip = getTooltip ( type , cachedDocumentCount ) ;
146+ this . iconPath = getDocumentsIconPath ( ) ;
147+ this . tooltip = getDocumentsTooltip ( type , cachedDocumentCount ) ;
169148 }
170149
171150 getTreeItem ( element : DocumentListTreeItem ) : DocumentListTreeItem {
0 commit comments