Skip to content

Commit a67454d

Browse files
committed
fix: disable edit for host_ip in dynamic env
1 parent d71d504 commit a67454d

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

src/data/dynamicEnvTypes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export const DYNAMIC_ENV_TYPES = ['Static', 'Host IP'] as const;
1+
export const DYNAMIC_ENV_TYPES = ['static', 'host_ip'] as const;

src/schemas/common.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ export const dynamicEnvEntrySchema = z
126126
if (!data.key) {
127127
return true;
128128
}
129-
// Check if any value is missing when key is present
130-
const hasEmptyValue = data.values.some((pair) => !pair.value);
129+
// Check if any value is missing when key is present (skip host_ip fields)
130+
const hasEmptyValue = data.values.some((pair) => pair.type !== 'host_ip' && !pair.value);
131131
return !hasEmptyValue;
132132
},
133133
{
@@ -139,6 +139,7 @@ export const dynamicEnvEntrySchema = z
139139
.refine(
140140
(data) => {
141141
if (!data.key) return true;
142+
if (data.values[0]?.type === 'host_ip') return true;
142143
return data.values[0]?.value || false;
143144
},
144145
{
@@ -149,6 +150,7 @@ export const dynamicEnvEntrySchema = z
149150
.refine(
150151
(data) => {
151152
if (!data.key) return true;
153+
if (data.values[1]?.type === 'host_ip') return true;
152154
return data.values[1]?.value || false;
153155
},
154156
{
@@ -159,6 +161,7 @@ export const dynamicEnvEntrySchema = z
159161
.refine(
160162
(data) => {
161163
if (!data.key) return true;
164+
if (data.values[2]?.type === 'host_ip') return true;
162165
return data.values[2]?.value || false;
163166
},
164167
{

src/shared/jobs/DynamicEnvSection.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { DYNAMIC_ENV_TYPES } from '@data/dynamicEnvTypes';
22
import { SelectItem } from '@heroui/select';
33
import StyledInput from '@shared/StyledInput';
44
import StyledSelect from '@shared/StyledSelect';
5-
import { Controller, useFieldArray, useFormContext } from 'react-hook-form';
5+
import { Controller, useFieldArray, useFormContext, useWatch } from 'react-hook-form';
66
import { RiAddLine } from 'react-icons/ri';
77
import VariableSectionIndex from './VariableSectionIndex';
88
import VariableSectionRemove from './VariableSectionRemove';
@@ -112,9 +112,17 @@ export default function DynamicEnvSection({ baseName = 'deployment' }: { baseNam
112112
// Check for specific error on this value input
113113
const specificValueError = entryError?.values?.[k]?.value;
114114

115+
// Watch the type value to conditionally disable input
116+
const typeValue = useWatch({
117+
control,
118+
name: `${baseName}.dynamicEnvVars.${index}.values.${k}.type`,
119+
});
120+
121+
const isHostIP = typeValue === 'host_ip';
122+
115123
return (
116124
<StyledInput
117-
placeholder="None"
125+
placeholder={isHostIP ? 'Auto-filled by system' : 'None'}
118126
value={field.value ?? ''}
119127
onChange={async (e) => {
120128
const value = e.target.value;
@@ -127,6 +135,7 @@ export default function DynamicEnvSection({ baseName = 'deployment' }: { baseNam
127135
errorMessage={
128136
fieldState.error?.message || specificValueError?.message
129137
}
138+
isDisabled={isHostIP}
130139
/>
131140
);
132141
}}

0 commit comments

Comments
 (0)