Skip to content

Commit

Permalink
Add gen2 flag to access key drawer - filter regions
Browse files Browse the repository at this point in the history
  • Loading branch information
jaalah committed Dec 19, 2024
1 parent f83171e commit a5e523d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import CloseIcon from '@mui/icons-material/Close';
import React from 'react';

import { Flag } from 'src/components/Flag';
import { useIsObjectStorageGen2Enabled } from 'src/features/ObjectStorage/hooks/useIsObjectStorageGen2Enabled';
import { useAllAccountAvailabilitiesQuery } from 'src/queries/account/availability';
import { getRegionCountryGroup } from 'src/utilities/formatRegion';

Expand Down Expand Up @@ -50,12 +51,18 @@ export const RegionMultiSelect = React.memo((props: RegionMultiSelectProps) => {
...rest
} = props;

const { isObjectStorageGen2Enabled } = useIsObjectStorageGen2Enabled();

const {
data: accountAvailability,
isLoading: accountAvailabilityLoading,
} = useAllAccountAvailabilitiesQuery();

const regionOptions = getRegionOptions({ currentCapability, regions });
const regionOptions = getRegionOptions({
currentCapability,
isObjectStorageGen2Enabled,
regions,
});

const selectedRegions = regionOptions.filter((r) =>
selectedIds.includes(r.id)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';

import { RegionMultiSelect } from 'src/components/RegionSelect/RegionMultiSelect';
import { useRegionsQuery } from 'src/queries/regions/regions';
import { useObjectStorageRegions } from 'src/features/ObjectStorage/hooks/useObjectStorageRegions';
import { sortByString } from 'src/utilities/sort-by';

import type { Region } from '@linode/api-v4';
Expand All @@ -22,10 +22,13 @@ const sortRegionOptions = (a: Region, b: Region) => {
export const AccessKeyRegions = (props: Props) => {
const { disabled, error, onChange, required, selectedRegion } = props;

const { data: regions, error: regionsError } = useRegionsQuery();
const {
allRegionsError,
availableStorageRegions,
} = useObjectStorageRegions();

// Error could be: 1. General Regions error, 2. Field error, 3. Nothing
const errorText = error || regionsError?.[0]?.reason;
const errorText = error || allRegionsError?.[0]?.reason;

return (
<RegionMultiSelect
Expand All @@ -38,7 +41,7 @@ export const AccessKeyRegions = (props: Props) => {
isClearable={false}
label="Regions"
onChange={onChange}
regions={regions ?? []}
regions={availableStorageRegions ?? []}
required={required}
selectedIds={selectedRegion}
sortRegionOptions={sortRegionOptions}
Expand Down

0 comments on commit a5e523d

Please sign in to comment.