-
Notifications
You must be signed in to change notification settings - Fork 430
Expand file tree
/
Copy pathfeature-license-notification.tsx
More file actions
251 lines (231 loc) · 8.35 KB
/
Copy pathfeature-license-notification.tsx
File metadata and controls
251 lines (231 loc) · 8.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
import { Flex, Text } from '@redpanda-data/ui';
import { Link } from 'components/redpanda-ui/components/typography';
import { type FC, type ReactElement, useEffect, useState } from 'react';
import {
coreHasEnterpriseFeatures,
ENTERPRISE_FEATURES_DOCS_LINK,
getEnterpriseCTALink,
getLatestExpiringLicense,
getMillisecondsToExpiration,
getPrettyExpirationDate,
getPrettyTimeToExpiration,
isBakedInTrial,
LICENSE_WEIGHT,
MS_IN_DAY,
RegisterButton,
UpgradeButton,
UploadLicenseButton,
} from './license-utils';
const WARNING_THRESHOLD_DAYS = 5;
import { InfoIcon } from 'components/icons';
import { Alert, AlertDescription, AlertTitle } from 'components/redpanda-ui/components/alert';
import {
type License,
License_Type,
type ListEnterpriseFeaturesResponse_Feature,
} from 'protogen/redpanda/api/console/v1alpha1/license_pb';
import { api } from 'state/backend-api';
import { RegisterModal } from './register-modal';
// biome-ignore lint/nursery/useMaxParams: Refactoring to options object would require updating all call sites
const getLicenseAlertContentForFeature = (
_featureName: 'rbac' | 'reassignPartitions',
license: License | undefined,
enterpriseFeaturesUsed: ListEnterpriseFeaturesResponse_Feature[],
bakedInTrial: boolean,
onRegisterModalOpen: () => void
// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: complex business logic
): { message: ReactElement; status: 'warning' | 'destructive' } | null => {
if (license === undefined) {
return null;
}
const msToExpiration = getMillisecondsToExpiration(license);
if (license.type === License_Type.TRIAL && api.isRedpanda) {
if (bakedInTrial) {
return {
message: (
<Alert icon={<InfoIcon />} variant="destructive">
<AlertDescription>
<Text>This is an enterprise feature. Register for an additional 30 days of enterprise features.</Text>
<Flex gap={2} my={2}>
<RegisterButton onRegisterModalOpen={onRegisterModalOpen} />
</Flex>
</AlertDescription>
</Alert>
),
status: msToExpiration > WARNING_THRESHOLD_DAYS * MS_IN_DAY ? 'warning' : 'destructive',
};
}
return {
message: (
<Alert
icon={<InfoIcon />}
variant={msToExpiration > WARNING_THRESHOLD_DAYS * MS_IN_DAY ? 'warning' : 'destructive'}
>
<AlertTitle>This is an enterprise feature.</AlertTitle>
</Alert>
),
status: msToExpiration > WARNING_THRESHOLD_DAYS * MS_IN_DAY ? 'warning' : 'destructive',
};
}
// Redpanda
if (api.isRedpanda) {
if (
msToExpiration > 15 * MS_IN_DAY &&
msToExpiration < 30 * MS_IN_DAY &&
coreHasEnterpriseFeatures(enterpriseFeaturesUsed)
) {
return {
message: (
<Alert icon={<InfoIcon />} variant="info">
<AlertDescription>
<Text>This is an enterprise feature, active until {getPrettyExpirationDate(license)}.</Text>
<Flex gap={2} my={2}>
<UploadLicenseButton />
<UpgradeButton />
</Flex>
</AlertDescription>
</Alert>
),
status: 'warning',
};
}
if (msToExpiration > -1 && msToExpiration < 15 * MS_IN_DAY && coreHasEnterpriseFeatures(enterpriseFeaturesUsed)) {
return {
message: (
<Alert icon={<InfoIcon />} variant="destructive">
<AlertDescription>
<Text>
Your Redpanda Enterprise trial is expiring in {getPrettyTimeToExpiration(license)}; at that point, your{' '}
<Link href={ENTERPRISE_FEATURES_DOCS_LINK} rel="noopener noreferrer" target="_blank">
enterprise features
</Link>{' '}
will become unavailable. To get a full Redpanda Enterprise license,{' '}
<Link href={getEnterpriseCTALink('upgrade')} rel="noopener noreferrer" target="_blank">
contact us
</Link>
.
</Text>
<Flex gap={2} my={2}>
<UploadLicenseButton />
<UpgradeButton />
</Flex>
</AlertDescription>
</Alert>
),
status: 'destructive',
};
}
} else {
// Kafka
if (msToExpiration > 15 * MS_IN_DAY && msToExpiration < 30 * MS_IN_DAY) {
if (license.type === License_Type.TRIAL) {
return {
message: (
<Alert icon={<InfoIcon />} variant="warning">
<AlertDescription>
<Text>
This is an enterprise feature. Your trial is active until {getPrettyExpirationDate(license)}
</Text>
<Flex gap={2} my={2}>
<UploadLicenseButton />
<UpgradeButton />
</Flex>
</AlertDescription>
</Alert>
),
status: 'warning',
};
}
return {
message: (
<Alert icon={<InfoIcon />} variant="warning">
<AlertDescription>
<Text>
This is a Redpanda Enterprise feature. Try it with our{' '}
<Link href={getEnterpriseCTALink('tryEnterprise')} rel="noopener noreferrer" target="_blank">
Redpanda Enterprise Trial
</Link>
.
</Text>
</AlertDescription>
</Alert>
),
status: 'warning',
};
}
if (msToExpiration > 0 && msToExpiration < 15 * MS_IN_DAY && license.type === License_Type.TRIAL) {
return {
message: (
<Alert icon={<InfoIcon />} variant="warning">
<AlertDescription>
<Text>
Your Redpanda Enterprise trial is expiring in {getPrettyTimeToExpiration(license)}; at that point, your{' '}
<Link href={ENTERPRISE_FEATURES_DOCS_LINK} rel="noopener noreferrer" target="_blank">
enterprise features
</Link>{' '}
will become unavailable. To get a full Redpanda Enterprise license,{' '}
<Link href={getEnterpriseCTALink('upgrade')} rel="noopener noreferrer" target="_blank">
contact us
</Link>
.
</Text>
<Flex gap={2} my={2}>
<UploadLicenseButton />
<UpgradeButton />
</Flex>
</AlertDescription>
</Alert>
),
status: 'destructive',
};
}
}
return null;
};
export const FeatureLicenseNotification: FC<{ featureName: 'reassignPartitions' | 'rbac' }> = ({ featureName }) => {
const [registerModalOpen, setIsRegisterModalOpen] = useState(false);
useEffect(() => {
api.refreshClusterOverview().catch(() => {
// Error handling managed by API layer
});
api.listLicenses().catch(() => {
// Error handling managed by API layer
});
}, []);
const licenses = api.licenses
.filter((lic) => lic.type === License_Type.TRIAL || lic.type === License_Type.COMMUNITY)
.sort((a, b) => LICENSE_WEIGHT[a.type] - LICENSE_WEIGHT[b.type]); // Sort by priority
// Choose the license with the latest expiration time
const license = getLatestExpiringLicense(licenses);
// Trial is either baked-in or extended. We need to check if any of the licenses are baked-in.
// We say the trial is baked-in if and only if all the licenses are baked-in. There can be a situation where,
// use has registered a license, it's updated in the brokers, but the console doesn't have the license re-loaded yet.
const bakedInTrial = licenses.every((lic) => isBakedInTrial(lic));
const enterpriseFeaturesUsed = api.enterpriseFeaturesUsed;
const alertContent = getLicenseAlertContentForFeature(
featureName,
license,
enterpriseFeaturesUsed,
bakedInTrial,
() => {
setIsRegisterModalOpen(true);
}
);
// 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;
}
if (!license) {
return null;
}
if (alertContent === null) {
return null;
}
const { message } = alertContent;
return (
<>
{message}
<RegisterModal isOpen={registerModalOpen} onClose={() => setIsRegisterModalOpen(false)} />
</>
);
};