Skip to content

Commit

Permalink
Merge pull request #3 from inventree/pct
Browse files Browse the repository at this point in the history
improve table rendering
  • Loading branch information
SchrodingersGat authored Nov 16, 2024
2 parents dd95249 + bff57ce commit 2f94641
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
32 changes: 29 additions & 3 deletions frontend/src/TestStatisticsPanel.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Box, LoadingOverlay, MantineProvider, Paper} from '@mantine/core';
import { Box, Group, LoadingOverlay, MantineProvider, Paper, Text} from '@mantine/core';
import { useMemo } from 'react';
import { createRoot } from 'react-dom/client';
import { QueryClient, useQuery } from '@tanstack/react-query';
Expand Down Expand Up @@ -56,11 +56,33 @@ function TestStatisticsPanel({context}: {context: any}) {
},
{
accessor: 'pass_count',
title: 'Pass',
title: 'Passed',
render: (record: any) => {
let total = record.pass_count + record.fail_count;
let pass_pct = total > 0 ? (record.pass_count / total) * 100 : 0;

return (
<Group justify='space-between' wrap="nowrap">
<Text>{record.pass_count}</Text>
{total > 0 && <Text size="xs">({pass_pct.toFixed(2)}%)</Text>}
</Group>
)
}
},
{
accessor: 'fail_count',
title: 'Fail',
title: 'Failed',
render: (record: any) => {
let total = record.pass_count + record.fail_count;
let fail_pct = total > 0 ? (record.fail_count / total) * 100 : 0;

return (
<Group justify='space-between' wrap="nowrap">
<Text>{record.fail_count}</Text>
{total > 0 && <Text size="xs">({fail_pct.toFixed(2)}%)</Text>}
</Group>
)
}
},
{
accessor: 'total',
Expand All @@ -78,6 +100,10 @@ function TestStatisticsPanel({context}: {context: any}) {
<Box pos="relative">
<LoadingOverlay visible={statsQuery.isLoading} />
<DataTable
striped
highlightOnHover
withTableBorder
withColumnBorders
records={statsQuery.data}
columns={columns}
/>
Expand Down
1 change: 1 addition & 0 deletions test_statistics/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def get_ui_panels(self, request, context=None, **kwargs):
'title': 'Test Statistics',
'template': 'test_statistics/panel.html',
'source': self.plugin_static_file('TestStatisticsPanel.js:renderPanel'),
'icon': 'ti:report-analytics:outline',
'context': {
'settings': self.plugin_settings,
'filters': stat_filters,
Expand Down

0 comments on commit 2f94641

Please sign in to comment.