mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-28 11:36:44 +00:00
Fix for plugin table (#8189)
- useServerApiState() was constantly refreshing - This was causing infinite update cycles
This commit is contained in:
parent
1522d1e615
commit
4d48a10bdd
@ -239,15 +239,10 @@ export default function PluginListTable() {
|
|||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const user = useUserState();
|
const user = useUserState();
|
||||||
|
|
||||||
const [pluginsEnabled, plugins_install_disabled] = useServerApiState(
|
const { server } = useServerApiState();
|
||||||
(state) => [
|
|
||||||
state.server.plugins_enabled,
|
|
||||||
state.server.plugins_install_disabled
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
const pluginTableColumns: TableColumn[] = useMemo(
|
const pluginTableColumns: TableColumn[] = useMemo(() => {
|
||||||
() => [
|
return [
|
||||||
{
|
{
|
||||||
accessor: 'name',
|
accessor: 'name',
|
||||||
title: t`Plugin`,
|
title: t`Plugin`,
|
||||||
@ -275,7 +270,6 @@ export default function PluginListTable() {
|
|||||||
accessor: 'meta.description',
|
accessor: 'meta.description',
|
||||||
title: t`Description`,
|
title: t`Description`,
|
||||||
sortable: false,
|
sortable: false,
|
||||||
|
|
||||||
render: function (record: any) {
|
render: function (record: any) {
|
||||||
if (record.active) {
|
if (record.active) {
|
||||||
return record?.meta.description;
|
return record?.meta.description;
|
||||||
@ -292,7 +286,10 @@ export default function PluginListTable() {
|
|||||||
{
|
{
|
||||||
accessor: 'meta.version',
|
accessor: 'meta.version',
|
||||||
title: t`Version`,
|
title: t`Version`,
|
||||||
sortable: false
|
sortable: false,
|
||||||
|
render: (record: any) => {
|
||||||
|
return record?.meta.version;
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Display date information if available
|
// TODO: Display date information if available
|
||||||
},
|
},
|
||||||
@ -301,9 +298,8 @@ export default function PluginListTable() {
|
|||||||
title: 'Author',
|
title: 'Author',
|
||||||
sortable: false
|
sortable: false
|
||||||
}
|
}
|
||||||
],
|
];
|
||||||
[]
|
}, []);
|
||||||
);
|
|
||||||
|
|
||||||
const [selectedPlugin, setSelectedPlugin] = useState<string>('');
|
const [selectedPlugin, setSelectedPlugin] = useState<string>('');
|
||||||
const [activate, setActivate] = useState<boolean>(false);
|
const [activate, setActivate] = useState<boolean>(false);
|
||||||
@ -330,6 +326,67 @@ export default function PluginListTable() {
|
|||||||
);
|
);
|
||||||
}, [activate]);
|
}, [activate]);
|
||||||
|
|
||||||
|
// Determine available actions for a given plugin
|
||||||
|
const rowActions = useCallback(
|
||||||
|
(record: any): RowAction[] => {
|
||||||
|
// Only superuser can perform plugin actions
|
||||||
|
if (!user.isSuperuser() || !server.plugins_enabled) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
hidden: record.is_builtin != false || record.is_installed != false,
|
||||||
|
title: t`Deactivate`,
|
||||||
|
color: 'red',
|
||||||
|
icon: <IconCircleX />,
|
||||||
|
onClick: () => {
|
||||||
|
setSelectedPlugin(record.key);
|
||||||
|
setActivate(false);
|
||||||
|
activatePluginModal.open();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
hidden: record.is_builtin != false || record.is_installed != true,
|
||||||
|
title: t`Activate`,
|
||||||
|
color: 'green',
|
||||||
|
icon: <IconCircleCheck />,
|
||||||
|
onClick: () => {
|
||||||
|
setSelectedPlugin(record.key);
|
||||||
|
setActivate(true);
|
||||||
|
activatePluginModal.open();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
hidden:
|
||||||
|
record.active != true ||
|
||||||
|
record.is_package != true ||
|
||||||
|
!record.package_name,
|
||||||
|
title: t`Update`,
|
||||||
|
color: 'blue',
|
||||||
|
icon: <IconRefresh />,
|
||||||
|
onClick: () => {
|
||||||
|
setPluginPackage(record.package_name);
|
||||||
|
installPluginModal.open();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
hidden: record.is_installed != false,
|
||||||
|
title: t`Delete`,
|
||||||
|
color: 'red',
|
||||||
|
icon: <IconCircleX />,
|
||||||
|
onClick: () => {
|
||||||
|
setSelectedPlugin(record.key);
|
||||||
|
deletePluginModal.open();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
];
|
||||||
|
},
|
||||||
|
[user, server]
|
||||||
|
);
|
||||||
|
|
||||||
|
const [pluginPackage, setPluginPackage] = useState<string>('');
|
||||||
|
|
||||||
const activatePluginModal = useEditApiFormModal({
|
const activatePluginModal = useEditApiFormModal({
|
||||||
title: t`Activate Plugin`,
|
title: t`Activate Plugin`,
|
||||||
url: ApiEndpoints.plugin_activate,
|
url: ApiEndpoints.plugin_activate,
|
||||||
@ -342,101 +399,15 @@ export default function PluginListTable() {
|
|||||||
: `The plugin was deactivated`,
|
: `The plugin was deactivated`,
|
||||||
fields: {
|
fields: {
|
||||||
active: {
|
active: {
|
||||||
value: activate,
|
|
||||||
hidden: true
|
hidden: true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
initialData: {
|
||||||
|
active: activate
|
||||||
|
},
|
||||||
table: table
|
table: table
|
||||||
});
|
});
|
||||||
|
|
||||||
// Determine available actions for a given plugin
|
|
||||||
const rowActions = useCallback(
|
|
||||||
(record: any): RowAction[] => {
|
|
||||||
// Only superuser can perform plugin actions
|
|
||||||
if (!user.isSuperuser()) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
let actions: RowAction[] = [];
|
|
||||||
|
|
||||||
if (!record.is_builtin && record.is_installed) {
|
|
||||||
if (record.active) {
|
|
||||||
actions.push({
|
|
||||||
title: t`Deactivate`,
|
|
||||||
color: 'red',
|
|
||||||
icon: <IconCircleX />,
|
|
||||||
onClick: () => {
|
|
||||||
setSelectedPlugin(record.key);
|
|
||||||
setActivate(false);
|
|
||||||
activatePluginModal.open();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
actions.push({
|
|
||||||
title: t`Activate`,
|
|
||||||
color: 'green',
|
|
||||||
icon: <IconCircleCheck />,
|
|
||||||
onClick: () => {
|
|
||||||
setSelectedPlugin(record.key);
|
|
||||||
setActivate(true);
|
|
||||||
activatePluginModal.open();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Active 'package' plugins can be updated
|
|
||||||
if (record.active && record.is_package && record.package_name) {
|
|
||||||
actions.push({
|
|
||||||
title: t`Update`,
|
|
||||||
color: 'blue',
|
|
||||||
icon: <IconRefresh />,
|
|
||||||
onClick: () => {
|
|
||||||
setPluginPackage(record.package_name);
|
|
||||||
installPluginModal.open();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Inactive 'package' plugins can be uninstalled
|
|
||||||
if (
|
|
||||||
!record.active &&
|
|
||||||
record.is_installed &&
|
|
||||||
record.is_package &&
|
|
||||||
record.package_name
|
|
||||||
) {
|
|
||||||
actions.push({
|
|
||||||
title: t`Uninstall`,
|
|
||||||
color: 'red',
|
|
||||||
icon: <IconCircleX />,
|
|
||||||
onClick: () => {
|
|
||||||
setSelectedPlugin(record.key);
|
|
||||||
uninstallPluginModal.open();
|
|
||||||
},
|
|
||||||
disabled: plugins_install_disabled || false
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Uninstalled 'package' plugins can be deleted
|
|
||||||
if (!record.is_installed) {
|
|
||||||
actions.push({
|
|
||||||
title: t`Delete`,
|
|
||||||
color: 'red',
|
|
||||||
icon: <IconCircleX />,
|
|
||||||
onClick: () => {
|
|
||||||
setSelectedPlugin(record.key);
|
|
||||||
deletePluginModal.open();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return actions;
|
|
||||||
},
|
|
||||||
[user, pluginsEnabled]
|
|
||||||
);
|
|
||||||
|
|
||||||
const [pluginPackage, setPluginPackage] = useState<string>('');
|
|
||||||
|
|
||||||
const installPluginModal = useCreateApiFormModal({
|
const installPluginModal = useCreateApiFormModal({
|
||||||
title: t`Install plugin`,
|
title: t`Install plugin`,
|
||||||
url: ApiEndpoints.plugin_install,
|
url: ApiEndpoints.plugin_install,
|
||||||
@ -459,7 +430,7 @@ export default function PluginListTable() {
|
|||||||
const uninstallPluginModal = useEditApiFormModal({
|
const uninstallPluginModal = useEditApiFormModal({
|
||||||
title: t`Uninstall Plugin`,
|
title: t`Uninstall Plugin`,
|
||||||
url: ApiEndpoints.plugin_uninstall,
|
url: ApiEndpoints.plugin_uninstall,
|
||||||
pathParams: { key: selectedPlugin },
|
// pathParams: { key: selectedPlugin },
|
||||||
fetchInitialData: false,
|
fetchInitialData: false,
|
||||||
timeout: 30000,
|
timeout: 30000,
|
||||||
fields: {
|
fields: {
|
||||||
@ -490,6 +461,8 @@ export default function PluginListTable() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const reloadPlugins = useCallback(() => {
|
const reloadPlugins = useCallback(() => {
|
||||||
|
console.log('reloadPlugins:');
|
||||||
|
|
||||||
api
|
api
|
||||||
.post(apiUrl(ApiEndpoints.plugin_reload), {
|
.post(apiUrl(ApiEndpoints.plugin_reload), {
|
||||||
full_reload: true,
|
full_reload: true,
|
||||||
@ -508,7 +481,7 @@ export default function PluginListTable() {
|
|||||||
|
|
||||||
// Custom table actions
|
// Custom table actions
|
||||||
const tableActions = useMemo(() => {
|
const tableActions = useMemo(() => {
|
||||||
if (!user.isSuperuser() || !pluginsEnabled) {
|
if (!user.isSuperuser() || !server.plugins_enabled) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -529,17 +502,17 @@ export default function PluginListTable() {
|
|||||||
setPluginPackage('');
|
setPluginPackage('');
|
||||||
installPluginModal.open();
|
installPluginModal.open();
|
||||||
}}
|
}}
|
||||||
disabled={plugins_install_disabled || false}
|
disabled={server.plugins_install_disabled || false}
|
||||||
/>
|
/>
|
||||||
];
|
];
|
||||||
}, [user, pluginsEnabled]);
|
}, [user, server]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{activatePluginModal.modal}
|
|
||||||
{installPluginModal.modal}
|
{installPluginModal.modal}
|
||||||
{uninstallPluginModal.modal}
|
{uninstallPluginModal.modal}
|
||||||
{deletePluginModal.modal}
|
{deletePluginModal.modal}
|
||||||
|
{activatePluginModal.modal}
|
||||||
<DetailDrawer
|
<DetailDrawer
|
||||||
title={t`Plugin Detail`}
|
title={t`Plugin Detail`}
|
||||||
size={'50%'}
|
size={'50%'}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user