|
1 | 1 | import * as React from 'react';
|
2 | 2 | import { useAsync } from 'react-use';
|
3 | 3 |
|
| 4 | +import { Entity, EntityMeta } from '@backstage/catalog-model'; |
4 | 5 | import { useApi } from '@backstage/core-plugin-api';
|
5 | 6 | import {
|
6 | 7 | PreviewCatalogInfoComponent,
|
@@ -161,50 +162,60 @@ export const PreviewPullRequest = ({
|
161 | 162 | }
|
162 | 163 | }
|
163 | 164 | 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 | + |
165 | 175 | setPullRequest({
|
166 | 176 | ...pullRequest,
|
167 | 177 | [repoName]: {
|
168 | 178 | ...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, |
177 | 181 | },
|
178 | 182 | });
|
179 | 183 | }
|
180 | 184 | 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 | + |
182 | 194 | setPullRequest({
|
183 | 195 | ...pullRequest,
|
184 | 196 | [repoName]: {
|
185 | 197 | ...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, |
194 | 200 | },
|
195 | 201 | });
|
196 | 202 | }
|
197 | 203 | 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 | + |
199 | 213 | setPullRequest({
|
200 | 214 | ...pullRequest,
|
201 | 215 | [repoName]: {
|
202 | 216 | ...pullRequest[repoName],
|
203 |
| - prSpec: event.target.value, |
204 |
| - yaml: { |
205 |
| - ...pullRequest[repoName]?.yaml, |
206 |
| - spec: spec, |
207 |
| - }, |
| 217 | + prSpec: specInput, |
| 218 | + yaml: yamlUpdate, |
208 | 219 | },
|
209 | 220 | });
|
210 | 221 | }
|
|
0 commit comments