chore: making the changes backwards compatible with default extensions being rendered when nothing supplied, and updating changeset to reflect This
Signed-off-by: blam <ben@blam.sh>
This commit is contained in:
@@ -25,20 +25,23 @@ import {
|
||||
FieldExtensionOptions,
|
||||
FIELD_EXTENSION_WRAPPER_KEY,
|
||||
FIELD_EXTENSION_KEY,
|
||||
DEFAULT_SCAFFOLDER_FIELD_EXTENSIONS,
|
||||
} from '../extensions';
|
||||
import { collectComponentData, collectChildren } from '../extensions/helpers';
|
||||
|
||||
export const Router = () => {
|
||||
const outlet = useOutlet();
|
||||
|
||||
const fieldExtensions = useMemo(
|
||||
() =>
|
||||
collectComponentData<FieldExtensionOptions>(
|
||||
collectChildren(outlet, FIELD_EXTENSION_WRAPPER_KEY).flat(),
|
||||
FIELD_EXTENSION_KEY,
|
||||
),
|
||||
[outlet],
|
||||
);
|
||||
const fieldExtensions = useMemo(() => {
|
||||
const registeredExtensions = collectComponentData<FieldExtensionOptions>(
|
||||
collectChildren(outlet, FIELD_EXTENSION_WRAPPER_KEY).flat(),
|
||||
FIELD_EXTENSION_KEY,
|
||||
);
|
||||
|
||||
return registeredExtensions.length
|
||||
? registeredExtensions
|
||||
: DEFAULT_SCAFFOLDER_FIELD_EXTENSIONS;
|
||||
}, [outlet]);
|
||||
|
||||
return (
|
||||
<Routes>
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright 2021 Spotify AB
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { OwnerPicker } from '../components/fields/OwnerPicker';
|
||||
import {
|
||||
RepoUrlPicker,
|
||||
repoPickerValidation,
|
||||
} from '../components/fields/RepoUrlPicker';
|
||||
import { FieldExtensionOptions } from './types';
|
||||
|
||||
export const DEFAULT_SCAFFOLDER_FIELD_EXTENSIONS: FieldExtensionOptions[] = [
|
||||
{
|
||||
component: RepoUrlPicker,
|
||||
name: 'RepoUrlPicker',
|
||||
validation: repoPickerValidation,
|
||||
},
|
||||
{
|
||||
component: OwnerPicker,
|
||||
name: 'OwnerPicker',
|
||||
},
|
||||
];
|
||||
@@ -15,14 +15,8 @@
|
||||
*/
|
||||
|
||||
import { Extension, attachComponentData } from '@backstage/core';
|
||||
import { FieldValidation, FieldProps } from '@rjsf/core';
|
||||
import React from 'react';
|
||||
|
||||
export type FieldExtensionOptions<T = any> = {
|
||||
name: string;
|
||||
component: (props: FieldProps<T>) => JSX.Element | null;
|
||||
validation?: (data: T, field: FieldValidation) => void;
|
||||
};
|
||||
import { FieldExtensionOptions } from './types';
|
||||
|
||||
export const FIELD_EXTENSION_WRAPPER_KEY = 'scaffolder.extensions.wrapper.v1';
|
||||
export const FIELD_EXTENSION_KEY = 'scaffolder.extensions.field.v1';
|
||||
@@ -51,3 +45,7 @@ attachComponentData(
|
||||
FIELD_EXTENSION_WRAPPER_KEY,
|
||||
true,
|
||||
);
|
||||
|
||||
export type { FieldExtensionOptions };
|
||||
|
||||
export { DEFAULT_SCAFFOLDER_FIELD_EXTENSIONS } from './default';
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright 2021 Spotify AB
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { FieldValidation, FieldProps } from '@rjsf/core';
|
||||
|
||||
export type FieldExtensionOptions<T = any> = {
|
||||
name: string;
|
||||
component: (props: FieldProps<T>) => JSX.Element | null;
|
||||
validation?: (data: T, field: FieldValidation) => void;
|
||||
};
|
||||
Reference in New Issue
Block a user