-
Notifications
You must be signed in to change notification settings - Fork 4
[NAE-2416] AbstractFileDefaultFieldComponent does not push upload event #326
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: release/7.0.0-rev10
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,8 @@ import {DATA_FIELD_PORTAL_DATA, DataFieldPortalData} from "../../models/data-fie | |
| import {FILE_FIELD_HEIGHT, FILE_FIELD_PADDING, PREVIEW, PREVIEW_BUTTON} from '../models/file-field-constants'; | ||
| import {FileFieldRequest} from "../../../resources/interface/file-field-request-body"; | ||
| import {AbstractFileFieldDefaultComponent} from '../../models/abstract-file-field-default-component'; | ||
| import {FrontAction} from "../../models/changed-fields"; | ||
| import {FrontActionService} from "../../../actions/services/front-action.service"; | ||
|
|
||
| export interface FileState { | ||
| progress: number; | ||
|
|
@@ -114,6 +116,7 @@ export abstract class AbstractFileDefaultFieldComponent extends AbstractFileFiel | |
| protected _translate: TranslateService, | ||
| protected _eventService: EventService, | ||
| protected _sanitizer: DomSanitizer, | ||
| protected _frontActionService: FrontActionService, | ||
| @Optional() @Inject(DATA_FIELD_PORTAL_DATA) dataFieldPortalData: DataFieldPortalData<FileField>) { | ||
| super(_log, _snackbar, _translate, dataFieldPortalData); | ||
| this.state = this.defaultState; | ||
|
|
@@ -217,60 +220,68 @@ export abstract class AbstractFileDefaultFieldComponent extends AbstractFileFiel | |
| fileFormData.append('file', fileToUpload); | ||
| fileFormData.append('data', new Blob([JSON.stringify(this.createRequestBody())], {type: 'application/json'})); | ||
| this._taskResourceService.uploadFile(this.taskId, fileFormData, false) | ||
| .subscribe((response: EventOutcomeMessageResource) => { | ||
| if ((response as ProviderProgress).type && (response as ProviderProgress).type === ProgressType.UPLOAD) { | ||
| this.state.progress = (response as ProviderProgress).progress; | ||
| } else { | ||
| this.state.completed = true; | ||
| this.state.uploading = false; | ||
| this.state.progress = 0; | ||
| .subscribe({ | ||
| next: (response: EventOutcomeMessageResource) => { | ||
| if ((response as ProviderProgress).type && (response as ProviderProgress).type === ProgressType.UPLOAD) { | ||
| this.state.progress = (response as ProviderProgress).progress; | ||
| } else { | ||
| this.state.completed = true; | ||
| this.state.uploading = false; | ||
| this.state.progress = 0; | ||
|
|
||
| if (response.error) { | ||
| this.state.error = true; | ||
| this._log.error( | ||
| `File [${this.dataField.stringId}] ${this.fileUploadEl.nativeElement.files.item(0)} uploading has failed!`, response.error | ||
| ); | ||
| if (response.error) { | ||
| this._snackbar.openErrorSnackBar(this._translate.instant(response.error)); | ||
| this.state.error = true; | ||
| this._log.error( | ||
| `File [${this.dataField.stringId}] ${this.fileUploadEl.nativeElement.files.item(0)} uploading has failed!`, response.error | ||
| ); | ||
| if (response.error) { | ||
| this._snackbar.openErrorSnackBar(this._translate.instant(response.error)); | ||
| } else { | ||
| this._snackbar.openErrorSnackBar(this._translate.instant('dataField.snackBar.fileUploadFailed')); | ||
| } | ||
|
Comment on lines
232
to
+241
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dead code: inner Line 232 already guards 🛠️ Proposed fix if (response.error) {
this.state.error = true;
this._log.error(
`File [${this.dataField.stringId}] ${this.fileUploadEl.nativeElement.files.item(0)} uploading has failed!`, response.error
);
- if (response.error) {
- this._snackbar.openErrorSnackBar(this._translate.instant(response.error));
- } else {
- this._snackbar.openErrorSnackBar(this._translate.instant('dataField.snackBar.fileUploadFailed'));
- }
+ this._snackbar.openErrorSnackBar(this._translate.instant(response.error));
} else {🤖 Prompt for AI Agents |
||
| } else { | ||
| this._snackbar.openErrorSnackBar(this._translate.instant('dataField.snackBar.fileUploadFailed')); | ||
| const changedFieldsMap: ChangedFieldsMap = this._eventService.parseChangedFieldsFromOutcomeTree(response.outcome); | ||
| this.dataField.emitChangedFields(changedFieldsMap); | ||
| this._log.debug( | ||
| `File [${this.dataField.stringId}] ${this.fileUploadEl.nativeElement.files.item(0).name} was successfully uploaded` | ||
| ); | ||
| this.state.error = false; | ||
| this.dataField.downloaded = false; | ||
| this.dataField.value.name = fileToUpload.name; | ||
| if (this.isFilePreview) { | ||
| this.initializePreviewIfDisplayable(); | ||
| } | ||
| this.fullSource.next(undefined); | ||
| this.fileForDownload = undefined; | ||
| this.formControlRef.setValue(this.dataField.value.name); | ||
| this._snackbar.openSuccessSnackBar(!!response.outcome.message ? response.outcome.message : this._translate.instant('tasks.snackbar.dataSaved')); | ||
| const frontActions: Array<FrontAction> = this._eventService.parseFrontActionsFromOutcomeTree(response.outcome); | ||
| if (frontActions?.length > 0) { | ||
| this._frontActionService.runAll(frontActions); | ||
| } | ||
|
Comment on lines
+258
to
+261
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Confirm the service still dereferences fn unconditionally.
rg -nP -C3 'public\s+run\s*\(' --type=ts -g '**/front-action.service.ts'
# And check parseFrontActionsFromOutcomeTree return contract.
ast-grep --pattern 'parseFrontActionsFromOutcomeTree($_) { $$$ }'Repository: netgrif/components Length of output: 891 🏁 Script executed: # Get the full implementation of the run() method and surrounding context
cat -n projects/netgrif-components-core/src/lib/actions/services/front-action.service.ts | head -30Repository: netgrif/components Length of output: 1156 🏁 Script executed: # Also check the runAll() method to understand the call pattern
rg -nP -A 10 'runAll\s*\(' --type=ts -g '**/front-action.service.ts'Repository: netgrif/components Length of output: 596 🏁 Script executed: # Check the context around the runAll call in the file-field component
rg -nP -B5 -A5 'runAll\s*\(' --type=ts -g '**/abstract-file-default-field.component.ts'Repository: netgrif/components Length of output: 2295 Fix unhandled TypeError when unregistered action IDs are in upload outcome. In 🤖 Prompt for AI Agents |
||
| } | ||
| this.dataField.touch = true; | ||
| this.dataField.update(); | ||
| this.fileUploadEl.nativeElement.value = ''; | ||
| } | ||
| }, | ||
| error: (error) => { | ||
| this.state.completed = true; | ||
| this.state.error = true; | ||
| this.state.uploading = false; | ||
| this.state.progress = 0; | ||
| this._log.error( | ||
| `File [${this.dataField.stringId}] ${this.fileUploadEl.nativeElement.files.item(0)} uploading has failed!`, error | ||
| ); | ||
| if (error?.error?.message) { | ||
| this._snackbar.openErrorSnackBar(this._translate.instant(error.error.message)); | ||
| } else { | ||
| const changedFieldsMap: ChangedFieldsMap = this._eventService.parseChangedFieldsFromOutcomeTree(response.outcome); | ||
| this.dataField.emitChangedFields(changedFieldsMap); | ||
| this._log.debug( | ||
| `File [${this.dataField.stringId}] ${this.fileUploadEl.nativeElement.files.item(0).name} was successfully uploaded` | ||
| ); | ||
| this.state.error = false; | ||
| this.dataField.downloaded = false; | ||
| this.dataField.value.name = fileToUpload.name; | ||
| if (this.isFilePreview) { | ||
| this.initializePreviewIfDisplayable(); | ||
| } | ||
| this.fullSource.next(undefined); | ||
| this.fileForDownload = undefined; | ||
| this.formControlRef.setValue(this.dataField.value.name); | ||
| this._snackbar.openErrorSnackBar(this._translate.instant('dataField.snackBar.fileUploadFailed')); | ||
| } | ||
| this.dataField.touch = true; | ||
| this.dataField.update(); | ||
| this.fileUploadEl.nativeElement.value = ''; | ||
| } | ||
| }, error => { | ||
| this.state.completed = true; | ||
| this.state.error = true; | ||
| this.state.uploading = false; | ||
| this.state.progress = 0; | ||
| this._log.error( | ||
| `File [${this.dataField.stringId}] ${this.fileUploadEl.nativeElement.files.item(0)} uploading has failed!`, error | ||
| ); | ||
| if (error?.error?.message) { | ||
| this._snackbar.openErrorSnackBar(this._translate.instant(error.error.message)); | ||
| } else { | ||
| this._snackbar.openErrorSnackBar(this._translate.instant('dataField.snackBar.fileUploadFailed')); | ||
| } | ||
| this.dataField.touch = true; | ||
| this.dataField.update(); | ||
| this.fileUploadEl.nativeElement.value = ''; | ||
| }); | ||
| } | ||
|
|
||
|
|
@@ -410,7 +421,8 @@ export abstract class AbstractFileDefaultFieldComponent extends AbstractFileFiel | |
| this.state.downloading = true; | ||
| let params = new HttpParams() | ||
| params = params.set("fieldId", this.dataField.stringId); | ||
| this._taskResourceService.downloadFilePreview(this.resolveParentTaskId(), params).subscribe(response => { if (response instanceof Blob) { | ||
| this._taskResourceService.downloadFilePreview(this.resolveParentTaskId(), params).subscribe(response => { | ||
| if (response instanceof Blob) { | ||
| this._log.debug(`Preview of file [${this.dataField.stringId}] ${this.dataField.value.name} was successfully downloaded`); | ||
| this.fileForPreview = new Blob([response], {type: 'application/octet-stream'}); | ||
| this.previewSource = this._sanitizer.bypassSecurityTrustUrl(URL.createObjectURL(this.fileForPreview)); | ||
|
|
@@ -445,7 +457,8 @@ export abstract class AbstractFileDefaultFieldComponent extends AbstractFileFiel | |
| } | ||
| let params = new HttpParams(); | ||
| params = params.set("fieldId", this.dataField.stringId); | ||
| this._taskResourceService.downloadFile(this.resolveParentTaskId(), params).subscribe(response => { if (!(response as ProviderProgress).type || (response as ProviderProgress).type !== ProgressType.DOWNLOAD) { | ||
| this._taskResourceService.downloadFile(this.resolveParentTaskId(), params).subscribe(response => { | ||
| if (!(response as ProviderProgress).type || (response as ProviderProgress).type !== ProgressType.DOWNLOAD) { | ||
| this._log.debug(`File [${this.dataField.stringId}] ${this.dataField.value.name} was successfully downloaded`); | ||
| this.initDownloadFile(response); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error logs print File object instead of file name.
this.fileUploadEl.nativeElement.files.item(0)returns aFilereference that renders as[object File]in most log sinks; the success-path log at line 246 correctly uses.name. Make the failure logs consistent so operators can identify which file failed.🛠️ Proposed fix
Also applies to: 273-275
🤖 Prompt for AI Agents