@@ -11,7 +11,8 @@ import {
1111 ProviderState ,
1212 mgtHtml ,
1313 MgtTemplatedTaskComponent ,
14- registerComponent
14+ registerComponent ,
15+ customElementHelper
1516} from '@microsoft/mgt-element' ;
1617import { DriveItem , SharedInsight } from '@microsoft/microsoft-graph-types' ;
1718import { html , TemplateResult } from 'lit' ;
@@ -589,7 +590,7 @@ export class MgtFileList extends MgtTemplatedTaskComponent implements CardSectio
589590 : null ;
590591
591592 return html `
592- <div class="shared_insight_file" @click=${ ( e : MouseEvent ) => this . handleFileClick ( file , e ) } tabindex="0">
593+ <div class="shared_insight_file" @click=${ ( e : MouseEvent ) => this . handleSharedInsightClick ( file , e ) } tabindex="0">
593594 <div class="shared_insight_file__icon">
594595 <img alt="${ file . resourceVisualization . title } " src=${ getFileTypeIconUri (
595596 file . resourceVisualization . type ,
@@ -667,17 +668,16 @@ export class MgtFileList extends MgtTemplatedTaskComponent implements CardSectio
667668 * @param event
668669 */
669670 private readonly onFileListKeyDown = ( event : KeyboardEvent ) : void => {
670- console . log ( event . target ) ;
671+ const target = event . target as HTMLElement ;
671672 let fileList : HTMLElement ;
672- if ( ! event . target . classList ) {
673+ if ( ! target . classList ) {
673674 fileList = this . renderRoot . querySelector ( '.file-list-children' ) ;
674675 } else {
675676 fileList = this . renderRoot . querySelector ( '.file-list' ) ;
676677 }
677678 let focusedItem : HTMLElement ;
678679
679680 if ( ! fileList ?. children . length ) {
680- console . log ( 'no children for ' , fileList ) ;
681681 return ;
682682 }
683683
@@ -915,57 +915,42 @@ export class MgtFileList extends MgtTemplatedTaskComponent implements CardSectio
915915 this . requestUpdate ( ) ;
916916 }
917917
918- private readonly handleFileClick = ( file : DriveItem | SharedInsight , e ?: MouseEvent ) => {
918+ private readonly handleSharedInsightClick = ( file : SharedInsight , e ?: MouseEvent ) => {
919+ if ( file . resourceReference ?. webUrl && ! this . disableOpenOnClick ) {
920+ e . preventDefault ( ) ;
921+ window . open ( file . resourceReference . webUrl , '_blank' , 'noreferrer' ) ;
922+ }
923+ } ;
924+
925+ private readonly handleFileClick = ( file : DriveItem ) => {
919926 const hasChildFolders = file ?. folder ?. childCount > 0 && file ?. children ;
920927 // the item has child folders, on click should get the child folders and render them
921928 if ( hasChildFolders ) {
922- this . showChildren ( file , e ) ;
929+ this . showChildren ( file . id ) ;
923930 return ;
924931 }
925932
926- if ( e && isSharedInsight ( file ) && file . resourceReference ?. webUrl && ! this . disableOpenOnClick ) {
927- e . preventDefault ( ) ;
928- window . open ( file . resourceReference . webUrl , '_blank' , 'noreferrer' ) ;
929- } else if ( ! isSharedInsight ( file ) && file ?. webUrl && ! this . disableOpenOnClick ) {
933+ if ( file ?. webUrl && ! this . disableOpenOnClick ) {
930934 window . open ( file . webUrl , '_blank' , 'noreferrer' ) ;
931935 }
932936 } ;
933937
934- private readonly showChildren = ( file : DriveItem | SharedInsight , e ?: MouseEvent ) => {
935- const itemDOM = this . renderRoot . querySelector ( `#file-list-item-${ file . id } ` ) ;
936- this . renderChildren ( file , itemDOM ) ;
938+ private readonly showChildren = ( fileId : string ) => {
939+ const itemDOM = this . renderRoot . querySelector ( `#file-list-item-${ fileId } ` ) ;
940+ this . renderChildren ( fileId , itemDOM ) ;
937941 } ;
938942
939- private readonly renderChildren = ( file : DriveItem | SharedInsight , itemDOM : Element ) => {
940- const childrenContainer = this . renderRoot . querySelector ( `#file-list-children-${ file ?. id } ` ) ;
943+ private readonly renderChildren = ( itemId : string , itemDOM : Element ) => {
944+ const fileListName = customElementHelper . isDisambiguated
945+ ? `${ customElementHelper . prefix } -file-list`
946+ : 'mgt-file-list' ;
947+ const childrenContainer = this . renderRoot . querySelector ( `#file-list-children-${ itemId } ` ) ;
941948 if ( ! childrenContainer ) {
942- // create and show the children container
943- const container = document . createElement ( 'div' ) ;
944- container . setAttribute ( 'id' , `file-list-children-${ file ?. id } ` ) ;
945- container . setAttribute ( 'class' , 'file-list-children-show' ) ;
946-
947- const itemListDOM = document . createElement ( 'ul' ) ;
948- itemListDOM . setAttribute ( 'class' , 'file-list-children' ) ;
949- container . appendChild ( itemListDOM ) ;
950- const children = file ?. children ?? [ ] ;
951- for ( const f of children ) {
952- const li = document . createElement ( 'li' ) ;
953- // TODO: fix for disambiguation
954- const fileDOM = document . createElement ( 'mgt-file' ) ;
955- fileDOM . setAttribute ( 'fileDetails' , JSON . stringify ( f ) ) ;
956- fileDOM . setAttribute ( 'view' , this . itemView ) ;
957- // add key down/up on the list
958- li . addEventListener ( 'keydown' , this . onFileListKeyDown ) ;
959- li . setAttribute ( 'class' , 'file-item' ) ;
960- li . appendChild ( fileDOM ) ;
961- itemListDOM . appendChild ( li ) ;
962- }
963-
964- // a11y - set tabindex on first element
965- itemListDOM . firstElementChild . setAttribute ( 'tabindex' , '0' ) ;
966- itemListDOM . firstElementChild . setAttribute ( 'focus' , '0' ) ;
967- this . _focusedItemIndex = 0 ;
968- itemDOM . after ( container ) ;
949+ const fl = document . createElement ( fileListName ) ;
950+ fl . setAttribute ( 'item-id' , itemId ) ;
951+ fl . setAttribute ( 'id' , `file-list-children-${ itemId } ` ) ;
952+ fl . setAttribute ( 'class' , 'file-list-children-show' ) ;
953+ itemDOM . after ( fl ) ;
969954 } else {
970955 // toggle to show/hide the children container
971956 if ( childrenContainer . classList . contains ( 'file-list-children-hide' ) ) {
0 commit comments