Changes functionality in line with comment

Based on [this comment](https://github.com/backstage/backstage/issues/28565#issuecomment-2624141216), the path is now the `id`

Signed-off-by: Severin Wischmann <severinwischmann@nianticlabs.com>
This commit is contained in:
Severin Wischmann
2025-01-30 13:36:11 +01:00
parent 5def47e1da
commit d0cd6a0dec
9 changed files with 15 additions and 28 deletions
@@ -79,8 +79,8 @@ describe('handleAutocompleteRequest', () => {
mockClient.Users.showCurrentUser.mockResolvedValue({ id: 3 });
mockClient.Groups.allProjects.mockResolvedValue([
{ name: 'Repo 1', path: 'repo-1', id: 1 },
{ name: 'Repo 2', path: 'repo-2', id: 2 },
{ name: 'Repo 1', path: 'repo-1' },
{ name: 'Repo 2', path: 'repo-2' },
]);
const result = await handleAutocompleteRequest({
@@ -91,8 +91,8 @@ describe('handleAutocompleteRequest', () => {
expect(result).toEqual({
results: [
{ title: 'Repo 1', path: 'repo-1', id: '1' },
{ title: 'Repo 2', path: 'repo-2', id: '2' },
{ title: 'Repo 1', id: 'repo-1' },
{ title: 'Repo 2', id: 'repo-2' },
],
});
});
@@ -104,8 +104,8 @@ describe('handleAutocompleteRequest', () => {
mockClient.Users.showCurrentUser.mockResolvedValue({ id: 1 });
mockClient.Users.allProjects.mockResolvedValue([
{ name: 'repo1', id: 1 },
{ name: 'repo2', id: 2 },
{ name: 'Repo 1', path: 'repo-1' },
{ name: 'Repo 2', path: 'repo-2' },
]);
const result = await handleAutocompleteRequest({
@@ -116,8 +116,8 @@ describe('handleAutocompleteRequest', () => {
expect(result).toEqual({
results: [
{ title: 'repo1', id: '1' },
{ title: 'repo2', id: '2' },
{ title: 'Repo 1', id: 'repo-1' },
{ title: 'Repo 2', id: 'repo-2' },
],
});
});
@@ -32,7 +32,6 @@ export function createHandleAutocompleteRequest(options: {
}): Promise<{
results: {
title?: string;
path?: string;
id: string;
}[];
}> {
@@ -98,8 +97,7 @@ export function createHandleAutocompleteRequest(options: {
return {
results: response.map(project => ({
title: project.name.trim(),
path: project.path,
id: project.id.toString(),
id: project.path,
})),
};
}
-1
View File
@@ -215,7 +215,6 @@ export interface ScaffolderApi {
}): Promise<{
results: {
title?: string;
path?: string;
id: string;
}[];
}>;
+1 -1
View File
@@ -245,5 +245,5 @@ export interface ScaffolderApi {
provider: string;
resource: string;
context?: Record<string, string>;
}): Promise<{ results: { title?: string; path?: string; id: string }[] }>;
}): Promise<{ results: { title?: string; id: string }[] }>;
}
@@ -98,7 +98,7 @@ export const GitlabRepoPicker = (
.then(({ results }) => {
onChange({
availableRepos: results.map(r => {
return { name: r.title!, path: r.path, id: r.id };
return { name: r.title!, id: r.id };
}),
});
})
@@ -244,8 +244,7 @@ export const RepoUrlPicker = (
onChange={repo =>
setState(prevState => ({
...prevState,
repoName: repo.path || repo.name,
id: repo.id || '',
repoName: repo.id || repo.name,
}))
}
rawErrors={rawErrors}
@@ -15,7 +15,6 @@
*/
export interface AvailableRepositories {
name: string;
path?: string;
id?: string;
}
@@ -26,7 +25,6 @@ export interface RepoUrlPickerState {
organization?: string;
workspace?: string;
project?: string;
id?: string;
availableRepos?: AvailableRepositories[];
}
@@ -53,10 +53,9 @@ describe('utils', () => {
organization: 'organization',
workspace: 'workspace',
project: 'backstage',
id: '1234',
}),
).toBe(
'github.com?owner=owner&repo=backstage&organization=organization&workspace=workspace&project=backstage&id=1234',
'github.com?owner=owner&repo=backstage&organization=organization&workspace=workspace&project=backstage',
);
});
});
@@ -65,7 +64,7 @@ describe('utils', () => {
it('should parse a complete string', () => {
expect(
parseRepoPickerUrl(
'github.com?owner=owner&repo=backstage&organization=organization&workspace=workspace&project=backstage&id=1234',
'github.com?owner=owner&repo=backstage&organization=organization&workspace=workspace&project=backstage',
),
).toEqual({
host: 'github.com',
@@ -74,7 +73,6 @@ describe('utils', () => {
organization: 'organization',
workspace: 'workspace',
project: 'backstage',
id: '1234',
});
});
});
@@ -37,9 +37,6 @@ export function serializeRepoPickerUrl(data: RepoUrlPickerState) {
if (data.project) {
params.set('project', data.project);
}
if (data.id) {
params.set('id', data.id);
}
return `${data.host}?${params.toString()}`;
}
@@ -53,7 +50,6 @@ export function parseRepoPickerUrl(
let organization = '';
let workspace = '';
let project = '';
let id = '';
try {
if (url) {
@@ -64,10 +60,9 @@ export function parseRepoPickerUrl(
organization = parsed.searchParams.get('organization') || '';
workspace = parsed.searchParams.get('workspace') || '';
project = parsed.searchParams.get('project') || '';
id = parsed.searchParams.get('id') || '';
}
} catch {
/* ok */
}
return { host, owner, repoName, organization, workspace, project, id };
return { host, owner, repoName, organization, workspace, project };
}