2022-12-11 06:58:22 +00:00
|
|
|
import { ComponentType } from 'react';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hides the wrapped component if portainer is running as a docker extension.
|
|
|
|
*/
|
|
|
|
export function withHideOnExtension<T>(
|
|
|
|
WrappedComponent: ComponentType<T>
|
|
|
|
): ComponentType<T> {
|
|
|
|
// Try to create a nice displayName for React Dev Tools.
|
|
|
|
const displayName =
|
|
|
|
WrappedComponent.displayName || WrappedComponent.name || 'Component';
|
|
|
|
|
2023-05-14 09:24:37 +00:00
|
|
|
function WrapperComponent(props: T & JSX.IntrinsicAttributes) {
|
2022-12-11 06:58:22 +00:00
|
|
|
if (window.ddExtension) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return <WrappedComponent {...props} />;
|
|
|
|
}
|
|
|
|
|
|
|
|
WrapperComponent.displayName = `withHideOnExtension(${displayName})`;
|
|
|
|
|
|
|
|
return WrapperComponent;
|
|
|
|
}
|