|
1 | 1 | import { Alert, AlertDescription, AlertIcon, Box, Flex, Text } from '@redpanda-data/ui'; |
2 | 2 | import { Link } from 'components/redpanda-ui/components/typography'; |
3 | | -import { observer } from 'mobx-react'; |
4 | 3 | import { type FC, type ReactElement, useEffect, useState } from 'react'; |
5 | 4 |
|
6 | 5 | import { |
@@ -173,66 +172,64 @@ const getLicenseAlertContentForFeature = ( |
173 | 172 | return null; |
174 | 173 | }; |
175 | 174 |
|
176 | | -export const FeatureLicenseNotification: FC<{ featureName: 'reassignPartitions' | 'rbac' }> = observer( |
177 | | - ({ featureName }) => { |
178 | | - const [registerModalOpen, setIsRegisterModalOpen] = useState(false); |
179 | | - |
180 | | - useEffect(() => { |
181 | | - api.refreshClusterOverview().catch(() => { |
182 | | - // Error handling managed by API layer |
183 | | - }); |
184 | | - api.listLicenses().catch(() => { |
185 | | - // Error handling managed by API layer |
186 | | - }); |
187 | | - }, []); |
188 | | - |
189 | | - const licenses = api.licenses |
190 | | - .filter((lic) => lic.type === License_Type.TRIAL || lic.type === License_Type.COMMUNITY) |
191 | | - .sort((a, b) => LICENSE_WEIGHT[a.type] - LICENSE_WEIGHT[b.type]); // Sort by priority |
192 | | - |
193 | | - // Choose the license with the latest expiration time |
194 | | - const license = getLatestExpiringLicense(licenses); |
195 | | - |
196 | | - // Trial is either baked-in or extended. We need to check if any of the licenses are baked-in. |
197 | | - // We say the trial is baked-in if and only if all the licenses are baked-in. There can be a situation where, |
198 | | - // use has registered a license, it's updated in the brokers, but the console doesn't have the license re-loaded yet. |
199 | | - const bakedInTrial = licenses.every((lic) => isBakedInTrial(lic)); |
200 | | - |
201 | | - const enterpriseFeaturesUsed = api.enterpriseFeaturesUsed; |
202 | | - const alertContent = getLicenseAlertContentForFeature( |
203 | | - featureName, |
204 | | - license, |
205 | | - enterpriseFeaturesUsed, |
206 | | - bakedInTrial, |
207 | | - () => { |
208 | | - setIsRegisterModalOpen(true); |
209 | | - } |
210 | | - ); |
211 | | - |
212 | | - // This component needs info about whether we're using Redpanda or Kafka, without fetching clusterOverview first, we might get a malformed result |
213 | | - if (api.clusterOverview === null) { |
214 | | - return null; |
| 175 | +export const FeatureLicenseNotification: FC<{ featureName: 'reassignPartitions' | 'rbac' }> = ({ featureName }) => { |
| 176 | + const [registerModalOpen, setIsRegisterModalOpen] = useState(false); |
| 177 | + |
| 178 | + useEffect(() => { |
| 179 | + api.refreshClusterOverview().catch(() => { |
| 180 | + // Error handling managed by API layer |
| 181 | + }); |
| 182 | + api.listLicenses().catch(() => { |
| 183 | + // Error handling managed by API layer |
| 184 | + }); |
| 185 | + }, []); |
| 186 | + |
| 187 | + const licenses = api.licenses |
| 188 | + .filter((lic) => lic.type === License_Type.TRIAL || lic.type === License_Type.COMMUNITY) |
| 189 | + .sort((a, b) => LICENSE_WEIGHT[a.type] - LICENSE_WEIGHT[b.type]); // Sort by priority |
| 190 | + |
| 191 | + // Choose the license with the latest expiration time |
| 192 | + const license = getLatestExpiringLicense(licenses); |
| 193 | + |
| 194 | + // Trial is either baked-in or extended. We need to check if any of the licenses are baked-in. |
| 195 | + // We say the trial is baked-in if and only if all the licenses are baked-in. There can be a situation where, |
| 196 | + // use has registered a license, it's updated in the brokers, but the console doesn't have the license re-loaded yet. |
| 197 | + const bakedInTrial = licenses.every((lic) => isBakedInTrial(lic)); |
| 198 | + |
| 199 | + const enterpriseFeaturesUsed = api.enterpriseFeaturesUsed; |
| 200 | + const alertContent = getLicenseAlertContentForFeature( |
| 201 | + featureName, |
| 202 | + license, |
| 203 | + enterpriseFeaturesUsed, |
| 204 | + bakedInTrial, |
| 205 | + () => { |
| 206 | + setIsRegisterModalOpen(true); |
215 | 207 | } |
| 208 | + ); |
216 | 209 |
|
217 | | - if (!license) { |
218 | | - return null; |
219 | | - } |
| 210 | + // This component needs info about whether we're using Redpanda or Kafka, without fetching clusterOverview first, we might get a malformed result |
| 211 | + if (api.clusterOverview === null) { |
| 212 | + return null; |
| 213 | + } |
220 | 214 |
|
221 | | - if (alertContent === null) { |
222 | | - return null; |
223 | | - } |
| 215 | + if (!license) { |
| 216 | + return null; |
| 217 | + } |
| 218 | + |
| 219 | + if (alertContent === null) { |
| 220 | + return null; |
| 221 | + } |
224 | 222 |
|
225 | | - const { message, status } = alertContent; |
| 223 | + const { message, status } = alertContent; |
226 | 224 |
|
227 | | - return ( |
228 | | - <Box> |
229 | | - <Alert mb={4} status={status} variant="subtle"> |
230 | | - <AlertIcon /> |
231 | | - <AlertDescription>{message}</AlertDescription> |
232 | | - </Alert> |
| 225 | + return ( |
| 226 | + <Box> |
| 227 | + <Alert mb={4} status={status} variant="subtle"> |
| 228 | + <AlertIcon /> |
| 229 | + <AlertDescription>{message}</AlertDescription> |
| 230 | + </Alert> |
233 | 231 |
|
234 | | - <RegisterModal isOpen={registerModalOpen} onClose={() => setIsRegisterModalOpen(false)} /> |
235 | | - </Box> |
236 | | - ); |
237 | | - } |
238 | | -); |
| 232 | + <RegisterModal isOpen={registerModalOpen} onClose={() => setIsRegisterModalOpen(false)} /> |
| 233 | + </Box> |
| 234 | + ); |
| 235 | +}; |
0 commit comments