adding filters to catalog import

Signed-off-by: Lucas De Souza <lucas.desouza@aa.com>
This commit is contained in:
Justin De Burgo
2022-11-11 11:02:33 -06:00
committed by Lucas De Souza
parent 07629e8109
commit c75d80fdf0
3 changed files with 14 additions and 6 deletions
@@ -46,6 +46,7 @@ export interface ImportStepperProps {
defaults: StepperProvider,
) => StepperProvider;
variant?: InfoCardVariants;
filters?: Array<String>;
}
/**
@@ -58,6 +59,7 @@ export const ImportStepper = (props: ImportStepperProps) => {
initialUrl,
generateStepper = defaultGenerateStepper,
variant,
filters = [],
} = props;
const catalogImportApi = useApi(catalogImportApiRef);
@@ -88,7 +90,8 @@ export const ImportStepper = (props: ImportStepperProps) => {
{render(
states.analyze(
state as Extract<ImportState, { activeState: 'analyze' }>,
{ apis: { catalogImportApi } },
{ apis: { catalogImportApi } },
filters,
),
)}
{render(
@@ -51,6 +51,7 @@ export interface StepperProvider {
analyze: (
s: Extract<ImportState, { activeState: 'analyze' }>,
opts: { apis: StepperApis },
filters?: String[],
) => StepConfiguration;
prepare: (
s: Extract<ImportState, { activeState: 'prepare' }>,
@@ -263,7 +264,7 @@ export function defaultGenerateStepper(
}
export const defaultStepper: StepperProvider = {
analyze: (state, { apis }) => ({
analyze: (state, { apis }, filters=[]) => ({
stepLabel: <StepLabel>Select URL</StepLabel>,
content: (
<StepInitAnalyzeUrl
@@ -271,6 +272,7 @@ export const defaultStepper: StepperProvider = {
analysisUrl={state.analysisUrl}
onAnalysis={state.onAnalysis}
disablePullRequest={!apis.catalogImportApi.preparePullRequest}
filters={filters}
/>
),
}),
@@ -42,6 +42,7 @@ export interface StepInitAnalyzeUrlProps {
disablePullRequest?: boolean;
analysisUrl?: string;
exampleLocationUrl?: string;
filters?: Array<string>,
}
/**
@@ -58,6 +59,7 @@ export const StepInitAnalyzeUrl = (props: StepInitAnalyzeUrlProps) => {
analysisUrl = '',
disablePullRequest = false,
exampleLocationUrl = 'https://github.com/backstage/backstage/blob/master/catalog-info.yaml',
filters = [],
} = props;
const errorApi = useApi(errorApiRef);
@@ -78,6 +80,8 @@ export const StepInitAnalyzeUrl = (props: StepInitAnalyzeUrlProps) => {
const [submitted, setSubmitted] = useState(false);
const [error, setError] = useState<string | undefined>(undefined);
const filteredRegex = new RegExp(`^http[s]?://${filters ? `[${filters.map((filter, i) => i === 0 ? filter : `|${filter}`)}]` : ''}`)
const handleResult = useCallback(
async ({ url }: FormData) => {
setSubmitted(true);
@@ -113,9 +117,8 @@ export const StepInitAnalyzeUrl = (props: StepInitAnalyzeUrlProps) => {
}
default: {
const err = `Received unknown analysis result of type ${
(analysisResult as any).type
}. Please contact the support team.`;
const err = `Received unknown analysis result of type ${(analysisResult as any).type
}. Please contact the support team.`;
setError(err);
setSubmitted(false);
@@ -140,7 +143,7 @@ export const StepInitAnalyzeUrl = (props: StepInitAnalyzeUrlProps) => {
validate: {
httpsValidator: (value: any) =>
(typeof value === 'string' &&
value.match(/^http[s]?:\/\//) !== null) ||
value.match(filteredRegex) !== null) ||
'Must start with http:// or https://.',
},
}),