mirror of
https://github.com/portainer/portainer.git
synced 2025-07-25 08:19:40 +02:00
refactor(edge/updates): sync changes from EE [EE-4288] (#7726)
This commit is contained in:
parent
4fee359247
commit
82e9e2a895
80 changed files with 1099 additions and 1892 deletions
38
app/react/hooks/useLimitToBE.tsx
Normal file
38
app/react/hooks/useLimitToBE.tsx
Normal file
|
@ -0,0 +1,38 @@
|
|||
import { useRouter } from '@uirouter/react';
|
||||
import { ComponentType } from 'react';
|
||||
|
||||
import { isBE } from '@/react/portainer/feature-flags/feature-flags.service';
|
||||
|
||||
export function useLimitToBE(defaultPath = 'portainer.home') {
|
||||
const router = useRouter();
|
||||
if (!isBE) {
|
||||
router.stateService.go(defaultPath);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
export function withLimitToBE<T>(
|
||||
WrappedComponent: ComponentType<T>,
|
||||
defaultPath = 'portainer.home'
|
||||
): ComponentType<T> {
|
||||
// Try to create a nice displayName for React Dev Tools.
|
||||
const displayName =
|
||||
WrappedComponent.displayName || WrappedComponent.name || 'Component';
|
||||
|
||||
function WrapperComponent(props: T) {
|
||||
const isLimitedToBE = useLimitToBE(defaultPath);
|
||||
|
||||
if (isLimitedToBE) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line react/jsx-props-no-spreading
|
||||
return <WrappedComponent {...props} />;
|
||||
}
|
||||
|
||||
WrapperComponent.displayName = `withLimitToBE(${displayName})`;
|
||||
|
||||
return WrapperComponent;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue