@@ -38,6 +38,7 @@ import {TagsDisplay, ViewEditTags} from '../../MythicComponents/MythicTag';
38
38
import SettingsIcon from '@mui/icons-material/Settings' ;
39
39
import { toLocalTime } from '../../utilities/Time' ;
40
40
import ListSubheader from '@mui/material/ListSubheader' ;
41
+ import { b64DecodeUnicode } from "./ResponseDisplay" ;
41
42
42
43
43
44
const getPermissionsDataQuery = gql `
@@ -49,8 +50,8 @@ const getPermissionsDataQuery = gql`
49
50
}
50
51
` ;
51
52
const getFileDownloadHistory = gql `
52
- query getFileDownloadHistory($mythictree_id: Int! ) {
53
- mythictree_by_pk(id: $mythictree_id ) {
53
+ query getFileDownloadHistory($full_path_text: String!, $host: String!, $group: [String!] ) {
54
+ mythictree(where: {tree_type: {_eq: "file"}, full_path_text: {_eq: $full_path_text}, host: {_eq: $host}, callback: {mythictree_groups: {_contains: $group}}} ) {
54
55
filemeta {
55
56
id
56
57
comment
@@ -59,6 +60,8 @@ const getFileDownloadHistory = gql`
59
60
complete
60
61
total_chunks
61
62
timestamp
63
+ filename_text
64
+ full_remote_path_text
62
65
task {
63
66
id
64
67
display_id
@@ -302,6 +305,38 @@ export const CallbacksTabsFileBrowserTable = (props) => {
302
305
} ;
303
306
const FileBrowserTableRowNameCell = ( { cellData, rowData, treeRootData, selectedFolderData } ) => {
304
307
const theme = useTheme ( ) ;
308
+ const [ downloadHistory , setDownloadHistory ] = React . useState ( [ ] ) ;
309
+ const [ fileHistoryDialogOpen , setFileHistoryDialogOpen ] = React . useState ( false ) ;
310
+ const [ getHistory ] = useLazyQuery ( getFileDownloadHistory , {
311
+ onCompleted : ( data ) => {
312
+ if ( data . mythictree . length === 0 ) {
313
+ snackActions . warning ( 'No download history recorded' ) ;
314
+ } else {
315
+ let files = [ ] ;
316
+ for ( let i = 0 ; i < data . mythictree . length ; i ++ ) {
317
+ files . push ( ...data . mythictree [ i ] . filemeta ) ;
318
+ }
319
+ if ( files . length === 0 ) {
320
+ snackActions . warning ( 'No download history recorded' ) ;
321
+ return ;
322
+ }
323
+ files = files . map ( f => {
324
+ return { ...f , filename_text : b64DecodeUnicode ( f . filename_text ) ,
325
+ full_remote_path_text : b64DecodeUnicode ( f . full_remote_path_text ) }
326
+ } ) ;
327
+ setDownloadHistory ( files ) ;
328
+ setFileHistoryDialogOpen ( true ) ;
329
+ }
330
+ } ,
331
+ fetchPolicy : 'network-only' ,
332
+ } ) ;
333
+ const onGetHistory = ( ) => {
334
+ getHistory ( { variables : {
335
+ full_path_text : treeRootData [ selectedFolderData . host ] [ cellData ] . full_path_text ,
336
+ host : selectedFolderData . host ,
337
+ group : [ selectedFolderData . group ] ,
338
+ } } ) ;
339
+ }
305
340
return (
306
341
< div style = { { alignItems : 'center' , display : 'flex' , maxHeight : "100%" , textDecoration : treeRootData [ selectedFolderData . host ] [ cellData ] ?. deleted ? 'line-through' : '' } } >
307
342
{ ! treeRootData [ selectedFolderData . host ] [ cellData ] ?. can_have_children ? (
@@ -319,7 +354,28 @@ const FileBrowserTableRowNameCell = ({cellData, rowData, treeRootData, selected
319
354
} }
320
355
/>
321
356
) }
322
- { treeRootData [ selectedFolderData . host ] [ cellData ] ?. filemeta . length > 0 ? < GetAppIcon color = "success" /> : null }
357
+ { treeRootData [ selectedFolderData . host ] [ cellData ] ?. filemeta . length > 0 ?
358
+ < GetAppIcon onClick = { onGetHistory } style = { { cursor : "pointer" } } color = "success" />
359
+ : null }
360
+ { fileHistoryDialogOpen && (
361
+ < MythicDialog
362
+ fullWidth = { true }
363
+ maxWidth = 'xl'
364
+ open = { fileHistoryDialogOpen }
365
+ onClose = { ( ) => {
366
+ setFileHistoryDialogOpen ( false ) ;
367
+ } }
368
+ innerDialog = {
369
+ < DownloadHistoryDialog
370
+ title = 'Download History'
371
+ value = { downloadHistory }
372
+ onClose = { ( ) => {
373
+ setFileHistoryDialogOpen ( false ) ;
374
+ } }
375
+ />
376
+ }
377
+ />
378
+ ) }
323
379
< pre
324
380
style = { {
325
381
color :
@@ -434,11 +490,22 @@ const FileBrowserTableRowActionCell = ({ rowData, cellData, onTaskRowAction, tre
434
490
} ) ;
435
491
const [ getHistory ] = useLazyQuery ( getFileDownloadHistory , {
436
492
onCompleted : ( data ) => {
437
- //console.log(data);
438
- if ( data . mythictree_by_pk . filemeta . length === 0 ) {
493
+ if ( data . mythictree . length === 0 ) {
439
494
snackActions . warning ( 'No download history recorded' ) ;
440
495
} else {
441
- setDownloadHistory ( data . mythictree_by_pk . filemeta ) ;
496
+ let files = [ ] ;
497
+ for ( let i = 0 ; i < data . mythictree . length ; i ++ ) {
498
+ files . push ( ...data . mythictree [ i ] . filemeta ) ;
499
+ }
500
+ if ( files . length === 0 ) {
501
+ snackActions . warning ( 'No download history recorded' ) ;
502
+ return ;
503
+ }
504
+ files = files . map ( f => {
505
+ return { ...f , filename_text : b64DecodeUnicode ( f . filename_text ) ,
506
+ full_remote_path_text : b64DecodeUnicode ( f . full_remote_path_text ) }
507
+ } ) ;
508
+ setDownloadHistory ( files ) ;
442
509
setFileHistoryDialogOpen ( true ) ;
443
510
}
444
511
} ,
@@ -497,7 +564,11 @@ const FileBrowserTableRowActionCell = ({ rowData, cellData, onTaskRowAction, tre
497
564
icon : < HistoryIcon style = { { paddingRight : '5px' } } /> ,
498
565
click : ( evt , callback_id , callback_display_id ) => {
499
566
evt . stopPropagation ( ) ;
500
- getHistory ( { variables : { mythictree_id : treeRootData [ selectedFolderData . host ] [ cellData ] . id } } ) ;
567
+ getHistory ( { variables : {
568
+ full_path_text : treeRootData [ selectedFolderData . host ] [ cellData ] . full_path_text ,
569
+ host : selectedFolderData . host ,
570
+ group : [ selectedFolderData . group ] ,
571
+ } } ) ;
501
572
} ,
502
573
} ,
503
574
{
@@ -690,7 +761,7 @@ const FileBrowserTableRowActionCell = ({ rowData, cellData, onTaskRowAction, tre
690
761
{ fileHistoryDialogOpen && (
691
762
< MythicDialog
692
763
fullWidth = { true }
693
- maxWidth = 'md '
764
+ maxWidth = 'xl '
694
765
open = { fileHistoryDialogOpen }
695
766
onClose = { ( ) => {
696
767
setFileHistoryDialogOpen ( false ) ;
0 commit comments