Skip to content

Commit 081c656

Browse files
authored
Merge pull request #2395 from gulfofmaine/react-query-4
Update to react-query 4 and group dependencies
2 parents dc02cce + 8393b40 commit 081c656

File tree

15 files changed

+152
-147
lines changed

15 files changed

+152
-147
lines changed

.github/dependabot.yml

Lines changed: 42 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,44 @@
11
version: 2
22
updates:
3-
- package-ecosystem: npm
4-
directory: "/"
5-
schedule:
6-
interval: daily
7-
time: '10:00'
8-
open-pull-requests-limit: 10
9-
reviewers:
10-
- abkfenris
11-
ignore:
12-
- dependency-name: cypress
13-
versions:
14-
- ">= 3.3.1.a, < 3.3.2"
15-
- package-ecosystem: docker
16-
directory: "/"
17-
schedule:
18-
interval: daily
19-
time: '10:00'
20-
open-pull-requests-limit: 10
21-
reviewers:
22-
- abkfenris
23-
# Maintain dependencies for GitHub Actions
24-
- package-ecosystem: "github-actions"
25-
directory: "/"
26-
open-pull-requests-limit: 10
27-
schedule:
28-
interval: daily
29-
time: '10:00'
3+
- package-ecosystem: npm
4+
directory: "/"
5+
schedule:
6+
interval: daily
7+
time: "10:00"
8+
open-pull-requests-limit: 10
9+
reviewers:
10+
- abkfenris
11+
ignore:
12+
- dependency-name: cypress
13+
versions:
14+
- ">= 3.3.1.a, < 3.3.2"
15+
# Group dependencies
16+
groups:
17+
storybook:
18+
patterns:
19+
- "@storybook/*"
20+
font-awesome:
21+
patterns:
22+
- "@fortawesome"
23+
react:
24+
patterns:
25+
- "react"
26+
- "react-dom"
27+
react-query:
28+
patterns:
29+
- "@tanstack/*"
30+
- package-ecosystem: docker
31+
directory: "/"
32+
schedule:
33+
interval: daily
34+
time: "10:00"
35+
open-pull-requests-limit: 10
36+
reviewers:
37+
- abkfenris
38+
# Maintain dependencies for GitHub Actions
39+
- package-ecosystem: "github-actions"
40+
directory: "/"
41+
open-pull-requests-limit: 10
42+
schedule:
43+
interval: daily
44+
time: "10:00"

cypress/e2e/Platform/44007_spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ describe("Platfrom 44007", () => {
1414
cy.contains("Station 44007")
1515
})
1616

17-
it("Shows platform status", () => {
17+
xit("Shows platform status", () => {
1818
cy.visit(platformUrl)
1919

2020
cy.contains("Lat:")

cypress/e2e/Platform/a01_spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ describe("Platform A01", () => {
2929
cy.contains("Last updated at:")
3030
})
3131

32-
it("Shows current conditions", () => {
32+
xit("Shows current conditions", () => {
3333
cy.visit(platformUrl)
3434

3535
cy.contains("Latest Conditions")

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
"@gulfofmaine/tsstac": "0.1.3",
1212
"@reduxjs/toolkit": "^1.9.1",
1313
"@sentry/react": "^7.59.2",
14+
"@tanstack/react-query": "^4.29.25",
15+
"@tanstack/react-query-devtools": "^4.29.25",
1416
"@turf/bbox-polygon": "6.5.0",
1517
"@turf/boolean-contains": "6.5.0",
1618
"@turf/helpers": "6.5.0",
@@ -30,7 +32,6 @@
3032
"react-dom": "18.2.0",
3133
"react-ga4": "^2.1.0",
3234
"react-jsx-highcharts": "^5.0.1",
33-
"react-query": "^3.39.2",
3435
"react-redux": "8.1.1",
3536
"react-router-dom": "6.14.2",
3637
"react-scripts": "^5.0.1",

src/Features/ERDDAP/hooks/TableDAPComponents.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Render prop components to standardize the loading of datasets
33
*/
44
import * as React from "react"
5-
import { useQueries } from "react-query"
5+
import { useQueries } from "@tanstack/react-query"
66
import { Alert } from "reactstrap"
77
import { tabledapHtmlUrl } from "Shared/erddap/tabledap"
88
import { aWeekAgoRounded } from "Shared/time"
@@ -41,13 +41,13 @@ export const UseDatasets: React.FunctionComponent<UseDatasetsProps> = ({ childre
4141

4242
startTime = startTime ?? aWeekAgoRounded()
4343

44-
const results: UseQueryGroupResult[] | undefined = useQueries(
45-
fetchGroups.map((group) => ({
44+
const results: UseQueryGroupResult[] | undefined = useQueries({
45+
queries: fetchGroups.map((group) => ({
4646
...defaultQueryConfig,
4747
queryKey: ["erddap-dataset", group.datasets, startTime],
4848
queryFn: () => getDatasetGroup(group, startTime),
49-
}))
50-
)
49+
})),
50+
})
5151

5252
if (results === undefined) {
5353
return <h4>Results is not defined</h4>

src/Features/ERDDAP/hooks/buoyBarn.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as Sentry from "@sentry/react"
2-
import { useQuery, useQueries } from "react-query"
2+
import { useQuery, useQueries } from "@tanstack/react-query"
33

44
import { ForecastJson, ForecastSource, PlatformFeatureCollection } from "../types"
55
import { defaultQueryConfig } from "./hookConfig"
@@ -28,7 +28,7 @@ const getPlatforms = async () => {
2828
* Load all the platforms
2929
*/
3030
export function usePlatforms() {
31-
return useQuery<PlatformFeatureCollection, Error>("buoybarn-platforms", getPlatforms, defaultQueryConfig)
31+
return useQuery<PlatformFeatureCollection, Error>(["buoybarn-platforms"], getPlatforms, defaultQueryConfig)
3232
}
3333

3434
/**
@@ -55,7 +55,7 @@ const getForecasts = async () => {
5555
* Load forecasts
5656
*/
5757
export function useForecastMeta() {
58-
return useQuery("buoybarn-forecasts", getForecasts, defaultQueryConfig)
58+
return useQuery(["buoybarn-forecasts"], getForecasts, defaultQueryConfig)
5959
}
6060

6161
/**
@@ -103,11 +103,11 @@ export function useForecast(lat: number, lon: number, forecast?: ForecastSource)
103103
* @param forecasts Forecast sources to load
104104
*/
105105
export function useForecasts(lat: number, lon: number, forecasts: ForecastSource[]) {
106-
return useQueries(
107-
forecasts.map((forecast) => ({
106+
return useQueries({
107+
queries: forecasts.map((forecast) => ({
108108
...defaultQueryConfig,
109109
queryKey: ["buoybarn-forecast", { forecast, lat, lon }],
110110
queryFn: () => getForecast(forecast, lat, lon),
111-
}))
112-
)
111+
})),
112+
})
113113
}

src/Features/ERDDAP/hooks/tabledap.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*/
44
import * as Sentry from "@sentry/react"
55
import { useState } from "react"
6-
import { useQuery } from "react-query"
6+
import { useQuery } from "@tanstack/react-query"
77

88
import { resultToTimeseries, tabledapUrl } from "Shared/erddap"
99
import { ErddapJson } from "Shared/erddap/types"

src/Features/WagtailApi/hooks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* React-Query custom hooks to load and cache data
33
*/
44
import * as Sentry from "@sentry/react"
5-
import { useQuery } from "react-query"
5+
import { useQuery } from "@tanstack/react-query"
66

77
import { WagtailContent } from "./constants"
88

src/Pages/Modeling/index.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from "react"
22
import Select from "react-select"
33
import { Col, Row, Nav, NavItem, NavLink, TabContent, TabPane } from "reactstrap"
4-
import { UseQueryResult, useQueries } from "react-query"
4+
import { UseQueryResult, useQueries } from "@tanstack/react-query"
55

66
import { IAsset, IItem } from "@gulfofmaine/tsstac"
77
// import type { DataCubeItem } from "@gulfofmaine/tsstac/extensions/datacube"
@@ -175,8 +175,8 @@ const ItemLayersTabs = ({
175175
return { url: undefined, item: itemLayer[0], layer: itemLayer[1] }
176176
})
177177

178-
const edrQueries = useQueries(
179-
edrSources.map((edrSource) => ({
178+
const edrQueries = useQueries({
179+
queries: edrSources.map((edrSource) => ({
180180
queryKey: ["edr-position", edrSource.url],
181181
queryFn: async () => {
182182
const raw = await fetch(edrSource.url!)
@@ -188,8 +188,8 @@ const ItemLayersTabs = ({
188188
},
189189
enabled: edrSource.url !== undefined,
190190
refetchOnWindowFocus: false,
191-
}))
192-
)
191+
})),
192+
})
193193

194194
const loaded = edrQueries
195195
// .filter((query): query is { data: LoadedData } => query.data !== undefined)

src/Pages/Modeling/stac-catalog.tsx

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
ListGroupItem,
1111
ListGroupItemHeading,
1212
} from "reactstrap"
13-
import { useQueries } from "react-query"
13+
import { useQueries } from "@tanstack/react-query"
1414

1515
import { ICatalog, ICollection, IItem } from "@gulfofmaine/tsstac"
1616

@@ -59,13 +59,13 @@ const STACCollectionsLoader = ({
5959

6060
const addChildrenUrls = (urls: StacURL[]) => setChildrenUrls((prev) => new Set([...prev, ...urls]))
6161

62-
const childrenQueries = useQueries(
63-
Array.from(childrenUrls).map(({ url, parent }) => ({
62+
const childrenQueries = useQueries({
63+
queries: Array.from(childrenUrls).map(({ url, parent }) => ({
6464
queryKey: ["get-stac-child", { url }],
6565
queryFn: () => getChildByUrl(url as string, parent, catalog),
6666
refetchOnWindowFocus: false,
67-
}))
68-
)
67+
})),
68+
})
6969

7070
childrenQueries.forEach((query) => {
7171
if (query.data) {
@@ -85,9 +85,11 @@ const STACCollectionsLoader = ({
8585
.filter((query) => query.data)
8686
.map((query) => query.data)
8787
.map((collection) =>
88-
collection!.get_item_links().map((link) => ({ url: collection!.url_for_link(link), parent: collection! }))
88+
(collection as ICollection)!
89+
.get_item_links()
90+
.map((link) => ({ url: (collection as ICollection)!.url_for_link(link), parent: collection! }))
8991
)
90-
.flat()
92+
.flat() as StacURL[]
9193

9294
if (0 < itemsUrls.length) {
9395
return <STACItemsLoader catalog={catalog} itemUrls={itemsUrls} />
@@ -103,16 +105,16 @@ const STACCollectionsLoader = ({
103105
}
104106

105107
const STACItemsLoader = ({ catalog, itemUrls }: { catalog: ICatalog; itemUrls: StacURL[] }) => {
106-
const itemsQuery = useQueries(
107-
Array.from(itemUrls).map(({ url, parent }) => ({
108+
const itemsQuery = useQueries({
109+
queries: Array.from(itemUrls).map(({ url, parent }) => ({
108110
queryKey: ["get-stac-item", { url }],
109111
queryFn: () => getItemByUrl(url as string, parent, catalog),
110112
refetchOnWindowFocus: false,
111-
}))
112-
)
113+
})),
114+
})
113115

114116
// First filter by which items are loaded
115-
const loadedItems = itemsQuery.filter((query) => query.isSuccess).map((query) => query.data)
117+
const loadedItems = itemsQuery.filter((query) => query.isSuccess).map((query) => query.data) as IItem[]
116118

117119
// Then group by collection
118120
const itemsByCollection = loadedItems.reduce((result, item) => {

0 commit comments

Comments
 (0)