2
0
mirror of https://github.com/inventree/InvenTree.git synced 2026-03-12 15:13:34 +00:00

Enhance MonitorDataOutput (#11458)

* Enhance MonitorDataOutput

- Optionally pass QueryClient
- Required when running outside of <ApiContext />

* Fix default base URL if not specified

* Remove "allow_null" from Mantine props

* Bump lib version to 0.8.2

* Bump CHANGELOG.md
This commit is contained in:
Oliver
2026-03-12 12:22:16 +11:00
committed by GitHub
parent f7da51b752
commit c292e807b9
5 changed files with 83 additions and 71 deletions

View File

@@ -2,6 +2,10 @@
This file contains historical changelog information for the InvenTree UI components library. This file contains historical changelog information for the InvenTree UI components library.
### 0.8.2 - March 2026
Bug fixes for the `monitorDataOutput` hook - https://github.com/inventree/InvenTree/pull/11458
### 0.8.0 - March 2026 ### 0.8.0 - March 2026
Exposes the `monitorDataOutput` hook, which allows plugins to monitor the output of a long-running task and display notifications when the task is complete. This is useful for plugins that need to perform long-running tasks and want to provide feedback to the user when the task is complete. Exposes the `monitorDataOutput` hook, which allows plugins to monitor the output of a long-running task and display notifications when the task is complete. This is useful for plugins that need to perform long-running tasks and want to provide feedback to the user when the task is complete.

View File

@@ -2,7 +2,7 @@ import { t } from '@lingui/core/macro';
import { useDocumentVisibility } from '@mantine/hooks'; import { useDocumentVisibility } from '@mantine/hooks';
import { notifications, showNotification } from '@mantine/notifications'; import { notifications, showNotification } from '@mantine/notifications';
import { IconCircleCheck, IconExclamationCircle } from '@tabler/icons-react'; import { IconCircleCheck, IconExclamationCircle } from '@tabler/icons-react';
import { useQuery } from '@tanstack/react-query'; import { type QueryClient, useQuery } from '@tanstack/react-query';
import type { AxiosInstance } from 'axios'; import type { AxiosInstance } from 'axios';
import { useEffect, useState } from 'react'; import { useEffect, useState } from 'react';
import { ProgressBar } from '../components/ProgressBar'; import { ProgressBar } from '../components/ProgressBar';
@@ -14,11 +14,13 @@ import { apiUrl } from '../functions/Api';
*/ */
export default function monitorDataOutput({ export default function monitorDataOutput({
api, api,
queryClient,
title, title,
hostname, hostname,
id id
}: { }: {
api: AxiosInstance; api: AxiosInstance;
queryClient?: QueryClient;
title: string; title: string;
hostname?: string; hostname?: string;
id?: number; id?: number;
@@ -41,7 +43,8 @@ export default function monitorDataOutput({
} else setLoading(false); } else setLoading(false);
}, [id, title]); }, [id, title]);
useQuery({ useQuery(
{
enabled: !!id && loading && visibility === 'visible', enabled: !!id && loading && visibility === 'visible',
refetchInterval: 500, refetchInterval: 500,
queryKey: ['data-output', id, title], queryKey: ['data-output', id, title],
@@ -80,7 +83,7 @@ export default function monitorDataOutput({
if (data.output) { if (data.output) {
const url = data.output; const url = data.output;
const base = hostname ?? window.location.hostname; const base = hostname ?? window.location.origin;
const downloadUrl = new URL(url, base); const downloadUrl = new URL(url, base);
@@ -106,17 +109,20 @@ export default function monitorDataOutput({
return data; return data;
}) })
.catch(() => { .catch((error: Error) => {
console.error('Error in monitorDataOutput:', error);
setLoading(false); setLoading(false);
notifications.update({ notifications.update({
id: `data-output-${id}`, id: `data-output-${id}`,
loading: false, loading: false,
autoClose: 2500, autoClose: 2500,
title: title, title: title,
message: t`Process failed`, message: error.message || t`Process failed`,
color: 'red' color: 'red'
}); });
return {}; return {};
}) })
}); },
queryClient
);
} }

View File

@@ -1,7 +1,7 @@
{ {
"name": "@inventreedb/ui", "name": "@inventreedb/ui",
"description": "UI components for the InvenTree project", "description": "UI components for the InvenTree project",
"version": "0.8.0", "version": "0.8.2",
"private": false, "private": false,
"type": "module", "type": "module",
"license": "MIT", "license": "MIT",

View File

@@ -85,6 +85,7 @@ export function ApiFormField({
onValueChange: undefined, onValueChange: undefined,
adjustFilters: undefined, adjustFilters: undefined,
adjustValue: undefined, adjustValue: undefined,
allow_null: undefined,
read_only: undefined, read_only: undefined,
children: undefined, children: undefined,
exclude: undefined exclude: undefined

View File

@@ -380,6 +380,7 @@ export function RelatedModelField({
onValueChange: undefined, onValueChange: undefined,
adjustFilters: undefined, adjustFilters: undefined,
exclude: undefined, exclude: undefined,
allow_null: undefined,
read_only: undefined read_only: undefined
}; };
}, [definition]); }, [definition]);