77 ChatWidget ,
88 IAutocompletionRegistry ,
99 IChatModel ,
10- IConfig ,
1110 readIcon
1211} from '@jupyter/chat' ;
1312import { ICollaborativeDrive } from '@jupyter/docprovider' ;
@@ -107,6 +106,7 @@ export class ChatPanel extends SidePanel {
107106 this . _drive = options . drive ;
108107 this . _rmRegistry = options . rmRegistry ;
109108 this . _themeManager = options . themeManager ;
109+ this . _defaultDirectory = options . defaultDirectory ;
110110 this . _autocompletionRegistry = options . autocompletionRegistry ;
111111
112112 const addChat = new CommandToolbarButton ( {
@@ -133,15 +133,21 @@ export class ChatPanel extends SidePanel {
133133 }
134134
135135 /**
136- * Getter and setter of the config, propagated to all the chat widgets .
136+ * Getter and setter of the defaultDirectory .
137137 */
138- get config ( ) : IConfig {
139- return this . _config ;
138+ get defaultDirectory ( ) : string {
139+ return this . _defaultDirectory ;
140140 }
141- set config ( value : Partial < IConfig > ) {
142- this . _config = { ...this . _config , ...value } ;
141+ set defaultDirectory ( value : string ) {
142+ if ( value === this . _defaultDirectory ) {
143+ return ;
144+ }
145+ this . _defaultDirectory = value ;
146+ // Update the list of discoverable chat (in default directory)
147+ this . updateChatList ( ) ;
148+ // Update the sections names.
143149 this . widgets . forEach ( w => {
144- ( w as ChatSection ) . model . config = value ;
150+ ( w as ChatSection ) . defaultDirectory = value ;
145151 } ) ;
146152 }
147153
@@ -151,15 +157,15 @@ export class ChatPanel extends SidePanel {
151157 * @param model - the model of the chat widget
152158 * @param name - the name of the chat.
153159 */
154- addChat ( model : IChatModel , name : string , path : string ) : void {
160+ addChat ( model : IChatModel , path : string ) : void {
155161 // Collapse all chats
156162 const content = this . content as AccordionPanel ;
157163 for ( let i = 0 ; i < this . widgets . length ; i ++ ) {
158164 content . collapse ( i ) ;
159165 }
160166
161- // Set the id of the model.
162- model . name = name ;
167+ // Set the name of the model.
168+ model . name = path ;
163169
164170 // Create a new widget.
165171 const widget = new ChatWidget ( {
@@ -168,25 +174,31 @@ export class ChatPanel extends SidePanel {
168174 themeManager : this . _themeManager ,
169175 autocompletionRegistry : this . _autocompletionRegistry
170176 } ) ;
177+
171178 this . addWidget (
172- new ChatSection ( { name, widget, commands : this . _commands , path } )
179+ new ChatSection ( {
180+ widget,
181+ commands : this . _commands ,
182+ path,
183+ defaultDirectory : this . _defaultDirectory
184+ } )
173185 ) ;
174186 }
175187
176188 /**
177- * Update the list of available chats in the root directory of the drive .
189+ * Update the list of available chats in the default directory.
178190 */
179- updateChatNames = async ( ) : Promise < void > => {
191+ updateChatList = async ( ) : Promise < void > => {
180192 const extension = chatFileType . extensions [ 0 ] ;
181193 this . _drive
182- . get ( '.' )
194+ . get ( this . _defaultDirectory )
183195 . then ( contentModel => {
184196 const chatsNames : { [ name : string ] : string } = { } ;
185197 ( contentModel . content as any [ ] )
186198 . filter ( f => f . type === 'file' && f . name . endsWith ( extension ) )
187- . forEach (
188- f => ( chatsNames [ PathExt . basename ( f . name , extension ) ] = f . name )
189- ) ;
199+ . forEach ( f => {
200+ chatsNames [ PathExt . basename ( f . name , extension ) ] = f . path ;
201+ } ) ;
190202
191203 this . _chatNamesChanged . emit ( chatsNames ) ;
192204 } )
@@ -212,7 +224,7 @@ export class ChatPanel extends SidePanel {
212224 */
213225 protected onAfterShow ( msg : Message ) : void {
214226 // Wait for the component to be rendered.
215- this . _openChat . renderPromise ?. then ( ( ) => this . updateChatNames ( ) ) ;
227+ this . _openChat . renderPromise ?. then ( ( ) => this . updateChatList ( ) ) ;
216228 }
217229
218230 /**
@@ -272,7 +284,7 @@ export class ChatPanel extends SidePanel {
272284 this
273285 ) ;
274286 private _commands : CommandRegistry ;
275- private _config : IConfig = { } ;
287+ private _defaultDirectory : string ;
276288 private _drive : ICollaborativeDrive ;
277289 private _openChat : ReactWidget ;
278290 private _rmRegistry : IRenderMimeRegistry ;
@@ -292,6 +304,7 @@ export namespace ChatPanel {
292304 drive : ICollaborativeDrive ;
293305 rmRegistry : IRenderMimeRegistry ;
294306 themeManager : IThemeManager | null ;
307+ defaultDirectory : string ;
295308 autocompletionRegistry ?: IAutocompletionRegistry ;
296309 }
297310}
@@ -305,11 +318,13 @@ class ChatSection extends PanelWithToolbar {
305318 */
306319 constructor ( options : ChatSection . IOptions ) {
307320 super ( options ) ;
321+
322+ this . addWidget ( options . widget ) ;
323+
308324 this . addClass ( SECTION_CLASS ) ;
309- this . _name = options . name ;
325+ this . _defaultDirectory = options . defaultDirectory ;
310326 this . _path = options . path ;
311- this . title . label = this . _name ;
312- this . title . caption = this . _path ;
327+ this . _updateTitle ( ) ;
313328 this . toolbar . addClass ( TOOLBAR_CLASS ) ;
314329
315330 this . _markAsRead = new ToolbarButton ( {
@@ -326,7 +341,7 @@ class ChatSection extends PanelWithToolbar {
326341 onClick : ( ) => {
327342 this . model . dispose ( ) ;
328343 options . commands . execute ( CommandIDs . openChat , {
329- filepath : ` ${ this . _name } ${ chatFileType . extensions [ 0 ] } `
344+ filepath : this . _path
330345 } ) ;
331346 this . dispose ( ) ;
332347 }
@@ -346,8 +361,6 @@ class ChatSection extends PanelWithToolbar {
346361 this . toolbar . addItem ( 'collaborativeChat-moveMain' , moveToMain ) ;
347362 this . toolbar . addItem ( 'collaborativeChat-close' , closeButton ) ;
348363
349- this . addWidget ( options . widget ) ;
350-
351364 this . model . unreadChanged ?. connect ( this . _unreadChanged ) ;
352365
353366 this . _markAsRead . enabled = this . model . unreadMessages . length > 0 ;
@@ -363,10 +376,11 @@ class ChatSection extends PanelWithToolbar {
363376 }
364377
365378 /**
366- * The name of the chat .
379+ * Set the default directory property .
367380 */
368- get name ( ) : string {
369- return this . _name ;
381+ set defaultDirectory ( value : string ) {
382+ this . _defaultDirectory = value ;
383+ this . _updateTitle ( ) ;
370384 }
371385
372386 /**
@@ -384,6 +398,27 @@ class ChatSection extends PanelWithToolbar {
384398 super . dispose ( ) ;
385399 }
386400
401+ /**
402+ * Update the section's title, depending on the default directory and chat file name.
403+ * If the chat file is in the default directory, the section's name is its relative
404+ * path to that default directory. Otherwise, it is it absolute path.
405+ */
406+ private _updateTitle ( ) : void {
407+ const inDefault = this . _defaultDirectory
408+ ? ! PathExt . relative ( this . _defaultDirectory , this . _path ) . startsWith ( '..' )
409+ : true ;
410+
411+ const pattern = new RegExp ( `${ chatFileType . extensions [ 0 ] } $` , 'g' ) ;
412+ this . title . label = (
413+ inDefault
414+ ? this . _defaultDirectory
415+ ? PathExt . relative ( this . _defaultDirectory , this . _path )
416+ : this . _path
417+ : '/' + this . _path
418+ ) . replace ( pattern , '' ) ;
419+ this . title . caption = this . _path ;
420+ }
421+
387422 /**
388423 * Change the title when messages are unread.
389424 *
@@ -397,7 +432,7 @@ class ChatSection extends PanelWithToolbar {
397432 // this.title.label = `${unread.length ? '* ' : ''}${this._name}`;
398433 } ;
399434
400- private _name : string ;
435+ private _defaultDirectory : string ;
401436 private _markAsRead : ToolbarButton ;
402437 private _path : string ;
403438}
@@ -411,7 +446,7 @@ export namespace ChatSection {
411446 */
412447 export interface IOptions extends Panel . IOptions {
413448 commands : CommandRegistry ;
414- name : string ;
449+ defaultDirectory : string ;
415450 widget : ChatWidget ;
416451 path : string ;
417452 }
0 commit comments