From 48787427b279ce02f17140c73de0d19bb33608fa Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Thu, 24 Oct 2024 03:16:52 +0000 Subject: [PATCH 1/4] Reorganize MachineManagementPanel - Use Accordion - More consistent with PluginManagementPanel --- .../AdminCenter/MachineManagementPanel.tsx | 119 +++++++++++------- 1 file changed, 77 insertions(+), 42 deletions(-) diff --git a/src/frontend/src/pages/Index/Settings/AdminCenter/MachineManagementPanel.tsx b/src/frontend/src/pages/Index/Settings/AdminCenter/MachineManagementPanel.tsx index 17888e6f28e6..40ab044a13f7 100644 --- a/src/frontend/src/pages/Index/Settings/AdminCenter/MachineManagementPanel.tsx +++ b/src/frontend/src/pages/Index/Settings/AdminCenter/MachineManagementPanel.tsx @@ -1,18 +1,21 @@ -import { Trans } from '@lingui/macro'; +import { Trans, t } from '@lingui/macro'; import { + Accordion, ActionIcon, + Alert, Code, Group, List, - Space, Stack, Text, Title } from '@mantine/core'; -import { IconRefresh } from '@tabler/icons-react'; +import { IconInfoCircle, IconRefresh } from '@tabler/icons-react'; import { useQuery } from '@tanstack/react-query'; +import { useMemo } from 'react'; import { api } from '../../../../App'; +import { StylishText } from '../../../../components/items/StylishText'; import { ApiEndpoints } from '../../../../enums/ApiEndpoints'; import { apiUrl } from '../../../../states/ApiState'; import { MachineListTable } from '../../../../tables/machine/MachineListTable'; @@ -32,45 +35,77 @@ export default function MachineManagementPanel() { staleTime: 10 * 1000 }); - return ( - - - - - - - - <Trans>Machine types</Trans> - - - + const hasErrors = useMemo(() => { + return ( + registryStatus?.registry_errors && + registryStatus.registry_errors.length > 0 + ); + }, [registryStatus]); - - - - - - <Trans>Machine Error Stack</Trans> - - refetch()}> - - - - {registryStatus?.registry_errors && - registryStatus.registry_errors.length === 0 ? ( - - There are no machine registry errors. - - ) : ( - - {registryStatus?.registry_errors?.map((error, i) => ( - - {error.message} - - ))} - - )} - - + return ( + + + + {t`Machines`} + + + + + + + + {t`Machine Types`} + + + + + + + + {t`Machine Errors`} + + + + + {hasErrors ? ( + } + > + {t`There are machine registry errors`} + + ) : ( + } + > + {t`There are no machine registry errors`} + + )} + refetch()}> + + + + {hasErrors && ( + + {registryStatus?.registry_errors?.map((error, i) => ( + + {error.message} + + ))} + + )} + + + + ); } From 5ff485c624079b14582d5cfffbd5f77b27a267f3 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Thu, 24 Oct 2024 03:17:57 +0000 Subject: [PATCH 2/4] Code cleanup --- .../Index/Settings/AdminCenter/MachineManagementPanel.tsx | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/frontend/src/pages/Index/Settings/AdminCenter/MachineManagementPanel.tsx b/src/frontend/src/pages/Index/Settings/AdminCenter/MachineManagementPanel.tsx index 40ab044a13f7..c3a292a9c1a5 100644 --- a/src/frontend/src/pages/Index/Settings/AdminCenter/MachineManagementPanel.tsx +++ b/src/frontend/src/pages/Index/Settings/AdminCenter/MachineManagementPanel.tsx @@ -1,4 +1,4 @@ -import { Trans, t } from '@lingui/macro'; +import { t } from '@lingui/macro'; import { Accordion, ActionIcon, @@ -7,8 +7,7 @@ import { Group, List, Stack, - Text, - Title + Text } from '@mantine/core'; import { IconInfoCircle, IconRefresh } from '@tabler/icons-react'; import { useQuery } from '@tanstack/react-query'; From 9230282d6cbafdb71d097b16876bd93594a0d3e6 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Thu, 24 Oct 2024 03:30:37 +0000 Subject: [PATCH 3/4] Refactor machine drawer display --- .../src/tables/machine/MachineListTable.tsx | 329 +++++++++--------- 1 file changed, 170 insertions(+), 159 deletions(-) diff --git a/src/frontend/src/tables/machine/MachineListTable.tsx b/src/frontend/src/tables/machine/MachineListTable.tsx index 2eb86b1105c1..70fb0ca77adc 100644 --- a/src/frontend/src/tables/machine/MachineListTable.tsx +++ b/src/frontend/src/tables/machine/MachineListTable.tsx @@ -1,6 +1,6 @@ import { Trans, t } from '@lingui/macro'; import { - ActionIcon, + Accordion, Badge, Box, Card, @@ -10,7 +10,6 @@ import { Indicator, List, LoadingOverlay, - Space, Stack, Text, Title @@ -30,6 +29,7 @@ import { OptionsActionDropdown } from '../../components/items/ActionDropdown'; import { InfoItem } from '../../components/items/InfoItem'; +import { StylishText } from '../../components/items/StylishText'; import { UnavailableIndicator } from '../../components/items/UnavailableIndicator'; import { DetailDrawer, @@ -237,165 +237,176 @@ function MachineDrawer({ }); return ( - - {machineEditModal.modal} - {machineDeleteModal.modal} - - - - - - {machine && } - {machine?.name} - + <> + + {machineEditModal.modal} + {machineDeleteModal.modal} + + + + {machine && } + {machine?.name} + - - {machine?.restart_required && ( - - Restart required - - )} - , - name: t`Restart`, - tooltip: - t`Restart machine` + - (machine?.restart_required - ? ' (' + t`manual restart required` + ')' - : ''), - indicator: machine?.restart_required - ? { color: 'red' } - : undefined, - onClick: () => machine && restartMachine(machine?.pk) - } - ]} - /> + + {machine?.restart_required && ( + + Restart required + + )} + , + name: t`Restart`, + tooltip: + t`Restart machine` + + (machine?.restart_required + ? ' (' + t`manual restart required` + ')' + : ''), + indicator: machine?.restart_required + ? { color: 'red' } + : undefined, + onClick: () => machine && restartMachine(machine?.pk) + } + ]} + /> + - - - - - - <Trans>Machine information</Trans> - - refetch()}> - - - - - - - - {machineType ? ( - + + + {t`Machine Information`} + + + + + + + + + {machineType ? ( + + ) : ( + {machine?.machine_type} + )} + {machine && !machineType && } + + + + + {machineDriver ? ( + + ) : ( + {machine?.driver} + )} + {!machine?.is_driver_available && ( + + )} + + + + + + + + + + + {machine?.status === -1 ? ( + No status + ) : ( + StatusRenderer({ + status: `${machine?.status || -1}`, + type: `MachineStatus__${machine?.status_model}` as any + }) + )} + {machine?.status_text} + + + + + Errors: + + {machine && machine?.machine_errors.length > 0 ? ( + + {machine?.machine_errors.length} + + ) : ( + + No errors reported + + )} + + {machine?.machine_errors.map((error, i) => ( + + {error} + + ))} + + + + + + + + {machine?.is_driver_available && ( + + + {t`Machine Settings`} + + + + - ) : ( - {machine?.machine_type} - )} - {machine && !machineType && } - - - - - {machineDriver ? ( - + + + )} + {machine?.is_driver_available && ( + + + {t`Driver Settings`} + + + + - ) : ( - {machine?.driver} - )} - {!machine?.is_driver_available && } - - - - - - - - - - - {machine?.status === -1 ? ( - No status - ) : ( - StatusRenderer({ - status: `${machine?.status || -1}`, - type: `MachineStatus__${machine?.status_model}` as any - }) - )} - {machine?.status_text} - - - - - Errors: - - {machine && machine?.machine_errors.length > 0 ? ( - - {machine?.machine_errors.length} - - ) : ( - - No errors reported - - )} - - {machine?.machine_errors.map((error, i) => ( - - {error} - - ))} - - - - - - - - {machine?.is_driver_available && ( - <> - - - <Trans>Machine Settings</Trans> - - - - - - - <Trans>Driver Settings</Trans> - - - - - )} - + + + + )} + + + ); } @@ -543,8 +554,8 @@ export function MachineListTable({ const tableActions = useMemo(() => { return [ { setCreateFormMachineType(null); createMachineForm.open(); @@ -558,7 +569,7 @@ export function MachineListTable({ {createMachineForm.modal} {renderMachineDrawer && ( { if (!id || !id.startsWith('machine-')) return false; From 95e5ef638a0016b27f02144ab657900c3e0e3337 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Thu, 24 Oct 2024 03:48:27 +0000 Subject: [PATCH 4/4] Refactor MachineTypeDetailDrawer --- .../src/tables/machine/MachineListTable.tsx | 2 +- .../src/tables/machine/MachineTypeTable.tsx | 197 ++++++++++-------- 2 files changed, 109 insertions(+), 90 deletions(-) diff --git a/src/frontend/src/tables/machine/MachineListTable.tsx b/src/frontend/src/tables/machine/MachineListTable.tsx index 70fb0ca77adc..a851ca096f0d 100644 --- a/src/frontend/src/tables/machine/MachineListTable.tsx +++ b/src/frontend/src/tables/machine/MachineListTable.tsx @@ -570,7 +570,7 @@ export function MachineListTable({ {renderMachineDrawer && ( { if (!id || !id.startsWith('machine-')) return false; return ( diff --git a/src/frontend/src/tables/machine/MachineTypeTable.tsx b/src/frontend/src/tables/machine/MachineTypeTable.tsx index 5e224d34d4d5..19acaead82c0 100644 --- a/src/frontend/src/tables/machine/MachineTypeTable.tsx +++ b/src/frontend/src/tables/machine/MachineTypeTable.tsx @@ -1,6 +1,8 @@ import { Trans, t } from '@lingui/macro'; import { + Accordion, ActionIcon, + Alert, Badge, Card, Code, @@ -11,11 +13,12 @@ import { Text, Title } from '@mantine/core'; -import { IconRefresh } from '@tabler/icons-react'; +import { IconExclamationCircle, IconRefresh } from '@tabler/icons-react'; import { useMemo } from 'react'; import { useNavigate } from 'react-router-dom'; import { InfoItem } from '../../components/items/InfoItem'; +import { StylishText } from '../../components/items/StylishText'; import { DetailDrawer } from '../../components/nav/DetailDrawer'; import { ApiEndpoints } from '../../enums/ApiEndpoints'; import { useTable } from '../../hooks/UseTable'; @@ -79,93 +82,109 @@ function MachineTypeDrawer({ ); return ( - - - - {machineType ? machineType.name : machineTypeSlug} - - - - {!machineType && ( - - Machine type not found. - - )} - - - - - - <Trans>Machine type information</Trans> - - refresh()}> - - - - - - - - - - {!machineType?.is_builtin && ( - - )} - - - - - - - - + <> + + - <Trans>Available drivers</Trans> + {machineType ? machineType.name : machineTypeSlug} + - { - return data.filter( - (d: any) => d.machine_type === machineTypeSlug - ); - }, - enableDownload: false, - enableSearch: false, - onRowClick: (machine) => navigate(`../driver-${machine.slug}/`) - }} - /> - - - + {!machineType && ( + } + > + {t`Machine type not found.`} + + )} + + + + + {t`Machine Type Information`} + + + + + + + + + {!machineType?.is_builtin && ( + + )} + + + + + + + + + {t`Available Drivers`} + + + + { + return data.filter( + (d: any) => d.machine_type === machineTypeSlug + ); + }, + enableDownload: false, + enableSearch: false, + onRowClick: (machine) => + navigate(`../driver-${machine.slug}/`) + }} + /> + + + + + + ); } @@ -335,8 +354,8 @@ export function MachineTypeListTable({ return ( <> { if (!id || !id.startsWith('type-')) return false; return ( @@ -345,8 +364,8 @@ export function MachineTypeListTable({ }} /> { if (!id || !id.startsWith('driver-')) return false; return (