11import { css , html , LitElement , nothing } from 'lit' ;
2- import { customElement , property , query } from 'lit/decorators.js' ;
2+ import { customElement , property , query , state } from 'lit/decorators.js' ;
33import { repeat } from 'lit/directives/repeat.js' ;
44import Sortable from 'sortablejs' ;
55import type { ComposerCommit , ComposerHunk } from '../../../../plus/composer/protocol' ;
@@ -67,6 +67,18 @@ export class DetailsPanel extends LitElement {
6767 .files-headline {
6868 font-size: 1.4rem;
6969 margin-block: 0 0.8rem;
70+ display: flex;
71+ align-items: center;
72+ justify-content: space-between;
73+ }
74+
75+ .files-headline__title {
76+ margin: 0;
77+ }
78+
79+ .files-headline__actions {
80+ display: flex;
81+ gap: 0.4rem;
7082 }
7183
7284 .files-list {
@@ -207,7 +219,7 @@ export class DetailsPanel extends LitElement {
207219 @property ( { type : Boolean } )
208220 filesChangedExpanded = true ;
209221
210- @property ( { type : Set } )
222+ @property ( { type : Object } )
211223 selectedHunkIds : Set < string > = new Set ( ) ;
212224
213225 @property ( { type : String } )
@@ -231,6 +243,9 @@ export class DetailsPanel extends LitElement {
231243 @property ( { type : Boolean } )
232244 hasChanges : boolean = true ;
233245
246+ @state ( )
247+ private defaultFilesExpanded : boolean = true ;
248+
234249 private hunksSortables : Sortable [ ] = [ ] ;
235250 private isDraggingHunks = false ;
236251 private draggedHunkIds : string [ ] = [ ] ;
@@ -507,6 +522,30 @@ export class DetailsPanel extends LitElement {
507522 ) ;
508523 }
509524
525+ private handleCollapseAllFiles ( ) {
526+ this . defaultFilesExpanded = false ;
527+ }
528+
529+ private handleExpandAllFiles ( ) {
530+ this . defaultFilesExpanded = true ;
531+ }
532+
533+ private renderFilesChangedHeader ( fileCount : number | string ) {
534+ return html `
535+ < div class ="files-headline ">
536+ < h3 class ="files-headline__title "> Files Changed (${ fileCount } )</ h3 >
537+ < div class ="files-headline__actions ">
538+ < gl-button appearance ="toolbar " @click =${ this . handleExpandAllFiles } tooltip ="Expand All">
539+ < code-icon icon ="expand-all "> </ code-icon >
540+ </ gl-button >
541+ < gl-button appearance ="toolbar " @click =${ this . handleCollapseAllFiles } tooltip ="Collapse All">
542+ < code-icon icon ="collapse-all "> </ code-icon >
543+ </ gl-button >
544+ </ div >
545+ </ div >
546+ ` ;
547+ }
548+
510549 private renderFileHierarchy ( hunks : ComposerHunk [ ] ) {
511550 const fileGroups = groupHunksByFile ( hunks ) ;
512551
@@ -521,7 +560,11 @@ export class DetailsPanel extends LitElement {
521560 private renderFile ( fileName : string , fileHunks : ComposerHunk [ ] ) {
522561 // const fileChanges = getFileChanges(fileHunks);
523562
524- return html `< gl-diff-file .filename =${ fileName } .hunks =${ fileHunks } > </ gl-diff-file > ` ;
563+ return html `< gl-diff-file
564+ .filename =${ fileName }
565+ .hunks =${ fileHunks }
566+ .defaultExpanded=${ this . defaultFilesExpanded }
567+ > </ gl-diff-file > ` ;
525568 }
526569
527570 // private renderFileOld(fileName: string, fileHunks: ComposerHunk[]) {
@@ -602,7 +645,7 @@ export class DetailsPanel extends LitElement {
602645 < gl-commit-message .message =${ this . getSectionTitle ( this . selectedUnassignedSection ) } > </ gl-commit-message >
603646
604647 < section >
605- < h3 class =" files-headline " > Files Changed ( ${ getUniqueFileNames ( hunks ) . length } ) </ h3 >
648+ ${ this . renderFilesChangedHeader ( getUniqueFileNames ( hunks ) . length ) }
606649 < div class ="files-list " data-source ="${ this . selectedUnassignedSection } ">
607650 ${ this . renderFileHierarchy ( hunks ) }
608651 </ div >
@@ -628,7 +671,7 @@ export class DetailsPanel extends LitElement {
628671 > </ gl-commit-message >
629672
630673 < section >
631- < h3 class =" files-headline " > Files Changed ( ${ getFileCountForCommit ( commit , this . hunks ) } ) </ h3 >
674+ ${ this . renderFilesChangedHeader ( getFileCountForCommit ( commit , this . hunks ) ) }
632675 < div class ="files-list " data-commit-id =${ commit . id } > ${ this . renderFileHierarchy ( commitHunks ) } </ div >
633676 </ section >
634677 </ article >
0 commit comments