Skip to content

Commit d8fcd35

Browse files
committed
fix: file utility updates attachments
1 parent a1d1398 commit d8fcd35

File tree

3 files changed

+34
-19
lines changed

3 files changed

+34
-19
lines changed

packages/react-sdk-components/src/components/field/SelectableCard/utils.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@ import { Link } from '@mui/material';
22

33
import { Utils } from '../../helpers/utils';
44

5-
export const getResolvedConstantValue = (pConnect, key) => {
6-
return pConnect.getValue(PCore.getResolvedConstantValue(key)) || pConnect.getValue(key);
7-
};
8-
95
export const resolveReferencedPConnect = pConnect => {
106
if (!pConnect || !pConnect.meta) return undefined;
117
const type = pConnect?._type ?? undefined;
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+
};

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

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,27 @@ import download from 'downloadjs';
77
// import SummaryList from '../../SummaryList';
88
// import ActionButtonsForFileUtil from '../ActionButtonsForFileUtil';
99
import './FileUtility.css';
10-
import { IconButton, Menu, MenuItem, Button, CircularProgress, Card } from '@mui/material';
10+
import { IconButton, Menu, MenuItem, Button, CircularProgress, Card, debounce } from '@mui/material';
1111
import MoreVertIcon from '@mui/icons-material/MoreVert';
1212

1313
import { validateMaxSize } from '../../../helpers/attachmentShared';
14+
import { getResolvedConstantValue } from '../../../helpers/object-utils';
1415
import { getComponentFromMap } from '../../../../bridge/helpers/sdk_component_map';
1516
import type { PConnProps } from '../../../../types/PConnProps';
1617

1718
interface FileUtilityProps extends PConnProps {
1819
// If any, enter additional props that only exist on this component
20+
caseId?: string;
1921
}
2022

2123
export default function FileUtility(props: FileUtilityProps) {
2224
// Get emitted components from map (so we can get any override that may exist)
2325
const SummaryList = getComponentFromMap('SummaryList');
2426
const ActionButtonsForFileUtil = getComponentFromMap('ActionButtonsForFileUtil');
2527

26-
const { getPConnect } = props;
28+
const { getPConnect, caseId } = props;
2729
const thePConn = getPConnect();
30+
const caseID = caseId ?? getResolvedConstantValue(thePConn, PCore.getConstants().CASE_INFO.CASE_INFO_ID);
2831
const required = true;
2932
const listTemp = {
3033
data: [],
@@ -210,7 +213,6 @@ export default function FileUtility(props: FileUtilityProps) {
210213

211214
const getAttachments = () => {
212215
const attachmentUtils = PCore.getAttachmentUtils();
213-
const caseID = thePConn.getValue(PCore.getConstants().CASE_INFO.CASE_INFO_ID, ''); // 2nd arg empty string until typedef marked correctly
214216

215217
if (caseID && caseID !== '') {
216218
const attPromise = attachmentUtils.getCaseAttachments(caseID, thePConn.getContextName());
@@ -245,25 +247,32 @@ export default function FileUtility(props: FileUtilityProps) {
245247
}
246248
};
247249

250+
const debouncedGetAttachments = debounce(getAttachments, 1000);
251+
248252
useEffect(() => {
249-
getAttachments();
253+
debouncedGetAttachments();
250254
}, []);
251255

252256
useEffect(() => {
253-
PCore.getPubSubUtils().subscribe(
254-
(PCore.getEvents().getCaseEvent() as any).CASE_ATTACHMENTS_UPDATED_FROM_CASEVIEW,
255-
getAttachments,
256-
'caseAttachmentsUpdateFromCaseview'
257-
);
258-
259-
return () => {
260-
PCore.getPubSubUtils().unsubscribe(
261-
(PCore.getEvents().getCaseEvent() as any).CASE_ATTACHMENTS_UPDATED_FROM_CASEVIEW,
262-
'caseAttachmentsUpdateFromCaseview'
263-
);
257+
const attachSubObject = {
258+
matcher: 'ATTACHMENTS',
259+
criteria: {
260+
ID: caseID
261+
}
262+
};
263+
const attachSubId = PCore.getMessagingServiceManager().subscribe(attachSubObject, debouncedGetAttachments, getPConnect().getContextName());
264+
265+
return function cleanup() {
266+
PCore.getMessagingServiceManager().unsubscribe(attachSubId);
264267
};
265268
}, []);
266269

270+
useEffect(() => {
271+
thePConn.registerAdditionalProps({
272+
lastRefreshTime: `@P ${PCore.getConstants().SUMMARY_OF_ATTACHMENTS_LAST_REFRESH_TIME}`
273+
});
274+
}, [thePConn]);
275+
267276
function setNewFiles(arFiles) {
268277
let index = 0;
269278
for (const file of arFiles) {

0 commit comments

Comments
 (0)