mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-28 11:36:44 +00:00
* A hook for caching active plugins * Add LocateItemButton * Implement "locate" button for location detail page too * Fix for StockApiMixin.get_serializer - Recent refactoring removed 'path_detail' attribute * Fix offloading of 'locate' * Remove debug msg * Add custom message * Remove force_async call * Add playwright tests
46 lines
1.1 KiB
TypeScript
46 lines
1.1 KiB
TypeScript
import { useCallback } from 'react';
|
|
import type { PluginInterface } from '../components/plugins/PluginInterface';
|
|
import { ApiEndpoints } from '../enums/ApiEndpoints';
|
|
import { useInstance } from './UseInstance';
|
|
|
|
export interface UsePluginResult {
|
|
plugins: PluginInterface[];
|
|
withMixin: (mixin: string) => PluginInterface[];
|
|
}
|
|
|
|
/**
|
|
* Hook for storing information on active plugins
|
|
*/
|
|
export const usePlugins = (): UsePluginResult => {
|
|
const pluginQuery = useInstance({
|
|
endpoint: ApiEndpoints.plugin_list,
|
|
defaultValue: [],
|
|
hasPrimaryKey: false,
|
|
refetchOnMount: true,
|
|
refetchOnWindowFocus: false,
|
|
params: {
|
|
active: true
|
|
}
|
|
});
|
|
|
|
const pluginsWithMixin = useCallback(
|
|
(mixin: string) => {
|
|
return pluginQuery.instance.filter((plugin: PluginInterface) => {
|
|
return !!plugin.mixins[mixin];
|
|
});
|
|
},
|
|
[pluginQuery.instance]
|
|
);
|
|
|
|
return {
|
|
plugins: pluginQuery.instance,
|
|
withMixin: pluginsWithMixin
|
|
};
|
|
};
|
|
|
|
export const usePluginsWithMixin = (mixin: string): PluginInterface[] => {
|
|
const plugins = usePlugins();
|
|
|
|
return plugins.withMixin(mixin);
|
|
};
|