Skip to content

Commit

Permalink
#EXUI-1832: 'Choose file' and 'no file chosen' not being sent via Wel…
Browse files Browse the repository at this point in the history
…sh translation API
  • Loading branch information
MunishSharmaHMCTS committed Oct 29, 2024
1 parent 38fa699 commit b1468a7
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 17 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hmcts/ccd-case-ui-toolkit",
"version": "7.0.74",
"version": "7.0.74-exui-1832-rc1",
"engines": {
"node": ">=18.19.0"
},
Expand Down
2 changes: 1 addition & 1 deletion projects/ccd-case-ui-toolkit/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hmcts/ccd-case-ui-toolkit",
"version": "7.0.74",
"version": "7.0.74-exui-1832-rc1",
"engines": {
"node": ">=18.19.0"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
.input-upload-file {
width: 100%;
display: none;
}

.upload-file-container {
display: flex;
align-items: baseline;
}

.input-label {
width: 8rem;
}

@import "../base-field/grey-bar.scss";
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,8 @@ describe('WriteDocumentFieldComponent', () => {
]
}
});

expect(component.fileName).toBe('test.pdf')
expect(component.caseField.value.document_filename).toBe('test.pdf');
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, ElementRef, OnDestroy, OnInit, ViewChild } from '@angular/core';
import { Component, ElementRef, OnDestroy, OnInit, ViewChild, ViewEncapsulation } from '@angular/core';
import { FormControl, FormGroup, Validators } from '@angular/forms';
import { MatLegacyDialog as MatDialog } from '@angular/material/legacy-dialog';
import { MatDialogConfig } from '@angular/material/dialog';
Expand All @@ -18,7 +18,8 @@ import { FileUploadStateService } from './file-upload-state.service';

@Component({
selector: 'ccd-write-document-field',
templateUrl: './write-document-field.html'
templateUrl: './write-document-field.html',
styleUrls: ['./../base-field/field-write.component.scss']
})
export class WriteDocumentFieldComponent extends AbstractFieldWriteComponent implements OnInit, OnDestroy {
public static readonly DOCUMENT_URL = 'document_url';
Expand All @@ -44,6 +45,7 @@ export class WriteDocumentFieldComponent extends AbstractFieldWriteComponent imp
public dialogSubscription: Subscription;
public caseNotifierSubscription: Subscription;
public jurisdictionSubs: Subscription;
public fileName = 'No file chosen';

private uploadedDocument: FormGroup;
private dialogConfig: MatDialogConfig;
Expand Down Expand Up @@ -119,9 +121,9 @@ export class WriteDocumentFieldComponent extends AbstractFieldWriteComponent imp
}

public fileChangeEvent(fileInput: any): void {

if (fileInput.target.files[0]) {
this.selectedFile = fileInput.target.files[0];
this.fileName = fileInput.target.files[0].name;
this.displayFileUploadMessages(WriteDocumentFieldComponent.UPLOAD_WAITING_FILE_STATUS);
const documentUpload: FormData = this.buildDocumentUploadData(this.selectedFile);
this.fileUploadStateService.setUploadInProgress(true);
Expand Down Expand Up @@ -249,7 +251,7 @@ export class WriteDocumentFieldComponent extends AbstractFieldWriteComponent imp
if (documentHash) {
this.uploadedDocument.get(WriteDocumentFieldComponent.DOCUMENT_HASH).setValue(documentHash);
}
if(this.uploadedDocument.get(WriteDocumentFieldComponent.UPLOAD_TIMESTAMP)){
if (this.uploadedDocument.get(WriteDocumentFieldComponent.UPLOAD_TIMESTAMP)) {
this.uploadedDocument.removeControl(WriteDocumentFieldComponent.UPLOAD_TIMESTAMP);
}
}
Expand All @@ -261,7 +263,7 @@ export class WriteDocumentFieldComponent extends AbstractFieldWriteComponent imp
document_filename: new FormControl(document.document_filename, Validators.required)
};

if(document.upload_timestamp && (typeof document.upload_timestamp === 'string' )){
if (document.upload_timestamp && (typeof document.upload_timestamp === 'string')) {
documentFormGroup = {
...documentFormGroup,
...{ upload_timestamp: new FormControl(document.upload_timestamp) }
Expand All @@ -283,7 +285,7 @@ export class WriteDocumentFieldComponent extends AbstractFieldWriteComponent imp
document_filename: new FormControl(document.document_filename)
};

if(document.upload_timestamp && (typeof document.upload_timestamp === 'string' )){
if (document.upload_timestamp && (typeof document.upload_timestamp === 'string')) {
documentFormGroup = {
...documentFormGroup,
...{ upload_timestamp: new FormControl(document.upload_timestamp) }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,60 @@
<div class="form-group" [ngClass]="{'form-group-error bottom-30': !valid}">
<label [for]="id()">
<span class="form-label" attr.aria-label="{{caseField | ccdFieldLabel}}">{{(caseField | ccdFieldLabel)}}</span>
<span class="form-label" attr.aria-label="{{caseField | ccdFieldLabel}}"
>{{(caseField | ccdFieldLabel)}}</span
>
</label>
<span class="form-hint" *ngIf="caseField.hint_text">{{caseField.hint_text | rpxTranslate}}</span>
<span class="error-message" *ngIf="fileUploadMessages && !valid">{{fileUploadMessages | rpxTranslate}}</span>
<span class="form-hint" *ngIf="caseField.hint_text"
>{{caseField.hint_text | rpxTranslate}}</span
>
<span class="error-message" *ngIf="fileUploadMessages && !valid"
>{{fileUploadMessages | rpxTranslate}}</span
>

<div>
<!--<span *ngIf="getUploadedFileName()" class="text-16">File name: {{getUploadedFileName()}}</span>-->
<ccd-read-document-field *ngIf="caseField" [caseField]="caseField"></ccd-read-document-field>
<ccd-read-document-field
*ngIf="caseField"
[caseField]="caseField"
></ccd-read-document-field>
</div>

<div style='position:relative'>
<div [id]="createElementId('fileInputWrapper')" (click)="fileSelectEvent()" (keyup)="fileSelectEvent()"></div>
<input class="form-control bottom-30" [id]="id()" type="file" (keydown.Tab)="fileValidationsOnTab()" (change)="fileChangeEvent($event)"
accept="{{caseField.field_type.regular_expression}}" #fileInput/>
<div style="position: relative">
<div
[id]="createElementId('fileInputWrapper')"
(click)="fileSelectEvent()"
(keyup)="fileSelectEvent()"
></div>
<div class="upload-file-container">
<label
[for]="id()"
class="button button-secondary input-label"
aria-label="Choose file"
>{{'Choose file' | rpxTranslate}}</label
>
<span class="form-control bottom-30">
<span>{{fileName | rpxTranslate}}</span>
</span>
</div>
<input
[id]="id()"
type="file"
class="input-upload-file"
(keydown.Tab)="fileValidationsOnTab()"
(change)="fileChangeEvent($event)"
accept="{{caseField.field_type.regular_expression}}"
#fileInput
/>
</div>
</div>
<div class="form-group bottom-30">
<button class="button button-secondary" type="button" aria-label="Cancel upload" (click)="cancelUpload()" [disabled]="!isUploadInProgress()">{{'Cancel upload' | rpxTranslate}}</button>
<button
class="button button-secondary"
type="button"
aria-label="Cancel upload"
(click)="cancelUpload()"
[disabled]="!isUploadInProgress()"
>
{{'Cancel upload' | rpxTranslate}}
</button>
</div>

0 comments on commit b1468a7

Please sign in to comment.