Make id mandatory and title optional

Signed-off-by: Severin Wischmann <severinwischmann@nianticlabs.com>
This commit is contained in:
Severin Wischmann
2024-11-06 16:14:06 +01:00
parent 42022d6778
commit 38682faf86
14 changed files with 232 additions and 39 deletions
+2 -1
View File
@@ -531,7 +531,8 @@ export class ScaffolderClient implements ScaffolderApi_2 {
context?: Record<string, string>;
}): Promise<{
results: {
title: string;
title?: string;
id: string;
}[];
}>;
// (undocumented)
+4 -5
View File
@@ -22,10 +22,6 @@ import {
} from '@backstage/core-plugin-api';
import { ResponseError } from '@backstage/errors';
import { ScmIntegrationRegistry } from '@backstage/integration';
import { Observable } from '@backstage/types';
import qs from 'qs';
import queryString from 'qs';
import ObservableImpl from 'zen-observable';
import {
ListActionsResponse,
LogEvent,
@@ -40,10 +36,13 @@ import {
ScaffolderTask,
TemplateParameterSchema,
} from '@backstage/plugin-scaffolder-react';
import { Observable } from '@backstage/types';
import {
EventSourceMessage,
fetchEventSource,
} from '@microsoft/fetch-event-source';
import { default as qs, default as queryString } from 'qs';
import ObservableImpl from 'zen-observable';
/**
* An API to interact with the scaffolder backend.
@@ -365,7 +364,7 @@ export class ScaffolderClient implements ScaffolderApi {
provider: string;
resource: string;
context?: Record<string, string>;
}): Promise<{ results: { title: string }[] }> {
}): Promise<{ results: { title?: string; id: string }[] }> {
const baseUrl = await this.discoveryApi.getBaseUrl('scaffolder');
const url = `${baseUrl}/v2/autocomplete/${provider}/${resource}`;
@@ -14,15 +14,15 @@
* limitations under the License.
*/
import { useApi } from '@backstage/core-plugin-api';
import { scaffolderApiRef } from '@backstage/plugin-scaffolder-react';
import FormControl from '@material-ui/core/FormControl';
import React, { useCallback, useState } from 'react';
import FormHelperText from '@material-ui/core/FormHelperText';
import TextField from '@material-ui/core/TextField';
import Autocomplete from '@material-ui/lab/Autocomplete';
import React, { useCallback, useState } from 'react';
import useDebounce from 'react-use/esm/useDebounce';
import { useApi } from '@backstage/core-plugin-api';
import { BaseRepoBranchPickerProps } from './types';
import FormHelperText from '@material-ui/core/FormHelperText';
/**
* The underlying component that is rendered in the form for the `BitbucketRepoBranchPicker`
@@ -66,7 +66,7 @@ export const BitbucketRepoBranchPicker = ({
provider: 'bitbucket-cloud',
})
.then(({ results }) => {
setAvailableBranches(results.map(r => r.title));
setAvailableBranches(results.map(r => r.title!));
})
.catch(() => {
setAvailableBranches([]);
@@ -63,8 +63,8 @@ export const GitlabRepoPicker = (
setAvailableGroups(
results.map(r => {
return {
title: r.title,
id: r.id!,
title: r.title!,
id: r.id,
};
}),
);
@@ -96,7 +96,7 @@ export const GitlabRepoPicker = (
provider: 'gitlab',
})
.then(({ results }) => {
onChange({ availableRepos: results.map(r => r.title) });
onChange({ availableRepos: results.map(r => r.title!) });
})
.catch(() => {
onChange({ availableRepos: [] });
@@ -20,6 +20,7 @@ export interface RepoUrlPickerState {
organization?: string;
workspace?: string;
project?: string;
id?: string;
availableRepos?: string[];
}
@@ -53,9 +53,10 @@ describe('utils', () => {
organization: 'organization',
workspace: 'workspace',
project: 'backstage',
id: '1234',
}),
).toBe(
'github.com?owner=owner&repo=backstage&organization=organization&workspace=workspace&project=backstage',
'github.com?owner=owner&repo=backstage&organization=organization&workspace=workspace&project=backstage&id=1234',
);
});
});
@@ -64,7 +65,7 @@ describe('utils', () => {
it('should parse a complete string', () => {
expect(
parseRepoPickerUrl(
'github.com?owner=owner&repo=backstage&organization=organization&workspace=workspace&project=backstage',
'github.com?owner=owner&repo=backstage&organization=organization&workspace=workspace&project=backstage&id=1234',
),
).toEqual({
host: 'github.com',
@@ -73,6 +74,7 @@ describe('utils', () => {
organization: 'organization',
workspace: 'workspace',
project: 'backstage',
id: '1234',
});
});
});
@@ -37,6 +37,9 @@ 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()}`;
}
@@ -50,6 +53,7 @@ export function parseRepoPickerUrl(
let organization = '';
let workspace = '';
let project = '';
let id = '';
try {
if (url) {
@@ -60,9 +64,10 @@ 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 };
return { host, owner, repoName, organization, workspace, project, id };
}