@tanstack/react-query-devtools 5.0.0-alpha.12 → 5.0.0-alpha.14
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.
- package/build/lib/CachePanel/ActiveQuery.d.ts +18 -0
- package/build/lib/CachePanel/ActiveQuery.esm.js +271 -0
- package/build/lib/CachePanel/ActiveQuery.esm.js.map +1 -0
- package/build/lib/CachePanel/ActiveQuery.js +275 -0
- package/build/lib/CachePanel/ActiveQuery.js.map +1 -0
- package/build/lib/CachePanel/ActiveQuery.mjs +257 -0
- package/build/lib/CachePanel/ActiveQuery.mjs.map +1 -0
- package/build/lib/CachePanel/CachePanel.d.ts +57 -0
- package/build/lib/CachePanel/CachePanel.esm.js +301 -0
- package/build/lib/CachePanel/CachePanel.esm.js.map +1 -0
- package/build/lib/CachePanel/CachePanel.js +306 -0
- package/build/lib/CachePanel/CachePanel.js.map +1 -0
- package/build/lib/CachePanel/CachePanel.mjs +301 -0
- package/build/lib/CachePanel/CachePanel.mjs.map +1 -0
- package/build/lib/CachePanel/Header/QueryStatusCount.d.ts +7 -0
- package/build/lib/CachePanel/Header/QueryStatusCount.esm.js +49 -0
- package/build/lib/CachePanel/Header/QueryStatusCount.esm.js.map +1 -0
- package/build/lib/CachePanel/Header/QueryStatusCount.js +53 -0
- package/build/lib/CachePanel/Header/QueryStatusCount.js.map +1 -0
- package/build/lib/CachePanel/Header/QueryStatusCount.mjs +49 -0
- package/build/lib/CachePanel/Header/QueryStatusCount.mjs.map +1 -0
- package/build/lib/CachePanel/QueryRow.d.ts +13 -0
- package/build/lib/CachePanel/QueryRow.esm.js +98 -0
- package/build/lib/CachePanel/QueryRow.esm.js.map +1 -0
- package/build/lib/CachePanel/QueryRow.js +102 -0
- package/build/lib/CachePanel/QueryRow.js.map +1 -0
- package/build/lib/CachePanel/QueryRow.mjs +82 -0
- package/build/lib/CachePanel/QueryRow.mjs.map +1 -0
- package/build/lib/devtools.d.ts +3 -64
- package/build/lib/devtools.esm.js +2 -669
- package/build/lib/devtools.esm.js.map +1 -1
- package/build/lib/devtools.js +3 -669
- package/build/lib/devtools.js.map +1 -1
- package/build/lib/devtools.mjs +2 -639
- package/build/lib/devtools.mjs.map +1 -1
- package/build/lib/index.esm.js +2 -1
- package/build/lib/index.esm.js.map +1 -1
- package/build/lib/index.js +2 -1
- package/build/lib/index.js.map +1 -1
- package/build/lib/index.mjs +2 -1
- package/build/lib/index.mjs.map +1 -1
- package/build/lib/index.prod.esm.js +745 -713
- package/build/lib/index.prod.esm.js.map +1 -1
- package/build/lib/index.prod.js +742 -710
- package/build/lib/index.prod.js.map +1 -1
- package/build/lib/index.prod.mjs +745 -713
- package/build/lib/index.prod.mjs.map +1 -1
- package/build/lib/styledComponents.esm.js +8 -0
- package/build/lib/styledComponents.esm.js.map +1 -1
- package/build/lib/styledComponents.js +8 -0
- package/build/lib/styledComponents.js.map +1 -1
- package/build/lib/styledComponents.mjs +8 -0
- package/build/lib/styledComponents.mjs.map +1 -1
- package/build/lib/types.d.ts +11 -0
- package/build/lib/useSubscribeToQueryCache.d.ts +3 -0
- package/build/lib/useSubscribeToQueryCache.esm.js +15 -0
- package/build/lib/useSubscribeToQueryCache.esm.js.map +1 -0
- package/build/lib/useSubscribeToQueryCache.js +19 -0
- package/build/lib/useSubscribeToQueryCache.js.map +1 -0
- package/build/lib/useSubscribeToQueryCache.mjs +15 -0
- package/build/lib/useSubscribeToQueryCache.mjs.map +1 -0
- package/build/umd/index.development.js +2385 -2353
- package/build/umd/index.development.js.map +1 -1
- package/package.json +1 -1
- package/src/CachePanel/ActiveQuery.tsx +380 -0
- package/src/CachePanel/CachePanel.tsx +427 -0
- package/src/CachePanel/Header/QueryStatusCount.tsx +93 -0
- package/src/CachePanel/QueryRow.tsx +125 -0
- package/src/devtools.tsx +5 -1008
- package/src/styledComponents.ts +16 -0
- package/src/types.ts +12 -0
- package/src/useSubscribeToQueryCache.ts +26 -0
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
import React__default from 'react';
|
|
2
|
+
import useSubscribeToQueryCache from '../useSubscribeToQueryCache.mjs';
|
|
3
|
+
import { ActiveQueryPanel, Code, Button, Select } from '../styledComponents.mjs';
|
|
4
|
+
import { displayValue, getQueryStatusColor, getQueryStatusLabel } from '../utils.mjs';
|
|
5
|
+
import Explorer from '../Explorer.mjs';
|
|
6
|
+
import { defaultTheme } from '../theme.mjs';
|
|
7
|
+
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
9
|
+
function noop() {}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Panel for the query currently being inspected
|
|
13
|
+
*
|
|
14
|
+
* It displays query details (key, observers...), query actions,
|
|
15
|
+
* the data explorer and the query explorer
|
|
16
|
+
*/
|
|
17
|
+
const ActiveQuery = ({
|
|
18
|
+
queryCache,
|
|
19
|
+
activeQueryHash,
|
|
20
|
+
queryClient,
|
|
21
|
+
errorTypes
|
|
22
|
+
}) => {
|
|
23
|
+
const activeQuery = useSubscribeToQueryCache(queryCache, () => queryCache.getAll().find(query => query.queryHash === activeQueryHash));
|
|
24
|
+
const activeQueryState = useSubscribeToQueryCache(queryCache, () => queryCache.getAll().find(query => query.queryHash === activeQueryHash)?.state);
|
|
25
|
+
const isStale = useSubscribeToQueryCache(queryCache, () => queryCache.getAll().find(query => query.queryHash === activeQueryHash)?.isStale()) ?? false;
|
|
26
|
+
const observerCount = useSubscribeToQueryCache(queryCache, () => queryCache.getAll().find(query => query.queryHash === activeQueryHash)?.getObserversCount()) ?? 0;
|
|
27
|
+
const handleRefetch = () => {
|
|
28
|
+
const promise = activeQuery?.fetch();
|
|
29
|
+
promise?.catch(noop);
|
|
30
|
+
};
|
|
31
|
+
const currentErrorTypeName = React__default.useMemo(() => {
|
|
32
|
+
if (activeQuery && activeQueryState?.error) {
|
|
33
|
+
const errorType = errorTypes.find(type => type.initializer(activeQuery).toString() === activeQueryState.error?.toString());
|
|
34
|
+
return errorType?.name;
|
|
35
|
+
}
|
|
36
|
+
return undefined;
|
|
37
|
+
}, [activeQuery, activeQueryState?.error, errorTypes]);
|
|
38
|
+
if (!activeQuery || !activeQueryState) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
const triggerError = errorType => {
|
|
42
|
+
const error = errorType?.initializer(activeQuery) ?? new Error('Unknown error from devtools');
|
|
43
|
+
const __previousQueryOptions = activeQuery.options;
|
|
44
|
+
activeQuery.setState({
|
|
45
|
+
status: 'error',
|
|
46
|
+
error,
|
|
47
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
|
48
|
+
fetchMeta: {
|
|
49
|
+
...activeQuery.state.fetchMeta,
|
|
50
|
+
__previousQueryOptions
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
};
|
|
54
|
+
const restoreQueryAfterLoadingOrError = () => {
|
|
55
|
+
activeQuery.fetch(activeQuery.state.fetchMeta.__previousQueryOptions, {
|
|
56
|
+
// Make sure this fetch will cancel the previous one
|
|
57
|
+
cancelRefetch: true
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
return /*#__PURE__*/React__default.createElement(ActiveQueryPanel, null, /*#__PURE__*/React__default.createElement("div", {
|
|
61
|
+
style: {
|
|
62
|
+
padding: '.5em',
|
|
63
|
+
background: defaultTheme.backgroundAlt,
|
|
64
|
+
position: 'sticky',
|
|
65
|
+
top: 0,
|
|
66
|
+
zIndex: 1
|
|
67
|
+
}
|
|
68
|
+
}, "Query Details"), /*#__PURE__*/React__default.createElement("div", {
|
|
69
|
+
style: {
|
|
70
|
+
padding: '.5em'
|
|
71
|
+
}
|
|
72
|
+
}, /*#__PURE__*/React__default.createElement("div", {
|
|
73
|
+
style: {
|
|
74
|
+
marginBottom: '.5em',
|
|
75
|
+
display: 'flex',
|
|
76
|
+
alignItems: 'flex-start',
|
|
77
|
+
justifyContent: 'space-between'
|
|
78
|
+
}
|
|
79
|
+
}, /*#__PURE__*/React__default.createElement(Code, {
|
|
80
|
+
style: {
|
|
81
|
+
lineHeight: '1.8em'
|
|
82
|
+
}
|
|
83
|
+
}, /*#__PURE__*/React__default.createElement("pre", {
|
|
84
|
+
style: {
|
|
85
|
+
margin: 0,
|
|
86
|
+
padding: 0,
|
|
87
|
+
overflow: 'auto'
|
|
88
|
+
}
|
|
89
|
+
}, displayValue(activeQuery.queryKey, true))), /*#__PURE__*/React__default.createElement("span", {
|
|
90
|
+
style: {
|
|
91
|
+
padding: '0.3em .6em',
|
|
92
|
+
borderRadius: '0.4em',
|
|
93
|
+
fontWeight: 'bold',
|
|
94
|
+
textShadow: '0 2px 10px black',
|
|
95
|
+
background: getQueryStatusColor({
|
|
96
|
+
queryState: activeQueryState,
|
|
97
|
+
isStale: isStale,
|
|
98
|
+
observerCount: observerCount,
|
|
99
|
+
theme: defaultTheme
|
|
100
|
+
}),
|
|
101
|
+
flexShrink: 0
|
|
102
|
+
}
|
|
103
|
+
}, getQueryStatusLabel(activeQuery))), /*#__PURE__*/React__default.createElement("div", {
|
|
104
|
+
style: {
|
|
105
|
+
marginBottom: '.5em',
|
|
106
|
+
display: 'flex',
|
|
107
|
+
alignItems: 'center',
|
|
108
|
+
justifyContent: 'space-between'
|
|
109
|
+
}
|
|
110
|
+
}, "Observers: ", /*#__PURE__*/React__default.createElement(Code, null, observerCount)), /*#__PURE__*/React__default.createElement("div", {
|
|
111
|
+
style: {
|
|
112
|
+
display: 'flex',
|
|
113
|
+
alignItems: 'center',
|
|
114
|
+
justifyContent: 'space-between'
|
|
115
|
+
}
|
|
116
|
+
}, "Last Updated:", ' ', /*#__PURE__*/React__default.createElement(Code, null, new Date(activeQueryState.dataUpdatedAt).toLocaleTimeString()))), /*#__PURE__*/React__default.createElement("div", {
|
|
117
|
+
style: {
|
|
118
|
+
background: defaultTheme.backgroundAlt,
|
|
119
|
+
padding: '.5em',
|
|
120
|
+
position: 'sticky',
|
|
121
|
+
top: 0,
|
|
122
|
+
zIndex: 1
|
|
123
|
+
}
|
|
124
|
+
}, "Actions"), /*#__PURE__*/React__default.createElement("div", {
|
|
125
|
+
style: {
|
|
126
|
+
padding: '0.5em',
|
|
127
|
+
display: 'flex',
|
|
128
|
+
flexWrap: 'wrap',
|
|
129
|
+
gap: '0.5em',
|
|
130
|
+
alignItems: 'flex-end'
|
|
131
|
+
}
|
|
132
|
+
}, /*#__PURE__*/React__default.createElement(Button, {
|
|
133
|
+
type: "button",
|
|
134
|
+
onClick: handleRefetch,
|
|
135
|
+
disabled: activeQueryState.fetchStatus === 'fetching',
|
|
136
|
+
style: {
|
|
137
|
+
background: defaultTheme.active
|
|
138
|
+
}
|
|
139
|
+
}, "Refetch"), ' ', /*#__PURE__*/React__default.createElement(Button, {
|
|
140
|
+
type: "button",
|
|
141
|
+
onClick: () => queryClient.invalidateQueries(activeQuery),
|
|
142
|
+
style: {
|
|
143
|
+
background: defaultTheme.warning,
|
|
144
|
+
color: defaultTheme.inputTextColor
|
|
145
|
+
}
|
|
146
|
+
}, "Invalidate"), ' ', /*#__PURE__*/React__default.createElement(Button, {
|
|
147
|
+
type: "button",
|
|
148
|
+
onClick: () => queryClient.resetQueries(activeQuery),
|
|
149
|
+
style: {
|
|
150
|
+
background: defaultTheme.gray
|
|
151
|
+
}
|
|
152
|
+
}, "Reset"), ' ', /*#__PURE__*/React__default.createElement(Button, {
|
|
153
|
+
type: "button",
|
|
154
|
+
onClick: () => queryClient.removeQueries(activeQuery),
|
|
155
|
+
style: {
|
|
156
|
+
background: defaultTheme.danger
|
|
157
|
+
}
|
|
158
|
+
}, "Remove"), ' ', /*#__PURE__*/React__default.createElement(Button, {
|
|
159
|
+
type: "button",
|
|
160
|
+
onClick: () => {
|
|
161
|
+
if (activeQuery.state.data === undefined) {
|
|
162
|
+
restoreQueryAfterLoadingOrError();
|
|
163
|
+
} else {
|
|
164
|
+
const __previousQueryOptions = activeQuery.options;
|
|
165
|
+
// Trigger a fetch in order to trigger suspense as well.
|
|
166
|
+
activeQuery.fetch({
|
|
167
|
+
...__previousQueryOptions,
|
|
168
|
+
queryFn: () => {
|
|
169
|
+
return new Promise(() => {
|
|
170
|
+
// Never resolve
|
|
171
|
+
});
|
|
172
|
+
},
|
|
173
|
+
gcTime: -1
|
|
174
|
+
});
|
|
175
|
+
activeQuery.setState({
|
|
176
|
+
data: undefined,
|
|
177
|
+
status: 'pending',
|
|
178
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
|
179
|
+
fetchMeta: {
|
|
180
|
+
...activeQuery.state.fetchMeta,
|
|
181
|
+
__previousQueryOptions
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
},
|
|
186
|
+
style: {
|
|
187
|
+
background: defaultTheme.paused
|
|
188
|
+
}
|
|
189
|
+
}, activeQuery.state.status === 'pending' ? 'Restore' : 'Trigger', ' ', "loading"), ' ', errorTypes.length === 0 || activeQuery.state.status === 'error' ? /*#__PURE__*/React__default.createElement(Button, {
|
|
190
|
+
type: "button",
|
|
191
|
+
onClick: () => {
|
|
192
|
+
if (!activeQuery.state.error) {
|
|
193
|
+
triggerError();
|
|
194
|
+
} else {
|
|
195
|
+
queryClient.resetQueries(activeQuery);
|
|
196
|
+
}
|
|
197
|
+
},
|
|
198
|
+
style: {
|
|
199
|
+
background: defaultTheme.danger
|
|
200
|
+
}
|
|
201
|
+
}, activeQuery.state.status === 'error' ? 'Restore' : 'Trigger', " error") : /*#__PURE__*/React__default.createElement("label", null, "Trigger error:", /*#__PURE__*/React__default.createElement(Select, {
|
|
202
|
+
value: currentErrorTypeName ?? '',
|
|
203
|
+
style: {
|
|
204
|
+
marginInlineStart: '.5em'
|
|
205
|
+
},
|
|
206
|
+
onChange: e => {
|
|
207
|
+
const errorType = errorTypes.find(t => t.name === e.target.value);
|
|
208
|
+
triggerError(errorType);
|
|
209
|
+
}
|
|
210
|
+
}, /*#__PURE__*/React__default.createElement("option", {
|
|
211
|
+
key: "",
|
|
212
|
+
value: ""
|
|
213
|
+
}), errorTypes.map(errorType => /*#__PURE__*/React__default.createElement("option", {
|
|
214
|
+
key: errorType.name,
|
|
215
|
+
value: errorType.name
|
|
216
|
+
}, errorType.name))))), /*#__PURE__*/React__default.createElement("div", {
|
|
217
|
+
style: {
|
|
218
|
+
background: defaultTheme.backgroundAlt,
|
|
219
|
+
padding: '.5em',
|
|
220
|
+
position: 'sticky',
|
|
221
|
+
top: 0,
|
|
222
|
+
zIndex: 1
|
|
223
|
+
}
|
|
224
|
+
}, "Data Explorer"), /*#__PURE__*/React__default.createElement("div", {
|
|
225
|
+
style: {
|
|
226
|
+
padding: '.5em'
|
|
227
|
+
}
|
|
228
|
+
}, /*#__PURE__*/React__default.createElement(Explorer, {
|
|
229
|
+
label: "Data",
|
|
230
|
+
value: activeQueryState.data,
|
|
231
|
+
defaultExpanded: {},
|
|
232
|
+
copyable: true
|
|
233
|
+
})), /*#__PURE__*/React__default.createElement("div", {
|
|
234
|
+
style: {
|
|
235
|
+
background: defaultTheme.backgroundAlt,
|
|
236
|
+
padding: '.5em',
|
|
237
|
+
position: 'sticky',
|
|
238
|
+
top: 0,
|
|
239
|
+
zIndex: 1
|
|
240
|
+
}
|
|
241
|
+
}, "Query Explorer"), /*#__PURE__*/React__default.createElement("div", {
|
|
242
|
+
style: {
|
|
243
|
+
padding: '.5em'
|
|
244
|
+
}
|
|
245
|
+
}, /*#__PURE__*/React__default.createElement(Explorer, {
|
|
246
|
+
label: "Query",
|
|
247
|
+
value: activeQuery,
|
|
248
|
+
defaultExpanded: {
|
|
249
|
+
queryKey: true
|
|
250
|
+
}
|
|
251
|
+
})));
|
|
252
|
+
};
|
|
253
|
+
ActiveQuery.displayName = 'ActiveQuery';
|
|
254
|
+
var ActiveQuery$1 = ActiveQuery;
|
|
255
|
+
|
|
256
|
+
export { ActiveQuery$1 as default };
|
|
257
|
+
//# sourceMappingURL=ActiveQuery.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ActiveQuery.mjs","sources":["../../../src/CachePanel/ActiveQuery.tsx"],"sourcesContent":["import React from 'react'\nimport type { QueryCache, QueryClient } from '@tanstack/react-query'\n\nimport useSubscribeToQueryCache from '../useSubscribeToQueryCache'\nimport { Button, Code, Select, ActiveQueryPanel } from '../styledComponents'\n\nimport {\n getQueryStatusLabel,\n getQueryStatusColor,\n displayValue,\n} from '../utils'\nimport Explorer from '../Explorer'\nimport type { DevToolsErrorType } from '../types'\nimport { defaultTheme as theme } from '../theme'\n\n// eslint-disable-next-line @typescript-eslint/no-empty-function\nfunction noop() {}\n\n/**\n * Panel for the query currently being inspected\n *\n * It displays query details (key, observers...), query actions,\n * the data explorer and the query explorer\n */\nconst ActiveQuery = ({\n queryCache,\n activeQueryHash,\n queryClient,\n errorTypes,\n}: {\n queryCache: QueryCache\n activeQueryHash: string\n queryClient: QueryClient\n errorTypes: DevToolsErrorType[]\n}) => {\n const activeQuery = useSubscribeToQueryCache(queryCache, () =>\n queryCache.getAll().find((query) => query.queryHash === activeQueryHash),\n )\n\n const activeQueryState = useSubscribeToQueryCache(\n queryCache,\n () =>\n queryCache.getAll().find((query) => query.queryHash === activeQueryHash)\n ?.state,\n )\n\n const isStale =\n useSubscribeToQueryCache(queryCache, () =>\n queryCache\n .getAll()\n .find((query) => query.queryHash === activeQueryHash)\n ?.isStale(),\n ) ?? false\n\n const observerCount =\n useSubscribeToQueryCache(queryCache, () =>\n queryCache\n .getAll()\n .find((query) => query.queryHash === activeQueryHash)\n ?.getObserversCount(),\n ) ?? 0\n\n const handleRefetch = () => {\n const promise = activeQuery?.fetch()\n promise?.catch(noop)\n }\n\n const currentErrorTypeName = React.useMemo(() => {\n if (activeQuery && activeQueryState?.error) {\n const errorType = errorTypes.find(\n (type) =>\n type.initializer(activeQuery).toString() ===\n activeQueryState.error?.toString(),\n )\n return errorType?.name\n }\n return undefined\n }, [activeQuery, activeQueryState?.error, errorTypes])\n\n if (!activeQuery || !activeQueryState) {\n return null\n }\n\n const triggerError = (errorType?: DevToolsErrorType) => {\n const error =\n errorType?.initializer(activeQuery) ??\n new Error('Unknown error from devtools')\n\n const __previousQueryOptions = activeQuery.options\n\n activeQuery.setState({\n status: 'error',\n error,\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n fetchMeta: {\n ...activeQuery.state.fetchMeta,\n __previousQueryOptions,\n } as any,\n })\n }\n\n const restoreQueryAfterLoadingOrError = () => {\n activeQuery.fetch(\n (activeQuery.state.fetchMeta as any).__previousQueryOptions,\n {\n // Make sure this fetch will cancel the previous one\n cancelRefetch: true,\n },\n )\n }\n\n return (\n <ActiveQueryPanel>\n <div\n style={{\n padding: '.5em',\n background: theme.backgroundAlt,\n position: 'sticky',\n top: 0,\n zIndex: 1,\n }}\n >\n Query Details\n </div>\n <div\n style={{\n padding: '.5em',\n }}\n >\n <div\n style={{\n marginBottom: '.5em',\n display: 'flex',\n alignItems: 'flex-start',\n justifyContent: 'space-between',\n }}\n >\n <Code\n style={{\n lineHeight: '1.8em',\n }}\n >\n <pre\n style={{\n margin: 0,\n padding: 0,\n overflow: 'auto',\n }}\n >\n {displayValue(activeQuery.queryKey, true)}\n </pre>\n </Code>\n <span\n style={{\n padding: '0.3em .6em',\n borderRadius: '0.4em',\n fontWeight: 'bold',\n textShadow: '0 2px 10px black',\n background: getQueryStatusColor({\n queryState: activeQueryState,\n isStale: isStale,\n observerCount: observerCount,\n theme,\n }),\n flexShrink: 0,\n }}\n >\n {getQueryStatusLabel(activeQuery)}\n </span>\n </div>\n <div\n style={{\n marginBottom: '.5em',\n display: 'flex',\n alignItems: 'center',\n justifyContent: 'space-between',\n }}\n >\n Observers: <Code>{observerCount}</Code>\n </div>\n <div\n style={{\n display: 'flex',\n alignItems: 'center',\n justifyContent: 'space-between',\n }}\n >\n Last Updated:{' '}\n <Code>\n {new Date(activeQueryState.dataUpdatedAt).toLocaleTimeString()}\n </Code>\n </div>\n </div>\n <div\n style={{\n background: theme.backgroundAlt,\n padding: '.5em',\n position: 'sticky',\n top: 0,\n zIndex: 1,\n }}\n >\n Actions\n </div>\n <div\n style={{\n padding: '0.5em',\n display: 'flex',\n flexWrap: 'wrap',\n gap: '0.5em',\n alignItems: 'flex-end',\n }}\n >\n <Button\n type=\"button\"\n onClick={handleRefetch}\n disabled={activeQueryState.fetchStatus === 'fetching'}\n style={{\n background: theme.active,\n }}\n >\n Refetch\n </Button>{' '}\n <Button\n type=\"button\"\n onClick={() => queryClient.invalidateQueries(activeQuery)}\n style={{\n background: theme.warning,\n color: theme.inputTextColor,\n }}\n >\n Invalidate\n </Button>{' '}\n <Button\n type=\"button\"\n onClick={() => queryClient.resetQueries(activeQuery)}\n style={{\n background: theme.gray,\n }}\n >\n Reset\n </Button>{' '}\n <Button\n type=\"button\"\n onClick={() => queryClient.removeQueries(activeQuery)}\n style={{\n background: theme.danger,\n }}\n >\n Remove\n </Button>{' '}\n <Button\n type=\"button\"\n onClick={() => {\n if (activeQuery.state.data === undefined) {\n restoreQueryAfterLoadingOrError()\n } else {\n const __previousQueryOptions = activeQuery.options\n // Trigger a fetch in order to trigger suspense as well.\n activeQuery.fetch({\n ...__previousQueryOptions,\n queryFn: () => {\n return new Promise(() => {\n // Never resolve\n })\n },\n gcTime: -1,\n })\n activeQuery.setState({\n data: undefined,\n status: 'pending',\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n fetchMeta: {\n ...activeQuery.state.fetchMeta,\n __previousQueryOptions,\n } as any,\n })\n }\n }}\n style={{\n background: theme.paused,\n }}\n >\n {activeQuery.state.status === 'pending' ? 'Restore' : 'Trigger'}{' '}\n loading\n </Button>{' '}\n {errorTypes.length === 0 || activeQuery.state.status === 'error' ? (\n <Button\n type=\"button\"\n onClick={() => {\n if (!activeQuery.state.error) {\n triggerError()\n } else {\n queryClient.resetQueries(activeQuery)\n }\n }}\n style={{\n background: theme.danger,\n }}\n >\n {activeQuery.state.status === 'error' ? 'Restore' : 'Trigger'} error\n </Button>\n ) : (\n <label>\n Trigger error:\n <Select\n value={currentErrorTypeName ?? ''}\n style={{ marginInlineStart: '.5em' }}\n onChange={(e) => {\n const errorType = errorTypes.find(\n (t) => t.name === e.target.value,\n )\n\n triggerError(errorType)\n }}\n >\n <option key=\"\" value=\"\" />\n {errorTypes.map((errorType) => (\n <option key={errorType.name} value={errorType.name}>\n {errorType.name}\n </option>\n ))}\n </Select>\n </label>\n )}\n </div>\n <div\n style={{\n background: theme.backgroundAlt,\n padding: '.5em',\n position: 'sticky',\n top: 0,\n zIndex: 1,\n }}\n >\n Data Explorer\n </div>\n <div\n style={{\n padding: '.5em',\n }}\n >\n <Explorer\n label=\"Data\"\n value={activeQueryState.data}\n defaultExpanded={{}}\n copyable\n />\n </div>\n <div\n style={{\n background: theme.backgroundAlt,\n padding: '.5em',\n position: 'sticky',\n top: 0,\n zIndex: 1,\n }}\n >\n Query Explorer\n </div>\n <div\n style={{\n padding: '.5em',\n }}\n >\n <Explorer\n label=\"Query\"\n value={activeQuery}\n defaultExpanded={{\n queryKey: true,\n }}\n />\n </div>\n </ActiveQueryPanel>\n )\n}\n\nActiveQuery.displayName = 'ActiveQuery'\n\nexport default ActiveQuery\n"],"names":["noop","ActiveQuery","queryCache","activeQueryHash","queryClient","errorTypes","activeQuery","useSubscribeToQueryCache","getAll","find","query","queryHash","activeQueryState","state","isStale","observerCount","getObserversCount","handleRefetch","promise","fetch","catch","currentErrorTypeName","React","useMemo","error","errorType","type","initializer","toString","name","undefined","triggerError","Error","__previousQueryOptions","options","setState","status","fetchMeta","restoreQueryAfterLoadingOrError","cancelRefetch","padding","background","theme","backgroundAlt","position","top","zIndex","marginBottom","display","alignItems","justifyContent","lineHeight","margin","overflow","displayValue","queryKey","borderRadius","fontWeight","textShadow","getQueryStatusColor","queryState","flexShrink","getQueryStatusLabel","Date","dataUpdatedAt","toLocaleTimeString","flexWrap","gap","fetchStatus","active","invalidateQueries","warning","color","inputTextColor","resetQueries","gray","removeQueries","danger","data","queryFn","Promise","gcTime","paused","length","marginInlineStart","e","t","target","value","map","displayName"],"mappings":";;;;;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,OAAO,EAAE,MAAA;AACX,KAAA;AAAE,GAAA,eAEFlB,6BAAC,QAAQ,EAAA;AACP,IAAA,KAAK,EAAC,MAAM;IACZ,KAAK,EAAEV,gBAAgB,CAACkE,IAAK;IAC7B,eAAe,EAAE,EAAG;IACpB,QAAQ,EAAA,IAAA;AAAA,GAAA,CACR,CACE,eACNxD,cAAA,CAAA,aAAA,CAAA,KAAA,EAAA;AACE,IAAA,KAAK,EAAE;MACLmB,UAAU,EAAEC,YAAK,CAACC,aAAa;AAC/BH,MAAAA,OAAO,EAAE,MAAM;AACfI,MAAAA,QAAQ,EAAE,QAAQ;AAClBC,MAAAA,GAAG,EAAE,CAAC;AACNC,MAAAA,MAAM,EAAE,CAAA;AACV,KAAA;GACD,EAAA,gBAED,CAAM,eACNxB,cAAA,CAAA,aAAA,CAAA,KAAA,EAAA;AACE,IAAA,KAAK,EAAE;AACLkB,MAAAA,OAAO,EAAE,MAAA;AACX,KAAA;AAAE,GAAA,eAEFlB,6BAAC,QAAQ,EAAA;AACP,IAAA,KAAK,EAAC,OAAO;AACb,IAAA,KAAK,EAAEhB,WAAY;AACnB,IAAA,eAAe,EAAE;AACfiD,MAAAA,QAAQ,EAAE,IAAA;AACZ,KAAA;AAAE,GAAA,CACF,CACE,CACW,CAAA;AAEvB,CAAC,CAAA;AAEDtD,WAAW,CAACyF,WAAW,GAAG,aAAa,CAAA;AAEvC,oBAAezF,WAAW;;;;"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { QueryClient } from '@tanstack/react-query';
|
|
3
|
+
import type { Side } from '../utils';
|
|
4
|
+
import type { DevToolsErrorType } from '../types';
|
|
5
|
+
interface DevtoolsPanelOptions {
|
|
6
|
+
/**
|
|
7
|
+
* The standard React style object used to style a component with inline styles
|
|
8
|
+
*/
|
|
9
|
+
style?: React.CSSProperties;
|
|
10
|
+
/**
|
|
11
|
+
* The standard React className property used to style a component with classes
|
|
12
|
+
*/
|
|
13
|
+
className?: string;
|
|
14
|
+
/**
|
|
15
|
+
* A boolean variable indicating whether the panel is open or closed
|
|
16
|
+
*/
|
|
17
|
+
isOpen?: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* nonce for style element for CSP
|
|
20
|
+
*/
|
|
21
|
+
styleNonce?: string;
|
|
22
|
+
/**
|
|
23
|
+
* A function that toggles the open and close state of the panel
|
|
24
|
+
*/
|
|
25
|
+
setIsOpen: (isOpen: boolean) => void;
|
|
26
|
+
/**
|
|
27
|
+
* Handles the opening and closing the devtools panel
|
|
28
|
+
*/
|
|
29
|
+
onDragStart: (e: React.MouseEvent<HTMLDivElement, MouseEvent>) => void;
|
|
30
|
+
/**
|
|
31
|
+
* The position of the React Query devtools panel.
|
|
32
|
+
* Defaults to 'bottom'.
|
|
33
|
+
*/
|
|
34
|
+
position?: Side;
|
|
35
|
+
/**
|
|
36
|
+
* Handles the panel position select change
|
|
37
|
+
*/
|
|
38
|
+
onPositionChange?: (side: Side) => void;
|
|
39
|
+
/**
|
|
40
|
+
* Show a close button inside the panel
|
|
41
|
+
*/
|
|
42
|
+
showCloseButton?: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Use this to add props to the close button. For example, you can add className, style (merge and override default style), onClick (extend default handler), etc.
|
|
45
|
+
*/
|
|
46
|
+
closeButtonProps?: React.ComponentPropsWithoutRef<'button'>;
|
|
47
|
+
/**
|
|
48
|
+
* Custom instance of QueryClient
|
|
49
|
+
*/
|
|
50
|
+
queryClient?: QueryClient;
|
|
51
|
+
/**
|
|
52
|
+
* Use this so you can define custom errors that can be shown in the devtools.
|
|
53
|
+
*/
|
|
54
|
+
errorTypes?: DevToolsErrorType[];
|
|
55
|
+
}
|
|
56
|
+
export declare const ReactQueryDevtoolsPanel: React.ForwardRefExoticComponent<DevtoolsPanelOptions & React.RefAttributes<HTMLDivElement>>;
|
|
57
|
+
export default ReactQueryDevtoolsPanel;
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
import { extends as _extends } from '../_virtual/_rollupPluginBabelHelpers.esm.js';
|
|
2
|
+
import React__default from 'react';
|
|
3
|
+
import { useQueryClient, onlineManager } from '@tanstack/react-query';
|
|
4
|
+
import { rankItem } from '@tanstack/match-sorter-utils';
|
|
5
|
+
import { Panel, Select, Input, Button } from '../styledComponents.esm.js';
|
|
6
|
+
import useSubscribeToQueryCache from '../useSubscribeToQueryCache.esm.js';
|
|
7
|
+
import QueryStatusCount from './Header/QueryStatusCount.esm.js';
|
|
8
|
+
import QueryRow from './QueryRow.esm.js';
|
|
9
|
+
import ActiveQuery from './ActiveQuery.esm.js';
|
|
10
|
+
import { sortFns, defaultPanelSize, getResizeHandleStyle } from '../utils.esm.js';
|
|
11
|
+
import { ThemeProvider, defaultTheme } from '../theme.esm.js';
|
|
12
|
+
import useLocalStorage from '../useLocalStorage.esm.js';
|
|
13
|
+
import Logo from '../Logo.esm.js';
|
|
14
|
+
import ScreenReader from '../screenreader.esm.js';
|
|
15
|
+
|
|
16
|
+
const ReactQueryDevtoolsPanel = /*#__PURE__*/React__default.forwardRef(function ReactQueryDevtoolsPanel(props, ref) {
|
|
17
|
+
const {
|
|
18
|
+
isOpen = true,
|
|
19
|
+
styleNonce,
|
|
20
|
+
setIsOpen,
|
|
21
|
+
queryClient,
|
|
22
|
+
onDragStart,
|
|
23
|
+
onPositionChange,
|
|
24
|
+
showCloseButton,
|
|
25
|
+
position,
|
|
26
|
+
closeButtonProps = {},
|
|
27
|
+
errorTypes = [],
|
|
28
|
+
...panelProps
|
|
29
|
+
} = props;
|
|
30
|
+
const {
|
|
31
|
+
onClick: onCloseClick,
|
|
32
|
+
...otherCloseButtonProps
|
|
33
|
+
} = closeButtonProps;
|
|
34
|
+
const client = useQueryClient(queryClient);
|
|
35
|
+
const queryCache = client.getQueryCache();
|
|
36
|
+
const [sort, setSort] = useLocalStorage('reactQueryDevtoolsSortFn', Object.keys(sortFns)[0]);
|
|
37
|
+
const [filter, setFilter] = useLocalStorage('reactQueryDevtoolsFilter', '');
|
|
38
|
+
const [baseSort, setBaseSort] = useLocalStorage('reactQueryDevtoolsBaseSort', 1);
|
|
39
|
+
const sortFn = React__default.useMemo(() => sortFns[sort], [sort]);
|
|
40
|
+
const queriesCount = useSubscribeToQueryCache(queryCache, () => queryCache.getAll().length, !isOpen);
|
|
41
|
+
const [activeQueryHash, setActiveQueryHash] = useLocalStorage('reactQueryDevtoolsActiveQueryHash', '');
|
|
42
|
+
const queries = React__default.useMemo(() => {
|
|
43
|
+
const unsortedQueries = queryCache.getAll();
|
|
44
|
+
if (queriesCount === 0) {
|
|
45
|
+
return [];
|
|
46
|
+
}
|
|
47
|
+
const filtered = filter ? unsortedQueries.filter(item => rankItem(item.queryHash, filter).passed) : [...unsortedQueries];
|
|
48
|
+
const sorted = sortFn ? filtered.sort((a, b) => sortFn(a, b) * baseSort) : filtered;
|
|
49
|
+
return sorted;
|
|
50
|
+
}, [baseSort, sortFn, filter, queriesCount, queryCache]);
|
|
51
|
+
const [isMockOffline, setMockOffline] = React__default.useState(false);
|
|
52
|
+
return /*#__PURE__*/React__default.createElement(ThemeProvider, {
|
|
53
|
+
theme: defaultTheme
|
|
54
|
+
}, /*#__PURE__*/React__default.createElement(Panel, _extends({
|
|
55
|
+
ref: ref,
|
|
56
|
+
className: "ReactQueryDevtoolsPanel",
|
|
57
|
+
"aria-label": "React Query Devtools Panel",
|
|
58
|
+
id: "ReactQueryDevtoolsPanel"
|
|
59
|
+
}, panelProps, {
|
|
60
|
+
style: {
|
|
61
|
+
height: defaultPanelSize,
|
|
62
|
+
position: 'relative',
|
|
63
|
+
...panelProps.style
|
|
64
|
+
}
|
|
65
|
+
}), /*#__PURE__*/React__default.createElement("style", {
|
|
66
|
+
nonce: styleNonce,
|
|
67
|
+
dangerouslySetInnerHTML: {
|
|
68
|
+
__html: `
|
|
69
|
+
.ReactQueryDevtoolsPanel * {
|
|
70
|
+
scrollbar-color: ${defaultTheme.backgroundAlt} ${defaultTheme.gray};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
.ReactQueryDevtoolsPanel *::-webkit-scrollbar, .ReactQueryDevtoolsPanel scrollbar {
|
|
74
|
+
width: 1em;
|
|
75
|
+
height: 1em;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
.ReactQueryDevtoolsPanel *::-webkit-scrollbar-track, .ReactQueryDevtoolsPanel scrollbar-track {
|
|
79
|
+
background: ${defaultTheme.backgroundAlt};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
.ReactQueryDevtoolsPanel *::-webkit-scrollbar-thumb, .ReactQueryDevtoolsPanel scrollbar-thumb {
|
|
83
|
+
background: ${defaultTheme.gray};
|
|
84
|
+
border-radius: .5em;
|
|
85
|
+
border: 3px solid ${defaultTheme.backgroundAlt};
|
|
86
|
+
}
|
|
87
|
+
`
|
|
88
|
+
}
|
|
89
|
+
}), /*#__PURE__*/React__default.createElement("div", {
|
|
90
|
+
style: getResizeHandleStyle(position),
|
|
91
|
+
onMouseDown: onDragStart
|
|
92
|
+
}), isOpen && /*#__PURE__*/React__default.createElement("div", {
|
|
93
|
+
style: {
|
|
94
|
+
flex: '1 1 500px',
|
|
95
|
+
minHeight: '40%',
|
|
96
|
+
maxHeight: '100%',
|
|
97
|
+
overflow: 'auto',
|
|
98
|
+
borderRight: `1px solid ${defaultTheme.grayAlt}`,
|
|
99
|
+
display: 'flex',
|
|
100
|
+
flexDirection: 'column'
|
|
101
|
+
}
|
|
102
|
+
}, /*#__PURE__*/React__default.createElement("div", {
|
|
103
|
+
style: {
|
|
104
|
+
padding: '.5em',
|
|
105
|
+
background: defaultTheme.backgroundAlt,
|
|
106
|
+
display: 'flex',
|
|
107
|
+
justifyContent: 'space-between',
|
|
108
|
+
alignItems: 'center'
|
|
109
|
+
}
|
|
110
|
+
}, /*#__PURE__*/React__default.createElement("button", {
|
|
111
|
+
type: "button",
|
|
112
|
+
"aria-label": "Close React Query Devtools",
|
|
113
|
+
"aria-controls": "ReactQueryDevtoolsPanel",
|
|
114
|
+
"aria-haspopup": "true",
|
|
115
|
+
"aria-expanded": "true",
|
|
116
|
+
onClick: () => setIsOpen(false),
|
|
117
|
+
style: {
|
|
118
|
+
display: 'inline-flex',
|
|
119
|
+
background: 'none',
|
|
120
|
+
border: 0,
|
|
121
|
+
padding: 0,
|
|
122
|
+
marginRight: '.5em',
|
|
123
|
+
cursor: 'pointer'
|
|
124
|
+
}
|
|
125
|
+
}, /*#__PURE__*/React__default.createElement(Logo, {
|
|
126
|
+
"aria-hidden": true
|
|
127
|
+
}), /*#__PURE__*/React__default.createElement(ScreenReader, {
|
|
128
|
+
text: "Close React Query Devtools"
|
|
129
|
+
})), /*#__PURE__*/React__default.createElement("div", {
|
|
130
|
+
style: {
|
|
131
|
+
display: 'flex',
|
|
132
|
+
flexDirection: 'column'
|
|
133
|
+
}
|
|
134
|
+
}, /*#__PURE__*/React__default.createElement("div", {
|
|
135
|
+
style: {
|
|
136
|
+
display: 'flex',
|
|
137
|
+
justifyContent: 'space-between',
|
|
138
|
+
alignItems: 'center',
|
|
139
|
+
marginBottom: '.5em'
|
|
140
|
+
}
|
|
141
|
+
}, /*#__PURE__*/React__default.createElement(QueryStatusCount, {
|
|
142
|
+
queryCache: queryCache
|
|
143
|
+
}), position && onPositionChange ? /*#__PURE__*/React__default.createElement(Select, {
|
|
144
|
+
"aria-label": "Panel position",
|
|
145
|
+
value: position,
|
|
146
|
+
style: {
|
|
147
|
+
marginInlineStart: '.5em'
|
|
148
|
+
},
|
|
149
|
+
onChange: e => onPositionChange(e.target.value)
|
|
150
|
+
}, /*#__PURE__*/React__default.createElement("option", {
|
|
151
|
+
value: "left"
|
|
152
|
+
}, "Left"), /*#__PURE__*/React__default.createElement("option", {
|
|
153
|
+
value: "right"
|
|
154
|
+
}, "Right"), /*#__PURE__*/React__default.createElement("option", {
|
|
155
|
+
value: "top"
|
|
156
|
+
}, "Top"), /*#__PURE__*/React__default.createElement("option", {
|
|
157
|
+
value: "bottom"
|
|
158
|
+
}, "Bottom")) : null), /*#__PURE__*/React__default.createElement("div", {
|
|
159
|
+
style: {
|
|
160
|
+
display: 'flex',
|
|
161
|
+
alignItems: 'center',
|
|
162
|
+
flexWrap: 'wrap',
|
|
163
|
+
gap: '0.5em'
|
|
164
|
+
}
|
|
165
|
+
}, /*#__PURE__*/React__default.createElement(Input, {
|
|
166
|
+
placeholder: "Filter",
|
|
167
|
+
"aria-label": "Filter by queryhash",
|
|
168
|
+
value: filter != null ? filter : '',
|
|
169
|
+
onChange: e => setFilter(e.target.value),
|
|
170
|
+
onKeyDown: e => {
|
|
171
|
+
if (e.key === 'Escape') setFilter('');
|
|
172
|
+
},
|
|
173
|
+
style: {
|
|
174
|
+
flex: '1',
|
|
175
|
+
width: '100%'
|
|
176
|
+
}
|
|
177
|
+
}), /*#__PURE__*/React__default.createElement(Select, {
|
|
178
|
+
"aria-label": "Sort queries",
|
|
179
|
+
value: sort,
|
|
180
|
+
onChange: e => setSort(e.target.value),
|
|
181
|
+
style: {
|
|
182
|
+
flex: '1',
|
|
183
|
+
minWidth: 75,
|
|
184
|
+
marginRight: '.5em'
|
|
185
|
+
}
|
|
186
|
+
}, Object.keys(sortFns).map(key => /*#__PURE__*/React__default.createElement("option", {
|
|
187
|
+
key: key,
|
|
188
|
+
value: key
|
|
189
|
+
}, "Sort by ", key))), /*#__PURE__*/React__default.createElement(Button, {
|
|
190
|
+
type: "button",
|
|
191
|
+
onClick: () => setBaseSort(old => old * -1),
|
|
192
|
+
style: {
|
|
193
|
+
padding: '.3em .4em',
|
|
194
|
+
marginRight: '.5em'
|
|
195
|
+
}
|
|
196
|
+
}, baseSort === 1 ? '⬆ Asc' : '⬇ Desc'), /*#__PURE__*/React__default.createElement(Button, {
|
|
197
|
+
type: "button",
|
|
198
|
+
onClick: () => {
|
|
199
|
+
if (isMockOffline) {
|
|
200
|
+
onlineManager.setOnline(undefined);
|
|
201
|
+
setMockOffline(false);
|
|
202
|
+
window.dispatchEvent(new Event('online'));
|
|
203
|
+
} else {
|
|
204
|
+
onlineManager.setOnline(false);
|
|
205
|
+
setMockOffline(true);
|
|
206
|
+
window.dispatchEvent(new Event('offline'));
|
|
207
|
+
}
|
|
208
|
+
},
|
|
209
|
+
"aria-label": isMockOffline ? 'Restore offline mock' : 'Mock offline behavior',
|
|
210
|
+
title: isMockOffline ? 'Restore offline mock' : 'Mock offline behavior',
|
|
211
|
+
style: {
|
|
212
|
+
padding: '0',
|
|
213
|
+
height: '2em'
|
|
214
|
+
}
|
|
215
|
+
}, /*#__PURE__*/React__default.createElement("svg", {
|
|
216
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
217
|
+
width: "2em",
|
|
218
|
+
height: "2em",
|
|
219
|
+
viewBox: "0 0 24 24",
|
|
220
|
+
stroke: isMockOffline ? defaultTheme.danger : 'currentColor',
|
|
221
|
+
fill: "none"
|
|
222
|
+
}, isMockOffline ? /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement("path", {
|
|
223
|
+
stroke: "none",
|
|
224
|
+
d: "M0 0h24v24H0z",
|
|
225
|
+
fill: "none"
|
|
226
|
+
}), /*#__PURE__*/React__default.createElement("line", {
|
|
227
|
+
x1: "12",
|
|
228
|
+
y1: "18",
|
|
229
|
+
x2: "12.01",
|
|
230
|
+
y2: "18"
|
|
231
|
+
}), /*#__PURE__*/React__default.createElement("path", {
|
|
232
|
+
d: "M9.172 15.172a4 4 0 0 1 5.656 0"
|
|
233
|
+
}), /*#__PURE__*/React__default.createElement("path", {
|
|
234
|
+
d: "M6.343 12.343a7.963 7.963 0 0 1 3.864 -2.14m4.163 .155a7.965 7.965 0 0 1 3.287 2"
|
|
235
|
+
}), /*#__PURE__*/React__default.createElement("path", {
|
|
236
|
+
d: "M3.515 9.515a12 12 0 0 1 3.544 -2.455m3.101 -.92a12 12 0 0 1 10.325 3.374"
|
|
237
|
+
}), /*#__PURE__*/React__default.createElement("line", {
|
|
238
|
+
x1: "3",
|
|
239
|
+
y1: "3",
|
|
240
|
+
x2: "21",
|
|
241
|
+
y2: "21"
|
|
242
|
+
})) : /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement("path", {
|
|
243
|
+
stroke: "none",
|
|
244
|
+
d: "M0 0h24v24H0z",
|
|
245
|
+
fill: "none"
|
|
246
|
+
}), /*#__PURE__*/React__default.createElement("line", {
|
|
247
|
+
x1: "12",
|
|
248
|
+
y1: "18",
|
|
249
|
+
x2: "12.01",
|
|
250
|
+
y2: "18"
|
|
251
|
+
}), /*#__PURE__*/React__default.createElement("path", {
|
|
252
|
+
d: "M9.172 15.172a4 4 0 0 1 5.656 0"
|
|
253
|
+
}), /*#__PURE__*/React__default.createElement("path", {
|
|
254
|
+
d: "M6.343 12.343a8 8 0 0 1 11.314 0"
|
|
255
|
+
}), /*#__PURE__*/React__default.createElement("path", {
|
|
256
|
+
d: "M3.515 9.515c4.686 -4.687 12.284 -4.687 17 0"
|
|
257
|
+
}))), /*#__PURE__*/React__default.createElement(ScreenReader, {
|
|
258
|
+
text: isMockOffline ? 'Restore offline mock' : 'Mock offline behavior'
|
|
259
|
+
}))))), /*#__PURE__*/React__default.createElement("div", {
|
|
260
|
+
style: {
|
|
261
|
+
overflowY: 'auto',
|
|
262
|
+
flex: '1'
|
|
263
|
+
}
|
|
264
|
+
}, queries.map(query => {
|
|
265
|
+
return /*#__PURE__*/React__default.createElement(QueryRow, {
|
|
266
|
+
queryKey: query.queryKey,
|
|
267
|
+
activeQueryHash: activeQueryHash,
|
|
268
|
+
setActiveQueryHash: setActiveQueryHash,
|
|
269
|
+
key: query.queryHash,
|
|
270
|
+
queryCache: queryCache
|
|
271
|
+
});
|
|
272
|
+
}))), activeQueryHash && isOpen ? /*#__PURE__*/React__default.createElement(ActiveQuery, {
|
|
273
|
+
activeQueryHash: activeQueryHash,
|
|
274
|
+
queryCache: queryCache,
|
|
275
|
+
queryClient: client,
|
|
276
|
+
errorTypes: errorTypes
|
|
277
|
+
}) : null, showCloseButton ? /*#__PURE__*/React__default.createElement(Button, _extends({
|
|
278
|
+
type: "button",
|
|
279
|
+
"aria-controls": "ReactQueryDevtoolsPanel",
|
|
280
|
+
"aria-haspopup": "true",
|
|
281
|
+
"aria-expanded": "true"
|
|
282
|
+
}, otherCloseButtonProps, {
|
|
283
|
+
style: {
|
|
284
|
+
position: 'absolute',
|
|
285
|
+
zIndex: 99999,
|
|
286
|
+
margin: '.5em',
|
|
287
|
+
bottom: 0,
|
|
288
|
+
left: 0,
|
|
289
|
+
...otherCloseButtonProps.style
|
|
290
|
+
},
|
|
291
|
+
onClick: e => {
|
|
292
|
+
setIsOpen(false);
|
|
293
|
+
onCloseClick == null ? void 0 : onCloseClick(e);
|
|
294
|
+
}
|
|
295
|
+
}), "Close") : null));
|
|
296
|
+
});
|
|
297
|
+
ReactQueryDevtoolsPanel.displayName = 'ReactQueryDevtoolsPanel';
|
|
298
|
+
var ReactQueryDevtoolsPanel$1 = ReactQueryDevtoolsPanel;
|
|
299
|
+
|
|
300
|
+
export { ReactQueryDevtoolsPanel, ReactQueryDevtoolsPanel$1 as default };
|
|
301
|
+
//# sourceMappingURL=CachePanel.esm.js.map
|