Skip to content

Commit

Permalink
ARTESCA-11299: Fix the typing of selectStorageOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
ChengYanJin committed May 14, 2024
1 parent 11b9ffe commit 77dd4d4
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 29 deletions.
10 changes: 7 additions & 3 deletions src/react/locations/LocationEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 1 addition & 5 deletions src/react/locations/__tests__/LocationEditor.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
12 changes: 6 additions & 6 deletions src/react/utils/storageOptions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { InstanceStateSnapshot } from '../../types/stats';
import type { Capabilities, InstanceStateSnapshot } from '../../types/stats';
import type {
LabelFunction,
StorageOptionSelect,
Expand All @@ -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,
Expand All @@ -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 {
Expand Down Expand Up @@ -104,13 +104,13 @@ export const getLocationTypeShort = (
};

export function selectStorageOptions(
capabilities: Pick<InstanceStateSnapshot, 'capabilities'>,
locations: Location[],
capabilities: Capabilities,
locations: LocationInfo[],
labelFn?: LabelFunction,
exceptHidden = true,
): Array<StorageOptionSelect> {
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) => {
Expand Down
31 changes: 16 additions & 15 deletions src/types/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 77dd4d4

Please sign in to comment.