From a39feb3f416f2393533da56dc2df5275876d4dd5 Mon Sep 17 00:00:00 2001 From: Beniamin Malinski Date: Fri, 29 Nov 2024 16:08:31 +0000 Subject: [PATCH] frontend: lint/fix tests for license work --- .../license/FeatureLicenseNotification.tsx | 57 ++++++----- .../license/OverviewLicenseNotification.tsx | 97 +++++++++---------- .../components/license/licenseUtils.spec.ts | 19 ++-- .../src/components/license/licenseUtils.tsx | 8 +- .../src/components/pages/acls/Acl.List.tsx | 2 +- .../pages/admin/LicenseExpiredPage.tsx | 4 +- .../components/pages/overview/Overview.tsx | 4 +- .../ReassignPartitions.tsx | 2 +- frontend/src/components/routes.tsx | 2 +- frontend/src/config.ts | 6 +- 10 files changed, 98 insertions(+), 103 deletions(-) diff --git a/frontend/src/components/license/FeatureLicenseNotification.tsx b/frontend/src/components/license/FeatureLicenseNotification.tsx index 23529bc84..ad170e8d2 100644 --- a/frontend/src/components/license/FeatureLicenseNotification.tsx +++ b/frontend/src/components/license/FeatureLicenseNotification.tsx @@ -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', @@ -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: ( @@ -90,23 +87,23 @@ const getLicenseAlertContentForFeature = ( ), status: 'info', }; - } else { - return { - message: ( - - - This is a Redpanda Enterprise feature. Try it with our{' '} - - Redpanda Enterprise Trial - - . - - - ), - status: 'info', - }; } - } else if (msToExpiration > 0 && msToExpiration < 15 * MS_IN_DAY && license.type === License_Type.TRIAL) { + return { + message: ( + + + This is a Redpanda Enterprise feature. Try it with our{' '} + + Redpanda Enterprise Trial + + . + + + ), + status: 'info', + }; + } + if (msToExpiration > 0 && msToExpiration < 15 * MS_IN_DAY && license.type === License_Type.TRIAL) { return { message: ( diff --git a/frontend/src/components/license/OverviewLicenseNotification.tsx b/frontend/src/components/license/OverviewLicenseNotification.tsx index 018280f96..34cbeb321 100644 --- a/frontend/src/components/license/OverviewLicenseNotification.tsx +++ b/frontend/src/components/license/OverviewLicenseNotification.tsx @@ -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, @@ -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: ( @@ -68,27 +69,26 @@ const getLicenseAlertContent = ( ), status: 'warning', }; - } else { - return { - message: ( - - - 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,{' '} - - contact us - - . - - - - - - - ), - status: 'warning', - }; } + return { + message: ( + + + 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,{' '} + + contact us + + . + + + + + + + ), + status: 'warning', + }; } } else { // Kafka @@ -117,27 +117,26 @@ const getLicenseAlertContent = ( ), status: 'warning', }; - } else { - return { - message: ( - - - 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,{' '} - - contact us - - . - - - - - - - ), - status: 'warning', - }; } + return { + message: ( + + + 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,{' '} + + contact us + + . + + + + + + + ), + status: 'warning', + }; } } diff --git a/frontend/src/components/license/licenseUtils.spec.ts b/frontend/src/components/license/licenseUtils.spec.ts index ccf1f7fd3..efef0e816 100644 --- a/frontend/src/components/license/licenseUtils.spec.ts +++ b/frontend/src/components/license/licenseUtils.spec.ts @@ -8,7 +8,6 @@ import { prettyLicenseType, resolveEnterpriseCTALink, } from './licenseUtils'; - import '../../utils/arrayExtensions'; describe('licenseUtils', () => { @@ -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'); }); diff --git a/frontend/src/components/license/licenseUtils.tsx b/frontend/src/components/license/licenseUtils.tsx index 625f04257..649698cd9 100644 --- a/frontend/src/components/license/licenseUtils.tsx +++ b/frontend/src/components/license/licenseUtils.tsx @@ -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, diff --git a/frontend/src/components/pages/acls/Acl.List.tsx b/frontend/src/components/pages/acls/Acl.List.tsx index f63ddd0d2..8bb4c3500 100644 --- a/frontend/src/components/pages/acls/Acl.List.tsx +++ b/frontend/src/components/pages/acls/Acl.List.tsx @@ -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({ diff --git a/frontend/src/components/pages/admin/LicenseExpiredPage.tsx b/frontend/src/components/pages/admin/LicenseExpiredPage.tsx index bcb42b4e9..40a74ca26 100644 --- a/frontend/src/components/pages/admin/LicenseExpiredPage.tsx +++ b/frontend/src/components/pages/admin/LicenseExpiredPage.tsx @@ -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 { diff --git a/frontend/src/components/pages/overview/Overview.tsx b/frontend/src/components/pages/overview/Overview.tsx index bdf5ae4cd..be9a199ee 100644 --- a/frontend/src/components/pages/overview/Overview.tsx +++ b/frontend/src/components/pages/overview/Overview.tsx @@ -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 { diff --git a/frontend/src/components/pages/reassign-partitions/ReassignPartitions.tsx b/frontend/src/components/pages/reassign-partitions/ReassignPartitions.tsx index 7ec719ee6..080a3f5cd 100644 --- a/frontend/src/components/pages/reassign-partitions/ReassignPartitions.tsx +++ b/frontend/src/components/pages/reassign-partitions/ReassignPartitions.tsx @@ -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'; @@ -67,7 +68,6 @@ import { partitionSelectionToTopicPartitions, topicAssignmentsToReassignmentRequest, } from './logic/utils'; -import { FeatureLicenseNotification } from '../../license/FeatureLicenseNotification'; export interface PartitionSelection { // Which partitions are selected? diff --git a/frontend/src/components/routes.tsx b/frontend/src/components/routes.tsx index 1a7e8f94a..2de911ff0 100644 --- a/frontend/src/components/routes.tsx +++ b/frontend/src/components/routes.tsx @@ -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'; @@ -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 diff --git a/frontend/src/config.ts b/frontend/src/config.ts index cdc2513b7..65cb39a75 100644 --- a/frontend/src/config.ts +++ b/frontend/src/config.ts @@ -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'; @@ -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;