Skip to content

Commit

Permalink
Address Crs
Browse files Browse the repository at this point in the history
  • Loading branch information
kimlisa committed Jan 3, 2025
1 parent 44e63fd commit 0578489
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ export function ManualDeploy(props: {
const showHint = useShowHint(active);

useEffect(() => {
return clearCachedJoinTokenResult([ResourceKind.Database]);
});
return () => clearCachedJoinTokenResult([ResourceKind.Database]);
}, []);

function handleNextStep() {
updateAgentMeta({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,11 @@ export function SingleEnrollment({
}
}, [vpc]);

useEffect(() => {
function onSelectRds(rds: CheckedAwsRdsDatabase) {
// when changing selected db, clear defined labels
setCustomLabels([]);
}, [selectedDb]);
setSelectedDb(rds);
}

function fetchNextPage() {
fetchRdsDatabases({ ...tableData }, vpc);
Expand Down Expand Up @@ -231,7 +232,7 @@ export function SingleEnrollment({
items={tableData?.items || []}
fetchStatus={tableData?.fetchStatus || 'loading'}
selectedDatabase={selectedDb}
onSelectDatabase={setSelectedDb}
onSelectDatabase={onSelectRds}
fetchNextPage={fetchNextPage}
/>
{selectedDb && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import { useCallback, useEffect, useState } from 'react';
import { useCallback, useState } from 'react';
import styled from 'styled-components';

import {
Expand Down Expand Up @@ -142,10 +142,16 @@ export function EnrollEksCluster(props: AgentStepProps) {

const ctx = useTeleport();

useEffect(() => {
function onSelectCluster(eks: CheckedEksCluster) {
// when changing selected cluster, clear defined labels
setCustomLabels([]);
}, [selectedCluster]);
setSelectedCluster(eks);
}

function clearSelectedCluster() {
setSelectedCluster(null);
setCustomLabels([]);
}

function fetchClustersWithNewRegion(region: Regions) {
setSelectedRegion(region);
Expand All @@ -158,7 +164,7 @@ export function EnrollEksCluster(props: AgentStepProps) {
}

function refreshClustersList() {
setSelectedCluster(null);
clearSelectedCluster();
// When refreshing, start the table back at page 1.
fetchClusters({ ...tableData, startKey: '', items: [] });
}
Expand Down Expand Up @@ -224,9 +230,7 @@ export function EnrollEksCluster(props: AgentStepProps) {
if (tableData.items.length > 0) {
setTableData(emptyTableData);
}
if (selectedCluster) {
setSelectedCluster(null);
}
clearSelectedCluster();
setEnrollmentState({ status: 'notStarted' });
}

Expand Down Expand Up @@ -491,7 +495,7 @@ export function EnrollEksCluster(props: AgentStepProps) {
autoDiscovery={isAutoDiscoveryEnabled}
fetchStatus={tableData.fetchStatus}
selectedCluster={selectedCluster}
onSelectCluster={setSelectedCluster}
onSelectCluster={onSelectCluster}
fetchNextPage={fetchNextPage}
/>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export function ManualHelmDialog({
setCommand(setJoinTokenAndGetCommand(joinToken));
}

return clearCachedJoinTokenResult(resourceKinds);
return () => clearCachedJoinTokenResult(resourceKinds);
}, [joinToken, command, setJoinTokenAndGetCommand]);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export default function Container(props: AgentStepProps) {
setClusterName={setClusterName}
labels={labels}
onChangeLabels={setLabels}
generateScript={fallbackProps.retry}
/>
<ActionButtons
onProceed={() => null}
Expand Down Expand Up @@ -188,7 +189,7 @@ export function HelmChart(
});

useEffect(() => {
return clearCachedJoinTokenResult(resourceKinds);
return () => clearCachedJoinTokenResult(resourceKinds);
});

return (
Expand Down Expand Up @@ -283,8 +284,11 @@ const StepTwo = ({
labels: ResourceLabel[];
onChangeLabels(l: ResourceLabel[]): void;
}) => {
function handleSubmit(validator: Validator) {
if (!validator.validate()) {
function handleSubmit(
inputFieldValidator: Validator,
labelsValidator: Validator
) {
if (!inputFieldValidator.validate() || !labelsValidator.validate()) {
return;
}
generateScript();
Expand All @@ -300,7 +304,7 @@ const StepTwo = ({
</Subtitle3>
</header>
<Validation>
{({ validator }) => (
{({ validator: inputFieldValidator }) => (
<>
<Box mb={4}>
<FieldInput
Expand Down Expand Up @@ -331,32 +335,40 @@ const StepTwo = ({
<Subtitle3>Add Labels (Optional)</Subtitle3>
<ResourceLabelTooltip resourceKind="kube" toolTipPosition="top" />
</Flex>
<Box mb={3}>
<LabelsCreater
labels={labels}
setLabels={onChangeLabels}
isLabelOptional={true}
disableBtns={disabled}
noDuplicateKey={true}
/>
</Box>
{disabled ? (
<ButtonSecondary
width="200px"
type="submit"
onClick={() => onEdit()}
>
Edit
</ButtonSecondary>
) : (
<ButtonSecondary
width="200px"
type="submit"
onClick={() => handleSubmit(validator)}
>
Next
</ButtonSecondary>
)}
<Validation>
{({ validator: labelsValidator }) => (
<>
<Box mb={3}>
<LabelsCreater
labels={labels}
setLabels={onChangeLabels}
isLabelOptional={true}
disableBtns={disabled}
noDuplicateKey={true}
/>
</Box>
{disabled ? (
<ButtonSecondary
width="200px"
type="submit"
onClick={() => onEdit()}
>
Edit
</ButtonSecondary>
) : (
<ButtonSecondary
width="200px"
type="submit"
onClick={() =>
handleSubmit(inputFieldValidator, labelsValidator)
}
>
Next
</ButtonSecondary>
)}
</>
)}
</Validation>
</>
)}
</Validation>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export function StepOne({
<H3>Step 1 (Optional)</H3>
<Flex alignItems="center" gap={1} mb={2}>
<Subtitle3>Add Labels</Subtitle3>
<ResourceLabelTooltip resourceKind="server" />
<ResourceLabelTooltip resourceKind="server" toolTipPosition="top" />
</Flex>
</header>
<Validation>
Expand Down

0 comments on commit 0578489

Please sign in to comment.