Skip to content

Commit 98b9e68

Browse files
Merge pull request #161 from pegasystems/bug/tor/BUG-811139
Fix Attachments not working on 8.23 hence the Pipeline
2 parents 998e8f1 + 61076c2 commit 98b9e68

File tree

1 file changed

+16
-12
lines changed
  • packages/react-sdk-components/src/components/widget/Attachment

1 file changed

+16
-12
lines changed

packages/react-sdk-components/src/components/widget/Attachment/Attachment.tsx

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,15 @@ import download from "downloadjs";
1111
// Remove this and use "real" PCore type once .d.ts is fixed (currently shows 2 errors)
1212
declare const PCore: any;
1313

14-
function getCurrentAttachmentsList(context) {
15-
return PCore.getStoreValue('.attachmentsList', 'context_data', context) || [];
14+
15+
const getAttachmentKey = (name='') => name ? `attachmentsList.${name}` : 'attachmentsList';
16+
17+
function getCurrentAttachmentsList(key, context) {
18+
return PCore.getStoreValue(`.${key}`, 'context_data', context) || [];
1619
}
1720

1821
export default function Attachment(props) {
22+
const PCoreVersion = PCore.getPCoreVersion();
1923
const {value, getPConnect, label, validatemessage} = props;
2024
/* this is a temporary fix because required is supposed to be passed as a boolean and NOT as a string */
2125
let { required, disabled } = props;
@@ -37,7 +41,7 @@ export default function Attachment(props) {
3741
const [file, setFile] = useState(fileTemp);
3842

3943
const resetAttachmentStoredState = () => {
40-
PCore.getStateUtils().updateState(pConn.getContextName(), 'attachmentsList', undefined, {
44+
PCore.getStateUtils().updateState(pConn.getContextName(), getAttachmentKey(PCoreVersion?.includes('8.23') ? valueRef : ''), undefined, {
4145
pageReference: 'context_data',
4246
isArrayDeepMerge: false
4347
});
@@ -213,7 +217,7 @@ export default function Attachment(props) {
213217
)
214218
.then((fileRes) => {
215219
let reqObj;
216-
if (PCore.getPCoreVersion()?.includes('8.7')) {
220+
if (PCoreVersion?.includes('8.7')) {
217221
reqObj = {
218222
type: "File",
219223
attachmentFieldName: valueRef,
@@ -229,12 +233,12 @@ export default function Attachment(props) {
229233
handle: fileRes.ID,
230234
ID: fileRes.clientFileID
231235
};
232-
const currentAttachmentList = getCurrentAttachmentsList(pConn.getContextName()).filter(
236+
const currentAttachmentList = getCurrentAttachmentsList( getAttachmentKey(PCoreVersion?.includes('8.23') ? valueRef : ''), pConn.getContextName()).filter(
233237
(f) => f.label !== valueRef
234238
);
235239
PCore.getStateUtils().updateState(
236240
pConn.getContextName(),
237-
'attachmentsList',
241+
getAttachmentKey(PCoreVersion?.includes('8.23') ? valueRef : ''),
238242
[...currentAttachmentList, reqObj],
239243
{
240244
pageReference: 'context_data',
@@ -285,7 +289,7 @@ export default function Attachment(props) {
285289
function _removeFileFromList(item: any, list) {
286290
const arFileList = file.props ? file.props.arFileList$ : list;
287291
const fileIndex = arFileList.findIndex(element => element?.id === item?.id);
288-
if (PCore.getPCoreVersion()?.includes('8.7')) {
292+
if (PCoreVersion?.includes('8.7')) {
289293
if (value) {
290294
pConn.attachmentsInfo = {
291295
type: "File",
@@ -305,7 +309,7 @@ export default function Attachment(props) {
305309
});
306310
} else {
307311
const attachmentsList = [];
308-
const currentAttachmentList = getCurrentAttachmentsList(pConn.getContextName()).filter(
312+
const currentAttachmentList = getCurrentAttachmentsList( getAttachmentKey(PCoreVersion?.includes('8.23') ? valueRef : ''), pConn.getContextName()).filter(
309313
(f) => f.label !== valueRef
310314
);
311315
if (value && value.pxResults && +value.pyCount > 0) {
@@ -320,7 +324,7 @@ export default function Attachment(props) {
320324
// updating the redux store to help form-handler in passing the data to delete the file from server
321325
PCore.getStateUtils().updateState(
322326
pConn.getContextName(),
323-
'attachmentsList',
327+
getAttachmentKey(PCoreVersion?.includes('8.23') ? valueRef : ''),
324328
[...currentAttachmentList, deletedFile],
325329
{
326330
pageReference: 'context_data',
@@ -330,7 +334,7 @@ export default function Attachment(props) {
330334
} else {
331335
PCore.getStateUtils().updateState(
332336
pConn.getContextName(),
333-
'attachmentsList',
337+
getAttachmentKey(PCoreVersion?.includes('8.23') ? valueRef : ''),
334338
[...currentAttachmentList, ...attachmentsList],
335339
{
336340
pageReference: 'context_data',
@@ -407,15 +411,15 @@ export default function Attachment(props) {
407411
}
408412

409413
if (fileTemp) {
410-
const currentAttachmentList = getCurrentAttachmentsList(pConn.getContextName());
414+
const currentAttachmentList = getCurrentAttachmentsList( getAttachmentKey(PCoreVersion?.includes('8.23') ? valueRef : ''), pConn.getContextName());
411415
const index = currentAttachmentList.findIndex(element => element.props.ID === fileTemp.props.ID);
412416
let tempFiles: any = [];
413417
if (index < 0) {
414418
tempFiles = [fileTemp];
415419
}
416420
PCore.getStateUtils().updateState(
417421
pConn.getContextName(),
418-
'attachmentsList',
422+
getAttachmentKey(PCoreVersion?.includes('8.23') ? valueRef : ''),
419423
[...currentAttachmentList, ...tempFiles],
420424
{
421425
pageReference: 'context_data',

0 commit comments

Comments
 (0)