mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-18 04:55:44 +00:00
Plugin helper function (#8220)
* Add helper function for constructing URL to static file * Fix PluginListTable - Allow uninstallation of plugin - Allow deletion of plugin config * Move helper method to InvenTreePlugin class * Bump API version info
This commit is contained in:
@ -17,7 +17,8 @@ import {
|
||||
IconHelpCircle,
|
||||
IconInfoCircle,
|
||||
IconPlaylistAdd,
|
||||
IconRefresh
|
||||
IconRefresh,
|
||||
IconTrash
|
||||
} from '@tabler/icons-react';
|
||||
import { useCallback, useMemo, useState } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
@ -352,9 +353,10 @@ export default function PluginListTable() {
|
||||
{
|
||||
hidden:
|
||||
record.is_builtin != false ||
|
||||
record.is_installed != true ||
|
||||
!record.is_installed ||
|
||||
record.active != false,
|
||||
title: t`Activate`,
|
||||
tooltip: t`Activate selected plugin`,
|
||||
color: 'green',
|
||||
icon: <IconCircleCheck />,
|
||||
onClick: () => {
|
||||
@ -364,11 +366,9 @@ export default function PluginListTable() {
|
||||
}
|
||||
},
|
||||
{
|
||||
hidden:
|
||||
record.active != true ||
|
||||
record.is_package != true ||
|
||||
!record.package_name,
|
||||
hidden: !record.active || !record.is_package || !record.package_name,
|
||||
title: t`Update`,
|
||||
tooltip: t`Update selected plugin`,
|
||||
color: 'blue',
|
||||
icon: <IconRefresh />,
|
||||
onClick: () => {
|
||||
@ -377,10 +377,37 @@ export default function PluginListTable() {
|
||||
}
|
||||
},
|
||||
{
|
||||
hidden: record.is_installed != false,
|
||||
title: t`Delete`,
|
||||
// Uninstall an installed plugin
|
||||
// Must be inactive, not a builtin, not a sample, and installed as a package
|
||||
hidden:
|
||||
!user.isSuperuser() ||
|
||||
record.active ||
|
||||
record.is_builtin ||
|
||||
record.is_sample ||
|
||||
!record.is_installed ||
|
||||
!record.is_package,
|
||||
title: t`Uninstall`,
|
||||
tooltip: t`Uninstall selected plugin`,
|
||||
color: 'red',
|
||||
icon: <IconCircleX />,
|
||||
onClick: () => {
|
||||
setSelectedPlugin(record.key);
|
||||
uninstallPluginModal.open();
|
||||
}
|
||||
},
|
||||
{
|
||||
// Delete a plugin configuration
|
||||
// Must be inactive, not a builtin, not a sample, and not installed (i.e. no matching plugin)
|
||||
hidden:
|
||||
record.active ||
|
||||
record.is_builtin ||
|
||||
record.is_sample ||
|
||||
record.is_installed ||
|
||||
!user.isSuperuser(),
|
||||
title: t`Delete`,
|
||||
tooltip: t`Delete selected plugin configuration`,
|
||||
color: 'red',
|
||||
icon: <IconTrash />,
|
||||
onClick: () => {
|
||||
setSelectedPlugin(record.key);
|
||||
deletePluginModal.open();
|
||||
@ -436,7 +463,7 @@ export default function PluginListTable() {
|
||||
const uninstallPluginModal = useEditApiFormModal({
|
||||
title: t`Uninstall Plugin`,
|
||||
url: ApiEndpoints.plugin_uninstall,
|
||||
// pathParams: { key: selectedPlugin },
|
||||
pathParams: { key: selectedPlugin },
|
||||
fetchInitialData: false,
|
||||
timeout: 30000,
|
||||
fields: {
|
||||
@ -460,15 +487,14 @@ export default function PluginListTable() {
|
||||
|
||||
const deletePluginModal = useDeleteApiFormModal({
|
||||
url: ApiEndpoints.plugin_list,
|
||||
pathParams: { key: selectedPlugin },
|
||||
pk: selectedPlugin,
|
||||
fetchInitialData: false,
|
||||
title: t`Delete Plugin`,
|
||||
preFormWarning: t`Deleting this plugin configuration will remove all associated settings and data. Are you sure you want to delete this plugin?`,
|
||||
table: table
|
||||
});
|
||||
|
||||
const reloadPlugins = useCallback(() => {
|
||||
console.log('reloadPlugins:');
|
||||
|
||||
api
|
||||
.post(apiUrl(ApiEndpoints.plugin_reload), {
|
||||
full_reload: true,
|
||||
|
Reference in New Issue
Block a user