mirror of
https://github.com/inventree/InvenTree.git
synced 2026-10-02 00:20:44 +00:00
[UI] Details tweaks (#12949)
* Fix hover div element * Improve badge formatting * Set staleTime for useQuery in NameBadge * add staleTime elsewhere * Improved error handlign for badges * Better caching for parameterTemplate useQuery * Disable remoteInstance query without pk
This commit is contained in:
1 parent
aa78504750
commit
afab76835f
3 files changed
+55
-31
No files matched your search
@@ -125,11 +125,18 @@ function HoverNameBadge(data: any, type: BadgeType) {
|
|||||||
data.username,
|
data.username,
|
||||||
getDetailUrl(ModelType.user, data.pk, true),
|
getDetailUrl(ModelType.user, data.pk, true),
|
||||||
data?.image,
|
data?.image,
|
||||||
<>
|
<Stack gap='xs'>
|
||||||
|
{data.email}
|
||||||
|
<Group gap='xs'>
|
||||||
{data.is_superuser && <Badge color='red'>{t`Superuser`}</Badge>}
|
{data.is_superuser && <Badge color='red'>{t`Superuser`}</Badge>}
|
||||||
{data.is_staff && <Badge color='orange'>{t`Administrator`}</Badge>}
|
{data.is_staff && (
|
||||||
{data.email && t`Email: ` + data.email}
|
<Badge color='orange'>{t`Administrator`}</Badge>
|
||||||
</>
|
)}
|
||||||
|
{data.is_active === false && (
|
||||||
|
<Badge color='gray'>{t`Inactive`}</Badge>
|
||||||
|
)}
|
||||||
|
</Group>
|
||||||
|
</Stack>
|
||||||
];
|
];
|
||||||
case 'group':
|
case 'group':
|
||||||
return [
|
return [
|
||||||
@@ -163,7 +170,7 @@ function HoverNameBadge(data: any, type: BadgeType) {
|
|||||||
</Stack>
|
</Stack>
|
||||||
</Group>
|
</Group>
|
||||||
|
|
||||||
<Text size='sm' mt='md'>
|
<Text size='sm' mt='md' component='div'>
|
||||||
{line_data[4]}
|
{line_data[4]}
|
||||||
</Text>
|
</Text>
|
||||||
</HoverCard.Dropdown>
|
</HoverCard.Dropdown>
|
||||||
@@ -181,8 +188,10 @@ function NameBadge({
|
|||||||
}: Readonly<{ pk: string | number; type: BadgeType }>) {
|
}: Readonly<{ pk: string | number; type: BadgeType }>) {
|
||||||
const api = useApi();
|
const api = useApi();
|
||||||
|
|
||||||
const { data } = useQuery({
|
const { data, isLoading, isError } = useQuery({
|
||||||
queryKey: ['badge', type, pk],
|
queryKey: ['badge', type, pk],
|
||||||
|
enabled: !!pk,
|
||||||
|
staleTime: 5 * 60 * 1000, // 5 minutes
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
let path = '';
|
let path = '';
|
||||||
|
|
||||||
@@ -202,14 +211,7 @@ function NameBadge({
|
|||||||
|
|
||||||
const url = apiUrl(path, pk);
|
const url = apiUrl(path, pk);
|
||||||
|
|
||||||
return api.get(url).then((response) => {
|
return api.get(url).then((response) => response.data);
|
||||||
switch (response.status) {
|
|
||||||
case 200:
|
|
||||||
return response.data;
|
|
||||||
default:
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -219,10 +221,14 @@ function NameBadge({
|
|||||||
return HoverNameBadge(data, type);
|
return HoverNameBadge(data, type);
|
||||||
}, [data]);
|
}, [data]);
|
||||||
|
|
||||||
if (!data || data.isLoading || data.isFetching) {
|
if (isLoading) {
|
||||||
return <Skeleton height={12} radius='md' />;
|
return <Skeleton height={12} radius='md' />;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!pk || isError || !data) {
|
||||||
|
return <Text size='sm'>'---'</Text>;
|
||||||
|
}
|
||||||
|
|
||||||
// Rendering a user's name for the badge
|
// Rendering a user's name for the badge
|
||||||
function _render_name() {
|
function _render_name() {
|
||||||
if (!data || !data.pk) {
|
if (!data || !data.pk) {
|
||||||
@@ -337,8 +343,20 @@ function TableAnchorValue(props: Readonly<FieldProps>) {
|
|||||||
const api = useApi();
|
const api = useApi();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
const { data } = useQuery({
|
const hasValue: boolean =
|
||||||
queryKey: ['detail', props.field_data.model, props.field_value],
|
props.field_value !== null &&
|
||||||
|
props.field_value !== undefined &&
|
||||||
|
props.field_value !== '';
|
||||||
|
|
||||||
|
const { data, isLoading } = useQuery({
|
||||||
|
queryKey: [
|
||||||
|
'detail',
|
||||||
|
props.field_data.model,
|
||||||
|
props.field_value,
|
||||||
|
props.field_data.model_filters
|
||||||
|
],
|
||||||
|
enabled: hasValue && !props.field_data.external,
|
||||||
|
staleTime: 5 * 60 * 1000, // 5 minutes
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
if (!props.field_data?.model) {
|
if (!props.field_data?.model) {
|
||||||
return {};
|
return {};
|
||||||
@@ -356,14 +374,7 @@ function TableAnchorValue(props: Readonly<FieldProps>) {
|
|||||||
.get(url, {
|
.get(url, {
|
||||||
params: props.field_data.model_filters ?? undefined
|
params: props.field_data.model_filters ?? undefined
|
||||||
})
|
})
|
||||||
.then((response) => {
|
.then((response) => response.data);
|
||||||
switch (response.status) {
|
|
||||||
case 200:
|
|
||||||
return response.data;
|
|
||||||
default:
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -385,7 +396,11 @@ function TableAnchorValue(props: Readonly<FieldProps>) {
|
|||||||
return `/${getBaseUrl()}${detailUrl}`;
|
return `/${getBaseUrl()}${detailUrl}`;
|
||||||
}, [detailUrl]);
|
}, [detailUrl]);
|
||||||
|
|
||||||
if (!data || data.isLoading || data.isFetching) {
|
if (!hasValue) {
|
||||||
|
return <Text size='sm'>'---'</Text>;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isLoading) {
|
||||||
return <Skeleton height={12} radius='md' />;
|
return <Skeleton height={12} radius='md' />;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -409,7 +424,7 @@ function TableAnchorValue(props: Readonly<FieldProps>) {
|
|||||||
// Construct the "return value" for the fetched data
|
// Construct the "return value" for the fetched data
|
||||||
let value = undefined;
|
let value = undefined;
|
||||||
|
|
||||||
if (props.field_data.model_formatter) {
|
if (data && props.field_data.model_formatter) {
|
||||||
value = props.field_data.model_formatter(data) ?? value;
|
value = props.field_data.model_formatter(data) ?? value;
|
||||||
} else if (props.field_data.model_field) {
|
} else if (props.field_data.model_field) {
|
||||||
value = data?.[props.field_data.model_field] ?? value;
|
value = data?.[props.field_data.model_field] ?? value;
|
||||||
|
|||||||
@@ -160,8 +160,10 @@ export function RenderRemoteInstance({
|
|||||||
}: Readonly<RemoteInstanceProps>): ReactNode {
|
}: Readonly<RemoteInstanceProps>): ReactNode {
|
||||||
const api = useApi();
|
const api = useApi();
|
||||||
|
|
||||||
const { data, isLoading, isFetching } = useQuery({
|
const { data, isLoading } = useQuery({
|
||||||
queryKey: ['model', model, pk],
|
queryKey: ['model', model, pk, modelUrl],
|
||||||
|
enabled: !!pk,
|
||||||
|
staleTime: 5 * 60 * 1000, // 5 minutes
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
const url = modelUrl
|
const url = modelUrl
|
||||||
? apiUrl(modelUrl, pk)
|
? apiUrl(modelUrl, pk)
|
||||||
@@ -171,7 +173,7 @@ export function RenderRemoteInstance({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (isLoading || isFetching) {
|
if (isLoading) {
|
||||||
return <Skeleton />;
|
return <Skeleton />;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -178,7 +178,14 @@ export default function ParametricDataTable({
|
|||||||
|
|
||||||
// Fetch all active parameter templates for the given model type
|
// Fetch all active parameter templates for the given model type
|
||||||
const parameterTemplates = useQuery({
|
const parameterTemplates = useQuery({
|
||||||
queryKey: ['parameter-templates', modelType],
|
queryKey: [
|
||||||
|
'parameter-templates',
|
||||||
|
modelType,
|
||||||
|
modelId,
|
||||||
|
relatedModel,
|
||||||
|
relatedModelId
|
||||||
|
],
|
||||||
|
staleTime: 5 * 60 * 1000, // 5 minutes
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
return api
|
return api
|
||||||
.get(apiUrl(ApiEndpoints.parameter_template_list), {
|
.get(apiUrl(ApiEndpoints.parameter_template_list), {
|
||||||
|
|||||||
Reference in new issue
Block a user