mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
[PUI] Helper to render an instance for an url (#5977)
* added helper to render an instance for an url * cleanup unsued imports
This commit is contained in:
parent
e9fe394d94
commit
87df9245eb
33
src/frontend/src/components/render/InstanceFromUrl.tsx
Normal file
33
src/frontend/src/components/render/InstanceFromUrl.tsx
Normal file
@ -0,0 +1,33 @@
|
||||
import { Loader } from '@mantine/core';
|
||||
import { useMemo, useState } from 'react';
|
||||
|
||||
import { api } from '../../App';
|
||||
import { ModelType } from '../../enums/ModelType';
|
||||
import { RenderInstance } from './Instance';
|
||||
|
||||
/**
|
||||
* Render a model instance from a URL
|
||||
* @param model Model type
|
||||
* @param url URL to fetch instance from
|
||||
* @returns JSX Element
|
||||
*/
|
||||
export function InstanceFromUrl({
|
||||
model,
|
||||
url
|
||||
}: {
|
||||
model: ModelType;
|
||||
url: string;
|
||||
}) {
|
||||
const [data, setData] = useState<any>(null);
|
||||
useMemo(
|
||||
() =>
|
||||
api.get(url).then((res) => {
|
||||
setData(res.data);
|
||||
}),
|
||||
[model, url]
|
||||
);
|
||||
|
||||
if (!data) return <Loader />;
|
||||
|
||||
return <RenderInstance instance={data} model={model} />;
|
||||
}
|
Loading…
Reference in New Issue
Block a user