1
1
import Grid from '@mui/material/Grid' ;
2
- import React from 'react' ;
2
+ import makeStyles from '@mui/styles/makeStyles' ;
3
+ import React , { useRef } from 'react' ;
3
4
import { useFragment } from 'react-relay' ;
5
+ import Typography from '@mui/material/Typography' ;
6
+ import Paper from '@mui/material/Paper' ;
7
+ import useHelper from 'src/utils/hooks/useHelper' ;
4
8
import { convertMarkings } from '../../../../utils/edition' ;
5
9
import { KNOWLEDGE_KNUPDATE } from '../../../../utils/hooks/useGranted' ;
10
+ import useQueryLoading from '../../../../utils/hooks/useQueryLoading' ;
6
11
import Security from '../../../../utils/Security' ;
7
12
import StixCoreObjectExternalReferences from '../../analyses/external_references/StixCoreObjectExternalReferences' ;
8
13
import StixCoreObjectOrStixCoreRelationshipNotes from '../../analyses/notes/StixCoreObjectOrStixCoreRelationshipNotes' ;
9
14
import ContainerStixObjectsOrStixRelationships from '../../common/containers/ContainerStixObjectsOrStixRelationships' ;
10
15
import StixCoreObjectLatestHistory from '../../common/stix_core_objects/StixCoreObjectLatestHistory' ;
11
16
import StixDomainObjectOverview from '../../common/stix_domain_objects/StixDomainObjectOverview' ;
12
17
import { CaseUtils_case$key } from '../__generated__/CaseUtils_case.graphql' ;
13
- import CaseTasksLines from '../tasks/CaseTasksLines' ;
18
+ import CaseTasksLines , { caseTasksLinesQuery } from '../tasks/CaseTasksLines' ;
14
19
import { caseFragment } from '../CaseUtils' ;
15
20
import CaseRfiDetails from './CaseRfiDetails' ;
16
21
import CaseRfiEdition from './CaseRfiEdition' ;
17
22
import { useFormatter } from '../../../../components/i18n' ;
18
- import useHelper from '../../../../utils/hooks/useHelper' ;
23
+ import { usePaginationLocalStorage } from '../../../../utils/hooks/useLocalStorage' ;
24
+ import { CaseTasksLinesQuery , CaseTasksLinesQuery$variables } from '../tasks/__generated__/CaseTasksLinesQuery.graphql' ;
25
+ import ListLines from '../../../../components/list_lines/ListLines' ;
26
+ import { tasksDataColumns } from '../tasks/TasksLine' ;
27
+ import { CaseTasksLineDummy } from '../tasks/CaseTasksLine' ;
28
+ import { isFilterGroupNotEmpty , useRemoveIdAndIncorrectKeysFromFilterGroupObject } from '../../../../utils/filters/filtersUtils' ;
29
+ import { FilterGroup } from '../../../../utils/filters/filtersHelpers-types' ;
19
30
import useOverviewLayoutCustomization from '../../../../utils/hooks/useOverviewLayoutCustomization' ;
20
- import { useGetCurrentUserAccessRight } from '../../../../utils/authorizedMembers' ;
31
+
32
+ // Deprecated - https://mui.com/system/styles/basics/
33
+ // Do not use it for new code.
34
+ const useStyles = makeStyles ( ( ) => ( {
35
+ paper : {
36
+ margin : '10px 0 0 0' ,
37
+ padding : 0 ,
38
+ borderRadius : 4 ,
39
+ } ,
40
+ } ) ) ;
21
41
22
42
interface CaseRfiProps {
23
43
caseRfiData : CaseUtils_case$key ;
24
44
enableReferences : boolean ;
25
45
}
26
46
27
47
const CaseRfi : React . FC < CaseRfiProps > = ( { caseRfiData, enableReferences } ) => {
48
+ const classes = useStyles ( ) ;
28
49
const { t_i18n } = useFormatter ( ) ;
50
+ const ref = useRef ( null ) ;
29
51
const caseRfi = useFragment ( caseFragment , caseRfiData ) ;
30
52
const { isFeatureEnable } = useHelper ( ) ;
31
53
const isFABReplaced = isFeatureEnable ( 'FAB_REPLACEMENT' ) ;
32
- const { canEdit } = useGetCurrentUserAccessRight ( caseRfi . currentUserAccessRight ) ;
33
54
const overviewLayoutCustomization = useOverviewLayoutCustomization ( caseRfi . entity_type ) ;
34
55
56
+ const LOCAL_STORAGE_KEY = `cases-${ caseRfi . id } -caseTask` ;
57
+ const { viewStorage, helpers, paginationOptions } = usePaginationLocalStorage < CaseTasksLinesQuery$variables > (
58
+ LOCAL_STORAGE_KEY ,
59
+ {
60
+ searchTerm : '' ,
61
+ sortBy : 'name' ,
62
+ orderAsc : true ,
63
+ } ,
64
+ ) ;
65
+ const { sortBy, orderAsc, filters } = viewStorage ;
66
+
67
+ const userFilters = useRemoveIdAndIncorrectKeysFromFilterGroupObject ( filters , [ 'Case-Rfi' ] ) ;
68
+ const contextTaskFilters : FilterGroup = {
69
+ mode : 'and' ,
70
+ filters : [
71
+ { key : 'entity_type' , operator : 'eq' , mode : 'or' , values : [ 'Task' ] } ,
72
+ { key : 'objects' , operator : 'eq' , mode : 'or' , values : [ caseRfi . id ] } ,
73
+ ] ,
74
+ filterGroups : userFilters && isFilterGroupNotEmpty ( userFilters ) ? [ userFilters ] : [ ] ,
75
+ } ;
76
+
77
+ const queryTaskPaginationOptions = {
78
+ ...paginationOptions ,
79
+ filters : contextTaskFilters ,
80
+ } as unknown as CaseTasksLinesQuery$variables ;
81
+ const queryRef = useQueryLoading < CaseTasksLinesQuery > (
82
+ caseTasksLinesQuery ,
83
+ queryTaskPaginationOptions ,
84
+ ) ;
35
85
return (
36
86
< >
37
87
< Grid
38
- container
88
+ container = { true }
39
89
spacing = { 3 }
40
90
style = { { marginBottom : 20 } }
41
91
>
@@ -60,12 +110,51 @@ const CaseRfi: React.FC<CaseRfiProps> = ({ caseRfiData, enableReferences }) => {
60
110
) ;
61
111
case 'task' :
62
112
return (
63
- < Grid key = { key } item xs = { width } >
64
- < CaseTasksLines
65
- caseId = { caseRfi . id }
66
- defaultMarkings = { convertMarkings ( caseRfi ) }
67
- enableReferences = { enableReferences }
68
- />
113
+ < Grid key = { key } item xs = { width } ref = { ref } >
114
+ { queryRef && (
115
+ < React . Suspense
116
+ fallback = {
117
+ < div style = { { height : '100%' } } >
118
+ < Typography
119
+ variant = "h4"
120
+ gutterBottom = { true }
121
+ style = { { marginBottom : 10 } }
122
+ >
123
+ { t_i18n ( 'Tasks' ) }
124
+ </ Typography >
125
+ < Paper classes = { { root : classes . paper } } variant = "outlined" >
126
+ < ListLines
127
+ helpers = { helpers }
128
+ sortBy = { sortBy }
129
+ orderAsc = { orderAsc }
130
+ handleSort = { helpers . handleSort }
131
+ dataColumns = { tasksDataColumns }
132
+ inline = { true }
133
+ secondaryAction = { true }
134
+ >
135
+ { Array ( 20 )
136
+ . fill ( 0 )
137
+ . map ( ( _ , idx ) => (
138
+ < CaseTasksLineDummy key = { idx } />
139
+ ) ) }
140
+ </ ListLines >
141
+ </ Paper >
142
+ </ div >
143
+ }
144
+ >
145
+ < CaseTasksLines
146
+ queryRef = { queryRef }
147
+ paginationOptions = { queryTaskPaginationOptions }
148
+ caseId = { caseRfi . id }
149
+ sortBy = { sortBy }
150
+ orderAsc = { orderAsc }
151
+ handleSort = { helpers . handleSort }
152
+ defaultMarkings = { convertMarkings ( caseRfi ) }
153
+ containerRef = { ref }
154
+ enableReferences = { enableReferences }
155
+ />
156
+ </ React . Suspense >
157
+ ) }
69
158
</ Grid >
70
159
) ;
71
160
case 'originOfTheCase' :
@@ -134,7 +223,7 @@ const CaseRfi: React.FC<CaseRfiProps> = ({ caseRfiData, enableReferences }) => {
134
223
}
135
224
</ Grid >
136
225
{ ! isFABReplaced && (
137
- < Security needs = { [ KNOWLEDGE_KNUPDATE ] } hasAccess = { canEdit } >
226
+ < Security needs = { [ KNOWLEDGE_KNUPDATE ] } >
138
227
< CaseRfiEdition caseId = { caseRfi . id } />
139
228
</ Security >
140
229
) }
0 commit comments