mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-29 20:16: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:
parent
fc9c75e4ca
commit
c72dc2b8e4
@ -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} />;
|
||||||
}
|
}
|
||||||
|
@ -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,
|
||||||
|
@ -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,26 +231,34 @@ export default function BomPricingPanel({
|
|||||||
modelField: 'sub_part'
|
modelField: 'sub_part'
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
{bomPricingData.length > 0 ? (
|
<Stack spacing="xs">
|
||||||
<Stack spacing="xs">
|
{table.isLoading && <LoadingPricingData />}
|
||||||
{chartType == 'bar' && (
|
{hasData && (
|
||||||
<BomBarChart data={bomPricingData} currency={pricing?.currency} />
|
<Stack spacing="xs">
|
||||||
)}
|
{chartType == 'bar' && (
|
||||||
{chartType == 'pie' && (
|
<BomBarChart
|
||||||
<BomPieChart data={bomPricingData} currency={pricing?.currency} />
|
data={bomPricingData}
|
||||||
)}
|
currency={pricing?.currency}
|
||||||
<SegmentedControl
|
/>
|
||||||
value={chartType}
|
)}
|
||||||
onChange={setChartType}
|
{chartType == 'pie' && (
|
||||||
data={[
|
<BomPieChart
|
||||||
{ value: 'pie', label: t`Pie Chart` },
|
data={bomPricingData}
|
||||||
{ value: 'bar', label: t`Bar Chart` }
|
currency={pricing?.currency}
|
||||||
]}
|
/>
|
||||||
/>
|
)}
|
||||||
</Stack>
|
<SegmentedControl
|
||||||
) : (
|
value={chartType}
|
||||||
<NoPricingData />
|
onChange={setChartType}
|
||||||
)}
|
data={[
|
||||||
|
{ value: 'pie', label: t`Pie Chart` },
|
||||||
|
{ value: 'bar', label: t`Bar Chart` }
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
</Stack>
|
||||||
|
)}
|
||||||
|
{!hasData && !table.isLoading && <NoPricingData />}
|
||||||
|
</Stack>
|
||||||
</SimpleGrid>
|
</SimpleGrid>
|
||||||
</Stack>
|
</Stack>
|
||||||
);
|
);
|
||||||
|
@ -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>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
@ -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 ?? []);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user