11import React , { useState , useEffect , useRef } from 'react'
22import SortableTable from '../Widgets/SortableTable'
3- import { formNameFromRule } from '../../Services/Ufixit'
4- import InfoPopover from '../Widgets/InfoPopover'
53import './IssuesTable.css'
64
75export default function IssuesTable ( {
86 t,
97 issues,
10- quickSearchTerm = null ,
118 isAdmin,
129 selectedCourse
1310} ) {
@@ -30,20 +27,19 @@ export default function IssuesTable({
3027 ascending : false ,
3128 pageNum : 0 ,
3229 } )
33- const [ localIssues , setLocalIssues ] = useState ( [ ] )
3430 const [ rows , setRows ] = useState ( [ ] )
3531
3632 const sortContent = ( ) => {
37- let tempRows = ( issues ) ? Object . values ( localIssues ) : [ ]
33+ let tempRows = ( issues ) ? Object . values ( issues ) : [ ]
3834 const { sortBy, ascending } = tableSettings
3935
4036 tempRows . sort ( ( a , b ) => {
4137 let aValue = a [ sortBy ]
4238 let bValue = b [ sortBy ]
4339
44- if ( sortBy === "label " ) {
45- aValue = a . labelText || ""
46- bValue = b . labelText || ""
40+ if ( typeof ( aValue ) === "object" && typeof ( bValue ) === "object ") {
41+ aValue = a [ sortBy + "_display" ] || ""
42+ bValue = b [ sortBy + "_display" ] || ""
4743 }
4844
4945 if ( isNaN ( aValue ) || isNaN ( bValue ) ) {
@@ -66,70 +62,7 @@ export default function IssuesTable({
6662
6763 useEffect ( ( ) => {
6864 setRows ( sortContent ( ) )
69- } , [ tableSettings , localIssues ] )
70-
71- useEffect ( ( ) => {
72- if ( issues ) {
73- let tempIssues = Object . values ( issues )
74- tempIssues . map ( ( issue => {
75- let label = ''
76- let searchTerm = ''
77- let formName = formNameFromRule ( issue . id )
78- if ( formName === 'review_only' ) {
79- label = t ( 'report.label.unhandled' ) + issue . id
80- searchTerm = issue . id
81- }
82- else {
83- label = t ( `form.${ formName } .title` )
84- searchTerm = t ( `form.${ formName } .title` )
85- }
86- issue . labelText = label
87- issue . label = (
88- < span className = "issue-label" >
89- { label }
90- < InfoPopover
91- t = { t }
92- content = { t ( `form.${ formName } .summary` ) }
93- />
94- </ span >
95- )
96- issue . summary = t ( `form.${ formName } .summary` )
97- if ( quickSearchTerm !== null ) {
98- issue . onClick = ( ) => quickSearchTerm ( searchTerm )
99- }
100- return issue
101- } ) )
102-
103- let mergedIssues = [ ]
104- let labels = [ ]
105- tempIssues . forEach ( ( issue ) => {
106- if ( ! labels . includes ( issue . label ) ) {
107- labels . push ( issue . label )
108- if ( issue . type === 'error' || issue . type === 'issue' ) {
109- issue . type = t ( 'filter.label.severity.issue' )
110- }
111- else if ( issue . type === 'potential' ) {
112- issue . type = t ( 'filter.label.severity.potential' )
113- }
114- else if ( issue . type === 'suggestion' ) {
115- issue . type = t ( 'filter.label.severity.suggestion' )
116- }
117- issue . handled = ( issue . fixed + issue . resolved > 0 ? 1 : 0 )
118- mergedIssues . push ( issue )
119- }
120- else {
121- let index = mergedIssues . findIndex ( ( i ) => i . label === issue . label )
122- mergedIssues [ index ] . total += issue . total
123- mergedIssues [ index ] . active += issue . active
124- mergedIssues [ index ] . handled += ( issue . fixed + issue . resolved > 0 ? 1 : 0 )
125- }
126- } )
127- setLocalIssues ( mergedIssues )
128- }
129- else {
130- setLocalIssues ( [ ] )
131- }
132- } , [ issues ] )
65+ } , [ tableSettings , issues ] )
13366
13467 return (
13568 < >
0 commit comments