Skip to content

Commit f2808ef

Browse files
authored
fix: [M3-9469] - Reset selected region when switching between Core and Distributed tabs (linode#12767)
## Description 📝 The Disk Encryption section maintains state from previously selected regions when users switch between Core and Distributed region tabs, showing inconsistent copy, tooltips, and checkbox states until a new region is selected from the current tab. This is because Disk Encryption state is tied to selected region rather than active region tab. When the tab changes without region selection, the component doesn't reset. > [!NOTE] > I tried adding unit tests for this but could not figure out why the tests were failing but the UI is working as expected. Joe is also stumped. ## Changes 🔄 - Clear the region when the region tab changes
1 parent cfd40d8 commit f2808ef

File tree

3 files changed

+26
-12
lines changed

3 files changed

+26
-12
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@linode/manager": Fixed
3+
---
4+
5+
Reset selected region when switching between Core and Distributed tabs ([#12767](https://github.com/linode/manager/pull/12767))

packages/manager/src/features/Linodes/LinodeCreate/Region.tsx

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,9 @@ export const Region = React.memo(() => {
8282
const showTwoStepRegion =
8383
isGeckoLAEnabled && isDistributedRegionSupported(createType ?? 'OS');
8484

85-
const onChange = async (region: RegionType) => {
85+
const onChange = async (region: null | RegionType) => {
8686
const values = getValues();
87-
88-
field.onChange(region.id);
87+
field.onChange(region?.id);
8988

9089
if (values.hasSignedEUAgreement) {
9190
// Reset the EU agreement checkbox if they checked it so they have to re-agree when they change regions
@@ -114,14 +113,14 @@ export const Region = React.memo(() => {
114113

115114
if (
116115
values.metadata?.user_data &&
117-
!region.capabilities.includes('Metadata')
116+
!region?.capabilities.includes('Metadata')
118117
) {
119118
// Clear metadata only if the new region does not support it
120119
setValue('metadata.user_data', null);
121120
}
122121

123122
// Handle maintenance policy based on region capabilities
124-
if (region.capabilities.includes('Maintenance Policy')) {
123+
if (region?.capabilities.includes('Maintenance Policy')) {
125124
// If the region supports maintenance policy, set it to the default value
126125
// or keep the current value if it's already set
127126
if (!values.maintenance_policy) {
@@ -140,28 +139,28 @@ export const Region = React.memo(() => {
140139
// Because distributed regions do not support some features,
141140
// we must disable those features here. Keep in mind, we should
142141
// prevent the user from enabling these features in their respective components.
143-
if (region.site_type === 'distributed') {
142+
if (region?.site_type === 'distributed') {
144143
setValue('backups_enabled', false);
145144
setValue('private_ip', false);
146145
}
147146

148147
if (isDiskEncryptionFeatureEnabled) {
149-
if (region.site_type === 'distributed') {
148+
if (region?.site_type === 'distributed') {
150149
// If a distributed region is selected, make sure we don't send disk_encryption in the payload.
151150
setValue('disk_encryption', undefined);
152151
} else {
153152
// Enable disk encryption by default if the region supports it
154153
const defaultDiskEncryptionValue =
155-
region.capabilities.includes('Disk Encryption') ||
156-
region.capabilities.includes('LA Disk Encryption')
154+
region?.capabilities.includes('Disk Encryption') ||
155+
region?.capabilities.includes('LA Disk Encryption')
157156
? 'enabled'
158157
: undefined;
159158

160159
setValue('disk_encryption', defaultDiskEncryptionValue);
161160
}
162161
}
163162

164-
if (!isLabelFieldDirty) {
163+
if (!isLabelFieldDirty && region) {
165164
// Auto-generate the Linode label because the region is included in the generated label
166165
const label = await getGeneratedLinodeLabel({
167166
queryClient,

packages/manager/src/features/Linodes/LinodeCreate/TwoStepRegion.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,16 @@ const GEOGRAPHICAL_AREA_OPTIONS: GeographicalAreaOption[] = [
6161
];
6262

6363
interface Props {
64-
onChange: (region: RegionType) => void;
64+
onChange: (region: null | RegionType) => void;
6565
}
6666

6767
type CombinedProps = Props & Omit<Partial<RegionSelectProps>, 'onChange'>;
6868

6969
export const TwoStepRegion = (props: CombinedProps) => {
7070
const { disabled, disabledRegions, errorText, onChange, value } = props;
7171

72+
const [tabIndex, setTabIndex] = React.useState(0);
73+
7274
const [regionFilter, setRegionFilter] =
7375
React.useState<RegionFilterValue>('distributed-ALL');
7476

@@ -97,7 +99,15 @@ export const TwoStepRegion = (props: CombinedProps) => {
9799
}
98100
/>
99101
</Box>
100-
<Tabs>
102+
<Tabs
103+
onChange={(index) => {
104+
if (index !== tabIndex) {
105+
setTabIndex(index);
106+
// M3-9469: Reset region selection when switching between site types
107+
onChange(null);
108+
}
109+
}}
110+
>
101111
<TabList>
102112
<Tab>Core</Tab>
103113
<Tab>Distributed</Tab>

0 commit comments

Comments
 (0)