Skip to content

Commit cbf5080

Browse files
committed
fix: reset hidden fields state on change
1 parent a2b1697 commit cbf5080

File tree

11 files changed

+61
-36
lines changed

11 files changed

+61
-36
lines changed

src/components/create-job/plugins/NativeInputsSection.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,27 @@
11
import ConfigSectionTitle from '@components/job/config/ConfigSectionTitle';
22
import { BOOLEAN_TYPES } from '@data/booleanTypes';
3-
import { PLUGIN_SIGNATURE_TYPES } from '@data/pluginSignatureTypes';
3+
import { CUSTOM_PLUGIN_SIGNATURE, PLUGIN_SIGNATURE_TYPES } from '@data/pluginSignatureTypes';
44
import CustomParametersSection from '@shared/jobs/native/CustomParametersSection';
55
import NativeAppIdentitySection from '@shared/jobs/native/NativeAppIdentitySection';
66
import PortMappingSection from '@shared/PortMappingSection';
77
import { useEffect } from 'react';
88
import { useFormContext } from 'react-hook-form';
99
import AppParametersSection from '../sections/AppParametersSection';
1010

11-
const CUSTOM_SIGNATURE = PLUGIN_SIGNATURE_TYPES[PLUGIN_SIGNATURE_TYPES.length - 1];
12-
1311
export default function NativeInputsSection({ name }: { name: string }) {
14-
const { watch, setValue } = useFormContext();
12+
const { watch, setValue, clearErrors } = useFormContext();
1513

1614
const pluginSignature: (typeof PLUGIN_SIGNATURE_TYPES)[number] = watch(`${name}.pluginSignature`);
1715

18-
const isCustomSignature = pluginSignature === CUSTOM_SIGNATURE;
16+
const isCustomSignature = pluginSignature === CUSTOM_PLUGIN_SIGNATURE;
1917

2018
useEffect(() => {
2119
if (!isCustomSignature) {
2220
setValue(`${name}.enableTunneling`, BOOLEAN_TYPES[1]);
2321
setValue(`${name}.tunnelingToken`, undefined);
22+
clearErrors(`${name}.tunnelingToken`);
2423
}
25-
}, [isCustomSignature, name, setValue]);
24+
}, [isCustomSignature, name, setValue, clearErrors]);
2625

2726
return (
2827
<div className="col gap-4">

src/components/create-job/sections/AppParametersSection.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { BOOLEAN_TYPES } from '@data/booleanTypes';
22
import InputWithLabel from '@shared/InputWithLabel';
3+
import DeeployInfoTag from '@shared/jobs/DeeployInfoTag';
34
import NumberInputWithLabel from '@shared/NumberInputWithLabel';
45
import SelectWithLabel from '@shared/SelectWithLabel';
56
import { useFormContext } from 'react-hook-form';
@@ -21,7 +22,7 @@ export default function AppParametersSection({
2122
disableTunneling?: boolean;
2223
tunnelingDisabledNote?: string;
2324
}) {
24-
const { watch, trigger } = useFormContext();
25+
const { watch, trigger, setValue, clearErrors } = useFormContext();
2526

2627
const enableTunneling: (typeof BOOLEAN_TYPES)[number] = watch(`${baseName}.enableTunneling`);
2728

@@ -36,8 +37,13 @@ export default function AppParametersSection({
3637
label="Enable Tunneling"
3738
options={BOOLEAN_TYPES}
3839
isDisabled={disableTunneling}
39-
onSelect={() => {
40+
onSelect={(value) => {
4041
trigger(`${baseName}.port`);
42+
43+
if (value === BOOLEAN_TYPES[1]) {
44+
setValue(`${baseName}.tunnelingToken`, undefined);
45+
clearErrors(`${baseName}.tunnelingToken`);
46+
}
4147
}}
4248
/>
4349
)}
@@ -52,7 +58,7 @@ export default function AppParametersSection({
5258
</div>
5359

5460
{disableTunneling && tunnelingDisabledNote && (
55-
<p className="text-sm text-default-500">{tunnelingDisabledNote}</p>
61+
<DeeployInfoTag text={tunnelingDisabledNote} />
5662
)}
5763
</div>
5864
)}

src/components/create-job/steps/deployment/ServiceDeployment.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function ServiceDeployment({ isEditingRunningJob }: { isEditingRunningJob?: bool
2828
const { setFormSubmissionDisabled, getProjectName } = useDeploymentContext() as DeploymentContextType;
2929
const { tunnelingSecrets } = useTunnelsContext() as TunnelsContextType;
3030

31-
const { watch, setValue } = useFormContext();
31+
const { watch, setValue, clearErrors } = useFormContext();
3232
const { projectHash } = useParams<{ projectHash?: string }>();
3333

3434
const serviceId: number = watch('serviceId');
@@ -73,6 +73,11 @@ function ServiceDeployment({ isEditingRunningJob }: { isEditingRunningJob?: bool
7373

7474
if (isPublicService) {
7575
setValue('deployment.ports', [], { shouldDirty: true });
76+
} else {
77+
setValue('deployment.tunnelingToken', undefined);
78+
setValue('deployment.tunnelingLabel', undefined);
79+
clearErrors('deployment.tunnelingToken');
80+
clearErrors('deployment.tunnelingLabel');
7681
}
7782
}, [isPublicService, setValue]);
7883

src/components/edit-job/JobEditFormWrapper.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import Plugins from '@components/create-job/steps/Plugins';
66
import Services from '@components/create-job/steps/Services';
77
import Specifications from '@components/create-job/steps/Specifications';
88
import { BOOLEAN_TYPES } from '@data/booleanTypes';
9-
import { PLUGIN_SIGNATURE_TYPES } from '@data/pluginSignatureTypes';
9+
import { CUSTOM_PLUGIN_SIGNATURE, PLUGIN_SIGNATURE_TYPES } from '@data/pluginSignatureTypes';
1010
import { getRunningService } from '@data/containerResources';
1111
import { CR_VISIBILITY_OPTIONS } from '@data/crVisibilityOptions';
1212
import { zodResolver } from '@hookform/resolvers/zod';
@@ -145,7 +145,7 @@ export default function JobEditFormWrapper({
145145
// Signature - if not in the predefined list, select CUSTOM and pre-fill customPluginSignature
146146
pluginSignature: isKnownSignature
147147
? pluginInfo.signature
148-
: PLUGIN_SIGNATURE_TYPES[PLUGIN_SIGNATURE_TYPES.length - 1],
148+
: CUSTOM_PLUGIN_SIGNATURE,
149149
customPluginSignature: isKnownSignature ? undefined : pluginInfo.signature,
150150

151151
// Tunneling

src/data/pluginSignatureTypes.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
// 'CUSTOM' must be the last element in the array
1+
export const CUSTOM_PLUGIN_SIGNATURE = 'CUSTOM' as const;
2+
23
export const PLUGIN_SIGNATURE_TYPES = [
34
'LLM_INFERENCE_API',
45
'STRUCT_DATA_API',
56
'CV_INFERENCE_API',
67
'SD_INFERENCE_API',
7-
'CUSTOM',
8+
CUSTOM_PLUGIN_SIGNATURE,
89
] as const;

src/lib/deeploy-utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
gpuTypes,
66
nativeWorkerTypes,
77
} from '@data/containerResources';
8-
import { PLUGIN_SIGNATURE_TYPES } from '@data/pluginSignatureTypes';
8+
import { CUSTOM_PLUGIN_SIGNATURE, PLUGIN_SIGNATURE_TYPES } from '@data/pluginSignatureTypes';
99
import services, { Service, serviceContainerTypes } from '@data/services';
1010
import { JobConfig } from '@typedefs/deeployApi';
1111
import {
@@ -312,7 +312,7 @@ const formatGenericJobVariables = (plugin: GenericPlugin) => {
312312
};
313313

314314
const formatNativeJobPluginSignature = (plugin: NativePlugin) => {
315-
return plugin.pluginSignature === PLUGIN_SIGNATURE_TYPES[PLUGIN_SIGNATURE_TYPES.length - 1]
315+
return plugin.pluginSignature === CUSTOM_PLUGIN_SIGNATURE
316316
? plugin.customPluginSignature
317317
: plugin.pluginSignature;
318318
};

src/lib/recover-job-from-pipeline.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { getRunningJobResources, getRunningService } from '@data/containerResour
33
import services, { Service } from '@data/services';
44
import { CR_VISIBILITY_OPTIONS } from '@data/crVisibilityOptions';
55
import { PIPELINE_INPUT_TYPES } from '@data/pipelineInputTypes';
6-
import { PLUGIN_SIGNATURE_TYPES } from '@data/pluginSignatureTypes';
6+
import { CUSTOM_PLUGIN_SIGNATURE, PLUGIN_SIGNATURE_TYPES } from '@data/pluginSignatureTypes';
77
import { POLICY_TYPES } from '@data/policyTypes';
88
import {
99
boolToBooleanType,
@@ -462,7 +462,7 @@ const formatNativePlugin = (signature: string, config: JobConfig) => {
462462

463463
return {
464464
basePluginType: BasePluginType.Native,
465-
pluginSignature: knownSignature ?? PLUGIN_SIGNATURE_TYPES[PLUGIN_SIGNATURE_TYPES.length - 1],
465+
pluginSignature: knownSignature ?? CUSTOM_PLUGIN_SIGNATURE,
466466
customPluginSignature: knownSignature ? undefined : signature,
467467
enableTunneling: boolToBooleanType(toBooleanValue(config.TUNNEL_ENGINE_ENABLED, false)),
468468
port: config.PORT ?? '',

src/schemas/steps/deployment.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { BOOLEAN_TYPES } from '@data/booleanTypes';
22
import { CR_VISIBILITY_OPTIONS } from '@data/crVisibilityOptions';
33
import { PIPELINE_INPUT_TYPES } from '@data/pipelineInputTypes';
4-
import { PLUGIN_SIGNATURE_TYPES } from '@data/pluginSignatureTypes';
4+
import { CUSTOM_PLUGIN_SIGNATURE, PLUGIN_SIGNATURE_TYPES } from '@data/pluginSignatureTypes';
55
import { POLICY_TYPES } from '@data/policyTypes';
66
import {
77
dynamicEnvEntrySchema,
@@ -204,7 +204,7 @@ export const applyDeploymentTypeRefinements = (schema) => {
204204
export const applyCustomPluginSignatureRefinements = (schema) => {
205205
return schema.refine(
206206
(data) => {
207-
if (data.pluginSignature === PLUGIN_SIGNATURE_TYPES[PLUGIN_SIGNATURE_TYPES.length - 1]) {
207+
if (data.pluginSignature === CUSTOM_PLUGIN_SIGNATURE) {
208208
return typeof data.customPluginSignature === 'string' && data.customPluginSignature.trim() !== '';
209209
}
210210
return true;

src/shared/jobs/deployment-type/ContainerSection.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { useFormContext } from 'react-hook-form';
44
import InputWithLabel from '../../InputWithLabel';
55

66
export default function ContainerSection({ baseName = 'deployment' }: { baseName?: string }) {
7-
const { watch } = useFormContext();
7+
const { watch, setValue, clearErrors } = useFormContext();
88

99
const crVisibility: 'Public' | 'Private' = watch(`${baseName}.deploymentType.crVisibility`);
1010

@@ -28,6 +28,14 @@ export default function ContainerSection({ baseName = 'deployment' }: { baseName
2828
name={`${baseName}.deploymentType.crVisibility`}
2929
label="Registry Visibility"
3030
options={CR_VISIBILITY_OPTIONS}
31+
onSelect={(value) => {
32+
if (value === 'Public') {
33+
setValue(`${baseName}.deploymentType.crUsername`, '');
34+
setValue(`${baseName}.deploymentType.crPassword`, '');
35+
clearErrors(`${baseName}.deploymentType.crUsername`);
36+
clearErrors(`${baseName}.deploymentType.crPassword`);
37+
}
38+
}}
3139
/>
3240
</div>
3341

src/shared/jobs/deployment-type/DeploymentTypeSectionCard.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@ import ContainerSection from './ContainerSection';
88
import WorkerSection from './WorkerSection';
99

1010
function DeploymentTypeSectionCard({ isEditingRunningJob }: { isEditingRunningJob?: boolean }) {
11-
const { setValue, watch } = useFormContext();
11+
const { setValue, watch, clearErrors } = useFormContext();
1212

1313
const deploymentType: DeploymentType = watch('deployment.deploymentType');
1414
const pluginType: PluginType = deploymentType.pluginType;
1515

1616
const onDeploymentTypeChange = (isGenericPluginTypeSelected: boolean) => {
1717
const selectedPluginType: PluginType = isGenericPluginTypeSelected ? PluginType.Container : PluginType.Worker;
1818

19+
clearErrors('deployment.deploymentType');
20+
1921
if (selectedPluginType === PluginType.Container) {
2022
setValue('deployment.deploymentType', {
2123
pluginType: selectedPluginType,

0 commit comments

Comments
 (0)