11import * as React from 'react' ;
2- import { ResultTableProps , className , emptyQueryResultsMessage } from './result-table-utils' ;
2+ import { ResultTableProps , className , emptyQueryResultsMessage , jumpToLocation } from './result-table-utils' ;
33import { RAW_RESULTS_LIMIT , RawResultsSortState } from '../../pure/interface-types' ;
44import { RawTableResultSet } from '../../pure/interface-types' ;
55import RawTableHeader from './RawTableHeader' ;
66import RawTableRow from './RawTableRow' ;
77import { ResultRow } from '../../pure/bqrs-cli-types' ;
8+ import { NavigationEvent , onNavigation } from './results' ;
9+ import { tryGetResolvableLocation } from '../../pure/bqrs-utils' ;
810
911export type RawTableProps = ResultTableProps & {
1012 resultSet : RawTableResultSet ;
@@ -20,6 +22,7 @@ export class RawTable extends React.Component<RawTableProps, RawTableState> {
2022 constructor ( props : RawTableProps ) {
2123 super ( props ) ;
2224 this . setSelection = this . setSelection . bind ( this ) ;
25+ this . handleNavigationEvent = this . handleNavigationEvent . bind ( this ) ;
2326 this . state = { } ;
2427 }
2528
@@ -73,4 +76,53 @@ export class RawTable extends React.Component<RawTableProps, RawTableState> {
7376 </ tbody >
7477 </ table > ;
7578 }
79+
80+ private handleNavigationEvent ( event : NavigationEvent ) {
81+ switch ( event . t ) {
82+ case 'navigateAlert' : {
83+ this . setState ( prevState => {
84+ const numberOfAlerts = this . props . resultSet . rows . length ;
85+ if ( numberOfAlerts === 0 ) {
86+ return prevState ;
87+ }
88+ const currentRow = prevState . selectedItem ?. row ;
89+ const nextRow = currentRow === undefined
90+ ? 0
91+ : ( currentRow + event . direction ) ;
92+ if ( nextRow < 0 || nextRow >= numberOfAlerts ) {
93+ return prevState ;
94+ }
95+ const column = prevState . selectedItem ?. column ?? 0 ;
96+ // Jump to the location of the new cell
97+ const rowData = this . props . resultSet . rows [ nextRow ] ;
98+ if ( column < 0 || column >= rowData . length ) {
99+ return prevState ;
100+ }
101+ const cellData = rowData [ column ] ;
102+ if ( cellData != null && typeof cellData === 'object' ) {
103+ const location = tryGetResolvableLocation ( cellData . url ) ;
104+ if ( location !== undefined ) {
105+ jumpToLocation ( location , this . props . databaseUri ) ;
106+ }
107+ }
108+ return {
109+ ...prevState ,
110+ selectedItem : { row : nextRow , column }
111+ } ;
112+ } ) ;
113+ break ;
114+ }
115+ case 'navigatePath' : {
116+ break ; // No effect for the raw result view, as results can not have associated paths.
117+ }
118+ }
119+ }
120+
121+ componentDidMount ( ) {
122+ onNavigation . addListener ( this . handleNavigationEvent ) ;
123+ }
124+
125+ componentWillUnmount ( ) {
126+ onNavigation . removeListener ( this . handleNavigationEvent ) ;
127+ }
76128}
0 commit comments