mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-17 12:35:46 +00:00
Prepend hostname to plugin source
This commit is contained in:
@ -2,9 +2,12 @@ import { t } from '@lingui/macro';
|
|||||||
import { Alert, Text } from '@mantine/core';
|
import { Alert, Text } from '@mantine/core';
|
||||||
import { AxiosInstance } from 'axios';
|
import { AxiosInstance } from 'axios';
|
||||||
import { useEffect, useRef } from 'react';
|
import { useEffect, useRef } from 'react';
|
||||||
|
import { useNavigate } from 'react-router-dom';
|
||||||
|
|
||||||
import { api } from '../../App';
|
import { api } from '../../App';
|
||||||
import { ModelType } from '../../enums/ModelType';
|
import { ModelType } from '../../enums/ModelType';
|
||||||
|
import { useLocalState } from '../../states/LocalState';
|
||||||
|
import { useUserState } from '../../states/UserState';
|
||||||
import { PanelType } from '../nav/Panel';
|
import { PanelType } from '../nav/Panel';
|
||||||
|
|
||||||
interface PluginPanelProps extends PanelType {
|
interface PluginPanelProps extends PanelType {
|
||||||
@ -25,6 +28,9 @@ interface PluginPanelParameters {
|
|||||||
targetId?: number | null;
|
targetId?: number | null;
|
||||||
targetInstance?: any;
|
targetInstance?: any;
|
||||||
api: AxiosInstance;
|
api: AxiosInstance;
|
||||||
|
user: any;
|
||||||
|
host: string;
|
||||||
|
navigate: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Placeholder content for a panel with no content
|
// Placeholder content for a panel with no content
|
||||||
@ -60,22 +66,40 @@ function PanelNoContent() {
|
|||||||
export default function PluginPanel({ props }: { props: PluginPanelProps }) {
|
export default function PluginPanel({ props }: { props: PluginPanelProps }) {
|
||||||
const ref = useRef<HTMLDivElement>();
|
const ref = useRef<HTMLDivElement>();
|
||||||
|
|
||||||
|
const host = useLocalState((s) => s.host);
|
||||||
|
const user = useUserState();
|
||||||
|
const navigate = useNavigate();
|
||||||
|
|
||||||
const loadExternalSource = async () => {
|
const loadExternalSource = async () => {
|
||||||
if (!props.source) {
|
let source: string = props.source ?? '';
|
||||||
|
|
||||||
|
if (!source) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (source.startsWith('/')) {
|
||||||
|
// Prefix the source with the host URL
|
||||||
|
source = `${host}${source}`;
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Gate where this content may be loaded from (e.g. only allow certain domains)
|
// TODO: Gate where this content may be loaded from (e.g. only allow certain domains)
|
||||||
|
|
||||||
// Load content from external source
|
// Load content from external source
|
||||||
const src = await import(/* @vite-ignore */ props.source ?? '');
|
const module = await import(/* @vite-ignore */ source ?? '');
|
||||||
|
|
||||||
// We expect the external source to define a function which will render the content
|
// We expect the external source to define a function which will render the content
|
||||||
if (src && src.render_panel && typeof src.render_panel === 'function') {
|
if (
|
||||||
src.render_panel({
|
module &&
|
||||||
|
module.render_panel &&
|
||||||
|
typeof module.render_panel === 'function'
|
||||||
|
) {
|
||||||
|
module.render_panel({
|
||||||
target: ref.current,
|
target: ref.current,
|
||||||
props: props,
|
props: props,
|
||||||
api: api,
|
api: api,
|
||||||
|
host: host,
|
||||||
|
user: user,
|
||||||
|
navigate: navigate,
|
||||||
targetModel: props.targetModel,
|
targetModel: props.targetModel,
|
||||||
targetId: props.targetId,
|
targetId: props.targetId,
|
||||||
targetInstance: props.targetInstance
|
targetInstance: props.targetInstance
|
||||||
|
Reference in New Issue
Block a user