From 77dd4d4089794b416dafb1c15d27d8bda5966eb9 Mon Sep 17 00:00:00 2001 From: YanJin Date: Wed, 7 Feb 2024 11:21:36 +0100 Subject: [PATCH] ARTESCA-11299: Fix the typing of selectStorageOptions --- src/react/locations/LocationEditor.tsx | 10 ++++-- .../__tests__/LocationEditor.test.tsx | 6 +--- src/react/utils/storageOptions.ts | 12 +++---- src/types/stats.ts | 31 ++++++++++--------- 4 files changed, 30 insertions(+), 29 deletions(-) diff --git a/src/react/locations/LocationEditor.tsx b/src/react/locations/LocationEditor.tsx index f4e71bd70..fde8596d8 100644 --- a/src/react/locations/LocationEditor.tsx +++ b/src/react/locations/LocationEditor.tsx @@ -74,9 +74,13 @@ function LocationEditor() { convertToForm({ ...newLocationDetails(), ...locationEditing }), ); const selectOptions = useMemo(() => { - if(!locations) return []; - //@ts-expect-error fix this when you are working on it - return selectStorageOptions(capabilities, locations, makeLabel, !editingExisting); + if (!locations) return []; + return selectStorageOptions( + capabilities, + locations, + makeLabel, + !editingExisting, + ); }, [capabilities, editingExisting, locations]); useMemo(() => { if (locationEditing) { diff --git a/src/react/locations/__tests__/LocationEditor.test.tsx b/src/react/locations/__tests__/LocationEditor.test.tsx index 49c4734a7..e5f939060 100644 --- a/src/react/locations/__tests__/LocationEditor.test.tsx +++ b/src/react/locations/__tests__/LocationEditor.test.tsx @@ -17,11 +17,7 @@ import { selectClick, } from '../../utils/testUtil'; import { setupServer } from 'msw/node'; -import { - ENDPOINTS, - USERS, - getConfigOverlay, -} from '../../../js/mock/managementClientMSWHandlers'; +import { getConfigOverlay } from '../../../js/mock/managementClientMSWHandlers'; import { INSTANCE_ID } from '../../actions/__tests__/utils/testUtil'; import userEvent from '@testing-library/user-event'; import { rest } from 'msw'; diff --git a/src/react/utils/storageOptions.ts b/src/react/utils/storageOptions.ts index 46bf4883e..b2da27dda 100644 --- a/src/react/utils/storageOptions.ts +++ b/src/react/utils/storageOptions.ts @@ -1,4 +1,4 @@ -import type { InstanceStateSnapshot } from '../../types/stats'; +import type { Capabilities, InstanceStateSnapshot } from '../../types/stats'; import type { LabelFunction, StorageOptionSelect, @@ -8,7 +8,6 @@ import { JAGUAR_S3_ENDPOINT, JAGUAR_S3_LOCATION_KEY, Location as LegacyLocation, - Locations, ORANGE_S3_ENDPOINT, ORANGE_S3_LOCATION_KEY, OUTSCALE_PUBLIC_S3_ENDPOINT, @@ -20,6 +19,7 @@ import { LocationForm } from '../../types/location'; import { Location } from '../next-architecture/domain/entities/location'; import { LocationInfo } from '../next-architecture/adapters/accounts-locations/ILocationsAdapter'; import { LocationV1 } from '../../js/managementClient/api'; + export function checkSupportsReplicationTarget( locations: LocationInfo[], ): boolean { @@ -104,13 +104,13 @@ export const getLocationTypeShort = ( }; export function selectStorageOptions( - capabilities: Pick, - locations: Location[], + capabilities: Capabilities, + locations: LocationInfo[], labelFn?: LabelFunction, exceptHidden = true, ): Array { - const hdLocation = locations?.find( - (l) => l.type === 'location-scality-hdclient-v2', + const hdLocation = locations.find( + (l) => l.type === LocationV1.LocationTypeEnum.ScalityHdclientV2, ); return Object.keys(storageOptions) .filter((o) => { diff --git a/src/types/stats.ts b/src/types/stats.ts index 80b8368c5..8e9f59c33 100644 --- a/src/types/stats.ts +++ b/src/types/stats.ts @@ -72,22 +72,23 @@ export type MetricsUnit = { 'crr-schedule'?: CrrScheduleUnit; 'ingest-schedule'?: IngestScheduleUnit; }; +export type Capabilities = { + readonly locationTypeCephRadosGW: boolean; + readonly locationTypeDigitalOcean: boolean; + readonly locationTypeHyperdriveV2: boolean; + readonly locationTypeLocal: boolean; + readonly locationTypeNFS: boolean; + readonly locationTypeS3Custom: boolean; + readonly locationTypeSproxyd: boolean; + readonly managedLifecycle: boolean; + readonly managedLifecycleTransition: boolean; + readonly preferredReadLocation: boolean; + readonly s3cIngestLocation: boolean; + readonly secureChannel: boolean; + readonly secureChannelOptimizedPath: boolean; +}; export type InstanceStateSnapshot = { - readonly capabilities: { - readonly locationTypeCephRadosGW: boolean; - readonly locationTypeDigitalOcean: boolean; - readonly locationTypeHyperdriveV2: boolean; - readonly locationTypeLocal: boolean; - readonly locationTypeNFS: boolean; - readonly locationTypeS3Custom: boolean; - readonly locationTypeSproxyd: boolean; - readonly managedLifecycle: boolean; - readonly managedLifecycleTransition: boolean; - readonly preferredReadLocation: boolean; - readonly s3cIngestLocation: boolean; - readonly secureChannel: boolean; - readonly secureChannelOptimizedPath: boolean; - }; + readonly capabilities: Capabilities; readonly latestConfigurationOverlay: ConfigurationOverlay; readonly runningConfigurationVersion: number; readonly lastSeen: string;