@inventreedb/ui 0.8.0 → 0.8.1

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.
@@ -1,9 +1,11 @@
1
+ import { QueryClient } from '@tanstack/react-query';
1
2
  import { AxiosInstance } from 'axios';
2
3
  /**
3
4
  * Hook for monitoring a data output process running on the server
4
5
  */
5
- export default function monitorDataOutput({ api, title, hostname, id }: {
6
+ export default function monitorDataOutput({ api, queryClient, title, hostname, id }: {
6
7
  api: AxiosInstance;
8
+ queryClient?: QueryClient;
7
9
  title: string;
8
10
  hostname?: string;
9
11
  id?: number;
@@ -13,6 +13,7 @@ const useEffect = window["React"].useEffect;
13
13
  const useState = window["React"].useState;
14
14
  function monitorDataOutput({
15
15
  api,
16
+ queryClient,
16
17
  title,
17
18
  hostname,
18
19
  id
@@ -104,7 +105,7 @@ function monitorDataOutput({
104
105
  });
105
106
  return {};
106
107
  })
107
- });
108
+ }, queryClient);
108
109
  }
109
110
  export {
110
111
  monitorDataOutput as default
@@ -1 +1 @@
1
- {"version":3,"file":"MonitorDataOutput.js","sources":["../../lib/hooks/MonitorDataOutput.tsx"],"sourcesContent":["import { t } from '@lingui/core/macro';\nimport { useDocumentVisibility } from '@mantine/hooks';\nimport { notifications, showNotification } from '@mantine/notifications';\nimport { IconCircleCheck, IconExclamationCircle } from '@tabler/icons-react';\nimport { useQuery } from '@tanstack/react-query';\nimport type { AxiosInstance } from 'axios';\nimport { useEffect, useState } from 'react';\nimport { ProgressBar } from '../components/ProgressBar';\nimport { ApiEndpoints } from '../enums/ApiEndpoints';\nimport { apiUrl } from '../functions/Api';\n\n/**\n * Hook for monitoring a data output process running on the server\n */\nexport default function monitorDataOutput({\n api,\n title,\n hostname,\n id\n}: {\n api: AxiosInstance;\n title: string;\n hostname?: string;\n id?: number;\n}) {\n const visibility = useDocumentVisibility();\n\n const [loading, setLoading] = useState<boolean>(false);\n\n useEffect(() => {\n if (!!id) {\n setLoading(true);\n showNotification({\n id: `data-output-${id}`,\n title: title,\n loading: true,\n autoClose: false,\n withCloseButton: false,\n message: <ProgressBar size='lg' value={0} progressLabel />\n });\n } else setLoading(false);\n }, [id, title]);\n\n useQuery({\n enabled: !!id && loading && visibility === 'visible',\n refetchInterval: 500,\n queryKey: ['data-output', id, title],\n queryFn: () =>\n api\n .get(apiUrl(ApiEndpoints.data_output, id))\n .then((response) => {\n const data = response?.data ?? {};\n\n if (!!data.errors || !!data.error) {\n setLoading(false);\n\n const error: string =\n data?.error ?? data?.errors?.error ?? t`Process failed`;\n\n notifications.update({\n id: `data-output-${id}`,\n loading: false,\n icon: <IconExclamationCircle />,\n autoClose: 2500,\n title: title,\n message: error,\n color: 'red'\n });\n } else if (data.complete) {\n setLoading(false);\n notifications.update({\n id: `data-output-${id}`,\n loading: false,\n autoClose: 2500,\n title: title,\n message: t`Process completed successfully`,\n color: 'green',\n icon: <IconCircleCheck />\n });\n\n if (data.output) {\n const url = data.output;\n const base = hostname ?? window.location.hostname;\n\n const downloadUrl = new URL(url, base);\n\n window.open(downloadUrl.toString(), '_blank');\n }\n } else {\n notifications.update({\n id: `data-output-${id}`,\n loading: true,\n autoClose: false,\n withCloseButton: false,\n message: (\n <ProgressBar\n size='lg'\n maximum={data.total}\n value={data.progress}\n progressLabel={data.total > 0}\n animated\n />\n )\n });\n }\n\n return data;\n })\n .catch(() => {\n setLoading(false);\n notifications.update({\n id: `data-output-${id}`,\n loading: false,\n autoClose: 2500,\n title: title,\n message: t`Process failed`,\n color: 'red'\n });\n return {};\n })\n });\n}\n"],"names":["monitorDataOutput","api","title","hostname","id","visibility","useDocumentVisibility","loading","setLoading","useState","useEffect","showNotification","autoClose","withCloseButton","message","useQuery","enabled","refetchInterval","queryKey","queryFn","get","apiUrl","ApiEndpoints","data_output","then","response","data","errors","error","_i18n","_","notifications","update","icon","color","complete","output","url","base","window","location","downloadUrl","URL","open","toString","jsx","total","progress","catch"],"mappings":";;;;;;;;AAAA,MAAA,QAAA,OAAA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AAA;AAAA,IACT,CAAC;AAAA,EAAA,CACN;AACH;"}
1
+ {"version":3,"file":"MonitorDataOutput.js","sources":["../../lib/hooks/MonitorDataOutput.tsx"],"sourcesContent":["import { t } from '@lingui/core/macro';\nimport { useDocumentVisibility } from '@mantine/hooks';\nimport { notifications, showNotification } from '@mantine/notifications';\nimport { IconCircleCheck, IconExclamationCircle } from '@tabler/icons-react';\nimport { type QueryClient, useQuery } from '@tanstack/react-query';\nimport type { AxiosInstance } from 'axios';\nimport { useEffect, useState } from 'react';\nimport { ProgressBar } from '../components/ProgressBar';\nimport { ApiEndpoints } from '../enums/ApiEndpoints';\nimport { apiUrl } from '../functions/Api';\n\n/**\n * Hook for monitoring a data output process running on the server\n */\nexport default function monitorDataOutput({\n api,\n queryClient,\n title,\n hostname,\n id\n}: {\n api: AxiosInstance;\n queryClient?: QueryClient;\n title: string;\n hostname?: string;\n id?: number;\n}) {\n const visibility = useDocumentVisibility();\n\n const [loading, setLoading] = useState<boolean>(false);\n\n useEffect(() => {\n if (!!id) {\n setLoading(true);\n showNotification({\n id: `data-output-${id}`,\n title: title,\n loading: true,\n autoClose: false,\n withCloseButton: false,\n message: <ProgressBar size='lg' value={0} progressLabel />\n });\n } else setLoading(false);\n }, [id, title]);\n\n useQuery(\n {\n enabled: !!id && loading && visibility === 'visible',\n refetchInterval: 500,\n queryKey: ['data-output', id, title],\n queryFn: () =>\n api\n .get(apiUrl(ApiEndpoints.data_output, id))\n .then((response) => {\n const data = response?.data ?? {};\n\n if (!!data.errors || !!data.error) {\n setLoading(false);\n\n const error: string =\n data?.error ?? data?.errors?.error ?? t`Process failed`;\n\n notifications.update({\n id: `data-output-${id}`,\n loading: false,\n icon: <IconExclamationCircle />,\n autoClose: 2500,\n title: title,\n message: error,\n color: 'red'\n });\n } else if (data.complete) {\n setLoading(false);\n notifications.update({\n id: `data-output-${id}`,\n loading: false,\n autoClose: 2500,\n title: title,\n message: t`Process completed successfully`,\n color: 'green',\n icon: <IconCircleCheck />\n });\n\n if (data.output) {\n const url = data.output;\n const base = hostname ?? window.location.hostname;\n\n const downloadUrl = new URL(url, base);\n\n window.open(downloadUrl.toString(), '_blank');\n }\n } else {\n notifications.update({\n id: `data-output-${id}`,\n loading: true,\n autoClose: false,\n withCloseButton: false,\n message: (\n <ProgressBar\n size='lg'\n maximum={data.total}\n value={data.progress}\n progressLabel={data.total > 0}\n animated\n />\n )\n });\n }\n\n return data;\n })\n .catch(() => {\n setLoading(false);\n notifications.update({\n id: `data-output-${id}`,\n loading: false,\n autoClose: 2500,\n title: title,\n message: t`Process failed`,\n color: 'red'\n });\n return {};\n })\n },\n queryClient\n );\n}\n"],"names":["monitorDataOutput","api","queryClient","title","hostname","id","visibility","useDocumentVisibility","loading","setLoading","useState","useEffect","showNotification","autoClose","withCloseButton","message","useQuery","enabled","refetchInterval","queryKey","queryFn","get","apiUrl","ApiEndpoints","data_output","then","response","data","errors","error","_i18n","_","notifications","update","icon","color","complete","output","url","base","window","location","downloadUrl","URL","open","toString","jsx","total","progress","catch"],"mappings":";;;;;;;;AAAA,MAAA,QAAA,OAAA,YAAA,EAAA;AAEA,MAAA,gBAAA,OAAA,sBAAA,EAAA;;AAIA,MAAA,YAAA,OAAA,OAAA,EAAA;;AAQA,SAAwBA,kBAAkB;AAAA,EACxCC;AAAAA,EACAC;AAAAA,EACAC;AAAAA,EACAC;AAAAA,EACAC;AAOF,GAAG;AACD,QAAMC,aAAaC,sBAAAA;AAEnB,QAAM,CAACC,SAASC,UAAU,IAAIC,SAAkB,KAAK;AAErDC,YAAU,MAAM;AACd,QAAI,CAAC,CAACN,IAAI;AACRI,iBAAW,IAAI;AACfG,uBAAiB;AAAA,QACfP,IAAI,eAAeA,EAAE;AAAA,QACrBF;AAAAA,QACAK,SAAS;AAAA,QACTK,WAAW;AAAA,QACXC,iBAAiB;AAAA,QACjBC,+CAAU,aAAA,EAAY,MAAK,MAAK,OAAO,GAAG,eAAa,KAAA,CAAA;AAAA,MAAA,CACxD;AAAA,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AErCC,iBAAOI,KAAKF,YAAYG,SAAAA,GAAY,QAAQ;AAAA,QAC9C;AAAA,MACF,OAAO;AACLb,sBAAcC,OAAO;AAAA,UACnB5B,IAAI,eAAeA,EAAE;AAAA,UACrBG,SAAS;AAAA,UACTK,WAAW;AAAA,UACXC,iBAAiB;AAAA,UACjBC,SACE+B,kCAAAA,IAAC,aAAA,EACC,MAAK,MACL,SAASnB,KAAKoB,OACd,OAAOpB,KAAKqB,UACZ,eAAerB,KAAKoB,QAAQ,GAC5B,UAAQ,KAAA,CAAA;AAAA,QAAA,CAGb;AAAA,MACH;AAEA,aAAOpB;AAAAA,IACT,CAAC,EACAsB,MAAM,MAAM;AACXxC,iBAAW,KAAK;AAChBuB,oBAAcC,OAAO;AAAA,QACnB5B,IAAI,eAAeA,EAAE;AAAA,QACrBG,SAAS;AAAA,QACTK,WAAW;AAAA,QACXV;AAAAA,QACAY,SAAOe,MAAAC;AAAAA;AAAAA,UAAE;AAAA,YAAA1B,IAAA;AAAA,UAAA;AAAA,QAAgB;AAAA,QACzB8B,OAAO;AAAA,MAAA,CACR;AACD,aAAO,CAAA;AAAA,IACT,CAAC;AAAA,EAAA,GAEPjC,WACF;AACF;"}
@@ -5,6 +5,9 @@ var QueryClientContext = React.createContext(
5
5
  );
6
6
  var useQueryClient = (queryClient) => {
7
7
  const client = React.useContext(QueryClientContext);
8
+ if (queryClient) {
9
+ return queryClient;
10
+ }
8
11
  if (!client) {
9
12
  throw new Error("No QueryClient set, use QueryClientProvider to set one");
10
13
  }
@@ -1 +1 @@
1
- {"version":3,"file":"QueryClientProvider.js","sources":["../../../../../../node_modules/@tanstack/react-query/build/modern/QueryClientProvider.js"],"sourcesContent":["\"use client\";\n\n// src/QueryClientProvider.tsx\nimport * as React from \"react\";\nimport { jsx } from \"react/jsx-runtime\";\nvar QueryClientContext = React.createContext(\n void 0\n);\nvar useQueryClient = (queryClient) => {\n const client = React.useContext(QueryClientContext);\n if (queryClient) {\n return queryClient;\n }\n if (!client) {\n throw new Error(\"No QueryClient set, use QueryClientProvider to set one\");\n }\n return client;\n};\nvar QueryClientProvider = ({\n client,\n children\n}) => {\n React.useEffect(() => {\n client.mount();\n return () => {\n client.unmount();\n };\n }, [client]);\n return /* @__PURE__ */ jsx(QueryClientContext.Provider, { value: client, children });\n};\nexport {\n QueryClientContext,\n QueryClientProvider,\n useQueryClient\n};\n//# sourceMappingURL=QueryClientProvider.js.map"],"names":[],"mappings":";AAGA,MAAA,QAAA,OAAA,OAAA;AAEG,IAAC,qBAAqB,MAAM;AAAA,EAC7B;AACF;AACG,IAAC,iBAAiB,CAAC,gBAAgB;AACpC,QAAM,SAAS,MAAM,WAAW,kBAAkB;AAIlD,MAAI,CAAC,QAAQ;AACX,UAAM,IAAI,MAAM,wDAAwD;AAAA,EAC1E;AACA,SAAO;AACT;","x_google_ignoreList":[0]}
1
+ {"version":3,"file":"QueryClientProvider.js","sources":["../../../../../../node_modules/@tanstack/react-query/build/modern/QueryClientProvider.js"],"sourcesContent":["\"use client\";\n\n// src/QueryClientProvider.tsx\nimport * as React from \"react\";\nimport { jsx } from \"react/jsx-runtime\";\nvar QueryClientContext = React.createContext(\n void 0\n);\nvar useQueryClient = (queryClient) => {\n const client = React.useContext(QueryClientContext);\n if (queryClient) {\n return queryClient;\n }\n if (!client) {\n throw new Error(\"No QueryClient set, use QueryClientProvider to set one\");\n }\n return client;\n};\nvar QueryClientProvider = ({\n client,\n children\n}) => {\n React.useEffect(() => {\n client.mount();\n return () => {\n client.unmount();\n };\n }, [client]);\n return /* @__PURE__ */ jsx(QueryClientContext.Provider, { value: client, children });\n};\nexport {\n QueryClientContext,\n QueryClientProvider,\n useQueryClient\n};\n//# sourceMappingURL=QueryClientProvider.js.map"],"names":[],"mappings":";AAGA,MAAA,QAAA,OAAA,OAAA;AAEG,IAAC,qBAAqB,MAAM;AAAA,EAC7B;AACF;AACG,IAAC,iBAAiB,CAAC,gBAAgB;AACpC,QAAM,SAAS,MAAM,WAAW,kBAAkB;AAClD,MAAI,aAAa;AACf,WAAO;AAAA,EACT;AACA,MAAI,CAAC,QAAQ;AACX,UAAM,IAAI,MAAM,wDAAwD;AAAA,EAC1E;AACA,SAAO;AACT;","x_google_ignoreList":[0]}
@@ -16,7 +16,7 @@ function useBaseQuery(options, Observer, queryClient) {
16
16
  }
17
17
  const isRestoring = useIsRestoring();
18
18
  const errorResetBoundary = useQueryErrorResetBoundary();
19
- const client = useQueryClient();
19
+ const client = useQueryClient(queryClient);
20
20
  const defaultedOptions = client.defaultQueryOptions(options);
21
21
  client.getDefaultOptions().queries?._experimental_beforeQuery?.(
22
22
  defaultedOptions
@@ -1 +1 @@
1
- {"version":3,"file":"useBaseQuery.js","sources":["../../../../../../node_modules/@tanstack/react-query/build/modern/useBaseQuery.js"],"sourcesContent":["\"use client\";\n\n// src/useBaseQuery.ts\nimport * as React from \"react\";\nimport { isServer, noop, notifyManager } from \"@tanstack/query-core\";\nimport { useQueryClient } from \"./QueryClientProvider.js\";\nimport { useQueryErrorResetBoundary } from \"./QueryErrorResetBoundary.js\";\nimport {\n ensurePreventErrorBoundaryRetry,\n getHasError,\n useClearResetErrorBoundary\n} from \"./errorBoundaryUtils.js\";\nimport { useIsRestoring } from \"./IsRestoringProvider.js\";\nimport {\n ensureSuspenseTimers,\n fetchOptimistic,\n shouldSuspend,\n willFetch\n} from \"./suspense.js\";\nfunction useBaseQuery(options, Observer, queryClient) {\n if (process.env.NODE_ENV !== \"production\") {\n if (typeof options !== \"object\" || Array.isArray(options)) {\n throw new Error(\n 'Bad argument type. Starting with v5, only the \"Object\" form is allowed when calling query related functions. Please use the error stack to find the culprit call. More info here: https://tanstack.com/query/latest/docs/react/guides/migrating-to-v5#supports-a-single-signature-one-object'\n );\n }\n }\n const isRestoring = useIsRestoring();\n const errorResetBoundary = useQueryErrorResetBoundary();\n const client = useQueryClient(queryClient);\n const defaultedOptions = client.defaultQueryOptions(options);\n client.getDefaultOptions().queries?._experimental_beforeQuery?.(\n defaultedOptions\n );\n if (process.env.NODE_ENV !== \"production\") {\n if (!defaultedOptions.queryFn) {\n console.error(\n `[${defaultedOptions.queryHash}]: No queryFn was passed as an option, and no default queryFn was found. The queryFn parameter is only optional when using a default queryFn. More info here: https://tanstack.com/query/latest/docs/framework/react/guides/default-query-function`\n );\n }\n }\n defaultedOptions._optimisticResults = isRestoring ? \"isRestoring\" : \"optimistic\";\n ensureSuspenseTimers(defaultedOptions);\n ensurePreventErrorBoundaryRetry(defaultedOptions, errorResetBoundary);\n useClearResetErrorBoundary(errorResetBoundary);\n const isNewCacheEntry = !client.getQueryCache().get(defaultedOptions.queryHash);\n const [observer] = React.useState(\n () => new Observer(\n client,\n defaultedOptions\n )\n );\n const result = observer.getOptimisticResult(defaultedOptions);\n const shouldSubscribe = !isRestoring && options.subscribed !== false;\n React.useSyncExternalStore(\n React.useCallback(\n (onStoreChange) => {\n const unsubscribe = shouldSubscribe ? observer.subscribe(notifyManager.batchCalls(onStoreChange)) : noop;\n observer.updateResult();\n return unsubscribe;\n },\n [observer, shouldSubscribe]\n ),\n () => observer.getCurrentResult(),\n () => observer.getCurrentResult()\n );\n React.useEffect(() => {\n observer.setOptions(defaultedOptions);\n }, [defaultedOptions, observer]);\n if (shouldSuspend(defaultedOptions, result)) {\n throw fetchOptimistic(defaultedOptions, observer, errorResetBoundary);\n }\n if (getHasError({\n result,\n errorResetBoundary,\n throwOnError: defaultedOptions.throwOnError,\n query: client.getQueryCache().get(defaultedOptions.queryHash),\n suspense: defaultedOptions.suspense\n })) {\n throw result.error;\n }\n ;\n client.getDefaultOptions().queries?._experimental_afterQuery?.(\n defaultedOptions,\n result\n );\n if (defaultedOptions.experimental_prefetchInRender && !isServer && willFetch(result, isRestoring)) {\n const promise = isNewCacheEntry ? (\n // Fetch immediately on render in order to ensure `.promise` is resolved even if the component is unmounted\n fetchOptimistic(defaultedOptions, observer, errorResetBoundary)\n ) : (\n // subscribe to the \"cache promise\" so that we can finalize the currentThenable once data comes in\n client.getQueryCache().get(defaultedOptions.queryHash)?.promise\n );\n promise?.catch(noop).finally(() => {\n observer.updateResult();\n });\n }\n return !defaultedOptions.notifyOnChangeProps ? observer.trackResult(result) : result;\n}\nexport {\n useBaseQuery\n};\n//# sourceMappingURL=useBaseQuery.js.map"],"names":[],"mappings":";;;;;;;AAGA,MAAA,QAAA,OAAA,OAAA;AAgBA,SAAS,aAAa,SAAS,UAAU,aAAa;AACpD,MAAI,QAAQ,IAAI,aAAa,cAAc;AACzC,QAAI,OAAO,YAAY,YAAY,MAAM,QAAQ,OAAO,GAAG;AACzD,YAAM,IAAI;AAAA,QACR;AAAA,MACR;AAAA,IACI;AAAA,EACF;AACA,QAAM,cAAc,eAAc;AAClC,QAAM,qBAAqB,2BAA0B;AACrD,QAAM,SAAS,eAA0B;AACzC,QAAM,mBAAmB,OAAO,oBAAoB,OAAO;AAC3D,SAAO,oBAAoB,SAAS;AAAA,IAClC;AAAA,EACJ;AACE,MAAI,QAAQ,IAAI,aAAa,cAAc;AACzC,QAAI,CAAC,iBAAiB,SAAS;AAC7B,cAAQ;AAAA,QACN,IAAI,iBAAiB,SAAS;AAAA,MACtC;AAAA,IACI;AAAA,EACF;AACA,mBAAiB,qBAAqB,cAAc,gBAAgB;AACpE,uBAAqB,gBAAgB;AACrC,kCAAgC,kBAAkB,kBAAkB;AACpE,6BAA2B,kBAAkB;AAC7C,QAAM,kBAAkB,CAAC,OAAO,cAAa,EAAG,IAAI,iBAAiB,SAAS;AAC9E,QAAM,CAAC,QAAQ,IAAI,MAAM;AAAA,IACvB,MAAM,IAAI;AAAA,MACR;AAAA,MACA;AAAA,IACN;AAAA,EACA;AACE,QAAM,SAAS,SAAS,oBAAoB,gBAAgB;AAC5D,QAAM,kBAAkB,CAAC,eAAe,QAAQ,eAAe;AAC/D,QAAM;AAAA,IACJ,MAAM;AAAA,MACJ,CAAC,kBAAkB;AACjB,cAAM,cAAc,kBAAkB,SAAS,UAAU,cAAc,WAAW,aAAa,CAAC,IAAI;AACpG,iBAAS,aAAY;AACrB,eAAO;AAAA,MACT;AAAA,MACA,CAAC,UAAU,eAAe;AAAA,IAChC;AAAA,IACI,MAAM,SAAS,iBAAgB;AAAA,IAC/B,MAAM,SAAS,iBAAgB;AAAA,EACnC;AACE,QAAM,UAAU,MAAM;AACpB,aAAS,WAAW,gBAAgB;AAAA,EACtC,GAAG,CAAC,kBAAkB,QAAQ,CAAC;AAC/B,MAAI,cAAc,kBAAkB,MAAM,GAAG;AAC3C,UAAM,gBAAgB,kBAAkB,UAAU,kBAAkB;AAAA,EACtE;AACA,MAAI,YAAY;AAAA,IACd;AAAA,IACA;AAAA,IACA,cAAc,iBAAiB;AAAA,IAC/B,OAAO,OAAO,cAAa,EAAG,IAAI,iBAAiB,SAAS;AAAA,IAC5D,UAAU,iBAAiB;AAAA,EAC/B,CAAG,GAAG;AACF,UAAM,OAAO;AAAA,EACf;AAEA,SAAO,oBAAoB,SAAS;AAAA,IAClC;AAAA,IACA;AAAA,EACJ;AACE,MAAI,iBAAiB,iCAAiC,CAAC,YAAY,UAAU,QAAQ,WAAW,GAAG;AACjG,UAAM,UAAU;AAAA;AAAA,MAEd,gBAAgB,kBAAkB,UAAU,kBAAkB;AAAA;AAAA;AAAA,MAG9D,OAAO,cAAa,EAAG,IAAI,iBAAiB,SAAS,GAAG;AAAA;AAE1D,aAAS,MAAM,IAAI,EAAE,QAAQ,MAAM;AACjC,eAAS,aAAY;AAAA,IACvB,CAAC;AAAA,EACH;AACA,SAAO,CAAC,iBAAiB,sBAAsB,SAAS,YAAY,MAAM,IAAI;AAChF;","x_google_ignoreList":[0]}
1
+ {"version":3,"file":"useBaseQuery.js","sources":["../../../../../../node_modules/@tanstack/react-query/build/modern/useBaseQuery.js"],"sourcesContent":["\"use client\";\n\n// src/useBaseQuery.ts\nimport * as React from \"react\";\nimport { isServer, noop, notifyManager } from \"@tanstack/query-core\";\nimport { useQueryClient } from \"./QueryClientProvider.js\";\nimport { useQueryErrorResetBoundary } from \"./QueryErrorResetBoundary.js\";\nimport {\n ensurePreventErrorBoundaryRetry,\n getHasError,\n useClearResetErrorBoundary\n} from \"./errorBoundaryUtils.js\";\nimport { useIsRestoring } from \"./IsRestoringProvider.js\";\nimport {\n ensureSuspenseTimers,\n fetchOptimistic,\n shouldSuspend,\n willFetch\n} from \"./suspense.js\";\nfunction useBaseQuery(options, Observer, queryClient) {\n if (process.env.NODE_ENV !== \"production\") {\n if (typeof options !== \"object\" || Array.isArray(options)) {\n throw new Error(\n 'Bad argument type. Starting with v5, only the \"Object\" form is allowed when calling query related functions. Please use the error stack to find the culprit call. More info here: https://tanstack.com/query/latest/docs/react/guides/migrating-to-v5#supports-a-single-signature-one-object'\n );\n }\n }\n const isRestoring = useIsRestoring();\n const errorResetBoundary = useQueryErrorResetBoundary();\n const client = useQueryClient(queryClient);\n const defaultedOptions = client.defaultQueryOptions(options);\n client.getDefaultOptions().queries?._experimental_beforeQuery?.(\n defaultedOptions\n );\n if (process.env.NODE_ENV !== \"production\") {\n if (!defaultedOptions.queryFn) {\n console.error(\n `[${defaultedOptions.queryHash}]: No queryFn was passed as an option, and no default queryFn was found. The queryFn parameter is only optional when using a default queryFn. More info here: https://tanstack.com/query/latest/docs/framework/react/guides/default-query-function`\n );\n }\n }\n defaultedOptions._optimisticResults = isRestoring ? \"isRestoring\" : \"optimistic\";\n ensureSuspenseTimers(defaultedOptions);\n ensurePreventErrorBoundaryRetry(defaultedOptions, errorResetBoundary);\n useClearResetErrorBoundary(errorResetBoundary);\n const isNewCacheEntry = !client.getQueryCache().get(defaultedOptions.queryHash);\n const [observer] = React.useState(\n () => new Observer(\n client,\n defaultedOptions\n )\n );\n const result = observer.getOptimisticResult(defaultedOptions);\n const shouldSubscribe = !isRestoring && options.subscribed !== false;\n React.useSyncExternalStore(\n React.useCallback(\n (onStoreChange) => {\n const unsubscribe = shouldSubscribe ? observer.subscribe(notifyManager.batchCalls(onStoreChange)) : noop;\n observer.updateResult();\n return unsubscribe;\n },\n [observer, shouldSubscribe]\n ),\n () => observer.getCurrentResult(),\n () => observer.getCurrentResult()\n );\n React.useEffect(() => {\n observer.setOptions(defaultedOptions);\n }, [defaultedOptions, observer]);\n if (shouldSuspend(defaultedOptions, result)) {\n throw fetchOptimistic(defaultedOptions, observer, errorResetBoundary);\n }\n if (getHasError({\n result,\n errorResetBoundary,\n throwOnError: defaultedOptions.throwOnError,\n query: client.getQueryCache().get(defaultedOptions.queryHash),\n suspense: defaultedOptions.suspense\n })) {\n throw result.error;\n }\n ;\n client.getDefaultOptions().queries?._experimental_afterQuery?.(\n defaultedOptions,\n result\n );\n if (defaultedOptions.experimental_prefetchInRender && !isServer && willFetch(result, isRestoring)) {\n const promise = isNewCacheEntry ? (\n // Fetch immediately on render in order to ensure `.promise` is resolved even if the component is unmounted\n fetchOptimistic(defaultedOptions, observer, errorResetBoundary)\n ) : (\n // subscribe to the \"cache promise\" so that we can finalize the currentThenable once data comes in\n client.getQueryCache().get(defaultedOptions.queryHash)?.promise\n );\n promise?.catch(noop).finally(() => {\n observer.updateResult();\n });\n }\n return !defaultedOptions.notifyOnChangeProps ? observer.trackResult(result) : result;\n}\nexport {\n useBaseQuery\n};\n//# sourceMappingURL=useBaseQuery.js.map"],"names":[],"mappings":";;;;;;;AAGA,MAAA,QAAA,OAAA,OAAA;AAgBA,SAAS,aAAa,SAAS,UAAU,aAAa;AACpD,MAAI,QAAQ,IAAI,aAAa,cAAc;AACzC,QAAI,OAAO,YAAY,YAAY,MAAM,QAAQ,OAAO,GAAG;AACzD,YAAM,IAAI;AAAA,QACR;AAAA,MACR;AAAA,IACI;AAAA,EACF;AACA,QAAM,cAAc,eAAc;AAClC,QAAM,qBAAqB,2BAA0B;AACrD,QAAM,SAAS,eAAe,WAAW;AACzC,QAAM,mBAAmB,OAAO,oBAAoB,OAAO;AAC3D,SAAO,oBAAoB,SAAS;AAAA,IAClC;AAAA,EACJ;AACE,MAAI,QAAQ,IAAI,aAAa,cAAc;AACzC,QAAI,CAAC,iBAAiB,SAAS;AA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AU,QAAQ,WAAW,GAAG;AACjG,UAAM,UAAU;AAAA;AAAA,MAEd,gBAAgB,kBAAkB,UAAU,kBAAkB;AAAA;AAAA;AAAA,MAG9D,OAAO,cAAa,EAAG,IAAI,iBAAiB,SAAS,GAAG;AAAA;AAE1D,aAAS,MAAM,IAAI,EAAE,QAAQ,MAAM;AACjC,eAAS,aAAY;AAAA,IACvB,CAAC;AAAA,EACH;AACA,SAAO,CAAC,iBAAiB,sBAAsB,SAAS,YAAY,MAAM,IAAI;AAChF;","x_google_ignoreList":[0]}
@@ -1,7 +1,7 @@
1
1
  import { QueryObserver } from "../../../query-core/build/modern/queryObserver.js";
2
2
  import { useBaseQuery } from "./useBaseQuery.js";
3
3
  function useQuery(options, queryClient) {
4
- return useBaseQuery(options, QueryObserver);
4
+ return useBaseQuery(options, QueryObserver, queryClient);
5
5
  }
6
6
  export {
7
7
  useQuery
@@ -1 +1 @@
1
- {"version":3,"file":"useQuery.js","sources":["../../../../../../node_modules/@tanstack/react-query/build/modern/useQuery.js"],"sourcesContent":["\"use client\";\n\n// src/useQuery.ts\nimport { QueryObserver } from \"@tanstack/query-core\";\nimport { useBaseQuery } from \"./useBaseQuery.js\";\nfunction useQuery(options, queryClient) {\n return useBaseQuery(options, QueryObserver, queryClient);\n}\nexport {\n useQuery\n};\n//# sourceMappingURL=useQuery.js.map"],"names":[],"mappings":";;AAKA,SAAS,SAAS,SAAS,aAAa;AACtC,SAAO,aAAa,SAAS,aAA0B;AACzD;","x_google_ignoreList":[0]}
1
+ {"version":3,"file":"useQuery.js","sources":["../../../../../../node_modules/@tanstack/react-query/build/modern/useQuery.js"],"sourcesContent":["\"use client\";\n\n// src/useQuery.ts\nimport { QueryObserver } from \"@tanstack/query-core\";\nimport { useBaseQuery } from \"./useBaseQuery.js\";\nfunction useQuery(options, queryClient) {\n return useBaseQuery(options, QueryObserver, queryClient);\n}\nexport {\n useQuery\n};\n//# sourceMappingURL=useQuery.js.map"],"names":[],"mappings":";;AAKA,SAAS,SAAS,SAAS,aAAa;AACtC,SAAO,aAAa,SAAS,eAAe,WAAW;AACzD;","x_google_ignoreList":[0]}
@@ -1,4 +1,4 @@
1
- const INVENTREE_PLUGIN_VERSION = "0.8.0";
1
+ const INVENTREE_PLUGIN_VERSION = "0.8.1";
2
2
  const INVENTREE_REACT_VERSION = "19.1.2";
3
3
  const INVENTREE_REACT_DOM_VERSION = (
4
4
  // @ts-ignore
@@ -2,7 +2,7 @@ import { t } from '@lingui/core/macro';
2
2
  import { useDocumentVisibility } from '@mantine/hooks';
3
3
  import { notifications, showNotification } from '@mantine/notifications';
4
4
  import { IconCircleCheck, IconExclamationCircle } from '@tabler/icons-react';
5
- import { useQuery } from '@tanstack/react-query';
5
+ import { type QueryClient, useQuery } from '@tanstack/react-query';
6
6
  import type { AxiosInstance } from 'axios';
7
7
  import { useEffect, useState } from 'react';
8
8
  import { ProgressBar } from '../components/ProgressBar';
@@ -14,11 +14,13 @@ import { apiUrl } from '../functions/Api';
14
14
  */
15
15
  export default function monitorDataOutput({
16
16
  api,
17
+ queryClient,
17
18
  title,
18
19
  hostname,
19
20
  id
20
21
  }: {
21
22
  api: AxiosInstance;
23
+ queryClient?: QueryClient;
22
24
  title: string;
23
25
  hostname?: string;
24
26
  id?: number;
@@ -41,82 +43,85 @@ export default function monitorDataOutput({
41
43
  } else setLoading(false);
42
44
  }, [id, title]);
43
45
 
44
- useQuery({
45
- enabled: !!id && loading && visibility === 'visible',
46
- refetchInterval: 500,
47
- queryKey: ['data-output', id, title],
48
- queryFn: () =>
49
- api
50
- .get(apiUrl(ApiEndpoints.data_output, id))
51
- .then((response) => {
52
- const data = response?.data ?? {};
46
+ useQuery(
47
+ {
48
+ enabled: !!id && loading && visibility === 'visible',
49
+ refetchInterval: 500,
50
+ queryKey: ['data-output', id, title],
51
+ queryFn: () =>
52
+ api
53
+ .get(apiUrl(ApiEndpoints.data_output, id))
54
+ .then((response) => {
55
+ const data = response?.data ?? {};
53
56
 
54
- if (!!data.errors || !!data.error) {
55
- setLoading(false);
57
+ if (!!data.errors || !!data.error) {
58
+ setLoading(false);
56
59
 
57
- const error: string =
58
- data?.error ?? data?.errors?.error ?? t`Process failed`;
60
+ const error: string =
61
+ data?.error ?? data?.errors?.error ?? t`Process failed`;
59
62
 
60
- notifications.update({
61
- id: `data-output-${id}`,
62
- loading: false,
63
- icon: <IconExclamationCircle />,
64
- autoClose: 2500,
65
- title: title,
66
- message: error,
67
- color: 'red'
68
- });
69
- } else if (data.complete) {
70
- setLoading(false);
71
- notifications.update({
72
- id: `data-output-${id}`,
73
- loading: false,
74
- autoClose: 2500,
75
- title: title,
76
- message: t`Process completed successfully`,
77
- color: 'green',
78
- icon: <IconCircleCheck />
79
- });
63
+ notifications.update({
64
+ id: `data-output-${id}`,
65
+ loading: false,
66
+ icon: <IconExclamationCircle />,
67
+ autoClose: 2500,
68
+ title: title,
69
+ message: error,
70
+ color: 'red'
71
+ });
72
+ } else if (data.complete) {
73
+ setLoading(false);
74
+ notifications.update({
75
+ id: `data-output-${id}`,
76
+ loading: false,
77
+ autoClose: 2500,
78
+ title: title,
79
+ message: t`Process completed successfully`,
80
+ color: 'green',
81
+ icon: <IconCircleCheck />
82
+ });
80
83
 
81
- if (data.output) {
82
- const url = data.output;
83
- const base = hostname ?? window.location.hostname;
84
+ if (data.output) {
85
+ const url = data.output;
86
+ const base = hostname ?? window.location.hostname;
84
87
 
85
- const downloadUrl = new URL(url, base);
88
+ const downloadUrl = new URL(url, base);
86
89
 
87
- window.open(downloadUrl.toString(), '_blank');
90
+ window.open(downloadUrl.toString(), '_blank');
91
+ }
92
+ } else {
93
+ notifications.update({
94
+ id: `data-output-${id}`,
95
+ loading: true,
96
+ autoClose: false,
97
+ withCloseButton: false,
98
+ message: (
99
+ <ProgressBar
100
+ size='lg'
101
+ maximum={data.total}
102
+ value={data.progress}
103
+ progressLabel={data.total > 0}
104
+ animated
105
+ />
106
+ )
107
+ });
88
108
  }
89
- } else {
109
+
110
+ return data;
111
+ })
112
+ .catch(() => {
113
+ setLoading(false);
90
114
  notifications.update({
91
115
  id: `data-output-${id}`,
92
- loading: true,
93
- autoClose: false,
94
- withCloseButton: false,
95
- message: (
96
- <ProgressBar
97
- size='lg'
98
- maximum={data.total}
99
- value={data.progress}
100
- progressLabel={data.total > 0}
101
- animated
102
- />
103
- )
116
+ loading: false,
117
+ autoClose: 2500,
118
+ title: title,
119
+ message: t`Process failed`,
120
+ color: 'red'
104
121
  });
105
- }
106
-
107
- return data;
108
- })
109
- .catch(() => {
110
- setLoading(false);
111
- notifications.update({
112
- id: `data-output-${id}`,
113
- loading: false,
114
- autoClose: 2500,
115
- title: title,
116
- message: t`Process failed`,
117
- color: 'red'
118
- });
119
- return {};
120
- })
121
- });
122
+ return {};
123
+ })
124
+ },
125
+ queryClient
126
+ );
122
127
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@inventreedb/ui",
3
3
  "description": "UI components for the InvenTree project",
4
- "version": "0.8.0",
4
+ "version": "0.8.1",
5
5
  "private": false,
6
6
  "type": "module",
7
7
  "license": "MIT",