mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-11-03 22:55:43 +00:00 
			
		
		
		
	Plugin loading improvements (#6056)
* Add API endpoint to reload plugin registry * Tweak debug * Add elements for CUI * Update API version * Reload plugins from PUI
This commit is contained in:
		@@ -11,7 +11,7 @@ import {
 | 
			
		||||
  Tooltip
 | 
			
		||||
} from '@mantine/core';
 | 
			
		||||
import { modals } from '@mantine/modals';
 | 
			
		||||
import { notifications } from '@mantine/notifications';
 | 
			
		||||
import { notifications, showNotification } from '@mantine/notifications';
 | 
			
		||||
import {
 | 
			
		||||
  IconCircleCheck,
 | 
			
		||||
  IconCircleX,
 | 
			
		||||
@@ -30,6 +30,7 @@ import { useCreateApiFormModal } from '../../../hooks/UseForm';
 | 
			
		||||
import { useInstance } from '../../../hooks/UseInstance';
 | 
			
		||||
import { useTable } from '../../../hooks/UseTable';
 | 
			
		||||
import { apiUrl, useServerApiState } from '../../../states/ApiState';
 | 
			
		||||
import { useUserState } from '../../../states/UserState';
 | 
			
		||||
import { ActionButton } from '../../buttons/ActionButton';
 | 
			
		||||
import { ActionDropdown, EditItemAction } from '../../items/ActionDropdown';
 | 
			
		||||
import { InfoItem } from '../../items/InfoItem';
 | 
			
		||||
@@ -423,11 +424,39 @@ export function PluginListTable({ props }: { props: InvenTreeTableProps }) {
 | 
			
		||||
    }
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  const user = useUserState();
 | 
			
		||||
 | 
			
		||||
  const reloadPlugins = useCallback(() => {
 | 
			
		||||
    api
 | 
			
		||||
      .post(apiUrl(ApiPaths.plugin_reload), {
 | 
			
		||||
        full_reload: true,
 | 
			
		||||
        force_reload: true,
 | 
			
		||||
        collect_plugins: true
 | 
			
		||||
      })
 | 
			
		||||
      .then(() => {
 | 
			
		||||
        showNotification({
 | 
			
		||||
          title: t`Plugins reloaded`,
 | 
			
		||||
          message: t`Plugins were reloaded successfully`,
 | 
			
		||||
          color: 'green'
 | 
			
		||||
        });
 | 
			
		||||
        table.refreshTable();
 | 
			
		||||
      });
 | 
			
		||||
  }, []);
 | 
			
		||||
 | 
			
		||||
  // Custom table actions
 | 
			
		||||
  const tableActions = useMemo(() => {
 | 
			
		||||
    let actions = [];
 | 
			
		||||
 | 
			
		||||
    if (pluginsEnabled) {
 | 
			
		||||
    if (user.user?.is_superuser && pluginsEnabled) {
 | 
			
		||||
      actions.push(
 | 
			
		||||
        <ActionButton
 | 
			
		||||
          color="green"
 | 
			
		||||
          icon={<IconRefresh />}
 | 
			
		||||
          tooltip={t`Reload Plugins`}
 | 
			
		||||
          onClick={reloadPlugins}
 | 
			
		||||
        />
 | 
			
		||||
      );
 | 
			
		||||
 | 
			
		||||
      actions.push(
 | 
			
		||||
        <ActionButton
 | 
			
		||||
          color="green"
 | 
			
		||||
@@ -439,7 +468,7 @@ export function PluginListTable({ props }: { props: InvenTreeTableProps }) {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return actions;
 | 
			
		||||
  }, []);
 | 
			
		||||
  }, [user, pluginsEnabled]);
 | 
			
		||||
 | 
			
		||||
  return (
 | 
			
		||||
    <>
 | 
			
		||||
 
 | 
			
		||||
@@ -86,6 +86,7 @@ export enum ApiPaths {
 | 
			
		||||
  plugin_list = 'api-plugin-list',
 | 
			
		||||
  plugin_setting_list = 'api-plugin-settings',
 | 
			
		||||
  plugin_install = 'api-plugin-install',
 | 
			
		||||
  plugin_reload = 'api-plugin-reload',
 | 
			
		||||
  plugin_registry_status = 'api-plugin-registry-status',
 | 
			
		||||
 | 
			
		||||
  project_code_list = 'api-project-code-list',
 | 
			
		||||
 
 | 
			
		||||
@@ -187,6 +187,8 @@ export function apiEndpoint(path: ApiPaths): string {
 | 
			
		||||
      return 'plugins/status/';
 | 
			
		||||
    case ApiPaths.plugin_install:
 | 
			
		||||
      return 'plugins/install/';
 | 
			
		||||
    case ApiPaths.plugin_reload:
 | 
			
		||||
      return 'plugins/reload/';
 | 
			
		||||
    case ApiPaths.project_code_list:
 | 
			
		||||
      return 'project-code/';
 | 
			
		||||
    case ApiPaths.custom_unit_list:
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user