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

refactor: [M3-6901, M3-6914] - Replace Select with Autocomplete in: kubernetes #10673

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": Tech Stories
---

Replace Select with Autocomplete component on Kubernetes Create page ([#10673](https://github.com/linode/manager/pull/10673))
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { pick, remove, update } from 'ramda';
import * as React from 'react';
import { useHistory } from 'react-router-dom';

import { Autocomplete } from 'src/components/Autocomplete/Autocomplete';
import { Box } from 'src/components/Box';
import { DocsLink } from 'src/components/DocsLink/DocsLink';
import { DocumentTitleSegment } from 'src/components/DocumentTitle';
import Select from 'src/components/EnhancedSelect/Select';
import { ErrorState } from 'src/components/ErrorState/ErrorState';
import { LandingHeader } from 'src/components/LandingHeader';
import { Notice } from 'src/components/Notice/Notice';
Expand Down Expand Up @@ -56,7 +56,6 @@ import type {
KubeNodePoolResponse,
} from '@linode/api-v4/lib/kubernetes';
import type { APIError } from '@linode/api-v4/lib/types';
import type { Item } from 'src/components/EnhancedSelect/Select';

export const CreateCluster = () => {
const { classes } = useStyles();
Expand All @@ -65,7 +64,7 @@ export const CreateCluster = () => {
>();
const [nodePools, setNodePools] = React.useState<KubeNodePoolResponse[]>([]);
const [label, setLabel] = React.useState<string | undefined>();
const [version, setVersion] = React.useState<Item<string> | undefined>();
const [version, setVersion] = React.useState<string | undefined>();
const [errors, setErrors] = React.useState<APIError[] | undefined>();
const [submitting, setSubmitting] = React.useState<boolean>(false);
const [hasAgreed, setAgreed] = React.useState<boolean>(false);
Expand Down Expand Up @@ -113,15 +112,14 @@ export const CreateCluster = () => {

React.useEffect(() => {
if (versions.length > 0) {
setVersion(getLatestVersion(versions));
setVersion(getLatestVersion(versions).value);
}
}, [versionData]);

const createCluster = () => {
const { push } = history;
setErrors(undefined);
setSubmitting(true);
const k8s_version = version ? version.value : undefined;

// Only type and count to the API.
const node_pools = nodePools.map(
Expand All @@ -130,7 +128,7 @@ export const CreateCluster = () => {

const payload: CreateKubeClusterPayload = {
control_plane: { high_availability: highAvailability ?? false },
k8s_version,
k8s_version: version,
label,
node_pools,
region: selectedRegionId,
Expand Down Expand Up @@ -244,16 +242,16 @@ export const CreateCluster = () => {
</StyledDocsLinkContainer>
</StyledRegionSelectStack>
<Divider sx={{ marginTop: 4 }} />
<Select
onChange={(selected: Item<string>) => {
setVersion(selected);
<Autocomplete
onChange={(_, selected) => {
setVersion(selected?.value);
}}
disableClearable={!!version}
errorText={errorMap.k8s_version}
isClearable={false}
label="Kubernetes Version"
options={versions}
placeholder={' '}
value={version || null}
value={versions.find((v) => v.value === version) ?? null}
/>
<Divider sx={{ marginTop: 4 }} />
{showHighAvailability ? (
Expand Down
Loading