Skip to content

Commit 7009f99

Browse files
anwesha-palit-redhatvikram-raj
authored andcommitted
fix: sync issue while creating pipeline using yaml editor
1 parent c8b4f00 commit 7009f99

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

src/components/pipeline-builder/PipelineBuilderForm.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ const PipelineBuilderForm: React.FC<PipelineBuilderFormProps> = (props) => {
280280
submitLabel={existingPipeline ? t('Save') : t('Create')}
281281
disableSubmit={
282282
editorType === EditorType.YAML
283-
? !dirty
283+
? !dirty || !_.isEmpty(errors) || !!status?.submitError
284284
: !dirty ||
285285
!_.isEmpty(errors) ||
286286
!_.isEmpty(status?.tasks) ||

src/components/pipeline-builder/SyncedEditorField.tsx

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,39 @@ const SyncedEditorField: React.FC<SyncedEditorFieldProps> = ({
140140
}
141141
}, [editorType, field.value, formContext.isDisabled, name, setFieldValue]);
142142

143+
React.useEffect(() => {
144+
// Sync formData when yamlData changes (while in YAML mode)
145+
if (editorType === EditorType.YAML && yamlData) {
146+
const syncFormDataFromYaml = async () => {
147+
try {
148+
const content = safeYAMLToJS(yamlData);
149+
if (!_.isEmpty(content) && formContext.sanitizeTo) {
150+
const sanitizedContent = await formContext.sanitizeTo(content);
151+
if (
152+
typeof sanitizedContent === 'object' &&
153+
!_.isEmpty(sanitizedContent)
154+
) {
155+
// Only update if the content is different
156+
if (!_.isEqual(sanitizedContent, formData)) {
157+
setFieldValue(formContext.name, sanitizedContent);
158+
}
159+
}
160+
}
161+
} catch (e) {
162+
console.warn('Failed to sync form data from YAML', e);
163+
}
164+
};
165+
syncFormDataFromYaml();
166+
}
167+
}, [
168+
yamlData,
169+
editorType,
170+
formContext.sanitizeTo,
171+
formContext.name,
172+
setFieldValue,
173+
formData,
174+
]);
175+
143176
return (
144177
<>
145178
<div

0 commit comments

Comments
 (0)