1- /*
2- * LogTable.js
3- *
4- * Handles the log viewing component.
5- */
1+ // src/LogTable.js
2+
63import React , { useState } from "react" ;
74import { useSortBy , useTable } from "react-table" ;
85import { FixedSizeList as List } from "react-window" ;
96import AutoSizer from "react-virtualized-auto-sizer" ;
107import _ from "lodash" ;
118
12- function Table ( {
13- columns,
14- data,
15- onSelectionChange,
16- listRef,
17- selectedRow,
18- centerOnLocation,
19- } ) {
20- const { getTableProps, getTableBodyProps, headerGroups, rows, prepareRow } =
21- useTable (
22- {
23- columns,
24- data,
25- autoResetSortBy : false ,
26- } ,
27- useSortBy
28- ) ;
9+ function Table ( { columns, data, onSelectionChange, listRef, selectedRow, centerOnLocation } ) {
10+ const { getTableProps, getTableBodyProps, headerGroups, rows, prepareRow } = useTable (
11+ {
12+ columns,
13+ data,
14+ autoResetSortBy : false ,
15+ } ,
16+ useSortBy
17+ ) ;
2918
3019 const handleRowSelection = React . useCallback (
3120 ( index , rowData ) => {
@@ -60,25 +49,13 @@ function Table({
6049 } ;
6150
6251 const handleLongPress = ( ) => {
63- const lat = _ . get (
64- row . original ,
65- "lastlocationResponse.rawlocation.latitude"
66- ) ;
67- const lng = _ . get (
68- row . original ,
69- "lastlocationResponse.rawlocation.longitude"
70- ) ;
52+ const lat = _ . get ( row . original , "lastlocationResponse.rawlocation.latitude" ) ;
53+ const lng = _ . get ( row . original , "lastlocationResponse.rawlocation.longitude" ) ;
7154 if ( lat && lng && centerOnLocation ) {
72- console . log (
73- "Calling centerOnLocation due to long press with:" ,
74- lat ,
75- lng
76- ) ;
55+ console . log ( "Calling centerOnLocation due to long press with:" , lat , lng ) ;
7756 centerOnLocation ( lat , lng ) ;
7857 } else {
79- console . log (
80- "Unable to center: Invalid coordinates or centerOnLocation not available"
81- ) ;
58+ console . log ( "Unable to center: Invalid coordinates or centerOnLocation not available" ) ;
8259 }
8360 } ;
8461
@@ -137,16 +114,11 @@ function Table({
137114 < div { ...getTableProps ( ) } >
138115 < div >
139116 { headerGroups . map ( ( headerGroup ) => (
140- < div
141- { ...headerGroup . getHeaderGroupProps ( ) }
142- className = "logtable-header-row"
143- >
117+ < div { ...headerGroup . getHeaderGroupProps ( ) } className = "logtable-header-row" >
144118 { headerGroup . headers . map ( ( column ) => (
145119 < div
146120 { ...column . getHeaderProps ( ) }
147- className = { `logtable-header-cell ${
148- column . className || ""
149- } `}
121+ className = { `logtable-header-cell ${ column . className || "" } ` }
150122 style = { { width : column . width } }
151123 >
152124 { column . render ( "Header" ) }
@@ -180,9 +152,7 @@ function LogTable(props) {
180152 const [ selectedRowIndex , setSelectedRowIndex ] = useState ( - 1 ) ;
181153 const minTime = props . timeRange . minTime ;
182154 const maxTime = props . timeRange . maxTime ;
183- const data = props . logData . tripLogs
184- . getLogs_ ( new Date ( minTime ) , new Date ( maxTime ) )
185- . value ( ) ;
155+ const data = props . logData . tripLogs . getLogs_ ( new Date ( minTime ) , new Date ( maxTime ) ) . value ( ) ;
186156 const columnShortWidth = 50 ;
187157 const columnRegularWidth = 120 ;
188158 const columnLargeWidth = 150 ;
@@ -192,21 +162,15 @@ function LogTable(props) {
192162 {
193163 Header : "DayTime" ,
194164 accessor : "formattedDate" ,
195- Cell : ( { cell : { value } } ) =>
196- value . substring ( 8 , 10 ) + "T" + value . substring ( 11 , 23 ) ,
165+ Cell : ( { cell : { value } } ) => value . substring ( 8 , 10 ) + "T" + value . substring ( 11 , 23 ) ,
197166 width : columnRegularWidth ,
198167 className : "logtable-cell" ,
199168 solutionTypes : [ "ODRD" , "LMFS" ] ,
200169 } ,
201170 {
202171 Header : "Method" ,
203172 accessor : "@type" ,
204- Cell : ( { cell : { value } } ) => (
205- < TrimCell
206- value = { value }
207- trim = "type.googleapis.com/maps.fleetengine."
208- />
209- ) ,
173+ Cell : ( { cell : { value } } ) => < TrimCell value = { value } trim = "type.googleapis.com/maps.fleetengine." /> ,
210174 width : columnRegularWidth ,
211175 className : "logtable-cell" ,
212176 solutionTypes : [ "ODRD" , "LMFS" ] ,
@@ -228,9 +192,7 @@ function LogTable(props) {
228192 Header : "Sensor" ,
229193 accessor : "lastlocation.rawlocationsensor" ,
230194 id : "lastlocation_rawlocationsensor" ,
231- Cell : ( { cell : { value } } ) => (
232- < TrimCell value = { value } trim = "LOCATION_SENSOR_" />
233- ) ,
195+ Cell : ( { cell : { value } } ) => < TrimCell value = { value } trim = "LOCATION_SENSOR_" /> ,
234196 width : columnShortWidth ,
235197 maxWidth : columnShortWidth ,
236198 className : "logtable-cell" ,
@@ -240,9 +202,7 @@ function LogTable(props) {
240202 Header : "Location" ,
241203 accessor : "lastlocation.locationsensor" ,
242204 id : "lastlocation_locationsensor" ,
243- Cell : ( { cell : { value } } ) => (
244- < TrimCell value = { value } trim = "_LOCATION_PROVIDER" />
245- ) ,
205+ Cell : ( { cell : { value } } ) => < TrimCell value = { value } trim = "_LOCATION_PROVIDER" /> ,
246206 width : columnRegularWidth ,
247207 className : "logtable-cell" ,
248208 solutionTypes : [ "ODRD" , "LMFS" ] ,
@@ -266,19 +226,15 @@ function LogTable(props) {
266226 Header : "Vehicle State" ,
267227 accessor : "response.vehiclestate" ,
268228 id : "response_vehiclestate" ,
269- Cell : ( { cell : { value } } ) => (
270- < TrimCell value = { value } trim = "VEHICLE_STATE_" />
271- ) ,
229+ Cell : ( { cell : { value } } ) => < TrimCell value = { value } trim = "VEHICLE_STATE_" /> ,
272230 width : columnRegularWidth ,
273231 className : "logtable-cell" ,
274232 solutionTypes : [ "ODRD" ] ,
275233 } ,
276234 {
277235 Header : "Task State" ,
278236 accessor : "response.state" ,
279- Cell : ( { cell : { value } } ) => (
280- < TrimCell value = { value } trim = "TASK_STATE_" />
281- ) ,
237+ Cell : ( { cell : { value } } ) => < TrimCell value = { value } trim = "TASK_STATE_" /> ,
282238 width : columnRegularWidth ,
283239 className : "logtable-cell" ,
284240 solutionTypes : [ "LMFS" ] ,
@@ -287,9 +243,7 @@ function LogTable(props) {
287243 Header : "Trip Status" ,
288244 accessor : "response.tripstatus" ,
289245 id : "response_tripstatus" ,
290- Cell : ( { cell : { value } } ) => (
291- < TrimCell value = { value } trim = "TRIP_STATUS_" />
292- ) ,
246+ Cell : ( { cell : { value } } ) => < TrimCell value = { value } trim = "TRIP_STATUS_" /> ,
293247 width : columnLargeWidth ,
294248 className : "logtable-cell" ,
295249 solutionTypes : [ "ODRD" ] ,
@@ -298,9 +252,7 @@ function LogTable(props) {
298252 Header : "Remaining tasks" ,
299253 id : "reamining_tasks" ,
300254 accessor : "response.remainingvehiclejourneysegments" ,
301- Cell : ( { cell : { value } } ) => (
302- < > { value && _ . sumBy ( value , "stop.tasks.length" ) } </ >
303- ) ,
255+ Cell : ( { cell : { value } } ) => < > { value && _ . sumBy ( value , "stop.tasks.length" ) } </ > ,
304256 width : columnRegularWidth ,
305257 className : "logtable-cell" ,
306258 solutionTypes : [ "LMFS" ] ,
@@ -323,9 +275,7 @@ function LogTable(props) {
323275 {
324276 Header : "Nav Status" ,
325277 accessor : "navStatus" ,
326- Cell : ( { cell : { value } } ) => (
327- < TrimCell value = { value } trim = "NAVIGATION_STATUS_" />
328- ) ,
278+ Cell : ( { cell : { value } } ) => < TrimCell value = { value } trim = "NAVIGATION_STATUS_" /> ,
329279 width : columnLargeWidth ,
330280 className : "logtable-cell" ,
331281 solutionTypes : [ "ODRD" , "LMFS" ] ,
@@ -348,8 +298,7 @@ function LogTable(props) {
348298 } ) ;
349299 const headers = [
350300 {
351- Header :
352- "Event Logs Table (click row to view full log entry and long click to also center map)" ,
301+ Header : "Event Logs Table (click row to view full log entry and long click to also center map)" ,
353302 columns : stdColumns ,
354303 } ,
355304 ] ;
@@ -367,9 +316,7 @@ function LogTable(props) {
367316 const focusOnRow = React . useCallback (
368317 ( rowData ) => {
369318 if ( rowData && listRef . current ) {
370- const rowIndex = data . findIndex (
371- ( row ) => row . timestamp === rowData . timestamp
372- ) ;
319+ const rowIndex = data . findIndex ( ( row ) => row . timestamp === rowData . timestamp ) ;
373320 if ( rowIndex !== - 1 ) {
374321 listRef . current . scrollToItem ( rowIndex , "center" ) ;
375322 setSelectedRowIndex ( rowIndex ) ;
@@ -404,6 +351,4 @@ const TrimCell = ({ value, trim }) => {
404351 return < > { value && value . replace ( trim , "" ) } </ > ;
405352} ;
406353
407- export default React . forwardRef ( ( props , ref ) => (
408- < LogTable { ...props } ref = { ref } />
409- ) ) ;
354+ export default React . forwardRef ( ( props , ref ) => < LogTable { ...props } ref = { ref } /> ) ;
0 commit comments