Add display for all units

This commit is contained in:
Matthias Mair 2024-08-30 18:01:14 +02:00
parent fa7eb38ddb
commit bd29203b71
No known key found for this signature in database
GPG Key ID: A593429DDA23B66A
3 changed files with 85 additions and 5 deletions

View File

@ -31,6 +31,7 @@ export enum ApiEndpoints {
// Generic API endpoints
currency_list = 'currency/exchange/',
currency_refresh = 'currency/refresh/',
all_units = 'units/all',
task_overview = 'background-task/',
task_pending_list = 'background-task/pending/',
task_scheduled_list = 'background-task/scheduled/',

View File

@ -52,6 +52,8 @@ const CurrencyManagmentPanel = Loadable(
lazy(() => import('./CurrencyManagmentPanel'))
);
const UnitManagmentPanel = Loadable(lazy(() => import('./UnitManagmentPanel')));
const PluginManagementPanel = Loadable(
lazy(() => import('./PluginManagementPanel'))
);
@ -76,10 +78,6 @@ const CustomStateTable = Loadable(
lazy(() => import('../../../../tables/settings/CustomStateTable'))
);
const CustomUnitsTable = Loadable(
lazy(() => import('../../../../tables/settings/CustomUnitsTable'))
);
const PartParameterTemplateTable = Loadable(
lazy(() => import('../../../../tables/part/PartParameterTemplateTable'))
);
@ -149,7 +147,7 @@ export default function AdminCenter() {
name: 'customunits',
label: t`Custom Units`,
icon: <IconScale />,
content: <CustomUnitsTable />
content: <UnitManagmentPanel />
},
{
name: 'part-parameters',

View File

@ -0,0 +1,81 @@
import { t } from '@lingui/macro';
import { Accordion, Stack } from '@mantine/core';
import { useMemo } from 'react';
import { StylishText } from '../../../../components/items/StylishText';
import { ApiEndpoints } from '../../../../enums/ApiEndpoints';
import { useTable } from '../../../../hooks/UseTable';
import { apiUrl } from '../../../../states/ApiState';
import { BooleanColumn } from '../../../../tables/ColumnRenderers';
import { InvenTreeTable } from '../../../../tables/InvenTreeTable';
import CustomUnitsTable from '../../../../tables/settings/CustomUnitsTable';
function AllUnitTable() {
const table = useTable('all-units');
const columns = useMemo(() => {
return [
{
accessor: 'name',
title: t`Name`
},
BooleanColumn({ accessor: 'is_alias', title: t`Alias` }),
BooleanColumn({ accessor: 'isdimensionless', title: t`Dimensionless` }),
{
accessor: 'default_format',
title: t`default_format`
}
];
}, []);
return (
<InvenTreeTable
url={apiUrl(ApiEndpoints.all_units)}
tableState={table}
columns={columns}
props={{
idAccessor: 'name',
enableSearch: false,
enablePagination: false,
enableColumnSwitching: false,
dataFormatter: (data: any) => {
let units = data.available_units ?? {};
return Object.entries(units).map(([key, values]) => {
console.log(values);
return {
name: values.name,
is_alias: values.is_alias,
compatible_units: values.compatible_units,
isdimensionless: values.isdimensionless,
default_format: values.default_format
};
});
}
}}
/>
);
}
export default function UnitManagmentPanel() {
return (
<Stack gap="xs">
<Accordion defaultValue="custom">
<Accordion.Item value="custom" key="custom">
<Accordion.Control>
<StylishText size="lg">{t`Custom Units`}</StylishText>
</Accordion.Control>
<Accordion.Panel>
<CustomUnitsTable />
</Accordion.Panel>
</Accordion.Item>
<Accordion.Item value="all" key="all">
<Accordion.Control>
<StylishText size="lg">{t`All units`}</StylishText>
</Accordion.Control>
<Accordion.Panel>
<AllUnitTable />
</Accordion.Panel>
</Accordion.Item>
</Accordion>
</Stack>
);
}