1
0
Fork 0
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:
Chaim Lev-Ari 2022-12-01 08:40:52 +02:00 committed by GitHub
parent 4fee359247
commit 82e9e2a895
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
80 changed files with 1099 additions and 1892 deletions

View 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;
}