Skip to content

Commit 98aa453

Browse files
authored
fix: attachments list is not getting updated in file utility (#405)
1 parent 971993f commit 98aa453

File tree

2 files changed

+34
-8
lines changed

2 files changed

+34
-8
lines changed

packages/angular-sdk-components/src/lib/_components/widget/file-utility/file-utility.component.ts

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,17 @@ import { MatButtonModule } from '@angular/material/button';
44
import { MatInputModule } from '@angular/material/input';
55
import { MatFormFieldModule } from '@angular/material/form-field';
66
import download from 'downloadjs';
7+
import debounce from 'lodash.debounce';
8+
79
import { AngularPConnectData, AngularPConnectService } from '../../../_bridge/angular-pconnect';
810
import { Utils } from '../../../_helpers/utils';
911
import { ComponentMapperComponent } from '../../../_bridge/component-mapper/component-mapper.component';
12+
import { getResolvedConstantValue } from '../../../_helpers/object-utils';
1013

1114
interface FileUtilityProps {
1215
// If any, enter additional props that only exist on this component
1316
label?: string;
17+
caseId?: string;
1418
}
1519

1620
@Component({
@@ -62,6 +66,8 @@ export class FileUtilityComponent implements OnInit, OnDestroy {
6266
closeSvgIcon$ = '';
6367

6468
currentCaseID = '';
69+
debouncedGetAttachments: any;
70+
attachSubId;
6571

6672
addAttachmentsActions: any;
6773

@@ -77,7 +83,9 @@ export class FileUtilityComponent implements OnInit, OnDestroy {
7783

7884
const configProps: FileUtilityProps = this.pConn$.resolveConfigProps(this.pConn$.getConfigProps());
7985

80-
this.lu_name$ = configProps.label ?? '';
86+
const { caseId, label } = configProps;
87+
88+
this.lu_name$ = label ?? '';
8189
this.lu_icon$ = 'paper-clip';
8290

8391
this.closeSvgIcon$ = this.utils.getImageSrc('times', this.utils.getSDKStaticContentUrl());
@@ -100,23 +108,31 @@ export class FileUtilityComponent implements OnInit, OnDestroy {
100108
this.removeFileFromList$ = { onClick: this.removeFileFromList.bind(this) };
101109
this.removeLinksFromList$ = { onClick: this.removeLinksFromList.bind(this) };
102110

111+
this.debouncedGetAttachments = debounce(this.refreshAttachments.bind(this), 1000);
112+
103113
this.updateSelf();
104114

105115
this.createModalButtons();
106116

107-
PCore.getPubSubUtils().subscribe(
108-
PCore.getEvents().getCaseEvent().CASE_ATTACHMENTS_UPDATED_FROM_CASEVIEW,
109-
this.updateSelf.bind(this),
110-
'caseAttachmentsUpdateFromCaseview'
111-
);
117+
const caseID = caseId ?? getResolvedConstantValue(this.pConn$, PCore.getConstants().CASE_INFO.CASE_INFO_ID);
118+
119+
const attachSubObject = {
120+
matcher: 'ATTACHMENTS',
121+
criteria: {
122+
ID: caseID
123+
}
124+
};
125+
this.attachSubId = PCore.getMessagingServiceManager().subscribe(attachSubObject, this.debouncedGetAttachments, this.pConn$.getContextName());
126+
127+
this.debouncedGetAttachments();
112128
}
113129

114130
ngOnDestroy(): void {
115131
if (this.angularPConnectData.unsubscribeFn) {
116132
this.angularPConnectData.unsubscribeFn();
117133
}
118134

119-
PCore.getPubSubUtils().unsubscribe(PCore.getEvents().getCaseEvent().CASE_ATTACHMENTS_UPDATED_FROM_CASEVIEW, 'caseAttachmentsUpdateFromCaseview');
135+
PCore.getMessagingServiceManager().unsubscribe(this.attachSubId);
120136
}
121137

122138
// Callback passed when subscribing to store change
@@ -136,7 +152,7 @@ export class FileUtilityComponent implements OnInit, OnDestroy {
136152
}
137153
}
138154

139-
onAttachFiles(files) {
155+
onAttachFiles(files: any[] = []) {
140156
const attachmentUtils = PCore.getAttachmentUtils();
141157
const caseID = this.pConn$.getValue(PCore.getConstants().CASE_INFO.CASE_INFO_ID);
142158

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* Returns the value of the key from objectInfo/caseInfo
3+
* Added fallback to retrieve from caseInfo if objectInfo not present.
4+
* @param pConnect
5+
* @param key
6+
* @returns the value of key
7+
*/
8+
export const getResolvedConstantValue = (pConnect: typeof PConnect, key: string) => {
9+
return pConnect.getValue(PCore.getResolvedConstantValue(key)) || pConnect.getValue(key);
10+
};

0 commit comments

Comments
 (0)