2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-04-29 12:06:44 +00:00

[PUI] Tweaks (#7180)

* Table: Add loading state

* Update BOM pricing panel

* Fix for TableStringValue

- Order of operations
This commit is contained in:
Oliver 2024-05-08 13:13:19 +10:00 committed by GitHub
parent fc9c75e4ca
commit c72dc2b8e4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 60 additions and 25 deletions

View File

@ -183,14 +183,14 @@ function NameBadge({ pk, type }: { pk: string | number; type: BadgeType }) {
function TableStringValue(props: Readonly<FieldProps>) { function TableStringValue(props: Readonly<FieldProps>) {
let value = props?.field_value; let value = props?.field_value;
if (value === undefined) {
return '---';
}
if (props.field_data?.value_formatter) { if (props.field_data?.value_formatter) {
value = props.field_data.value_formatter(); value = props.field_data.value_formatter();
} }
if (value === undefined) {
return '---';
}
if (props.field_data?.badge) { if (props.field_data?.badge) {
return <NameBadge pk={value} type={props.field_data.badge} />; return <NameBadge pk={value} type={props.field_data.badge} />;
} }

View File

@ -17,6 +17,8 @@ export type TableState = {
tableKey: string; tableKey: string;
refreshTable: () => void; refreshTable: () => void;
activeFilters: TableFilter[]; activeFilters: TableFilter[];
isLoading: boolean;
setIsLoading: (value: boolean) => void;
setActiveFilters: (filters: TableFilter[]) => void; setActiveFilters: (filters: TableFilter[]) => void;
clearActiveFilters: () => void; clearActiveFilters: () => void;
expandedRecords: any[]; expandedRecords: any[];
@ -120,9 +122,13 @@ export function useTable(tableName: string): TableState {
[records] [records]
); );
const [isLoading, setIsLoading] = useState<boolean>(false);
return { return {
tableKey, tableKey,
refreshTable, refreshTable,
isLoading,
setIsLoading,
activeFilters, activeFilters,
setActiveFilters, setActiveFilters,
clearActiveFilters, clearActiveFilters,

View File

@ -34,7 +34,7 @@ import { apiUrl } from '../../../states/ApiState';
import { TableColumn } from '../../../tables/Column'; import { TableColumn } from '../../../tables/Column';
import { DateColumn, PartColumn } from '../../../tables/ColumnRenderers'; import { DateColumn, PartColumn } from '../../../tables/ColumnRenderers';
import { InvenTreeTable } from '../../../tables/InvenTreeTable'; import { InvenTreeTable } from '../../../tables/InvenTreeTable';
import { NoPricingData } from './PricingPanel'; import { LoadingPricingData, NoPricingData } from './PricingPanel';
// Display BOM data as a pie chart // Display BOM data as a pie chart
function BomPieChart({ function BomPieChart({
@ -209,6 +209,10 @@ export default function BomPricingPanel({
const [chartType, setChartType] = useState<string>('pie'); const [chartType, setChartType] = useState<string>('pie');
const hasData: boolean = useMemo(() => {
return !table.isLoading && bomPricingData.length > 0;
}, [table.isLoading, bomPricingData.length]);
return ( return (
<Stack spacing="xs"> <Stack spacing="xs">
<SimpleGrid cols={2}> <SimpleGrid cols={2}>
@ -227,13 +231,21 @@ export default function BomPricingPanel({
modelField: 'sub_part' modelField: 'sub_part'
}} }}
/> />
{bomPricingData.length > 0 ? ( <Stack spacing="xs">
{table.isLoading && <LoadingPricingData />}
{hasData && (
<Stack spacing="xs"> <Stack spacing="xs">
{chartType == 'bar' && ( {chartType == 'bar' && (
<BomBarChart data={bomPricingData} currency={pricing?.currency} /> <BomBarChart
data={bomPricingData}
currency={pricing?.currency}
/>
)} )}
{chartType == 'pie' && ( {chartType == 'pie' && (
<BomPieChart data={bomPricingData} currency={pricing?.currency} /> <BomPieChart
data={bomPricingData}
currency={pricing?.currency}
/>
)} )}
<SegmentedControl <SegmentedControl
value={chartType} value={chartType}
@ -244,9 +256,9 @@ export default function BomPricingPanel({
]} ]}
/> />
</Stack> </Stack>
) : (
<NoPricingData />
)} )}
{!hasData && !table.isLoading && <NoPricingData />}
</Stack>
</SimpleGrid> </SimpleGrid>
</Stack> </Stack>
); );

View File

@ -4,6 +4,8 @@ import {
AccordionControlProps, AccordionControlProps,
Alert, Alert,
Box, Box,
Center,
Loader,
Space, Space,
Stack, Stack,
Text, Text,
@ -68,3 +70,14 @@ export function NoPricingData() {
</Stack> </Stack>
); );
} }
export function LoadingPricingData() {
return (
<Center>
<Stack spacing="xs">
<Text>{t`Loading pricing data`}</Text>
<Loader />
</Stack>
</Center>
);
}

View File

@ -454,6 +454,10 @@ export function InvenTreeTable<T = any>({
refetchOnMount: true refetchOnMount: true
}); });
useEffect(() => {
tableState.setIsLoading(isFetching);
}, [isFetching]);
// Update tableState.records when new data received // Update tableState.records when new data received
useEffect(() => { useEffect(() => {
tableState.setRecords(data ?? []); tableState.setRecords(data ?? []);