Merge pull request #8282 from marshmalien/8044-inventory-file-bug

Fix inventory file dropdown placeholder value

Reviewed-by: https://github.com/apps/softwarefactory-project-zuul
This commit is contained in:
softwarefactory-project-zuul[bot]
2020-10-02 20:35:08 +00:00
committed by GitHub
2 changed files with 11 additions and 5 deletions

View File

@@ -47,6 +47,7 @@ const InventorySourceFormFields = ({ source, sourceOptions, i18n }) => {
values, values,
initialValues, initialValues,
resetForm, resetForm,
setFieldTouched,
setFieldValue, setFieldValue,
} = useFormikContext(); } = useFormikContext();
const [sourceField, sourceMeta] = useField({ const [sourceField, sourceMeta] = useField({
@@ -92,6 +93,7 @@ const InventorySourceFormFields = ({ source, sourceOptions, i18n }) => {
}; };
Object.keys(defaults).forEach(label => { Object.keys(defaults).forEach(label => {
setFieldValue(label, defaults[label]); setFieldValue(label, defaults[label]);
setFieldTouched(label, false);
}); });
} }
}; };
@@ -255,7 +257,7 @@ const InventorySourceForm = ({
overwrite: source?.overwrite || false, overwrite: source?.overwrite || false,
overwrite_vars: source?.overwrite_vars || false, overwrite_vars: source?.overwrite_vars || false,
source: source?.source || '', source: source?.source || '',
source_path: source?.source_path === '' ? '/ (project root)' : '', source_path: source?.source_path || '',
source_project: source?.summary_fields?.source_project || null, source_project: source?.summary_fields?.source_project || null,
source_script: source?.summary_fields?.source_script || null, source_script: source?.summary_fields?.source_script || null,
source_vars: source?.source_vars || '---\n', source_vars: source?.source_vars || '---\n',

View File

@@ -21,7 +21,7 @@ import {
} from './SharedFields'; } from './SharedFields';
const SCMSubForm = ({ autoPopulateProject, i18n }) => { const SCMSubForm = ({ autoPopulateProject, i18n }) => {
const { setFieldValue } = useFormikContext(); const { setFieldValue, setFieldTouched } = useFormikContext();
const [credentialField] = useField('credential'); const [credentialField] = useField('credential');
const [projectField, projectMeta, projectHelpers] = useField({ const [projectField, projectMeta, projectHelpers] = useField({
name: 'source_project', name: 'source_project',
@@ -47,16 +47,20 @@ const SCMSubForm = ({ autoPopulateProject, i18n }) => {
useEffect(() => { useEffect(() => {
if (projectMeta.initialValue) { if (projectMeta.initialValue) {
fetchSourcePath(projectMeta.initialValue.id); fetchSourcePath(projectMeta.initialValue.id);
} if (sourcePathField.value === '') {
sourcePathHelpers.setValue('/ (project root)');
}
} // eslint-disable-next-line react-hooks/exhaustive-deps
}, [fetchSourcePath, projectMeta.initialValue]); }, [fetchSourcePath, projectMeta.initialValue]);
const handleProjectUpdate = useCallback( const handleProjectUpdate = useCallback(
value => { value => {
setFieldValue('source_path', '');
setFieldValue('source_project', value); setFieldValue('source_project', value);
setFieldValue('source_path', '');
setFieldTouched('source_path', false);
fetchSourcePath(value.id); fetchSourcePath(value.id);
}, },
[fetchSourcePath, setFieldValue] [fetchSourcePath, setFieldValue, setFieldTouched]
); );
const handleCredentialUpdate = useCallback( const handleCredentialUpdate = useCallback(