11import React , { useState , useEffect , useRef } from 'react'
22import SortableTable from '../Widgets/SortableTable'
33import { formNameFromRule } from '../../Services/Ufixit'
4- import InfoIcon from '../Icons/FilledInfoIcon '
4+ import InfoPopover from '../Widgets/InfoPopover '
55import './IssuesTable.css'
66
77export default function IssuesTable ( {
@@ -33,13 +33,6 @@ export default function IssuesTable({
3333 } )
3434 const [ localIssues , setLocalIssues ] = useState ( [ ] )
3535 const [ rows , setRows ] = useState ( [ ] )
36- const [ popover , setPopover ] = useState ( { open : false , content : '' , x : 0 , y : 0 } ) ;
37- const popoverContentRef = useRef ( null ) ;
38- const lastButtonRef = useRef ( null ) ;
39- const [ ariaLive , setAriaLive ] = useState ( '' ) ;
40- const closeButtonRef = useRef ( null ) ;
41-
42- const dialogRef = useRef ( null ) ;
4336
4437 const sortContent = ( ) => {
4538 let tempRows = ( issues ) ? Object . values ( localIssues ) : [ ]
@@ -49,7 +42,6 @@ export default function IssuesTable({
4942 let aValue = a [ sortBy ]
5043 let bValue = b [ sortBy ]
5144
52- // If sorting by label, use labelText for comparison
5345 if ( sortBy === "label" ) {
5446 aValue = a . labelText || ""
5547 bValue = b . labelText || ""
@@ -77,31 +69,6 @@ export default function IssuesTable({
7769 setRows ( sortContent ( ) )
7870 } , [ tableSettings , localIssues ] )
7971
80- useEffect ( ( ) => {
81- if ( popover . open && dialogRef . current ) {
82- if ( ! dialogRef . current . open ) {
83- dialogRef . current . showModal ( ) ;
84- }
85- if ( closeButtonRef . current ) {
86- closeButtonRef . current . focus ( ) ;
87- }
88- setAriaLive ( popover . content ) ;
89-
90- const close = ( ) => setPopover ( p => ( { ...p , open : false } ) ) ;
91- window . addEventListener ( 'click' , close ) ;
92- return ( ) => window . removeEventListener ( 'click' , close ) ;
93- } else if ( dialogRef . current && dialogRef . current . open ) {
94- dialogRef . current . close ( ) ;
95- }
96- } , [ popover . open , popover . content ] ) ;
97-
98- // When popover closes, return focus to the last info button
99- useEffect ( ( ) => {
100- if ( ! popover . open && lastButtonRef . current ) {
101- lastButtonRef . current . focus ( ) ;
102- }
103- } , [ popover . open ] ) ;
104-
10572 useEffect ( ( ) => {
10673 if ( issues ) {
10774 let tempIssues = Object . values ( issues )
@@ -121,31 +88,10 @@ export default function IssuesTable({
12188 issue . label = (
12289 < span className = "issue-label" >
12390 { label }
124- < button
125- type = "button"
126- title = { t ( 'report.button.issue_tooltip' ) }
127- aria-haspopup = "dialog"
128- aria-expanded = { popover . open }
129- aria-controls = { popover . open ? "issue-info-popover" : undefined }
130- className = "issue-info-btn"
131- ref = { el => {
132- if ( popover . open ) return ;
133- lastButtonRef . current = el ;
134- } }
135- onClick = { e => {
136- e . stopPropagation ( ) ;
137- const rect = e . target . getBoundingClientRect ( ) ;
138- setPopover ( {
139- open : true ,
140- content : t ( `form.${ formName } .summary` ) ,
141- x : rect . right + window . scrollX + 8 ,
142- y : rect . top + window . scrollY - 120 ,
143- } ) ;
144- lastButtonRef . current = e . target ;
145- } }
146- >
147- < InfoIcon width = { 18 } height = { 18 } className = "icon-info" circleColor = "var(--link-color)" iconColor = "#fff" />
148- </ button >
91+ < InfoPopover
92+ t = { t }
93+ content = { t ( `form.${ formName } .summary` ) }
94+ />
14995 </ span >
15096 )
15197 issue . summary = t ( `form.${ formName } .summary` )
@@ -155,7 +101,6 @@ export default function IssuesTable({
155101 return issue
156102 } ) )
157103
158- // Merge the issues with the same labels
159104 let mergedIssues = [ ]
160105 let labels = [ ]
161106 tempIssues . forEach ( ( issue ) => {
@@ -197,42 +142,6 @@ export default function IssuesTable({
197142 handleTableSettings = { handleTableSettings }
198143 t = { t }
199144 />
200- { /* ARIA for screen readers */ }
201- < div aria-live = "polite" className = "sr-only" >
202- { ariaLive }
203- </ div >
204- { popover . open && (
205- < dialog
206- id = "issue-info-popover"
207- ref = { dialogRef }
208- className = "issue-info-popover"
209- style = { {
210- left : popover . x ,
211- top : popover . y ,
212- } }
213- tabIndex = { 0 }
214- aria-labelledby = "issue-info-popover-title"
215- aria-describedby = "issue-info-popover-content"
216- onClick = { e => e . stopPropagation ( ) }
217- >
218- < div
219- id = "issue-info-popover-content"
220- className = "issue-info-popover-content"
221- tabIndex = { - 1 }
222- ref = { popoverContentRef }
223- >
224- { popover . content }
225- </ div >
226- < button
227- type = "button"
228- className = "issue-info-popover-close"
229- ref = { closeButtonRef }
230- onClick = { ( ) => setPopover ( { ...popover , open : false } ) }
231- >
232- { t ( 'fix.button.close_learn_more' ) }
233- </ button >
234- </ dialog >
235- ) }
236145 </ >
237146 )
238147}
0 commit comments