Skip to content

Commit c602b9e

Browse files
authored
refactor(console): remove create tenant modal dev feature guard (#7933)
1 parent 4c09aca commit c602b9e

File tree

2 files changed

+13
-58
lines changed

2 files changed

+13
-58
lines changed

packages/console/src/components/CreateTenantModal/index.tsx

Lines changed: 9 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import Region, {
1616
logtoDropdownItem,
1717
type InstanceDropdownItemProps,
1818
} from '@/components/Region';
19-
import { isDevFeaturesEnabled } from '@/consts/env';
2019
import Button from '@/ds-components/Button';
2120
import DangerousRaw from '@/ds-components/DangerousRaw';
2221
import FormField from '@/ds-components/FormField';
@@ -53,12 +52,11 @@ const getInstanceDropdownItems = (regions: RegionType[]): InstanceDropdownItemPr
5352
return condArray(hasPublicRegions && logtoDropdownItem, ...privateInstances);
5453
};
5554

56-
// eslint-disable-next-line complexity
5755
function CreateTenantModal({ isOpen, onClose }: Props) {
5856
const [tenantData, setTenantData] = useState<CreateTenantData>();
5957
const theme = useTheme();
6058
const cloudApi = useCloudApi();
61-
const { regions, regionsError, getRegionById } = useAvailableRegions();
59+
const { regions, regionsError, getRegionByName } = useAvailableRegions();
6260

6361
const defaultValues = Object.freeze({
6462
tag: TenantTag.Development,
@@ -95,26 +93,16 @@ function CreateTenantModal({ isOpen, onClose }: Props) {
9593
[regions]
9694
);
9795

98-
const isLogtoInstance = instanceId === logtoDropdownItem.name;
96+
const isLogtoInstance = useMemo(() => instanceId === logtoDropdownItem.name, [instanceId]);
9997

100-
const currentRegion = useMemo(() => {
101-
if (isDevFeaturesEnabled) {
102-
return getRegionById(isLogtoInstance ? regionName : instanceId);
103-
}
104-
105-
if (isLogtoInstance) {
106-
return getRegionById(regionName);
107-
}
108-
// For private instances, find the region that matches the instance
109-
return regions?.find((region) => region.name === instanceId);
110-
}, [isLogtoInstance, regionName, instanceId, getRegionById, regions]);
98+
const currentRegion = useMemo(
99+
() => getRegionByName(isLogtoInstance ? regionName : instanceId),
100+
[isLogtoInstance, regionName, instanceId, getRegionByName]
101+
);
111102

112103
const getFinalRegionName = useCallback(
113104
(instanceId: string, regionName: string) => {
114-
if (isDevFeaturesEnabled) {
115-
return isLogtoInstance ? regionName : instanceId;
116-
}
117-
return regionName;
105+
return isLogtoInstance ? regionName : instanceId;
118106
},
119107
[isLogtoInstance]
120108
);
@@ -189,41 +177,8 @@ function CreateTenantModal({ isOpen, onClose }: Props) {
189177
/>
190178
</FormField>
191179

192-
{!isDevFeaturesEnabled && (
193-
<FormField
194-
title="tenants.settings.tenant_region"
195-
tip={t('tenants.settings.tenant_region_description')}
196-
>
197-
{!regions && !regionsError && <Ring />}
198-
{regionsError && <span className={styles.error}>{regionsError.message}</span>}
199-
{regions && !regionsError && (
200-
<Controller
201-
control={control}
202-
name="regionName"
203-
rules={{ required: true }}
204-
render={({ field: { onChange, value, name } }) => (
205-
<RadioGroup type="plain" name={name} value={value} onChange={onChange}>
206-
{regions.map((region) => (
207-
<Radio
208-
key={region.name}
209-
title={
210-
<DangerousRaw>
211-
<Region region={region} />
212-
</DangerousRaw>
213-
}
214-
value={region.name}
215-
isDisabled={isSubmitting}
216-
/>
217-
))}
218-
</RadioGroup>
219-
)}
220-
/>
221-
)}
222-
</FormField>
223-
)}
224-
225180
{/* Only show the instance selector (dropdown) if there are private regions available. */}
226-
{isDevFeaturesEnabled && hasPrivateRegionsAccess && (
181+
{hasPrivateRegionsAccess && (
227182
<FormField
228183
title="tenants.settings.tenant_instance"
229184
tip={t('tenants.settings.tenant_instance_description')}
@@ -248,7 +203,7 @@ function CreateTenantModal({ isOpen, onClose }: Props) {
248203
)}
249204
</FormField>
250205
)}
251-
{isDevFeaturesEnabled && isLogtoInstance && (
206+
{isLogtoInstance && (
252207
<FormField
253208
title="tenants.settings.tenant_region"
254209
tip={t('tenants.settings.tenant_region_description')}

packages/console/src/hooks/use-available-regions.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ const useAvailableRegions = () => {
2020
return regions;
2121
}
2222
);
23-
const getRegionById = useCallback(
24-
(id: string) => regions?.find((region) => region.name === id),
23+
const getRegionByName = useCallback(
24+
(name: string) => regions?.find((region) => region.name === name),
2525
[regions]
2626
);
2727

@@ -30,8 +30,8 @@ const useAvailableRegions = () => {
3030
regions,
3131
/** Error encountered while fetching regions. */
3232
regionsError,
33-
/** Function to get a region by its ID. If the region is not found, returns undefined. */
34-
getRegionById,
33+
/** Function to get a region by its name. If the region is not found, returns undefined. */
34+
getRegionByName,
3535
};
3636
};
3737

0 commit comments

Comments
 (0)