@@ -2,46 +2,63 @@ import { ChangeDetectionStrategy, Component, EventEmitter, Input, Output } from
22import { IconType } from '@hypertrace/assets-library' ;
33import { Color } from '@hypertrace/common' ;
44import { IconSize } from '../../icon/icon-size' ;
5- import { FileUploadState } from './file-display' ;
5+ import {
6+ FileUploadEvent ,
7+ FileUploadEventType ,
8+ FileUploadFailureEvent ,
9+ FileUploadProgressEvent
10+ } from '../file-upload.service' ;
611
712@Component ( {
813 selector : 'ht-file-display' ,
914 styleUrls : [ './file-display.component.scss' ] ,
1015 changeDetection : ChangeDetectionStrategy . OnPush ,
1116 template : `
12- <div *ngIf="this.file" class="file-display" [ngClass]="{ error: this.state === '${ FileUploadState . Failure } ' }">
13- <ht-icon class="note-icon" icon="${ IconType . Note } " size="${ IconSize . Medium } " color="${ Color . Blue4 } "></ht-icon>
14- <div class="file-info">
15- <div class="basic-detail">
16- <div class="file-name" [htTooltip]="this.file.name">{{ this.file.name }}</div>
17- <div class="file-size">{{ this.file.size | htDisplayFileSize }}</div>
17+ <div class="file-display-container">
18+ <ht-progress-bar
19+ *ngIf="this.latestUploadEvent?.type === '${ FileUploadEventType . Progress } '"
20+ class="progress-bar"
21+ [progress]="this.getProgress()"
22+ ></ht-progress-bar>
23+ <div
24+ *ngIf="this.file"
25+ class="file-display"
26+ [ngClass]="{ error: this.latestUploadEvent?.type === '${ FileUploadEventType . Failure } ' }"
27+ >
28+ <ht-icon class="note-icon" icon="${ IconType . Note } " size="${ IconSize . Medium } " color="${ Color . Blue4 } "></ht-icon>
29+ <div class="file-info">
30+ <div class="basic-detail">
31+ <div class="file-name" [htTooltip]="this.file.name">{{ this.file.name }}</div>
32+ <div class="file-size">{{ this.file.size | htDisplayFileSize }}</div>
33+ </div>
1834 </div>
35+ <ng-container *ngIf="this.latestUploadEvent">
36+ <ng-container [ngSwitch]="this.latestUploadEvent?.type"
37+ ><ng-container *ngSwitchCase="'${ FileUploadEventType . Success } '"
38+ ><ht-icon class="success-icon" icon="${ IconType . CheckCircle } " color="${ Color . Green5 } "></ht-icon
39+ ></ng-container>
40+ <ng-container *ngSwitchCase="'${ FileUploadEventType . Failure } '"
41+ ><ht-icon
42+ class="failure-icon"
43+ icon="${ IconType . Alert } "
44+ color="${ Color . Red6 } "
45+ [htTooltip]="this.getError()"
46+ ></ht-icon>
47+ </ng-container>
48+ <ng-container *ngSwitchCase="'${ FileUploadEventType . Progress } '">
49+ <ht-loader class="progress-icon" htTooltip="Progress"></ht-loader>
50+ </ng-container>
51+ </ng-container>
52+ </ng-container>
53+ <ht-icon
54+ class="delete-icon"
55+ *ngIf="this.showDelete"
56+ icon="${ IconType . CloseCircleFilled } "
57+ size="${ IconSize . Small } "
58+ color="${ Color . Gray9 } "
59+ (click)="this.onDeleteClick()"
60+ ></ht-icon>
1961 </div>
20- <ng-container *ngIf="this.showState">
21- <ng-container [ngSwitch]="this.state"
22- ><ng-container *ngSwitchCase="'${ FileUploadState . Success } '"
23- ><ht-icon
24- class="success-icon"
25- icon="${ IconType . CheckCircle } "
26- color="${ Color . Green5 } "
27- ></ht-icon></ng-container
28- ><ng-container *ngSwitchCase="'${ FileUploadState . Failure } '"
29- ><ht-icon
30- class="failure-icon"
31- icon="${ IconType . Alert } "
32- color="${ Color . Red6 } "
33- [htTooltip]="this.errorStateTooltipText"
34- ></ht-icon></ng-container
35- ></ng-container>
36- </ng-container>
37- <ht-icon
38- *ngIf="this.showDelete"
39- class="delete-icon"
40- icon="${ IconType . CloseCircleFilled } "
41- size="${ IconSize . Small } "
42- color="${ Color . Gray9 } "
43- (click)="this.onDeleteClick()"
44- ></ht-icon>
4562 </div>
4663 `
4764} )
@@ -50,23 +67,27 @@ export class FileDisplayComponent {
5067 public file ?: File ;
5168
5269 @Input ( )
53- public state : FileUploadState = FileUploadState . NotStarted ;
54-
55- @Input ( )
56- public showState : boolean = false ;
57-
58- @Input ( )
59- public errorStateTooltipText : string = '' ;
70+ public latestUploadEvent ?: FileUploadEvent < unknown > ;
6071
6172 @Output ( )
6273 public readonly deleteClick : EventEmitter < void > = new EventEmitter ( ) ;
6374
64- // Only show file delete option if file upload has not started or it has resulted in failure
6575 public get showDelete ( ) : boolean {
66- return this . state === FileUploadState . NotStarted || this . state === FileUploadState . Failure ;
76+ return (
77+ this . latestUploadEvent ?. type === FileUploadEventType . Failure ||
78+ this . latestUploadEvent ?. type === FileUploadEventType . Success
79+ ) ;
6780 }
6881
6982 public onDeleteClick ( ) : void {
7083 this . deleteClick . emit ( ) ;
7184 }
85+
86+ public getError ( ) : string {
87+ return ( this . latestUploadEvent as FileUploadFailureEvent ) ?. error ?? '' ;
88+ }
89+
90+ public getProgress ( ) : number {
91+ return ( this . latestUploadEvent as FileUploadProgressEvent ) ?. progress ?? 0 ;
92+ }
7293}
0 commit comments