@dhis2/app-service-data 3.12.0-alpha.1 → 3.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,8 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.CustomDataProvider = void 0;
7
+ var _reactQuery = require("@tanstack/react-query");
7
8
  var _react = _interopRequireDefault(require("react"));
8
- var _reactQuery = require("react-query");
9
9
  var _engine = require("../../engine");
10
10
  var _links = require("../../links");
11
11
  var _DataContext = require("../context/DataContext");
@@ -5,8 +5,8 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.queryClientOptions = exports.DataProvider = void 0;
7
7
  var _appServiceConfig = require("@dhis2/app-service-config");
8
+ var _reactQuery = require("@tanstack/react-query");
8
9
  var _react = _interopRequireDefault(require("react"));
9
- var _reactQuery = require("react-query");
10
10
  var _engine = require("../../engine");
11
11
  var _links = require("../../links");
12
12
  var _DataContext = require("../context/DataContext");
@@ -25,7 +25,11 @@ const queryClientOptions = exports.queryClientOptions = {
25
25
  // Don't refetch when the window regains focus
26
26
  refetchOnWindowFocus: false,
27
27
  // Don't refetch after connection issues
28
- refetchOnReconnect: false
28
+ refetchOnReconnect: false,
29
+ // RQv4 uses 'online' as the default, which pauses queries without network connection.
30
+ // 'always' reestablishes behavior from v3, and lets requests fire when offline
31
+ // https://tanstack.com/query/latest/docs/framework/react/guides/network-mode
32
+ networkMode: 'always'
29
33
  }
30
34
  }
31
35
  };
@@ -4,23 +4,11 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.useDataQuery = void 0;
7
+ var _reactQuery = require("@tanstack/react-query");
7
8
  var _react = require("react");
8
- var _reactQuery = require("react-query");
9
9
  var _mergeAndCompareVariables = require("./mergeAndCompareVariables");
10
10
  var _useDataEngine = require("./useDataEngine");
11
11
  var _useStaticInput = require("./useStaticInput");
12
- const noop = () => {
13
- /**
14
- * Used to silence the default react-query logger. Eventually we
15
- * could expose the setLogger functionality and remove the call
16
- * to setLogger here.
17
- */
18
- };
19
- (0, _reactQuery.setLogger)({
20
- log: noop,
21
- warn: noop,
22
- error: noop
23
- });
24
12
  const useDataQuery = function (query) {
25
13
  let {
26
14
  onComplete: userOnSuccess,
@@ -80,13 +68,14 @@ const useDataQuery = function (query) {
80
68
  variables: queryState.current.variables
81
69
  });
82
70
  const {
83
- isIdle,
84
- isFetching,
85
- isLoading,
71
+ status,
72
+ fetchStatus,
86
73
  error,
87
74
  data,
88
75
  refetch: queryRefetch
89
- } = (0, _reactQuery.useQuery)(queryKey, queryFn, {
76
+ } = (0, _reactQuery.useQuery)({
77
+ queryKey,
78
+ queryFn,
90
79
  enabled: queryState.current.enabled,
91
80
  onSuccess,
92
81
  onError
@@ -114,7 +103,6 @@ const useDataQuery = function (query) {
114
103
  */
115
104
  if (queryState.current.enabled && identical) {
116
105
  return queryRefetch({
117
- cancelRefetch: true,
118
106
  throwOnError: false
119
107
  }).then(_ref => {
120
108
  let {
@@ -146,10 +134,15 @@ const useDataQuery = function (query) {
146
134
  const ourError = error || undefined;
147
135
  return {
148
136
  engine,
149
- // A query is idle if it is lazy and no initial data is available.
150
- called: !isIdle,
151
- loading: isLoading,
152
- fetching: isFetching,
137
+ // A query has not been called if it is lazy (fetchStatus = 'idle') and no initial data is available (status = 'loading').
138
+ // https://tanstack.com/query/v4/docs/framework/react/guides/queries
139
+ called: !(status === 'loading' && fetchStatus === 'idle'),
140
+ // 'loading' should only be true when actively fetching (fetchStatus = 'fetching') while there is no data yet (status = 'loading').
141
+ // If there is already data for the query, then 'loading' will not become 'true' when refetching, so the previous data can still be
142
+ // displayed while new data is fetched in the background
143
+ loading: fetchStatus === 'fetching' && status === 'loading',
144
+ // 'fetching' reflects the fetching behavior behind the scenes
145
+ fetching: fetchStatus === 'fetching',
153
146
  error: ourError,
154
147
  data,
155
148
  refetch
@@ -1,5 +1,5 @@
1
+ import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
1
2
  import React from 'react';
2
- import { QueryClient, QueryClientProvider } from 'react-query';
3
3
  import { DataEngine } from '../../engine';
4
4
  import { CustomDataLink } from '../../links';
5
5
  import { DataContext } from '../context/DataContext';
@@ -1,8 +1,8 @@
1
1
  /* eslint-disable react/no-unused-prop-types */
2
2
 
3
3
  import { useConfig } from '@dhis2/app-service-config';
4
+ import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
4
5
  import React from 'react';
5
- import { QueryClient, QueryClientProvider } from 'react-query';
6
6
  import { DataEngine } from '../../engine';
7
7
  import { RestAPILink } from '../../links';
8
8
  import { DataContext } from '../context/DataContext';
@@ -18,7 +18,11 @@ export const queryClientOptions = {
18
18
  // Don't refetch when the window regains focus
19
19
  refetchOnWindowFocus: false,
20
20
  // Don't refetch after connection issues
21
- refetchOnReconnect: false
21
+ refetchOnReconnect: false,
22
+ // RQv4 uses 'online' as the default, which pauses queries without network connection.
23
+ // 'always' reestablishes behavior from v3, and lets requests fire when offline
24
+ // https://tanstack.com/query/latest/docs/framework/react/guides/network-mode
25
+ networkMode: 'always'
22
26
  }
23
27
  }
24
28
  };
@@ -1,20 +1,8 @@
1
+ import { useQuery } from '@tanstack/react-query';
1
2
  import { useState, useRef, useCallback, useDebugValue } from 'react';
2
- import { useQuery, setLogger } from 'react-query';
3
3
  import { mergeAndCompareVariables } from './mergeAndCompareVariables';
4
4
  import { useDataEngine } from './useDataEngine';
5
5
  import { useStaticInput } from './useStaticInput';
6
- const noop = () => {
7
- /**
8
- * Used to silence the default react-query logger. Eventually we
9
- * could expose the setLogger functionality and remove the call
10
- * to setLogger here.
11
- */
12
- };
13
- setLogger({
14
- log: noop,
15
- warn: noop,
16
- error: noop
17
- });
18
6
  export const useDataQuery = function (query) {
19
7
  let {
20
8
  onComplete: userOnSuccess,
@@ -74,13 +62,14 @@ export const useDataQuery = function (query) {
74
62
  variables: queryState.current.variables
75
63
  });
76
64
  const {
77
- isIdle,
78
- isFetching,
79
- isLoading,
65
+ status,
66
+ fetchStatus,
80
67
  error,
81
68
  data,
82
69
  refetch: queryRefetch
83
- } = useQuery(queryKey, queryFn, {
70
+ } = useQuery({
71
+ queryKey,
72
+ queryFn,
84
73
  enabled: queryState.current.enabled,
85
74
  onSuccess,
86
75
  onError
@@ -108,7 +97,6 @@ export const useDataQuery = function (query) {
108
97
  */
109
98
  if (queryState.current.enabled && identical) {
110
99
  return queryRefetch({
111
- cancelRefetch: true,
112
100
  throwOnError: false
113
101
  }).then(_ref => {
114
102
  let {
@@ -140,10 +128,15 @@ export const useDataQuery = function (query) {
140
128
  const ourError = error || undefined;
141
129
  return {
142
130
  engine,
143
- // A query is idle if it is lazy and no initial data is available.
144
- called: !isIdle,
145
- loading: isLoading,
146
- fetching: isFetching,
131
+ // A query has not been called if it is lazy (fetchStatus = 'idle') and no initial data is available (status = 'loading').
132
+ // https://tanstack.com/query/v4/docs/framework/react/guides/queries
133
+ called: !(status === 'loading' && fetchStatus === 'idle'),
134
+ // 'loading' should only be true when actively fetching (fetchStatus = 'fetching') while there is no data yet (status = 'loading').
135
+ // If there is already data for the query, then 'loading' will not become 'true' when refetching, so the previous data can still be
136
+ // displayed while new data is fetched in the background
137
+ loading: fetchStatus === 'fetching' && status === 'loading',
138
+ // 'fetching' reflects the fetching behavior behind the scenes
139
+ fetching: fetchStatus === 'fetching',
147
140
  error: ourError,
148
141
  data,
149
142
  refetch
@@ -1,18 +1,9 @@
1
+ import { type QueryClientConfig } from '@tanstack/react-query';
1
2
  import React from 'react';
2
3
  export interface ProviderInput {
3
4
  baseUrl?: string;
4
5
  apiVersion?: number;
5
6
  children: React.ReactNode;
6
7
  }
7
- export declare const queryClientOptions: {
8
- defaultOptions: {
9
- queries: {
10
- retry: boolean;
11
- retryOnMount: boolean;
12
- refetchOnMount: boolean;
13
- refetchOnWindowFocus: boolean;
14
- refetchOnReconnect: boolean;
15
- };
16
- };
17
- };
8
+ export declare const queryClientOptions: QueryClientConfig;
18
9
  export declare const DataProvider: (props: ProviderInput) => JSX.Element;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhis2/app-service-data",
3
- "version": "3.12.0-alpha.1",
3
+ "version": "3.12.0",
4
4
  "main": "./build/cjs/index.js",
5
5
  "module": "./build/es/index.js",
6
6
  "types": "build/types/index.d.ts",
@@ -32,10 +32,10 @@
32
32
  "coverage": "yarn test --coverage"
33
33
  },
34
34
  "dependencies": {
35
- "react-query": "^3.13.11"
35
+ "@tanstack/react-query": "^4.36.1"
36
36
  },
37
37
  "peerDependencies": {
38
- "@dhis2/app-service-config": "3.12.0-alpha.1",
38
+ "@dhis2/app-service-config": "3.12.0",
39
39
  "prop-types": "^15.7.2",
40
40
  "react": "^16.8 || ^18",
41
41
  "react-dom": "^16.8 || ^18"