4
4
* License, v. 2.0. If a copy of the MPL was not distributed with this
5
5
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
6
*/
7
- import React , { memo , useCallback , useEffect , useState , useMemo , useRef } from 'react' ;
7
+ import React , { memo , useCallback , useEffect , useMemo , useRef , useState } from 'react' ;
8
8
import { useIntl } from 'react-intl' ;
9
9
import { CustomAGGrid } from '@gridsuite/commons-ui' ;
10
10
import { alpha , useTheme } from '@mui/material/styles' ;
@@ -15,13 +15,12 @@ import { getColumnFilterValue, useAggridRowFilter } from 'hooks/use-aggrid-row-f
15
15
import { LOGS_STORE_FIELD } from 'utils/store-sort-filter-fields' ;
16
16
import { useReportFetcher } from 'hooks/use-report-fetcher' ;
17
17
import { useDispatch } from 'react-redux' ;
18
- import { getDefaultSeverityFilter , orderSeverityList , REPORT_SEVERITY } from '../../utils/report/report-severity' ;
19
- import PropTypes from 'prop-types' ;
18
+ import { getDefaultSeverityFilter , getReportSeverities , REPORT_SEVERITY } from '../../utils/report/report-severity' ;
20
19
import { QuickSearch } from './QuickSearch' ;
21
20
import { Box , Chip , Theme } from '@mui/material' ;
22
21
import { CellClickedEvent , GridApi , ICellRendererParams , IRowNode , RowClassParams , RowStyle } from 'ag-grid-community' ;
23
22
import { AgGridReact } from 'ag-grid-react' ;
24
- import { ReportLog , ReportType , SeverityLevel } from 'utils/report/report.type' ;
23
+ import { Report , ReportLog , ReportType } from 'utils/report/report.type' ;
25
24
import { COMPUTING_AND_NETWORK_MODIFICATION_TYPE } from 'utils/report/report.constant' ;
26
25
import VisibilityOffIcon from '@mui/icons-material/VisibilityOff' ;
27
26
import VisibilityIcon from '@mui/icons-material/Visibility' ;
@@ -60,14 +59,14 @@ const styles = {
60
59
const SEVERITY_COLUMN_FIXED_WIDTH = 115 ;
61
60
62
61
type LogTableProps = {
62
+ report : Report ;
63
63
selectedReportId : string ;
64
64
reportType : string ;
65
65
reportNature : ReportType ;
66
- severities : SeverityLevel [ ] ;
67
66
onRowClick : ( data : ReportLog ) => void ;
68
67
} ;
69
68
70
- const LogTable = ( { selectedReportId, reportType, reportNature, severities , onRowClick } : LogTableProps ) => {
69
+ const LogTable = ( { report , selectedReportId, reportType, reportNature, onRowClick } : LogTableProps ) => {
71
70
const intl = useIntl ( ) ;
72
71
73
72
const theme = useTheme < Theme > ( ) ;
@@ -90,7 +89,7 @@ const LogTable = ({ selectedReportId, reportType, reportNature, severities, onRo
90
89
91
90
const severityFilter = useMemo ( ( ) => getColumnFilterValue ( filterSelector , 'severity' ) ?? [ ] , [ filterSelector ] ) ;
92
91
const messageFilter = useMemo ( ( ) => getColumnFilterValue ( filterSelector , 'message' ) , [ filterSelector ] ) ;
93
- const orderedSeverities = useMemo ( ( ) => orderSeverityList ( severities ) , [ severities ] ) ;
92
+ const severities = useMemo ( ( ) => getReportSeverities ( report ) , [ report ] ) ;
94
93
95
94
const resetSearch = useCallback ( ( ) => {
96
95
setSearchResults ( [ ] ) ;
@@ -118,10 +117,9 @@ const LogTable = ({ selectedReportId, reportType, reportNature, severities, onRo
118
117
setRowData ( transformedLogs ) ;
119
118
resetSearch ( ) ;
120
119
} ) ;
121
- } , [ fetchReportLogs , messageFilter , reportNature , severityFilter , selectedReportId , resetSearch ] ) ;
120
+ } , [ severityFilter , fetchReportLogs , selectedReportId , reportNature , messageFilter , resetSearch ] ) ;
122
121
123
122
useEffect ( ( ) => {
124
- // initialize the filter with the severities
125
123
if ( filterSelector ?. length === 0 && severities ?. length > 0 ) {
126
124
dispatch (
127
125
setLogsFilter ( reportType , [
@@ -134,19 +132,13 @@ const LogTable = ({ selectedReportId, reportType, reportNature, severities, onRo
134
132
] )
135
133
) ;
136
134
}
135
+ } , [ severities , dispatch , reportType , filterSelector ] ) ;
136
+
137
+ useEffect ( ( ) => {
137
138
if ( selectedReportId && reportNature ) {
138
139
refreshLogsOnSelectedReport ( ) ;
139
140
}
140
- } , [
141
- dispatch ,
142
- filterSelector ?. length ,
143
- refreshLogsOnSelectedReport ,
144
- reportNature ,
145
- reportType ,
146
- selectedReportId ,
147
- severities ,
148
- updateFilter ,
149
- ] ) ;
141
+ } , [ refreshLogsOnSelectedReport , reportNature , selectedReportId ] ) ;
150
142
151
143
const COLUMNS_DEFINITIONS = useMemo (
152
144
( ) => [
@@ -328,7 +320,7 @@ const LogTable = ({ selectedReportId, reportType, reportNature, severities, onRo
328
320
/>
329
321
</ Box >
330
322
< Box sx = { styles . chipContainer } >
331
- { orderedSeverities . map ( ( severity , index ) => (
323
+ { severities . map ( ( severity , index ) => (
332
324
< Chip
333
325
key = { severity }
334
326
label = { severity }
@@ -354,12 +346,4 @@ const LogTable = ({ selectedReportId, reportType, reportNature, severities, onRo
354
346
) ;
355
347
} ;
356
348
357
- LogTable . propTypes = {
358
- selectedReportId : PropTypes . string ,
359
- reportType : PropTypes . string ,
360
- reportNature : PropTypes . string ,
361
- severities : PropTypes . arrayOf ( PropTypes . string ) ,
362
- onRowClick : PropTypes . func ,
363
- } ;
364
-
365
349
export default memo ( LogTable ) ;
0 commit comments