Skip to content

Commit

Permalink
frontend: lint/fix tests for license work
Browse files Browse the repository at this point in the history
  • Loading branch information
malinskibeniamin committed Nov 29, 2024
1 parent 6d36b19 commit a39feb3
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 103 deletions.
57 changes: 27 additions & 30 deletions frontend/src/components/license/FeatureLicenseNotification.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
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 { type FC, type ReactElement, useEffect } from 'react';
import {
License,
type License,
License_Type,
ListEnterpriseFeaturesResponse_Feature,
type ListEnterpriseFeaturesResponse_Feature,
} from '../../protogen/redpanda/api/console/v1alpha1/license_pb';
import { api } from '../../state/backendApi';
import {
LICENSE_WEIGHT,
MS_IN_DAY,
UpgradeButton,
UploadLicenseButton,
coreHasEnterpriseFeatures,
getEnterpriseCTALink,
getMillisecondsToExpiration,
getPrettyExpirationDate,
getPrettyTimeToExpiration,
LICENSE_WEIGHT,
MS_IN_DAY,
coreHasEnterpriseFeatures,
UploadLicenseButton,
UpgradeButton,
} from './licenseUtils';
import { api } from '../../state/backendApi';

const getLicenseAlertContentForFeature = (
featureName: 'rbac' | 'reassignPartitions',
Expand Down Expand Up @@ -49,11 +49,8 @@ const getLicenseAlertContentForFeature = (
),
status: 'info',
};
} else if (
msToExpiration > 0 &&
msToExpiration < 15 * MS_IN_DAY &&
coreHasEnterpriseFeatures(enterpriseFeaturesUsed)
) {
}
if (msToExpiration > 0 && msToExpiration < 15 * MS_IN_DAY && coreHasEnterpriseFeatures(enterpriseFeaturesUsed)) {
return {
message: (
<Box>
Expand Down Expand Up @@ -90,23 +87,23 @@ const getLicenseAlertContentForFeature = (
),
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>
This is a Redpanda Enterprise feature. Try it with our{' '}
<Link href={getEnterpriseCTALink('tryEnterprise')} target="_blank">
Redpanda Enterprise Trial
</Link>
.
</Text>
</Box>
),
status: 'info',
};
}
if (msToExpiration > 0 && msToExpiration < 15 * MS_IN_DAY && license.type === License_Type.TRIAL) {
return {
message: (
<Box>
Expand Down
97 changes: 48 additions & 49 deletions frontend/src/components/license/OverviewLicenseNotification.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import { Alert, AlertDescription, AlertIcon, Box, Flex, Link, Text } from '@redpanda-data/ui';
import { observer } from 'mobx-react';
import { FC, ReactElement, useEffect } from 'react';
import { type FC, type ReactElement, useEffect } from 'react';
import {
License,
type License,
License_Type,
ListEnterpriseFeaturesResponse_Feature,
type ListEnterpriseFeaturesResponse_Feature,
} from '../../protogen/redpanda/api/console/v1alpha1/license_pb';
import { api } from '../../state/backendApi';
import {
consoleHasEnterpriseFeature,
DISABLE_SSO_DOCS_LINK,
getEnterpriseCTALink,
getMillisecondsToExpiration,
getPrettyTimeToExpiration,
MS_IN_DAY,
UpgradeButton,
UploadLicenseButton,
consoleHasEnterpriseFeature,
getEnterpriseCTALink,
getMillisecondsToExpiration,
getPrettyTimeToExpiration,
} from './licenseUtils';
import { api } from '../../state/backendApi';

const getLicenseAlertContent = (
license: License | undefined,
Expand All @@ -43,7 +43,8 @@ const getLicenseAlertContent = (
),
status: 'info',
};
} else if (msToExpiration > 0 && msToExpiration < 15 * MS_IN_DAY) {
}
if (msToExpiration > 0 && msToExpiration < 15 * MS_IN_DAY) {
if (consoleHasEnterpriseFeature('SINGLE_SIGN_ON')) {
return {
message: (
Expand All @@ -68,27 +69,26 @@ const getLicenseAlertContent = (
),
status: 'warning',
};
} else {
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 {
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
Expand Down Expand Up @@ -117,27 +117,26 @@ const getLicenseAlertContent = (
),
status: 'warning',
};
} else {
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 {
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',
};
}
}

Expand Down
19 changes: 9 additions & 10 deletions frontend/src/components/license/licenseUtils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
prettyLicenseType,
resolveEnterpriseCTALink,
} from './licenseUtils';

import '../../utils/arrayExtensions';

describe('licenseUtils', () => {
Expand Down Expand Up @@ -156,32 +155,32 @@ describe('licenseUtils', () => {
});

describe('resolveEnterpriseCTALink', () => {
it('should return the correct URL for tryEnterprise with query parameters', () => {
test('should return the correct URL for tryEnterprise with query parameters', () => {
const result = resolveEnterpriseCTALink('tryEnterprise', '12345-uuid', true);
expect(result).toBe('https://redpanda.com/try-enterprise?cluster_uuid=12345-uuid&platform=1');
expect(result).toBe('https://redpanda.com/try-enterprise?cluster_id=12345-uuid&platform=1');
});

it('should return the correct URL for upgrade with query parameters', () => {
test('should return the correct URL for upgrade with query parameters', () => {
const result = resolveEnterpriseCTALink('upgrade', '67890-uuid', false);
expect(result).toBe('https://redpanda.com/upgrade?cluster_uuid=67890-uuid&platform=2');
expect(result).toBe('https://redpanda.com/upgrade?cluster_id=67890-uuid&platform=2');
});

it('should encode special characters in query parameters', () => {
test('should encode special characters in query parameters', () => {
const result = resolveEnterpriseCTALink('tryEnterprise', '12345&uuid', true);
expect(result).toBe('https://redpanda.com/try-enterprise?cluster_uuid=12345%26uuid&platform=1');
expect(result).toBe('https://redpanda.com/try-enterprise?cluster_id=12345%26uuid&platform=1');
});

it('should throw an error for an invalid EnterpriseLinkType', () => {
test('should throw an error for an invalid EnterpriseLinkType', () => {
// @ts-expect-error Testing invalid input
expect(() => resolveEnterpriseCTALink('invalidType', '12345-uuid', true)).toThrow();
});

it('should handle redpanda platform correctly', () => {
test('should handle redpanda platform correctly', () => {
const result = resolveEnterpriseCTALink('tryEnterprise', '12345-uuid', true);
expect(result).toContain('platform=1');
});

it('should handle kafka platform correctly', () => {
test('should handle kafka platform correctly', () => {
const result = resolveEnterpriseCTALink('upgrade', '12345-uuid', false);
expect(result).toContain('platform=2');
});
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/components/license/licenseUtils.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Button, Link } from '@redpanda-data/ui';
import { Link as ReactRouterLink } from 'react-router-dom';
import {
type License,
License_Source,
License_Type,
ListEnterpriseFeaturesResponse_Feature,
type ListEnterpriseFeaturesResponse_Feature,
} from '../../protogen/redpanda/api/console/v1alpha1/license_pb';
import { prettyMilliseconds } from '../../utils/utils';
import { api } from '../../state/backendApi';
import { AppFeatures } from '../../utils/env';
import { Button, Link } from '@redpanda-data/ui';
import { Link as ReactRouterLink } from 'react-router-dom';
import { prettyMilliseconds } from '../../utils/utils';

enum Platform {
PLATFORM_UNSPECIFIED = 0,
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/pages/acls/Acl.List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ import {
import type { AclPrincipalGroup } from './Models';
import { AclPrincipalGroupEditor } from './PrincipalGroupEditor';

import { UserRoleTags } from './UserPermissionAssignments';
import { FeatureLicenseNotification } from '../../license/FeatureLicenseNotification';
import { UserRoleTags } from './UserPermissionAssignments';

// TODO - once AclList is migrated to FC, we could should move this code to use useToast()
const { ToastContainer, toast } = createStandaloneToast({
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/pages/admin/LicenseExpiredPage.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Avatars, Box, Flex, Image, Link, Text, VStack } from '@redpanda-data/ui';
import { observer } from 'mobx-react';
import { PageComponent } from '../Page';
import { api } from '../../../state/backendApi';
import { appGlobal } from '../../../state/appGlobal';
import { api } from '../../../state/backendApi';
import { DISABLE_SSO_DOCS_LINK } from '../../license/licenseUtils';
import { PageComponent } from '../Page';

@observer
export default class LicenseExpiredPage extends PageComponent {
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/pages/overview/Overview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ import { FaCrown } from 'react-icons/fa';
import { MdCheck, MdError, MdOutlineError } from 'react-icons/md';
import { Link as ReactRouterLink } from 'react-router-dom';
import colors from '../../../colors';
import { Statistic } from '../../misc/Statistic';
import ClusterHealthOverview from './ClusterHealthOverview';
import { OverviewLicenseNotification } from '../../license/OverviewLicenseNotification';
import {
getEnterpriseCTALink,
isLicenseWithEnterpriseAccess,
licensesToSimplifiedPreview,
} from '../../license/licenseUtils';
import { Statistic } from '../../misc/Statistic';
import ClusterHealthOverview from './ClusterHealthOverview';

@observer
class Overview extends PageComponent {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import { IsDev } from '../../../utils/env';
import { clone, toJson } from '../../../utils/jsonUtils';
import { DefaultSkeleton } from '../../../utils/tsxUtils';
import { scrollTo, scrollToTop } from '../../../utils/utils';
import { FeatureLicenseNotification } from '../../license/FeatureLicenseNotification';
import { showErrorModal } from '../../misc/ErrorModal';
import PageContent from '../../misc/PageContent';
import Section from '../../misc/Section';
Expand All @@ -67,7 +68,6 @@ import {
partitionSelectionToTopicPartitions,
topicAssignmentsToReassignmentRequest,
} from './logic/utils';
import { FeatureLicenseNotification } from '../../license/FeatureLicenseNotification';

export interface PartitionSelection {
// Which partitions are selected?
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import UserDetailsPage from './pages/acls/UserDetails';
import UserEditPage from './pages/acls/UserEdit';
import AdminPageDebugBundleProgress from './pages/admin/Admin.DebugBundleProgress';
import AdminPage from './pages/admin/AdminPage';
import LicenseExpiredPage from './pages/admin/LicenseExpiredPage';
import UploadLicensePage from './pages/admin/UploadLicensePage';
import KafkaClusterDetails from './pages/connect/Cluster.Details';
import KafkaConnectorDetails from './pages/connect/Connector.Details';
Expand All @@ -69,7 +70,6 @@ import { TopicProducePage } from './pages/topics/Topic.Produce';
import TransformDetails from './pages/transforms/Transform.Details';
import TransformsList from './pages/transforms/Transforms.List';
import { TransformsSetup } from './pages/transforms/Transforms.Setup';
import LicenseExpiredPage from './pages/admin/LicenseExpiredPage';

//
// Route Types
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {
Code,
ConnectError,
type Interceptor as ConnectRpcInterceptor,
type PromiseClient,
type StreamRequest,
type UnaryRequest,
createPromiseClient,
ConnectError,
Code,
} from '@connectrpc/connect';
import { createConnectTransport } from '@connectrpc/connect-web';
import { type Monaco, loader } from '@monaco-editor/react';
Expand Down Expand Up @@ -33,10 +33,10 @@ import { PipelineService } from './protogen/redpanda/api/console/v1alpha1/pipeli
import { SecurityService } from './protogen/redpanda/api/console/v1alpha1/security_connect';
import { TransformService } from './protogen/redpanda/api/console/v1alpha1/transform_connect';
import { SecretService as RPCNSecretService } from './protogen/redpanda/api/dataplane/v1alpha2/secret_connect';
import { appGlobal } from './state/appGlobal';
import { api } from './state/backendApi';
import { uiState } from './state/uiState';
import { AppFeatures, getBasePath } from './utils/env';
import { appGlobal } from './state/appGlobal';

declare const __webpack_public_path__: string;

Expand Down

0 comments on commit a39feb3

Please sign in to comment.