From 2039ec475d981cdee2e28d059f93d496d89c284c Mon Sep 17 00:00:00 2001 From: tammy Date: Fri, 26 Dec 2025 15:14:33 +0530 Subject: [PATCH 1/3] fix: Redux to update files properly after removing from UI --- .../_components/widget/attachment/AttachmentUtils.ts | 8 +------- .../widget/attachment/attachment.component.ts | 12 ++++++------ 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/packages/angular-sdk-components/src/lib/_components/widget/attachment/AttachmentUtils.ts b/packages/angular-sdk-components/src/lib/_components/widget/attachment/AttachmentUtils.ts index 08799459..981537b7 100644 --- a/packages/angular-sdk-components/src/lib/_components/widget/attachment/AttachmentUtils.ts +++ b/packages/angular-sdk-components/src/lib/_components/widget/attachment/AttachmentUtils.ts @@ -126,8 +126,7 @@ export const updateReduxState = ( valueRef: string, options: PageInstructionOptions ) => { - const { allowMultiple, isOldAttachment, insertRedux, deleteRedux } = options; - let deleteIndex = -1; + const { allowMultiple, isOldAttachment, insertRedux, deleteRedux, deleteIndex } = options; if (allowMultiple || isOldAttachment) { transformedAttachments.forEach(attachment => { @@ -147,11 +146,6 @@ export const updateReduxState = ( }; PCore.getStore()?.dispatch(actionPayLoad); } else if (deleteRedux) { - const uniqueKey = getMappedValue('pzInsKey'); - deleteIndex = existingAttachments.findIndex( - existingAttachment => - existingAttachment[uniqueKey as keyof ReduxAttachments] === transformedAttachments[0][uniqueKey as keyof ReduxAttachments] - ); const actionPayLoad = { type: 'LIST_ACTION', payload: { diff --git a/packages/angular-sdk-components/src/lib/_components/widget/attachment/attachment.component.ts b/packages/angular-sdk-components/src/lib/_components/widget/attachment/attachment.component.ts index 92808c70..5c6cdd1f 100644 --- a/packages/angular-sdk-components/src/lib/_components/widget/attachment/attachment.component.ts +++ b/packages/angular-sdk-components/src/lib/_components/widget/attachment/attachment.component.ts @@ -339,6 +339,12 @@ export class AttachmentComponent implements OnInit, OnDestroy { populateErrorAndUpdateRedux(file) { const fieldName = (this.pConn$.getStateProps() as any).value; + insertAttachments([file], this.pConn$, this.multiAttachmentsInInlineEdit, { + allowMultiple: this.allowMultiple$, + isOldAttachment: this.isOldAttachment, + isMultiAttachmentInInlineEditTable: this.isMultiAttachmentInInlineEditTable, + attachmentCount: this.attachmentCount + } as any); // set errors to property to block submit even on errors in file upload PCore.getMessageManager().addMessages({ messages: [ @@ -351,12 +357,6 @@ export class AttachmentComponent implements OnInit, OnDestroy { pageReference: this.pConn$.getPageReference(), context: this.contextName }); - insertAttachments([file], this.pConn$, this.multiAttachmentsInInlineEdit, { - allowMultiple: this.allowMultiple$, - isOldAttachment: this.isOldAttachment, - isMultiAttachmentInInlineEditTable: this.isMultiAttachmentInInlineEditTable, - attachmentCount: this.attachmentCount - } as any); } errorHandler(isFetchCanceled, file) { From e8b13cf421b67f7c5172299a81370022f8cef351 Mon Sep 17 00:00:00 2001 From: Siva Rama Krishna Date: Fri, 26 Dec 2025 20:44:39 +0530 Subject: [PATCH 2/3] fix: improve attachment handling and state updates in AttachmentComponent --- .../widget/attachment/AttachmentUtils.ts | 8 +++++++- .../widget/attachment/attachment.component.ts | 16 +++++++++------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/packages/angular-sdk-components/src/lib/_components/widget/attachment/AttachmentUtils.ts b/packages/angular-sdk-components/src/lib/_components/widget/attachment/AttachmentUtils.ts index 981537b7..08799459 100644 --- a/packages/angular-sdk-components/src/lib/_components/widget/attachment/AttachmentUtils.ts +++ b/packages/angular-sdk-components/src/lib/_components/widget/attachment/AttachmentUtils.ts @@ -126,7 +126,8 @@ export const updateReduxState = ( valueRef: string, options: PageInstructionOptions ) => { - const { allowMultiple, isOldAttachment, insertRedux, deleteRedux, deleteIndex } = options; + const { allowMultiple, isOldAttachment, insertRedux, deleteRedux } = options; + let deleteIndex = -1; if (allowMultiple || isOldAttachment) { transformedAttachments.forEach(attachment => { @@ -146,6 +147,11 @@ export const updateReduxState = ( }; PCore.getStore()?.dispatch(actionPayLoad); } else if (deleteRedux) { + const uniqueKey = getMappedValue('pzInsKey'); + deleteIndex = existingAttachments.findIndex( + existingAttachment => + existingAttachment[uniqueKey as keyof ReduxAttachments] === transformedAttachments[0][uniqueKey as keyof ReduxAttachments] + ); const actionPayLoad = { type: 'LIST_ACTION', payload: { diff --git a/packages/angular-sdk-components/src/lib/_components/widget/attachment/attachment.component.ts b/packages/angular-sdk-components/src/lib/_components/widget/attachment/attachment.component.ts index 5c6cdd1f..0a77aae4 100644 --- a/packages/angular-sdk-components/src/lib/_components/widget/attachment/attachment.component.ts +++ b/packages/angular-sdk-components/src/lib/_components/widget/attachment/attachment.component.ts @@ -159,11 +159,12 @@ export class AttachmentComponent implements OnInit, OnDestroy { const rawValue = this.pConn$.getComponentConfig().value; const isAttachmentAnnotationPresent = typeof rawValue === 'object' ? false : rawValue?.includes('@ATTACHMENT'); const { attachments, isOldAttachment } = isAttachmentAnnotationPresent ? value : PCore.getAttachmentUtils().prepareAttachmentData(value); + const isAttachmentsChanged = !PCore.isDeepEqual(this.attachments, attachments); // JSON.stringify(this.attachments) !== JSON.stringify(attachments); this.isOldAttachment = isOldAttachment; this.attachments = attachments; // update the attachments shown in the UI - if (this.attachments.length) { + if (isAttachmentsChanged) { this.updateAttachments(); } } @@ -339,12 +340,6 @@ export class AttachmentComponent implements OnInit, OnDestroy { populateErrorAndUpdateRedux(file) { const fieldName = (this.pConn$.getStateProps() as any).value; - insertAttachments([file], this.pConn$, this.multiAttachmentsInInlineEdit, { - allowMultiple: this.allowMultiple$, - isOldAttachment: this.isOldAttachment, - isMultiAttachmentInInlineEditTable: this.isMultiAttachmentInInlineEditTable, - attachmentCount: this.attachmentCount - } as any); // set errors to property to block submit even on errors in file upload PCore.getMessageManager().addMessages({ messages: [ @@ -357,6 +352,12 @@ export class AttachmentComponent implements OnInit, OnDestroy { pageReference: this.pConn$.getPageReference(), context: this.contextName }); + insertAttachments([file], this.pConn$, this.multiAttachmentsInInlineEdit, { + allowMultiple: this.allowMultiple$, + isOldAttachment: this.isOldAttachment, + isMultiAttachmentInInlineEditTable: this.isMultiAttachmentInInlineEditTable, + attachmentCount: this.attachmentCount + } as any); } errorHandler(isFetchCanceled, file) { @@ -421,6 +422,7 @@ export class AttachmentComponent implements OnInit, OnDestroy { fileResponses[index].value.thumbnail = localFile.props.thumbnail; localFile.inProgress = false; localFile.ID = fileResponses[index].value.ID; + localFile.props.id = fileResponses[index].value.ID; localFile.props.meta = this.localizationService.getLocalizedText('Uploaded successfully'); localFile.props.progress = 100; localFile.handle = fileResponses[index].value.ID; From f4b8d9d77ced3d5ea28c9368465c0f5671a6283e Mon Sep 17 00:00:00 2001 From: Siva Rama Krishna Date: Fri, 26 Dec 2025 20:46:46 +0530 Subject: [PATCH 3/3] fix: streamline attachment change detection logic in AttachmentComponent --- .../lib/_components/widget/attachment/attachment.component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/angular-sdk-components/src/lib/_components/widget/attachment/attachment.component.ts b/packages/angular-sdk-components/src/lib/_components/widget/attachment/attachment.component.ts index 0a77aae4..0ab18f1f 100644 --- a/packages/angular-sdk-components/src/lib/_components/widget/attachment/attachment.component.ts +++ b/packages/angular-sdk-components/src/lib/_components/widget/attachment/attachment.component.ts @@ -159,7 +159,7 @@ export class AttachmentComponent implements OnInit, OnDestroy { const rawValue = this.pConn$.getComponentConfig().value; const isAttachmentAnnotationPresent = typeof rawValue === 'object' ? false : rawValue?.includes('@ATTACHMENT'); const { attachments, isOldAttachment } = isAttachmentAnnotationPresent ? value : PCore.getAttachmentUtils().prepareAttachmentData(value); - const isAttachmentsChanged = !PCore.isDeepEqual(this.attachments, attachments); // JSON.stringify(this.attachments) !== JSON.stringify(attachments); + const isAttachmentsChanged = !PCore.isDeepEqual(this.attachments, attachments); this.isOldAttachment = isOldAttachment; this.attachments = attachments;