Skip to content

Commit

Permalink
upcoming: [M3-7423] - Show regions instead of clusterIds in Create Dr…
Browse files Browse the repository at this point in the history
…awer
  • Loading branch information
cpathipa committed Dec 7, 2023
1 parent d6a9890 commit be7305b
Showing 1 changed file with 3 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { Region } from '@linode/api-v4/lib/regions';
import * as React from 'react';

import { RegionSelect } from 'src/components/RegionSelect/RegionSelect';
import { useObjectStorageClusters } from 'src/queries/objectStorage';
import { useRegionsQuery } from 'src/queries/regions';

interface Props {
Expand All @@ -24,23 +22,10 @@ export const ClusterSelect: React.FC<Props> = (props) => {
selectedCluster,
} = props;

const { data: clusters, error: clustersError } = useObjectStorageClusters();
const { data: regions } = useRegionsQuery();

const regionOptions = clusters?.reduce<Region[]>((acc, cluster) => {
const region = regions?.find((r) => r.id === cluster.region);
if (region) {
acc.push({ ...region, id: cluster.id });
}
return acc;
}, []);
const { data: regions, error: regionsError } = useRegionsQuery();

// Error could be: 1. General Clusters error, 2. Field error, 3. Nothing
const errorText = clustersError
? 'Error loading regions'
: error
? error
: undefined;
const errorText = error || regionsError?.[0]?.reason;

return (
<RegionSelect
Expand All @@ -53,7 +38,7 @@ export const ClusterSelect: React.FC<Props> = (props) => {
label="Region"
onBlur={onBlur}
placeholder="Select a Region"
regions={regionOptions ?? []}
regions={regions ?? []}
required={required}
selectedId={selectedCluster}
/>
Expand Down

0 comments on commit be7305b

Please sign in to comment.