@@ -3,13 +3,14 @@ import { map } from 'lit/directives/map.js';
33import { customElement , property , state } from "lit/decorators.js" ;
44import { tailwind } from "../../style/index.js" ;
55import { FileUnderTestModel , Metrics , MetricsResult , MutationTestMetricsResult , TestFileModel , TestMetrics } from "mutation-testing-metrics" ;
6+ import { calculateFileMetrics , calculateMutationTestMetrics } from "../../../../metrics/src/calculateMetrics.js" ;
67
78@customElement ( 'mte-file-picker' )
89export class MutationTestReportFilePickerComponent extends LitElement {
910 static styles = [ tailwind ] ;
1011
1112 #currentPressedKeys = new Set < string > ( ) ;
12- #searchMap = new Map < string , string > ( ) ;
13+ #searchMap = new Map < string , FileUnderTestModel > ( ) ;
1314
1415 @property ( { type : Object } )
1516 public declare rootModel : MutationTestMetricsResult ;
@@ -18,7 +19,7 @@ export class MutationTestReportFilePickerComponent extends LitElement {
1819 public declare openPicker : boolean ;
1920
2021 @state ( )
21- public declare filteredFiles : string [ ] ;
22+ public declare filteredFiles : { name : string , file : FileUnderTestModel } [ ] ;
2223
2324 constructor ( ) {
2425 super ( ) ;
@@ -43,7 +44,7 @@ export class MutationTestReportFilePickerComponent extends LitElement {
4344
4445 return html `
4546 < div @click ="${ this . #closePicker} " class ="fixed flex justify-center items-center top-0 left-0 h-full w-full bg-black/50 backdrop-blur-lg z-50 ">
46- < div @click ="${ ( e : MouseEvent ) => e . stopPropagation ( ) } " role ="dialog " id ="picker " class ="flex flex-col bg-gray-200/60 backdrop-blur-lg h-full md:h-1/2 w-full md:w-1/2 max-w-[40rem] rounded-lg p-4 m-4 ">
47+ < div @click ="${ ( e : MouseEvent ) => e . stopPropagation ( ) } " role ="dialog " id ="picker " class ="flex flex-col bg-gray-200/60 backdrop-blur-lg h-full md:h-3/4 w-full md:w-1/2 max-w-[40rem] rounded-lg p-4 m-4 ">
4748 < div class ="flex items-center mb-2 p-2 rounded bg-gray-200/60 backdrop-blur-lg ">
4849 < div class ="h-full flex items-center mx-2 text-gray-800 ">
4950 < svg xmlns ="http://www.w3.org/2000/svg " fill ="none " viewBox ="0 0 24 24 " stroke-width ="1.5 " stroke ="currentColor " class ="size-6 ">
@@ -56,7 +57,7 @@ export class MutationTestReportFilePickerComponent extends LitElement {
5657 style ="box-shadow: none "
5758 class ="mr-2 w-full text-gray-800 bg-transparent border-transparent border-0 focus:shadow-none rounded " placeholder ="Search for a file " />
5859 </ div >
59- < div class ="height-full overflow-auto ">
60+ < div tabindex =" -1 " class ="height-full overflow-auto ">
6061 ${ this . #renderFoundFiles( ) }
6162 </ div >
6263 </ div >
@@ -66,11 +67,18 @@ export class MutationTestReportFilePickerComponent extends LitElement {
6667
6768 #renderFoundFiles( ) {
6869 return html `
69- < ul class ="flex flex-col ">
70- ${ map ( this . filteredFiles , ( file ) => {
70+ < ul id =" files " class ="flex flex-col ">
71+ ${ map ( this . filteredFiles , ( { name , file} ) => {
7172 return html `
7273 < li >
73- < a class ="flex border-2 border-black bg-black rounded p-1 my-1 text-gray-800 focus-visible:border-primary-500 outline-none " @click ="${ this . #closePicker} " href ="#mutant/ ${ file } "> ${ file } </ a >
74+ < a
75+ @focusout ="${ this . #handleFocus} "
76+ @click ="${ this . #closePicker} "
77+ class ="flex border-2 border-black bg-black rounded p-1 px-2 my-1 text-gray-800 focus-visible:border-primary-500 outline-none "
78+ href ="#mutant/ ${ name } "
79+ >
80+ ${ file . result ?. name } < span class ="mx-2 "> •</ span > < span class ="text-gray-400 "> ${ name } </ span >
81+ </ a >
7482 </ li > `
7583 } ) }
7684 </ ul >
@@ -80,16 +88,19 @@ export class MutationTestReportFilePickerComponent extends LitElement {
8088 #prepareMap( ) {
8189 const prepareFiles = ( result : MetricsResult < FileUnderTestModel , Metrics > , parentPath : string | null = null ) => {
8290 if ( result . file != null ) {
83- this . #searchMap. set ( parentPath == null ? result . name : `${ parentPath } /${ result . name } ` , '' ) ;
91+ this . #searchMap. set ( parentPath == null ? result . name : `${ parentPath } /${ result . name } ` , result . file ) ;
8492 }
8593
8694 result . childResults . forEach ( ( child ) => {
87- if ( parentPath != null && parentPath !== 'All files' ) {
95+ if ( ( parentPath !== 'All files' && parentPath !== null ) && result . name !== null ) {
8896 prepareFiles ( child , `${ parentPath } /${ result . name } ` ) ;
8997 }
90- else {
98+ else if ( ( parentPath === 'All files' || parentPath === null ) && result . name !== "All files" ) {
9199 prepareFiles ( child , result . name ) ;
92100 }
101+ else {
102+ prepareFiles ( child ) ;
103+ }
93104 } ) ;
94105 }
95106
@@ -108,7 +119,19 @@ export class MutationTestReportFilePickerComponent extends LitElement {
108119 }
109120
110121 if ( this . #currentPressedKeys. has ( 'Escape' ) ) {
111- this . openPicker = false ;
122+ this . #closePicker( ) ;
123+ }
124+ }
125+
126+ #handleFocus( e : KeyboardEvent ) {
127+ const allLinks = this . shadowRoot ?. querySelectorAll ( '#files li a' ) ;
128+ if ( allLinks === undefined || allLinks . length === 0 ) {
129+ return ;
130+ }
131+
132+ const lastLink = allLinks [ allLinks . length - 1 ] ;
133+ if ( e . target === lastLink ) {
134+ this . #focusInput( ) ;
112135 }
113136 }
114137
@@ -125,10 +148,14 @@ export class MutationTestReportFilePickerComponent extends LitElement {
125148 }
126149
127150 setTimeout ( ( ) => {
128- this . shadowRoot ?. querySelector ( 'input' ) ?. focus ( ) ;
151+ this . #focusInput ( ) ;
129152 } , 10 ) ;
130153 }
131154
155+ #focusInput( ) {
156+ this . shadowRoot ?. querySelector ( 'input' ) ?. focus ( ) ;
157+ }
158+
132159 #closePicker( ) {
133160 document . body . style . overflow = 'auto' ;
134161 this . openPicker = false ;
@@ -148,6 +175,8 @@ export class MutationTestReportFilePickerComponent extends LitElement {
148175 }
149176
150177 #filter( filterKey : string ) {
151- this . filteredFiles = Array . from ( this . #searchMap. keys ( ) ) . filter ( ( file ) => file . includes ( filterKey ) ) ;
178+ this . filteredFiles = Array . from ( this . #searchMap. keys ( ) )
179+ . filter ( ( file ) => file . includes ( filterKey ) )
180+ . map ( ( file ) => ( { name : file , file : this . #searchMap. get ( file ) ! } ) ) ;
152181 }
153182}
0 commit comments