diff --git a/.changeset/dirty-buckets-flow.md b/.changeset/dirty-buckets-flow.md
new file mode 100644
index 0000000000..b76ab5d35c
--- /dev/null
+++ b/.changeset/dirty-buckets-flow.md
@@ -0,0 +1,6 @@
+---
+'@backstage/plugin-catalog-import': patch
+---
+
+This updates the `catalog-import` plugin to omit the default metadata namespace
+field and also use the short form entity reference format for selected group owners.
diff --git a/plugins/catalog-import/src/components/ImportStepper/defaults.tsx b/plugins/catalog-import/src/components/ImportStepper/defaults.tsx
index f2dd1d62f4..5252b0aeae 100644
--- a/plugins/catalog-import/src/components/ImportStepper/defaults.tsx
+++ b/plugins/catalog-import/src/components/ImportStepper/defaults.tsx
@@ -230,7 +230,7 @@ export function defaultGenerateStepper(
errorHelperText="required value"
textFieldProps={{
label: 'Entity Owner',
- placeholder: 'Group:default/my-group',
+ placeholder: 'my-group',
}}
rules={{ required: true }}
required
diff --git a/plugins/catalog-import/src/components/StepPrepareCreatePullRequest/StepPrepareCreatePullRequest.test.tsx b/plugins/catalog-import/src/components/StepPrepareCreatePullRequest/StepPrepareCreatePullRequest.test.tsx
index 0b38fdaf58..606f9ff88e 100644
--- a/plugins/catalog-import/src/components/StepPrepareCreatePullRequest/StepPrepareCreatePullRequest.test.tsx
+++ b/plugins/catalog-import/src/components/StepPrepareCreatePullRequest/StepPrepareCreatePullRequest.test.tsx
@@ -21,7 +21,10 @@ import { act, render, RenderResult } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import React from 'react';
import { AnalyzeResult, catalogImportApiRef } from '../../api';
-import { StepPrepareCreatePullRequest } from './StepPrepareCreatePullRequest';
+import {
+ generateEntities,
+ StepPrepareCreatePullRequest,
+} from './StepPrepareCreatePullRequest';
describe('', () => {
const catalogImportApi: jest.Mocked = {
@@ -60,6 +63,7 @@ describe('', () => {
kind: 'Component',
metadata: {
name: 'my-component',
+ namespace: 'default',
},
spec: {
owner: 'my-owner',
@@ -282,6 +286,46 @@ spec:
renderFormFieldsFn.mock.calls[
renderFormFieldsFn.mock.calls.length - 1
][0],
- ).toMatchObject({ groups: ['Group:my-group'], groupsLoading: false });
+ ).toMatchObject({ groups: ['my-group'], groupsLoading: false });
+ });
+
+ describe('generateEntities', () => {
+ it.each([[undefined], [null]])(
+ 'should not include blank namespace for %s',
+ namespace => {
+ expect(
+ generateEntities(
+ [{ metadata: { namespace: namespace as any } }],
+ 'my-component',
+ 'group-1',
+ ),
+ ).toEqual([
+ expect.objectContaining({
+ metadata: expect.not.objectContaining({
+ namespace: 'default',
+ }),
+ }),
+ ]);
+ },
+ );
+
+ it.each([['default'], ['my-namespace']])(
+ 'should include explicit namespace %s',
+ namespace => {
+ expect(
+ generateEntities(
+ [{ metadata: { namespace } }],
+ 'my-component',
+ 'group-1',
+ ),
+ ).toEqual([
+ expect.objectContaining({
+ metadata: expect.objectContaining({
+ namespace,
+ }),
+ }),
+ ]);
+ },
+ );
});
});
diff --git a/plugins/catalog-import/src/components/StepPrepareCreatePullRequest/StepPrepareCreatePullRequest.tsx b/plugins/catalog-import/src/components/StepPrepareCreatePullRequest/StepPrepareCreatePullRequest.tsx
index d9e7b962ab..333df76026 100644
--- a/plugins/catalog-import/src/components/StepPrepareCreatePullRequest/StepPrepareCreatePullRequest.tsx
+++ b/plugins/catalog-import/src/components/StepPrepareCreatePullRequest/StepPrepareCreatePullRequest.tsx
@@ -14,9 +14,12 @@
* limitations under the License.
*/
-import { Entity, serializeEntityRef } from '@backstage/catalog-model';
+import { Entity } from '@backstage/catalog-model';
import { useApi } from '@backstage/core';
-import { catalogApiRef } from '@backstage/plugin-catalog-react';
+import {
+ catalogApiRef,
+ formatEntityRefTitle,
+} from '@backstage/plugin-catalog-react';
import { Box, FormHelperText, Grid, Typography } from '@material-ui/core';
import { makeStyles } from '@material-ui/core/styles';
import React, { useCallback, useState } from 'react';
@@ -66,7 +69,7 @@ type Props = {
) => React.ReactNode;
};
-function generateEntities(
+export function generateEntities(
entities: PartialEntity[],
componentName: string,
owner: string,
@@ -78,7 +81,6 @@ function generateEntities(
metadata: {
...e.metadata,
name: componentName,
- namespace: e.metadata?.namespace ?? 'default',
},
spec: {
...e.spec,
@@ -107,8 +109,9 @@ export const StepPrepareCreatePullRequest = ({
filter: { kind: 'group' },
});
- // TODO: defaultKind (=group), defaultNamespace (=same as entity)
- return groupEntities.items.map(e => serializeEntityRef(e) as string).sort();
+ return groupEntities.items
+ .map(e => formatEntityRefTitle(e, { defaultKind: 'group' }))
+ .sort();
});
const handleResult = useCallback(