Skip to content

Commit

Permalink
[PUI] Task table enhancements (#8369)
Browse files Browse the repository at this point in the history
* Refresh task counts when updating tables

* Handle case where error is null
  • Loading branch information
SchrodingersGat authored Oct 26, 2024
1 parent 3253a4a commit 9fd882f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,15 @@ import { FactCollection } from '../../../../components/settings/FactCollection';
import { ApiEndpoints } from '../../../../enums/ApiEndpoints';
import { Loadable } from '../../../../functions/loading';
import { useInstance } from '../../../../hooks/UseInstance';

const PendingTasksTable = Loadable(
lazy(() => import('../../../../tables/settings/PendingTasksTable'))
);
import FailedTasksTable from '../../../../tables/settings/FailedTasksTable';
import PendingTasksTable from '../../../../tables/settings/PendingTasksTable';

const ScheduledTasksTable = Loadable(
lazy(() => import('../../../../tables/settings/ScheduledTasksTable'))
);

const FailedTasksTable = Loadable(
lazy(() => import('../../../../tables/settings/FailedTasksTable'))
);

export default function TaskManagementPanel() {
const { instance: taskInfo } = useInstance({
const { instance: taskInfo, refreshInstance: refreshTaskInfo } = useInstance({
endpoint: ApiEndpoints.task_overview,
hasPrimaryKey: false,
refetchOnMount: true,
Expand Down Expand Up @@ -51,7 +45,7 @@ export default function TaskManagementPanel() {
<StylishText size="lg">{t`Pending Tasks`}</StylishText>
</Accordion.Control>
<Accordion.Panel>
<PendingTasksTable />
<PendingTasksTable onRecordsUpdated={refreshTaskInfo} />
</Accordion.Panel>
</Accordion.Item>
<Accordion.Item value="scheduled" key="scheduled-tasks">
Expand All @@ -67,7 +61,7 @@ export default function TaskManagementPanel() {
<StylishText size="lg">{t`Failed Tasks`}</StylishText>
</Accordion.Control>
<Accordion.Panel>
<FailedTasksTable />
<FailedTasksTable onRecordsUpdated={refreshTaskInfo} />
</Accordion.Panel>
</Accordion.Item>
</Accordion>
Expand Down
24 changes: 21 additions & 3 deletions src/frontend/src/tables/settings/FailedTasksTable.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { t } from '@lingui/macro';
import { Drawer, Text } from '@mantine/core';
import { useDisclosure } from '@mantine/hooks';
import { hideNotification, showNotification } from '@mantine/notifications';
import { IconExclamationCircle } from '@tabler/icons-react';
import { useMemo, useState } from 'react';

import { StylishText } from '../../components/items/StylishText';
Expand All @@ -11,7 +13,11 @@ import { useUserState } from '../../states/UserState';
import { TableColumn } from '../Column';
import { InvenTreeTable } from '../InvenTreeTable';

export default function FailedTasksTable() {
export default function FailedTasksTable({
onRecordsUpdated
}: {
onRecordsUpdated: () => void;
}) {
const table = useTable('tasks-failed');
const user = useUserState();

Expand Down Expand Up @@ -73,10 +79,22 @@ export default function FailedTasksTable() {
columns={columns}
props={{
enableBulkDelete: user.isStaff(),
afterBulkDelete: onRecordsUpdated,
enableSelection: true,
onRowClick: (row: any) => {
setError(row.result);
open();
if (row.result) {
setError(row.result);
open();
} else {
hideNotification('failed-task');
showNotification({
id: 'failed-task',
title: t`No Information`,
message: t`No error details are available for this task`,
color: 'red',
icon: <IconExclamationCircle />
});
}
}
}}
/>
Expand Down
7 changes: 6 additions & 1 deletion src/frontend/src/tables/settings/PendingTasksTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import { useUserState } from '../../states/UserState';
import { TableColumn } from '../Column';
import { InvenTreeTable } from '../InvenTreeTable';

export default function PendingTasksTable() {
export default function PendingTasksTable({
onRecordsUpdated
}: {
onRecordsUpdated: () => void;
}) {
const table = useTable('tasks-pending');
const user = useUserState();

Expand Down Expand Up @@ -50,6 +54,7 @@ export default function PendingTasksTable() {
tableState={table}
columns={columns}
props={{
afterBulkDelete: onRecordsUpdated,
enableBulkDelete: user.isStaff(),
enableSelection: true
}}
Expand Down

0 comments on commit 9fd882f

Please sign in to comment.