mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Add display for all units
This commit is contained in:
parent
fa7eb38ddb
commit
bd29203b71
@ -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/',
|
||||
|
@ -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',
|
||||
|
@ -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>
|
||||
);
|
||||
}
|
Loading…
Reference in New Issue
Block a user