Fixed race condition that would occasionally set the dataset path to the first one when editing a job
This commit is contained in:
parent
3f7a3d8d87
commit
89d2090962
|
|
@ -6,7 +6,7 @@ import { defaultJobConfig, defaultDatasetConfig, migrateJobConfig } from './jobC
|
|||
import { jobTypeOptions } from './options';
|
||||
import { JobConfig } from '@/types';
|
||||
import { objectCopy } from '@/utils/basic';
|
||||
import { useNestedState } from '@/utils/hooks';
|
||||
import { useNestedState, setNestedValue } from '@/utils/hooks';
|
||||
import { SelectInput } from '@/components/formInputs';
|
||||
import useSettings from '@/hooks/useSettings';
|
||||
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 }));
|
||||
setDatasetOptions(datasetOptions);
|
||||
const defaultDatasetPath = defaultDatasetConfig.folder_path;
|
||||
|
||||
for (let i = 0; i < jobConfig.config.process[0].datasets.length; i++) {
|
||||
const dataset = jobConfig.config.process[0].datasets[i];
|
||||
if (dataset.folder_path === defaultDatasetPath) {
|
||||
if (datasetOptions.length > 0) {
|
||||
setJobConfig(datasetOptions[0].value, `config.process[0].datasets[${i}].folder_path`);
|
||||
if (datasetOptions.length > 0) {
|
||||
const defaultDatasetPath = defaultDatasetConfig.folder_path;
|
||||
// Use functional updater so we check the *current* state, not a stale closure
|
||||
setJobConfig((prev: JobConfig) => {
|
||||
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]);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue