Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions src/pages/ocotillo/thing/well-show.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
useShow,
useNavigation,
useList,
useInfiniteList,
} from '@refinedev/core'
import { useParams } from 'react-router-dom'
import { Breadcrumb, CreateButton, Show, useDataGrid } from '@refinedev/mui'
Expand Down Expand Up @@ -108,6 +109,22 @@
]
}, [])

const { isLoading: transducerIsLoading,
fetchNextPage,
hasNextPage,
data: transducerData } = useInfiniteList({
resource: 'observation/transducer-groundwater-level',
dataProviderName: 'ocotillo',
meta: {
params: {
thing_id: id,
},
},
pagination: {
pageSize: 10000,
},
})

const { dataGridProps: observationDataGridProps } = useDataGrid({
resource: 'observation/groundwater-level',
dataProviderName: 'ocotillo',
Expand Down Expand Up @@ -183,6 +200,34 @@
setHydrographDatasource(source)
}, [observations])

useEffect(() => {
console.log('transducerData', transducerData)

if (!transducerData || transducerData.pages.length === 0) return
if (transducerIsLoading) return
if (hasNextPage) {
fetchNextPage()
return
}

const allTransducerRows = transducerData.pages.flatMap(page => page.data) ?? []
console.log('allTransducerRows', allTransducerRows)
const source: IHydrographDatasource[] =
{
id: 2,

Check failure on line 217 in src/pages/ocotillo/thing/well-show.tsx

View workflow job for this annotation

GitHub Actions / Check Production Build

Object literal may only specify known properties, and 'id' does not exist in type 'IHydrographDatasource[]'.

Check failure on line 217 in src/pages/ocotillo/thing/well-show.tsx

View workflow job for this annotation

GitHub Actions / integration-tests

Object literal may only specify known properties, and 'id' does not exist in type 'IHydrographDatasource[]'.
name: 'Transducer',
style: 'line',
data:
allTransducerRows.map((obs) => ({
phenomenonTime: new Date(obs.observation.observation_datetime),
result: Number(obs.observation.value),
})) || [],
}
console.log('source', source)
setHydrographDatasource((prevState)=> [...prevState, source])

Check failure on line 227 in src/pages/ocotillo/thing/well-show.tsx

View workflow job for this annotation

GitHub Actions / Check Production Build

Argument of type '(prevState: IHydrographDatasource[]) => (IHydrographDatasource | IHydrographDatasource[])[]' is not assignable to parameter of type 'SetStateAction<IHydrographDatasource[]>'.

Check failure on line 227 in src/pages/ocotillo/thing/well-show.tsx

View workflow job for this annotation

GitHub Actions / integration-tests

Argument of type '(prevState: IHydrographDatasource[]) => (IHydrographDatasource | IHydrographDatasource[])[]' is not assignable to parameter of type 'SetStateAction<IHydrographDatasource[]>'.
Comment on lines +215 to +227
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P0 Badge Assign correct type when creating transducer datasource

The transducer useEffect declares const source: IHydrographDatasource[] = { … } but initializes it with a single object rather than an array. Because IHydrographDatasource[] expects an array, TypeScript will complain that the object literal is missing array members (length, push, etc.) and the file will fail to compile. This needs to be either typed as IHydrographDatasource or wrapped in an array literal before appending it to state.

Useful? React with 👍 / 👎.


}, [transducerData, transducerIsLoading, hasNextPage, fetchNextPage])

return (
<Show
isLoading={isLoading}
Expand Down
8 changes: 6 additions & 2 deletions src/providers/ocotillo-data-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,12 @@ export const ocotilloDataProvider: DataProvider = {
}

if (pagination) {
params.append('page', pagination.current.toString())
params.append('size', pagination.pageSize.toString())
if (pagination.current !== undefined) {
params.append('page', pagination.current.toString())
}
if (pagination.pageSize !== undefined){
params.append('size', pagination.pageSize.toString())
}
}

if (sorters && sorters.length > 0) {
Expand Down
Loading