1
- import React , { useEffect , useState } from 'react' ;
1
+ import React , { useMemo } from 'react' ;
2
2
import { useSimpleTabularView , NoData } from '@opensrp/react-utils' ;
3
3
import { RouteComponentProps } from 'react-router' ;
4
4
import {
7
7
URL_LOCATION_UNIT_ADD ,
8
8
} from '../../constants' ;
9
9
import { BrokenPage , TableLayout , PageHeader , SearchForm } from '@opensrp/react-utils' ;
10
- import { Dictionary } from '@onaio/utils' ;
11
10
import { Helmet } from 'react-helmet' ;
12
11
import { useTranslation } from '../../mls' ;
13
12
import { Row , Col , Button , Divider , Dropdown } from 'antd' ;
@@ -45,8 +44,6 @@ export const AllLocationListFlat: React.FC<LocationListPropTypes> = (props) => {
45
44
const { fhirBaseURL } = props ;
46
45
const { t } = useTranslation ( ) ;
47
46
const history = useHistory ( ) ;
48
- const [ _ , setDetailId ] = useState < string > ( ) ;
49
- const [ tableData , setTableData ] = useState < Dictionary < string > [ ] > ( [ ] ) ;
50
47
51
48
const {
52
49
queryValues : { data, isFetching, isLoading, error } ,
@@ -59,23 +56,21 @@ export const AllLocationListFlat: React.FC<LocationListPropTypes> = (props) => {
59
56
getEntryFromBundle
60
57
) ;
61
58
62
- useEffect ( ( ) => {
63
- const updatedTableData = getTableData ( data ?. records ?? [ ] ) ;
64
- setTableData ( updatedTableData ) ;
65
- } , [ data ] ) ;
59
+ const tableData = useMemo ( ( ) => getTableData ( data ?. records ?? [ ] ) , [ data ] ) ;
66
60
67
61
if ( error && ! data ) {
68
62
return < BrokenPage errorMessage = { ( error as Error ) . message } /> ;
69
63
}
70
64
71
65
type TableData = typeof tableData [ 0 ] ;
72
66
73
- const getItems = ( record : TableData ) : MenuProps [ 'items' ] => {
67
+ const getItems = ( _ : TableData ) : MenuProps [ 'items' ] => {
68
+ // Todo: replace _ above when handling onClick
74
69
return [
75
70
{
76
71
key : '1' ,
77
72
label : (
78
- < Button disabled type = "link" onClick = { ( ) => setDetailId ( record . id ) } >
73
+ < Button disabled type = "link" >
79
74
{ t ( 'View details' ) }
80
75
</ Button >
81
76
) ,
@@ -145,7 +140,7 @@ export const AllLocationListFlat: React.FC<LocationListPropTypes> = (props) => {
145
140
if ( ! tableData . length && ( ! isFetching || ! isLoading ) ) {
146
141
const description = nameSearchActive
147
142
? ''
148
- : t ( 'No data available to display, you can start adding data now ' ) ;
143
+ : t ( 'No data available to display, you can start adding data now' ) ;
149
144
return {
150
145
emptyText : (
151
146
< NoData description = { description } > { ! nameSearchActive && < AddLocationBtn /> } </ NoData >
0 commit comments