Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upcoming: [M3-7220, M3-7355] - Add DC Get Well logic to various user flows pt2 and cleanup #9945

Merged
merged 17 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/manager": Upcoming Features
---

Add DC Get Well logic to various user flows pt2 and cleanup logic ([#9945](https://github.com/linode/manager/pull/9945))
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const Default: StoryObj<RegionSelectProps> = {

const meta: Meta<RegionSelectProps> = {
args: {
currentCapability: undefined,
disabled: false,
errorText: '',
helperText: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ import type {
} from './RegionSelect.types';
import type { ListItemComponentsPropsOverrides } from '@mui/material/ListItem';

/**
* A specific select for regions.
*
* The RegionSelect automatically filters regions based on capability using its `currentCapability` prop. For example, if
* `currentCapability="VPCs"`, only regions that support VPCs will appear in the RegionSelect dropdown. There is no need to
* prefilter regions when passing them to the RegionSelect. See the description of `currentCapability` prop for more information.
*/
export const RegionSelect = React.memo((props: RegionSelectProps) => {
const {
currentCapability,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,14 @@ export interface RegionSelectProps
EnhancedAutocompleteProps<RegionSelectOption, false>,
'label' | 'onChange' | 'options'
> {
// TODO DC_GET_WELL
// Make this prop required & remove the undefined union type once all consumers are updated
currentCapability?: Capabilities | undefined;
/**
* The specified capability to filter the regions on. Any region that does not have the `currentCapability` will not appear in the RegionSelect dropdown.
* Only use `undefined` for situations where there is no relevant capability for the RegionSelect - this will not filter any of the regions passed in.
* Otherwise, a capability should always be passed in.
*
* See `ImageUpload.tsx` for an example of a RegionSelect with an undefined `currentCapability` - there is no capability associated with Images yet.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"there is no capability associated with Images yet" -- is this something API is planning on adding?

Copy link
Contributor Author

@coliu-akamai coliu-akamai Dec 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not completely sure to be honest. Images is currently out of scope, but we'll make a backlog ticket to ask API about this soon

Edit: M3-7525

*/
currentCapability: Capabilities | undefined;
handleSelection: (id: string) => void;
helperText?: string;
isClearable?: boolean;
Expand All @@ -36,8 +41,6 @@ export interface RegionSelectProps

export interface RegionOptionAvailability {
accountAvailabilityData: AccountAvailability[] | undefined;
// TODO DC_GET_WELL
// remove the undefined union type once all consumers are updated
currentCapability: Capabilities | undefined;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { Capabilities } from '@linode/api-v4';
import React from 'react';

import { regionFactory } from 'src/factories';
import { renderWithTheme } from 'src/utilities/testHelpers';

import { SelectRegionPanel } from './SelectRegionPanel';

const pricingMocks = vi.hoisted(() => ({
Expand Down Expand Up @@ -37,6 +40,7 @@ describe('SelectRegionPanel in Create Flow', () => {

const { findByText } = renderWithTheme(
<SelectRegionPanel
currentCapability={'Linodes'}
handleSelection={vi.fn()}
regions={regions}
selectedId="id-cgk"
Expand Down Expand Up @@ -65,6 +69,7 @@ describe('SelectRegionPanel on the Clone Flow', () => {

const regions = [...regionFactory.buildList(3)];
const mockedProps = {
currentCapability: 'Linodes' as Capabilities,
handleSelection: () => vi.fn(),
regions,
selectedLinodeTypeId: 'g6-standard-2',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { DynamicPriceNotice } from '../DynamicPriceNotice';
import { Link } from '../Link';

interface SelectRegionPanelProps {
currentCapability?: Capabilities | undefined;
currentCapability: Capabilities;
disabled?: boolean;
error?: string;
handleSelection: (id: string) => void;
Expand Down
1 change: 1 addition & 0 deletions packages/manager/src/features/Images/ImageUpload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ export const ImageUpload: React.FC<Props> = (props) => {
helperText="For fastest initial upload, select the region that is geographically
closest to you. Once uploaded you will be able to deploy the image
to other regions."
currentCapability={undefined}
disabled={!canCreateImage}
errorText={errorMap.region}
handleSelection={setRegion}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,7 @@
import { Theme } from '@mui/material/styles';
import { makeStyles } from '@mui/styles';
import { makeStyles } from 'tss-react/mui';

export const useStyles = makeStyles((theme: Theme) => ({
inputWidth: {
'& .react-select__menu': {
maxWidth: 440,
},
maxWidth: 440,
},
regionSubtitle: {
'& .MuiInput-root': {
maxWidth: 440,
},
'& .react-select__menu': {
maxWidth: 440,
},
'& p': {
lineHeight: '1.43rem',
margin: 0,
maxWidth: '100%',
},
},
export const useStyles = makeStyles()((theme: Theme) => ({
root: {
'& .mlMain': {
flexBasis: '100%',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ import { HAControlPlane } from './HAControlPlane';
import { NodePoolPanel } from './NodePoolPanel';

export const CreateCluster = () => {
const classes = useStyles();
const { classes } = useStyles();
const [selectedRegionID, setSelectedRegionID] = React.useState<string>('');
const [nodePools, setNodePools] = React.useState<KubeNodePoolResponse[]>([]);
const [label, setLabel] = React.useState<string | undefined>();
Expand Down Expand Up @@ -82,15 +82,6 @@ export const CreateCluster = () => {
mutateAsync: createKubernetesCluster,
} = useCreateKubernetesClusterMutation();

// Only include regions that have LKE capability
const filteredRegions = React.useMemo(() => {
return regionsData
? regionsData.filter((thisRegion) =>
thisRegion.capabilities.includes('Kubernetes')
)
: [];
}, [regionsData]);

const {
data: versionData,
isError: versionLoadError,
Expand All @@ -101,12 +92,6 @@ export const CreateCluster = () => {
value: thisVersion.id,
}));

React.useEffect(() => {
if (filteredRegions.length === 1 && !selectedRegionID) {
setSelectedRegionID(filteredRegions[0].id);
}
}, [filteredRegions, selectedRegionID]);
Comment on lines -104 to -108
Copy link
Contributor Author

@coliu-akamai coliu-akamai Nov 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deleted this logic to preselect a region if there's only one region with kubernetes capability: we've moved the region filtering logic inside the RegionSelect (filteredRegions is no longer declared). We can't preselect a region anymore because we can no longer assume that all regions in regionsData have Kubernetes as a capability, even if regionsData.length === 1.


React.useEffect(() => {
if (versions.length > 0) {
setVersion(getLatestVersion(versions));
Expand Down Expand Up @@ -224,7 +209,6 @@ export const CreateCluster = () => {
onChange={(e: React.ChangeEvent<HTMLInputElement>) =>
updateLabel(e.target.value)
}
className={classes.inputWidth}
data-qa-label-input
errorText={errorMap.label}
label="Cluster Label"
Expand All @@ -239,9 +223,9 @@ export const CreateCluster = () => {
helperText: <RegionHelperText mb={2} />,
helperTextPosition: 'top',
}}
className={classes.regionSubtitle}
currentCapability="Kubernetes"
errorText={errorMap.region}
regions={filteredRegions}
regions={regionsData}
selectedId={selectedId}
/>
{showPricingNotice && (
Expand All @@ -252,7 +236,6 @@ export const CreateCluster = () => {
onChange={(selected: Item<string>) => {
setVersion(selected);
}}
className={classes.inputWidth}
errorText={errorMap.k8s_version}
isClearable={false}
label="Kubernetes Version"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const VPCCreateDrawer = (props: Props) => {
isLoadingCreateVPC,
onChangeField,
onCreateVPC,
regionsWithVPCCapability,
regionsData,
setGeneralAPIError,
setGeneralSubnetErrorsFromAPI,
userCannotAddVPC,
Expand Down Expand Up @@ -59,7 +59,7 @@ export const VPCCreateDrawer = (props: Props) => {
errors={errors}
isDrawer
onChangeField={onChangeField}
regions={regionsWithVPCCapability}
regions={regionsData}
values={values}
/>
</Box>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const VPCTopSectionContent = (props: Props) => {
</StyledBodyTypography>
<RegionSelect
aria-label="Choose a region"
currentCapability="VPCs"
disabled={isDrawer ? true : disabled}
errorText={errors.region}
handleSelection={(region: string) => onChangeField('region', region)}
Expand Down
4 changes: 2 additions & 2 deletions packages/manager/src/features/VPCs/VPCCreate/VPCCreate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const VPCCreate = () => {
isLoadingCreateVPC,
onChangeField,
onCreateVPC,
regionsWithVPCCapability,
regionsData,
userCannotAddVPC,
} = useCreateVPC({ pushToVPCPage: true });

Expand Down Expand Up @@ -57,7 +57,7 @@ const VPCCreate = () => {
disabled={userCannotAddVPC}
errors={errors}
onChangeField={onChangeField}
regions={regionsWithVPCCapability}
regions={regionsData}
values={values}
/>
</Paper>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import * as React from 'react';

import { ActionsPanel } from 'src/components/ActionsPanel/ActionsPanel';
import { Drawer } from 'src/components/Drawer';
import { RegionSelect } from 'src/components/RegionSelect/RegionSelect';
import { Notice } from 'src/components/Notice/Notice';
import { RegionSelect } from 'src/components/RegionSelect/RegionSelect';
import { TextField } from 'src/components/TextField';
import { useGrants, useProfile } from 'src/queries/profile';
import { useRegionsQuery } from 'src/queries/regions';
Expand Down Expand Up @@ -113,6 +113,7 @@ export const VPCEditDrawer = (props: Props) => {
/>
{regionsData && (
<RegionSelect
currentCapability="VPCs"
disabled // the Region field will not be editable during beta
errorText={(regionsError && regionsError[0].reason) || undefined}
handleSelection={() => null}
Expand Down
5 changes: 2 additions & 3 deletions packages/manager/src/hooks/useCreateVPC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ export const useCreateVPC = (inputs: UseCreateVPCInputs) => {
const userCannotAddVPC = profile?.restricted && !grants?.global.add_vpcs;

const { data: regions } = useRegionsQuery();
const regionsWithVPCCapability =
regions?.filter((region) => region.capabilities.includes('VPCs')) ?? [];
const regionsData = regions ?? [];

const [
generalSubnetErrorsFromAPI,
Expand Down Expand Up @@ -218,7 +217,7 @@ export const useCreateVPC = (inputs: UseCreateVPCInputs) => {
isLoadingCreateVPC,
onChangeField,
onCreateVPC,
regionsWithVPCCapability,
regionsData,
setGeneralAPIError,
setGeneralSubnetErrorsFromAPI,
userCannotAddVPC,
Expand Down