Skip to content

Commit 0d3bedf

Browse files
committed
Remove empty input fields in yaml preview
Signed-off-by: Yi Cai <[email protected]>
1 parent a208fa5 commit 0d3bedf

File tree

1 file changed

+35
-24
lines changed

1 file changed

+35
-24
lines changed

plugins/bulk-import/src/components/PreviewFile/PreviewPullRequest.tsx

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as React from 'react';
22
import { useAsync } from 'react-use';
33

4+
import { Entity, EntityMeta } from '@backstage/catalog-model';
45
import { useApi } from '@backstage/core-plugin-api';
56
import {
67
PreviewCatalogInfoComponent,
@@ -161,50 +162,60 @@ export const PreviewPullRequest = ({
161162
}
162163
}
163164
if (event.target.name.split('.').find(s => s === 'prAnnotations')) {
164-
const annotations = getYamlKeyValuePairs(event.target.value);
165+
const annotationsInput = event.target.value;
166+
const yamlUpdate = { ...pullRequest[repoName]?.yaml };
167+
168+
if (annotationsInput.length === 0) {
169+
delete yamlUpdate.metadata.annotations;
170+
} else {
171+
yamlUpdate.metadata.annotations =
172+
getYamlKeyValuePairs(annotationsInput);
173+
}
174+
165175
setPullRequest({
166176
...pullRequest,
167177
[repoName]: {
168178
...pullRequest[repoName],
169-
prAnnotations: event.target.value,
170-
yaml: {
171-
...pullRequest[repoName]?.yaml,
172-
metadata: {
173-
...pullRequest[repoName]?.yaml.metadata,
174-
annotations: annotations,
175-
},
176-
},
179+
prAnnotations: annotationsInput,
180+
yaml: yamlUpdate,
177181
},
178182
});
179183
}
180184
if (event.target.name.split('.').find(s => s === 'prLabels')) {
181-
const labels = getYamlKeyValuePairs(event.target.value);
185+
const labelsInput = event.target.value;
186+
const yamlUpdate = { ...pullRequest[repoName]?.yaml };
187+
188+
if (labelsInput.length === 0) {
189+
delete yamlUpdate.metadata.labels;
190+
} else {
191+
yamlUpdate.metadata.labels = getYamlKeyValuePairs(labelsInput);
192+
}
193+
182194
setPullRequest({
183195
...pullRequest,
184196
[repoName]: {
185197
...pullRequest[repoName],
186-
prLabels: event.target.value,
187-
yaml: {
188-
...pullRequest[repoName]?.yaml,
189-
metadata: {
190-
...pullRequest[repoName]?.yaml.metadata,
191-
labels: labels,
192-
},
193-
},
198+
prLabels: labelsInput,
199+
yaml: yamlUpdate,
194200
},
195201
});
196202
}
197203
if (event.target.name.split('.').find(s => s === 'prSpec')) {
198-
const spec = getYamlKeyValuePairs(event.target.value);
204+
const specInput = event.target.value;
205+
const yamlUpdate = { ...pullRequest[repoName]?.yaml };
206+
207+
if (specInput.length === 0) {
208+
delete yamlUpdate.spec;
209+
} else {
210+
yamlUpdate.spec = getYamlKeyValuePairs(specInput);
211+
}
212+
199213
setPullRequest({
200214
...pullRequest,
201215
[repoName]: {
202216
...pullRequest[repoName],
203-
prSpec: event.target.value,
204-
yaml: {
205-
...pullRequest[repoName]?.yaml,
206-
spec: spec,
207-
},
217+
prSpec: specInput,
218+
yaml: yamlUpdate,
208219
},
209220
});
210221
}

0 commit comments

Comments
 (0)