Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PUI] Tweaks #7180

Merged
merged 3 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/frontend/src/components/details/Details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,14 @@ function NameBadge({ pk, type }: { pk: string | number; type: BadgeType }) {
function TableStringValue(props: Readonly<FieldProps>) {
let value = props?.field_value;

if (value === undefined) {
return '---';
}

if (props.field_data?.value_formatter) {
value = props.field_data.value_formatter();
}

if (value === undefined) {
return '---';
}

if (props.field_data?.badge) {
return <NameBadge pk={value} type={props.field_data.badge} />;
}
Expand Down
6 changes: 6 additions & 0 deletions src/frontend/src/hooks/UseTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export type TableState = {
tableKey: string;
refreshTable: () => void;
activeFilters: TableFilter[];
isLoading: boolean;
setIsLoading: (value: boolean) => void;
setActiveFilters: (filters: TableFilter[]) => void;
clearActiveFilters: () => void;
expandedRecords: any[];
Expand Down Expand Up @@ -120,9 +122,13 @@ export function useTable(tableName: string): TableState {
[records]
);

const [isLoading, setIsLoading] = useState<boolean>(false);

return {
tableKey,
refreshTable,
isLoading,
setIsLoading,
activeFilters,
setActiveFilters,
clearActiveFilters,
Expand Down
54 changes: 33 additions & 21 deletions src/frontend/src/pages/part/pricing/BomPricingPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import { apiUrl } from '../../../states/ApiState';
import { TableColumn } from '../../../tables/Column';
import { DateColumn, PartColumn } from '../../../tables/ColumnRenderers';
import { InvenTreeTable } from '../../../tables/InvenTreeTable';
import { NoPricingData } from './PricingPanel';
import { LoadingPricingData, NoPricingData } from './PricingPanel';

// Display BOM data as a pie chart
function BomPieChart({
Expand Down Expand Up @@ -209,6 +209,10 @@ export default function BomPricingPanel({

const [chartType, setChartType] = useState<string>('pie');

const hasData: boolean = useMemo(() => {
return !table.isLoading && bomPricingData.length > 0;
}, [table.isLoading, bomPricingData.length]);

return (
<Stack spacing="xs">
<SimpleGrid cols={2}>
Expand All @@ -227,26 +231,34 @@ export default function BomPricingPanel({
modelField: 'sub_part'
}}
/>
{bomPricingData.length > 0 ? (
<Stack spacing="xs">
{chartType == 'bar' && (
<BomBarChart data={bomPricingData} currency={pricing?.currency} />
)}
{chartType == 'pie' && (
<BomPieChart data={bomPricingData} currency={pricing?.currency} />
)}
<SegmentedControl
value={chartType}
onChange={setChartType}
data={[
{ value: 'pie', label: t`Pie Chart` },
{ value: 'bar', label: t`Bar Chart` }
]}
/>
</Stack>
) : (
<NoPricingData />
)}
<Stack spacing="xs">
{table.isLoading && <LoadingPricingData />}
{hasData && (
<Stack spacing="xs">
{chartType == 'bar' && (
<BomBarChart
data={bomPricingData}
currency={pricing?.currency}
/>
)}
{chartType == 'pie' && (
<BomPieChart
data={bomPricingData}
currency={pricing?.currency}
/>
)}
<SegmentedControl
value={chartType}
onChange={setChartType}
data={[
{ value: 'pie', label: t`Pie Chart` },
{ value: 'bar', label: t`Bar Chart` }
]}
/>
</Stack>
)}
{!hasData && !table.isLoading && <NoPricingData />}
</Stack>
</SimpleGrid>
</Stack>
);
Expand Down
13 changes: 13 additions & 0 deletions src/frontend/src/pages/part/pricing/PricingPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import {
AccordionControlProps,
Alert,
Box,
Center,
Loader,
Space,
Stack,
Text,
Expand Down Expand Up @@ -68,3 +70,14 @@ export function NoPricingData() {
</Stack>
);
}

export function LoadingPricingData() {
return (
<Center>
<Stack spacing="xs">
<Text>{t`Loading pricing data`}</Text>
<Loader />
</Stack>
</Center>
);
}
4 changes: 4 additions & 0 deletions src/frontend/src/tables/InvenTreeTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,10 @@ export function InvenTreeTable<T = any>({
refetchOnMount: true
});

useEffect(() => {
tableState.setIsLoading(isFetching);
}, [isFetching]);

// Update tableState.records when new data received
useEffect(() => {
tableState.setRecords(data ?? []);
Expand Down
Loading