Skip to content

Commit 1596adc

Browse files
committed
fix(FR-1783): fix session launcher resource form initialization on page refresh
- Add null check in InputNumberWithSlider to prevent undefined value causing incorrect setValue(0) calls during page refresh - Add optional chaining for shmem field in ResourceAllocationFormItems to handle undefined resource values - Fix form error detection in SessionLauncherPreview to explicitly check resource field keys for proper error status display
1 parent 7026414 commit 1596adc

File tree

3 files changed

+14
-20
lines changed

3 files changed

+14
-20
lines changed

react/src/components/InputNumberWithSlider.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const InputNumberWithSlider: React.FC<InputNumberWithSliderProps> = ({
4242
const [value, setValue] = useControllableState_deprecated(otherProps);
4343
const inputRef = React.useRef<GetRef<typeof InputNumber>>(null);
4444
useEffect(() => {
45-
if (!allowNegative) {
45+
if (!allowNegative && !_.isNil(value)) {
4646
// when step is 1, make sure the value is integer
4747
if (step === 1 && value % 1 !== 0) {
4848
setValue(_.max([Math.round(value), min]));

react/src/components/SessionFormItems/ResourceAllocationFormItems.tsx

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -450,19 +450,10 @@ const ResourceAllocationFormItems: React.FC<
450450
currentAllocationPreset === 'auto-select' &&
451451
!_.isUndefined(resourceSlotsInRG)
452452
) {
453-
if (
454-
_.includes(
455-
['custom', 'minimum-required'],
456-
form.getFieldValue('allocationPreset'),
457-
)
458-
) {
453+
if (_.includes(['custom', 'minimum-required'], currentAllocationPreset)) {
459454
// if the current preset is custom or minimum-required, do nothing.
460455
} else {
461-
if (
462-
allocatablePresetNames.includes(
463-
form.getFieldValue('allocationPreset'),
464-
)
465-
) {
456+
if (allocatablePresetNames.includes(currentAllocationPreset)) {
466457
// if the current preset is available in the current resource group, do nothing.
467458
} else if (enableResourcePresets && allocatablePresetNames[0]) {
468459
const autoSelectedPreset = _.sortBy(allocatablePresetNames)[0];
@@ -704,7 +695,7 @@ const ResourceAllocationFormItems: React.FC<
704695
<Form.Item
705696
noStyle
706697
shouldUpdate={(prev, next) =>
707-
prev.resource.shmem !== next.resource.shmem
698+
prev.resource?.shmem !== next.resource?.shmem
708699
}
709700
hidden={!baiClient._config.allowCustomResourceAllocation}
710701
>
@@ -854,7 +845,7 @@ const ResourceAllocationFormItems: React.FC<
854845
}}
855846
</Form.Item>
856847
<SharedMemoryFormItems
857-
min={resourceLimits.shmem?.min}
848+
min={resourceLimits?.shmem?.min}
858849
onChangeResourceShmem={() => {
859850
if (baiClient._config.allowCustomResourceAllocation) {
860851
form.setFieldValue('allocationPreset', 'custom');
@@ -1543,6 +1534,7 @@ export const getAllocatablePresetNames = (
15431534
);
15441535
}
15451536
}).map((preset) => preset.name);
1537+
15461538
return currentImageAcceleratorLimits.length === 0
15471539
? bySliderLimit
15481540
: _.intersection(bySliderLimit, byImageAcceleratorLimits);

react/src/components/SessionLauncherPreview.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -402,12 +402,14 @@ const SessionLauncherPreview: React.FC<{
402402
title={t('session.launcher.ResourceAllocation')}
403403
showDivider
404404
status={
405-
_.some(form.getFieldValue('resource'), (_v, key) => {
406-
return (
407-
// @ts-ignore
408-
form.getFieldError(['resource', key]).length > 0
409-
);
410-
}) ||
405+
// When retrieving a key using getFieldValue, there are cases where the field key cannot be obtained
406+
// if the corresponding field value does not exist, so it must be explicitly declared.
407+
_.some(
408+
['cpu', 'mem', 'shmem', 'accelerator', 'acceleratorType'] as const,
409+
(key) => {
410+
return form.getFieldError(['resource', key]).length > 0;
411+
},
412+
) ||
411413
form.getFieldError(['num_of_sessions']).length > 0 ||
412414
form.getFieldError('resourceGroup').length > 0
413415
? 'error'

0 commit comments

Comments
 (0)