2023-02-19 04:17:50 +00:00
|
|
|
import { ArrowUpCircle } from 'lucide-react';
|
2022-12-11 06:58:22 +00:00
|
|
|
import { useState } from 'react';
|
2023-02-19 04:17:50 +00:00
|
|
|
import clsx from 'clsx';
|
2022-12-11 06:58:22 +00:00
|
|
|
|
|
|
|
import { useAnalytics } from '@/angulartics.matomo/analytics-services';
|
|
|
|
import { useNodesCount } from '@/react/portainer/system/useNodesCount';
|
|
|
|
import {
|
|
|
|
ContainerPlatform,
|
|
|
|
useSystemInfo,
|
|
|
|
} from '@/react/portainer/system/useSystemInfo';
|
2023-02-19 04:17:50 +00:00
|
|
|
import { useCurrentUser } from '@/react/hooks/useUser';
|
2022-12-11 06:58:22 +00:00
|
|
|
import { withEdition } from '@/react/portainer/feature-flags/withEdition';
|
|
|
|
import { withHideOnExtension } from '@/react/hooks/withHideOnExtension';
|
2023-02-19 04:17:50 +00:00
|
|
|
import { useUser } from '@/portainer/users/queries/useUser';
|
2022-12-11 06:58:22 +00:00
|
|
|
|
|
|
|
import { useSidebarState } from '../useSidebarState';
|
|
|
|
|
|
|
|
import { UpgradeDialog } from './UpgradeDialog';
|
|
|
|
|
|
|
|
export const UpgradeBEBannerWrapper = withHideOnExtension(
|
|
|
|
withEdition(UpgradeBEBanner, 'CE')
|
|
|
|
);
|
|
|
|
|
2022-12-13 20:52:06 +00:00
|
|
|
const enabledPlatforms: Array<ContainerPlatform> = [
|
|
|
|
'Docker Standalone',
|
|
|
|
'Docker Swarm',
|
|
|
|
];
|
2022-12-11 06:58:22 +00:00
|
|
|
|
|
|
|
function UpgradeBEBanner() {
|
2023-02-19 04:17:50 +00:00
|
|
|
const {
|
|
|
|
isAdmin,
|
|
|
|
user: { Id },
|
|
|
|
} = useCurrentUser();
|
|
|
|
|
2022-12-11 06:58:22 +00:00
|
|
|
const { trackEvent } = useAnalytics();
|
|
|
|
const { isOpen: isSidebarOpen } = useSidebarState();
|
2023-02-19 04:17:50 +00:00
|
|
|
|
2022-12-11 06:58:22 +00:00
|
|
|
const nodesCountQuery = useNodesCount();
|
|
|
|
const systemInfoQuery = useSystemInfo();
|
2023-02-19 04:17:50 +00:00
|
|
|
const userQuery = useUser(Id);
|
2022-12-11 06:58:22 +00:00
|
|
|
|
|
|
|
const [isOpen, setIsOpen] = useState(false);
|
|
|
|
|
2023-02-19 04:17:50 +00:00
|
|
|
if (!nodesCountQuery.isSuccess || !systemInfoQuery.data || !userQuery.data) {
|
2022-12-11 06:58:22 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
const nodesCount = nodesCountQuery.data;
|
|
|
|
const systemInfo = systemInfoQuery.data;
|
|
|
|
|
|
|
|
const metadata = {
|
|
|
|
upgrade: false,
|
|
|
|
nodeCount: nodesCount,
|
|
|
|
platform: systemInfo.platform,
|
|
|
|
edgeAgents: systemInfo.edgeAgents,
|
|
|
|
edgeDevices: systemInfo.edgeDevices,
|
|
|
|
agents: systemInfo.agents,
|
|
|
|
};
|
|
|
|
|
2023-02-19 04:17:50 +00:00
|
|
|
if (
|
|
|
|
!enabledPlatforms.includes(systemInfo.platform) &&
|
|
|
|
process.env.NODE_ENV !== 'development'
|
|
|
|
) {
|
2022-12-11 06:58:22 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2023-02-19 04:17:50 +00:00
|
|
|
const subtleButton = userQuery.data.ThemeSettings.subtleUpgradeButton;
|
|
|
|
|
2022-12-11 06:58:22 +00:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<button
|
|
|
|
type="button"
|
2023-02-19 04:17:50 +00:00
|
|
|
className={clsx(
|
|
|
|
'flex w-full items-center justify-center gap-1 py-2 pr-2 hover:underline',
|
|
|
|
{
|
|
|
|
'border-0 bg-warning-5 font-semibold text-warning-9': !subtleButton,
|
|
|
|
'border border-solid border-blue-9 bg-[#023959] font-medium text-white th-dark:border-[#343434] th-dark:bg-black':
|
|
|
|
subtleButton,
|
|
|
|
},
|
|
|
|
'th-highcontrast:border th-highcontrast:border-solid th-highcontrast:border-white th-highcontrast:bg-black th-highcontrast:font-medium th-highcontrast:text-white'
|
|
|
|
)}
|
2022-12-11 06:58:22 +00:00
|
|
|
onClick={handleClick}
|
|
|
|
>
|
2023-02-19 04:17:50 +00:00
|
|
|
<ArrowUpCircle
|
|
|
|
className={clsx(
|
|
|
|
'lucide text-lg',
|
|
|
|
{
|
|
|
|
'fill-warning-9 stroke-warning-5': !subtleButton,
|
|
|
|
'fill-warning-6 stroke-[#023959] th-dark:stroke-black':
|
|
|
|
subtleButton,
|
|
|
|
},
|
|
|
|
'th-highcontrast:fill-warning-6 th-highcontrast:stroke-black'
|
|
|
|
)}
|
|
|
|
/>
|
2022-12-11 06:58:22 +00:00
|
|
|
{isSidebarOpen && <>Upgrade to Business Edition</>}
|
|
|
|
</button>
|
|
|
|
|
|
|
|
{isOpen && <UpgradeDialog onDismiss={() => setIsOpen(false)} />}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
|
|
|
|
function handleClick() {
|
|
|
|
trackEvent(
|
|
|
|
isAdmin ? 'portainer-upgrade-admin' : 'portainer-upgrade-non-admin',
|
|
|
|
{
|
|
|
|
category: 'portainer',
|
|
|
|
metadata,
|
|
|
|
}
|
|
|
|
);
|
|
|
|
setIsOpen(true);
|
|
|
|
}
|
|
|
|
}
|