Fixed race condition that would occasionally set the dataset path to the first one when editing a job
This commit is contained in:
@@ -6,7 +6,7 @@ import { defaultJobConfig, defaultDatasetConfig, migrateJobConfig } from './jobC
|
|||||||
import { jobTypeOptions } from './options';
|
import { jobTypeOptions } from './options';
|
||||||
import { JobConfig } from '@/types';
|
import { JobConfig } from '@/types';
|
||||||
import { objectCopy } from '@/utils/basic';
|
import { objectCopy } from '@/utils/basic';
|
||||||
import { useNestedState } from '@/utils/hooks';
|
import { useNestedState, setNestedValue } from '@/utils/hooks';
|
||||||
import { SelectInput } from '@/components/formInputs';
|
import { SelectInput } from '@/components/formInputs';
|
||||||
import useSettings from '@/hooks/useSettings';
|
import useSettings from '@/hooks/useSettings';
|
||||||
import useGPUInfo from '@/hooks/useGPUInfo';
|
import useGPUInfo from '@/hooks/useGPUInfo';
|
||||||
@@ -87,15 +87,19 @@ export default function TrainingForm() {
|
|||||||
|
|
||||||
const datasetOptions = datasets.map(name => ({ value: path.join(settings.DATASETS_FOLDER, name), label: name }));
|
const datasetOptions = datasets.map(name => ({ value: path.join(settings.DATASETS_FOLDER, name), label: name }));
|
||||||
setDatasetOptions(datasetOptions);
|
setDatasetOptions(datasetOptions);
|
||||||
const defaultDatasetPath = defaultDatasetConfig.folder_path;
|
|
||||||
|
|
||||||
for (let i = 0; i < jobConfig.config.process[0].datasets.length; i++) {
|
if (datasetOptions.length > 0) {
|
||||||
const dataset = jobConfig.config.process[0].datasets[i];
|
const defaultDatasetPath = defaultDatasetConfig.folder_path;
|
||||||
if (dataset.folder_path === defaultDatasetPath) {
|
// Use functional updater so we check the *current* state, not a stale closure
|
||||||
if (datasetOptions.length > 0) {
|
setJobConfig((prev: JobConfig) => {
|
||||||
setJobConfig(datasetOptions[0].value, `config.process[0].datasets[${i}].folder_path`);
|
let updated = prev;
|
||||||
|
for (let i = 0; i < prev.config.process[0].datasets.length; i++) {
|
||||||
|
if (prev.config.process[0].datasets[i].folder_path === defaultDatasetPath) {
|
||||||
|
updated = setNestedValue(updated, datasetOptions[0].value, `config.process[0].datasets[${i}].folder_path`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
return updated;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}, [datasets, settings, isSettingsLoaded, datasetFetchStatus]);
|
}, [datasets, settings, isSettingsLoaded, datasetFetchStatus]);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user