-
Notifications
You must be signed in to change notification settings - Fork 354
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
561 additions
and
435 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
244 changes: 143 additions & 101 deletions
244
frontend/src/components/license/FeatureLicenseNotification.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,132 +1,174 @@ | ||
import { Alert, AlertDescription, AlertIcon, Box, Button, Flex, Link, Text } from '@redpanda-data/ui'; | ||
import { observer } from 'mobx-react'; | ||
import { FC, ReactElement, useEffect } from 'react'; | ||
import { License, License_Type, ListEnterpriseFeaturesResponse_Feature } from '../../protogen/redpanda/api/console/v1alpha1/license_pb'; | ||
import { getEnterpriseCTALink, getMillisecondsToExpiration, getPrettyExpirationDate, getPrettyTimeToExpiration, LICENSE_WEIGHT, MS_IN_DAY, coreHasEnterpriseFeatures, UploadLicenseButton, UpgradeButton } from './licenseUtils'; | ||
import { | ||
License, | ||
License_Type, | ||
ListEnterpriseFeaturesResponse_Feature, | ||
} from '../../protogen/redpanda/api/console/v1alpha1/license_pb'; | ||
import { | ||
getEnterpriseCTALink, | ||
getMillisecondsToExpiration, | ||
getPrettyExpirationDate, | ||
getPrettyTimeToExpiration, | ||
LICENSE_WEIGHT, | ||
MS_IN_DAY, | ||
coreHasEnterpriseFeatures, | ||
UploadLicenseButton, | ||
UpgradeButton, | ||
} from './licenseUtils'; | ||
import { api } from '../../state/backendApi'; | ||
|
||
const getLicenseAlertContentForFeature = (featureName: 'rbac' | 'reassignPartitions', license: License | undefined, enterpriseFeaturesUsed: ListEnterpriseFeaturesResponse_Feature[]): { message: ReactElement, status: 'warning' | 'info' } | null => { | ||
if (license === undefined || license.type !== License_Type.TRIAL) { | ||
return null | ||
} | ||
const getLicenseAlertContentForFeature = ( | ||
featureName: 'rbac' | 'reassignPartitions', | ||
license: License | undefined, | ||
enterpriseFeaturesUsed: ListEnterpriseFeaturesResponse_Feature[], | ||
): { message: ReactElement; status: 'warning' | 'info' } | null => { | ||
if (license === undefined || license.type !== License_Type.TRIAL) { | ||
return null; | ||
} | ||
|
||
const msToExpiration = getMillisecondsToExpiration(license); | ||
const msToExpiration = getMillisecondsToExpiration(license); | ||
|
||
// Redpanda | ||
if (api.isRedpanda) { | ||
if (msToExpiration > 15 * MS_IN_DAY && msToExpiration < 30 * MS_IN_DAY && coreHasEnterpriseFeatures(enterpriseFeaturesUsed)) { | ||
return { | ||
message: <Box> | ||
<Text>This is an enterprise feature, active until {getPrettyExpirationDate(license)}.</Text> | ||
<Flex gap={2} my={2}> | ||
<UploadLicenseButton /> | ||
<UpgradeButton /> | ||
</Flex> | ||
</Box>, | ||
status: 'info', | ||
} | ||
} else if (msToExpiration > 0 && msToExpiration < 15 * MS_IN_DAY && coreHasEnterpriseFeatures(enterpriseFeaturesUsed)) { | ||
return { | ||
message: <Box> | ||
<Text> | ||
Your Redpanda Enterprise trial is expiring in {getPrettyTimeToExpiration(license)}; at that point, your enterprise features will become unavailable. To get a full Redpanda Enterprise license, <Link href={getEnterpriseCTALink('upgrade')} target="_blank">contact us</Link>. | ||
</Text> | ||
<Flex gap={2} my={2}> | ||
<UploadLicenseButton/> | ||
<UpgradeButton /> | ||
</Flex> | ||
</Box>, | ||
status: 'warning' | ||
}; | ||
} | ||
} else { | ||
// Kafka | ||
if (msToExpiration > 15 * MS_IN_DAY && msToExpiration < 30 * MS_IN_DAY) { | ||
if (license.type === License_Type.TRIAL) { | ||
return { | ||
message: | ||
<Box> | ||
<Text> | ||
This is an enterprise feature. Your trial is active until {getPrettyExpirationDate(license)} | ||
</Text> | ||
<Flex gap={2} my={2}> | ||
<UploadLicenseButton /> | ||
<UpgradeButton /> | ||
</Flex> | ||
</Box>, | ||
status: 'info' | ||
}; | ||
} else { | ||
return { | ||
message: <Box> | ||
<Text> | ||
This is a Redpanda Enterprise feature. Try it with our <Link href={getEnterpriseCTALink('tryEnterprise')} target="_blank">Redpanda Enterprise Trial</Link>. | ||
</Text> | ||
</Box>, | ||
status: 'info' | ||
}; | ||
} | ||
} else if (msToExpiration > 0 && msToExpiration < 15 * MS_IN_DAY && license.type === License_Type.TRIAL) { | ||
return { | ||
message: <Box> | ||
<Text> | ||
Your Redpanda Enterprise trial is expiring in {getPrettyTimeToExpiration(license)}; at that point, your enterprise features will become unavailable. To get a full Redpanda Enterprise license, <Link href={getEnterpriseCTALink('upgrade')} target="_blank">contact us</Link>. | ||
</Text> | ||
<Flex gap={2} my={2}> | ||
<UploadLicenseButton /> | ||
<UpgradeButton /> | ||
</Flex> | ||
</Box>, | ||
status: 'warning' | ||
}; | ||
} | ||
// Redpanda | ||
if (api.isRedpanda) { | ||
if ( | ||
msToExpiration > 15 * MS_IN_DAY && | ||
msToExpiration < 30 * MS_IN_DAY && | ||
coreHasEnterpriseFeatures(enterpriseFeaturesUsed) | ||
) { | ||
return { | ||
message: ( | ||
<Box> | ||
<Text>This is an enterprise feature, active until {getPrettyExpirationDate(license)}.</Text> | ||
<Flex gap={2} my={2}> | ||
<UploadLicenseButton /> | ||
<UpgradeButton /> | ||
</Flex> | ||
</Box> | ||
), | ||
status: 'info', | ||
}; | ||
} else if ( | ||
msToExpiration > 0 && | ||
msToExpiration < 15 * MS_IN_DAY && | ||
coreHasEnterpriseFeatures(enterpriseFeaturesUsed) | ||
) { | ||
return { | ||
message: ( | ||
<Box> | ||
<Text> | ||
Your Redpanda Enterprise trial is expiring in {getPrettyTimeToExpiration(license)}; at that point, your | ||
enterprise features will become unavailable. To get a full Redpanda Enterprise license,{' '} | ||
<Link href={getEnterpriseCTALink('upgrade')} target="_blank"> | ||
contact us | ||
</Link> | ||
. | ||
</Text> | ||
<Flex gap={2} my={2}> | ||
<UploadLicenseButton /> | ||
<UpgradeButton /> | ||
</Flex> | ||
</Box> | ||
), | ||
status: 'warning', | ||
}; | ||
} | ||
} else { | ||
// Kafka | ||
if (msToExpiration > 15 * MS_IN_DAY && msToExpiration < 30 * MS_IN_DAY) { | ||
if (license.type === License_Type.TRIAL) { | ||
return { | ||
message: ( | ||
<Box> | ||
<Text>This is an enterprise feature. Your trial is active until {getPrettyExpirationDate(license)}</Text> | ||
<Flex gap={2} my={2}> | ||
<UploadLicenseButton /> | ||
<UpgradeButton /> | ||
</Flex> | ||
</Box> | ||
), | ||
status: 'info', | ||
}; | ||
} else { | ||
return { | ||
message: ( | ||
<Box> | ||
<Text> | ||
This is a Redpanda Enterprise feature. Try it with our{' '} | ||
<Link href={getEnterpriseCTALink('tryEnterprise')} target="_blank"> | ||
Redpanda Enterprise Trial | ||
</Link> | ||
. | ||
</Text> | ||
</Box> | ||
), | ||
status: 'info', | ||
}; | ||
} | ||
} else if (msToExpiration > 0 && msToExpiration < 15 * MS_IN_DAY && license.type === License_Type.TRIAL) { | ||
return { | ||
message: ( | ||
<Box> | ||
<Text> | ||
Your Redpanda Enterprise trial is expiring in {getPrettyTimeToExpiration(license)}; at that point, your | ||
enterprise features will become unavailable. To get a full Redpanda Enterprise license,{' '} | ||
<Link href={getEnterpriseCTALink('upgrade')} target="_blank"> | ||
contact us | ||
</Link> | ||
. | ||
</Text> | ||
<Flex gap={2} my={2}> | ||
<UploadLicenseButton /> | ||
<UpgradeButton /> | ||
</Flex> | ||
</Box> | ||
), | ||
status: 'warning', | ||
}; | ||
} | ||
} | ||
|
||
return null; | ||
return null; | ||
}; | ||
|
||
export const FeatureLicenseNotification: FC<{ featureName: 'reassignPartitions' | 'rbac' }> = observer(({ featureName}) => { | ||
export const FeatureLicenseNotification: FC<{ featureName: 'reassignPartitions' | 'rbac' }> = observer( | ||
({ featureName }) => { | ||
useEffect(() => { | ||
void api.refreshClusterOverview() | ||
void api.listLicenses(); | ||
void api.refreshClusterOverview(); | ||
void api.listLicenses(); | ||
}, []); | ||
|
||
const license = api | ||
.licenses | ||
.filter(license => license.type === License_Type.TRIAL || license.type === License_Type.COMMUNITY) | ||
.sort((a, b) => LICENSE_WEIGHT[a.type] - LICENSE_WEIGHT[b.type]) // Sort by priority | ||
.first(); | ||
const license = api.licenses | ||
.filter((license) => license.type === License_Type.TRIAL || license.type === License_Type.COMMUNITY) | ||
.sort((a, b) => LICENSE_WEIGHT[a.type] - LICENSE_WEIGHT[b.type]) // Sort by priority | ||
.first(); | ||
|
||
const enterpriseFeaturesUsed = api.enterpriseFeaturesUsed | ||
const enterpriseFeaturesUsed = api.enterpriseFeaturesUsed; | ||
const alertContent = getLicenseAlertContentForFeature(featureName, license, enterpriseFeaturesUsed); | ||
|
||
// This component needs info about whether we're using Redpanda or Kafka, without fetching clusterOverview first, we might get a malformed result | ||
if (api.clusterOverview === null) { | ||
return null | ||
return null; | ||
} | ||
|
||
if (!license) { | ||
return null; | ||
return null; | ||
} | ||
|
||
if (alertContent === null) { | ||
return null; | ||
return null; | ||
} | ||
|
||
const { message, status } = alertContent; | ||
|
||
return ( | ||
<Box> | ||
<Alert | ||
mb={4} | ||
status={status} | ||
variant="subtle" | ||
> | ||
<AlertIcon/> | ||
<AlertDescription> | ||
{message} | ||
</AlertDescription> | ||
</Alert> | ||
</Box> | ||
<Box> | ||
<Alert mb={4} status={status} variant="subtle"> | ||
<AlertIcon /> | ||
<AlertDescription>{message}</AlertDescription> | ||
</Alert> | ||
</Box> | ||
); | ||
}); | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.