@@ -7,24 +7,27 @@ import download from 'downloadjs';
77// import SummaryList from '../../SummaryList';
88// import ActionButtonsForFileUtil from '../ActionButtonsForFileUtil';
99import './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' ;
1111import MoreVertIcon from '@mui/icons-material/MoreVert' ;
1212
1313import { validateMaxSize } from '../../../helpers/attachmentShared' ;
14+ import { getResolvedConstantValue } from '../../../helpers/object-utils' ;
1415import { getComponentFromMap } from '../../../../bridge/helpers/sdk_component_map' ;
1516import type { PConnProps } from '../../../../types/PConnProps' ;
1617
1718interface FileUtilityProps extends PConnProps {
1819 // If any, enter additional props that only exist on this component
20+ caseId ?: string ;
1921}
2022
2123export 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