2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-22 14:50:53 +00:00

[Refactor] Remove 'test statistics' ()

* [Refactor] Remove 'test statistics'

* Bump API version
This commit is contained in:
Oliver
2024-11-19 01:05:38 +11:00
committed by GitHub
parent 6bf6733268
commit 03c3417841
19 changed files with 6 additions and 556 deletions

@ -138,8 +138,6 @@ export enum ApiEndpoints {
stock_uninstall = 'stock/:id/uninstall/',
stock_serialize = 'stock/:id/serialize/',
stock_return = 'stock/:id/return/',
build_test_statistics = 'test-statistics/by-build/:id/',
part_test_statistics = 'test-statistics/by-part/:id/',
// Generator API endpoints
generate_batch_code = 'generate/batch-code/',

@ -8,7 +8,6 @@ import {
IconList,
IconListCheck,
IconListNumbers,
IconReportAnalytics,
IconSitemap
} from '@tabler/icons-react';
import { useMemo } from 'react';
@ -57,7 +56,6 @@ import { BuildOrderTable } from '../../tables/build/BuildOrderTable';
import BuildOrderTestTable from '../../tables/build/BuildOrderTestTable';
import BuildOutputTable from '../../tables/build/BuildOutputTable';
import { StockItemTable } from '../../tables/stock/StockItemTable';
import { TestStatisticsTable } from '../../tables/stock/TestStatisticsTable';
/**
* Detail page for a single Build Order
@ -342,20 +340,6 @@ export default function BuildDetail() {
<Skeleton />
)
},
{
name: 'test-statistics',
label: t`Test Statistics`,
icon: <IconReportAnalytics />,
content: (
<TestStatisticsTable
params={{
pk: build.pk,
apiEndpoint: ApiEndpoints.build_test_statistics
}}
/>
),
hidden: !build?.part_detail?.testable
},
AttachmentPanel({
model_type: ModelType.build,
model_id: build.pk

@ -21,7 +21,6 @@ import {
IconListTree,
IconLock,
IconPackages,
IconReportAnalytics,
IconShoppingCart,
IconStack2,
IconTestPipe,
@ -98,7 +97,6 @@ import { RelatedPartTable } from '../../tables/part/RelatedPartTable';
import { ReturnOrderTable } from '../../tables/sales/ReturnOrderTable';
import { SalesOrderTable } from '../../tables/sales/SalesOrderTable';
import { StockItemTable } from '../../tables/stock/StockItemTable';
import { TestStatisticsTable } from '../../tables/stock/TestStatisticsTable';
import PartAllocationPanel from './PartAllocationPanel';
import PartPricingPanel from './PartPricingPanel';
import PartSchedulingDetail from './PartSchedulingDetail';
@ -722,22 +720,6 @@ export default function PartDetail() {
<Skeleton />
)
},
{
name: 'test_statistics',
label: t`Test Statistics`,
icon: <IconReportAnalytics />,
hidden: !part.testable,
content: part?.pk ? (
<TestStatisticsTable
params={{
pk: part.pk,
apiEndpoint: ApiEndpoints.part_test_statistics
}}
/>
) : (
<Skeleton />
)
},
{
name: 'related_parts',
label: t`Related Parts`,

@ -1,124 +0,0 @@
import { t } from '@lingui/macro';
import { useCallback, useMemo, useState } from 'react';
import { useTable } from '../../hooks/UseTable';
import { apiUrl } from '../../states/ApiState';
import type { TableColumn } from '../Column';
import { InvenTreeTable } from '../InvenTreeTable';
export function TestStatisticsTable({
params = {}
}: Readonly<{ params?: any }>) {
const initialColumns: TableColumn[] = [];
const [templateColumnList, setTemplateColumnList] = useState(initialColumns);
const testTemplateColumns: TableColumn[] = useMemo(() => {
const data = templateColumnList ?? [];
return data;
}, [templateColumnList]);
const tableColumns: TableColumn[] = useMemo(() => {
const firstColumn: TableColumn = {
accessor: 'col_0',
title: '',
sortable: true,
switchable: false,
noWrap: true
};
const lastColumn: TableColumn = {
accessor: 'col_total',
sortable: true,
switchable: false,
noWrap: true,
title: t`Total`
};
return [firstColumn, ...testTemplateColumns, lastColumn];
}, [testTemplateColumns]);
function statCountString(count: number, total: number) {
if (count > 0) {
const percentage = ` (${((100.0 * count) / total).toLocaleString(
undefined,
{
minimumFractionDigits: 0,
maximumFractionDigits: 2
}
)}%)`;
return count.toString() + percentage;
}
return '-';
}
// Format the test results based on the returned data
const formatRecords = useCallback((records: any[]): any[] => {
// interface needed to being able to dynamically assign keys
interface ResultRow {
[key: string]: string;
}
// Construct a list of test templates
const results: ResultRow[] = [
{ id: 'row_passed', col_0: t`Passed` },
{ id: 'row_failed', col_0: t`Failed` },
{ id: 'row_total', col_0: t`Total` }
];
let columnIndex = 0;
columnIndex = 1;
const newColumns: TableColumn[] = [];
for (const key in records[0]) {
if (key == 'total') continue;
const acc = `col_${columnIndex.toString()}`;
const resultKeys = ['passed', 'failed', 'total'];
results[0][acc] = statCountString(
records[0][key]['passed'],
records[0][key]['total']
);
results[1][acc] = statCountString(
records[0][key]['failed'],
records[0][key]['total']
);
results[2][acc] = records[0][key]['total'].toString();
newColumns.push({
accessor: `col_${columnIndex.toString()}`,
title: key
});
columnIndex++;
}
setTemplateColumnList(newColumns);
results[0]['col_total'] = statCountString(
records[0]['total']['passed'],
records[0]['total']['total']
);
results[1]['col_total'] = statCountString(
records[0]['total']['failed'],
records[0]['total']['total']
);
results[2]['col_total'] = records[0]['total']['total'].toString();
return results;
}, []);
const table = useTable('teststatistics');
return (
<InvenTreeTable
url={`${apiUrl(params.apiEndpoint, params.pk)}/`}
tableState={table}
columns={tableColumns}
props={{
dataFormatter: formatRecords,
enableDownload: false,
enableSearch: false,
enablePagination: false
}}
/>
);
}