chore: adaptable -> swappable
Signed-off-by: benjdlambert <ben@blam.sh> Signed-off-by: benjdlambert <ben@blam.sh>
This commit is contained in:
+10
-10
@@ -14,19 +14,19 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { renderInTestApp } from '@backstage/frontend-test-utils';
|
||||
import { createAdaptableComponent } from '../components';
|
||||
import { AdaptableComponentBlueprint } from './AdaptableComponentBlueprint';
|
||||
import { createSwappableComponent } from '../components';
|
||||
import { SwappableComponentBlueprint } from './SwappableComponentBlueprint';
|
||||
import { PageBlueprint } from './PageBlueprint';
|
||||
import { waitFor, screen } from '@testing-library/react';
|
||||
|
||||
describe('AdaptableComponentBlueprint', () => {
|
||||
describe('SwappableComponentBlueprint', () => {
|
||||
it('should allow defining a component override for a component ref', () => {
|
||||
const Component = createAdaptableComponent({
|
||||
const Component = createSwappableComponent({
|
||||
id: 'test.component',
|
||||
loader: () => (props: { hello: string }) => <div>{props.hello}</div>,
|
||||
});
|
||||
|
||||
const extension = AdaptableComponentBlueprint.make({
|
||||
const extension = SwappableComponentBlueprint.make({
|
||||
params: define =>
|
||||
define({
|
||||
component: Component,
|
||||
@@ -43,7 +43,7 @@ describe('AdaptableComponentBlueprint', () => {
|
||||
});
|
||||
|
||||
it('should render default component refs in the app', async () => {
|
||||
const TestComponent = createAdaptableComponent({
|
||||
const TestComponent = createSwappableComponent({
|
||||
id: 'test.component',
|
||||
loader: () => (props: { hello: string }) => <div>{props.hello}</div>,
|
||||
});
|
||||
@@ -66,7 +66,7 @@ describe('AdaptableComponentBlueprint', () => {
|
||||
});
|
||||
|
||||
it('should render a component ref without a default implementation', async () => {
|
||||
const TestComponent = createAdaptableComponent({
|
||||
const TestComponent = createSwappableComponent({
|
||||
id: 'test.component',
|
||||
});
|
||||
|
||||
@@ -89,7 +89,7 @@ describe('AdaptableComponentBlueprint', () => {
|
||||
});
|
||||
|
||||
it('should render a component ref with an async loader implementation', async () => {
|
||||
const TestComponent = createAdaptableComponent({
|
||||
const TestComponent = createSwappableComponent({
|
||||
id: 'test.component',
|
||||
loader: async () => (props: { hello: string }) =>
|
||||
<div>{props.hello}</div>,
|
||||
@@ -113,12 +113,12 @@ describe('AdaptableComponentBlueprint', () => {
|
||||
});
|
||||
|
||||
it('should allow overriding a component ref with the blueprint', async () => {
|
||||
const TestComponent = createAdaptableComponent({
|
||||
const TestComponent = createSwappableComponent({
|
||||
id: 'test.component',
|
||||
loader: () => (props: { hello: string }) => <div>{props.hello}</div>,
|
||||
});
|
||||
|
||||
const extension = AdaptableComponentBlueprint.make({
|
||||
const extension = SwappableComponentBlueprint.make({
|
||||
params: define =>
|
||||
define({
|
||||
component: TestComponent,
|
||||
+2
-2
@@ -28,11 +28,11 @@ export const componentDataRef = createExtensionDataRef<{
|
||||
}>().with({ id: 'core.component.component' });
|
||||
|
||||
/**
|
||||
* Blueprint for creating adaptable components from a componentRef and a loader
|
||||
* Blueprint for creating swappable components from a componentRef and a loader
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export const AdaptableComponentBlueprint = createExtensionBlueprint({
|
||||
export const SwappableComponentBlueprint = createExtensionBlueprint({
|
||||
kind: 'component',
|
||||
attachTo: { id: 'api:app/components', input: 'components' },
|
||||
output: [componentDataRef],
|
||||
@@ -33,4 +33,4 @@ export { RouterBlueprint } from './RouterBlueprint';
|
||||
export { SignInPageBlueprint } from './SignInPageBlueprint';
|
||||
export { ThemeBlueprint } from './ThemeBlueprint';
|
||||
export { TranslationBlueprint } from './TranslationBlueprint';
|
||||
export { AdaptableComponentBlueprint } from './AdaptableComponentBlueprint';
|
||||
export { SwappableComponentBlueprint } from './SwappableComponentBlueprint';
|
||||
|
||||
+4
-4
@@ -19,12 +19,12 @@ import {
|
||||
CoreNotFoundErrorPageProps,
|
||||
CoreProgressProps,
|
||||
} from '../types';
|
||||
import { createAdaptableComponent } from './createAdaptableComponent';
|
||||
import { createSwappableComponent } from './createSwappableComponent';
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export const Progress = createAdaptableComponent<CoreProgressProps>({
|
||||
export const Progress = createSwappableComponent<CoreProgressProps>({
|
||||
id: 'core.components.progress',
|
||||
});
|
||||
|
||||
@@ -32,7 +32,7 @@ export const Progress = createAdaptableComponent<CoreProgressProps>({
|
||||
* @public
|
||||
*/
|
||||
export const NotFoundErrorPage =
|
||||
createAdaptableComponent<CoreNotFoundErrorPageProps>({
|
||||
createSwappableComponent<CoreNotFoundErrorPageProps>({
|
||||
id: 'core.components.notFoundErrorPage',
|
||||
});
|
||||
|
||||
@@ -40,6 +40,6 @@ export const NotFoundErrorPage =
|
||||
* @public
|
||||
*/
|
||||
export const ErrorBoundary =
|
||||
createAdaptableComponent<CoreErrorBoundaryFallbackProps>({
|
||||
createSwappableComponent<CoreErrorBoundaryFallbackProps>({
|
||||
id: 'core.components.errorBoundary',
|
||||
});
|
||||
@@ -29,7 +29,7 @@ import { AppNode } from '../apis';
|
||||
import { Progress } from '@backstage/core-components';
|
||||
import { coreExtensionData } from '../wiring';
|
||||
import { AppNodeProvider } from './AppNodeProvider';
|
||||
import { ErrorBoundary as ErrorBoundaryComponent } from './DefaultAdaptableComponents';
|
||||
import { ErrorBoundary as ErrorBoundaryComponent } from './DefaultSwappableComponents';
|
||||
|
||||
type RouteTrackerProps = PropsWithChildren<{
|
||||
enabled?: boolean;
|
||||
|
||||
+14
-14
@@ -15,11 +15,11 @@
|
||||
*/
|
||||
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { createAdaptableComponent } from './createAdaptableComponent';
|
||||
import { createSwappableComponent } from './createSwappableComponent';
|
||||
|
||||
describe('createAdaptableComponent', () => {
|
||||
describe('createSwappableComponent', () => {
|
||||
it('can be created and read', () => {
|
||||
const { ref } = createAdaptableComponent({ id: 'foo' });
|
||||
const { ref } = createSwappableComponent({ id: 'foo' });
|
||||
expect(ref.id).toBe('foo');
|
||||
expect(String(ref)).toBe('ComponentRef{id=foo}');
|
||||
});
|
||||
@@ -27,7 +27,7 @@ describe('createAdaptableComponent', () => {
|
||||
it('should allow defining a default component implementation', () => {
|
||||
const Test = () => <div>test</div>;
|
||||
|
||||
createAdaptableComponent<{ foo: string }, { bar: string }>({
|
||||
createSwappableComponent<{ foo: string }, { bar: string }>({
|
||||
id: 'foo',
|
||||
loader:
|
||||
() =>
|
||||
@@ -35,7 +35,7 @@ describe('createAdaptableComponent', () => {
|
||||
<Test key={foo} />,
|
||||
});
|
||||
|
||||
createAdaptableComponent<{ foo: string }, { bar: string }>({
|
||||
createSwappableComponent<{ foo: string }, { bar: string }>({
|
||||
id: 'foo',
|
||||
loader:
|
||||
async () =>
|
||||
@@ -43,7 +43,7 @@ describe('createAdaptableComponent', () => {
|
||||
<Test key={foo} />,
|
||||
});
|
||||
|
||||
createAdaptableComponent<{ foo: string }, { bar: string }>({
|
||||
createSwappableComponent<{ foo: string }, { bar: string }>({
|
||||
id: 'foo',
|
||||
});
|
||||
|
||||
@@ -51,12 +51,12 @@ describe('createAdaptableComponent', () => {
|
||||
});
|
||||
|
||||
it('should allow transformings props', () => {
|
||||
createAdaptableComponent<{ foo: string }, { bar: string }>({
|
||||
createSwappableComponent<{ foo: string }, { bar: string }>({
|
||||
id: 'foo',
|
||||
transformProps: props => ({ foo: props.bar }),
|
||||
});
|
||||
|
||||
createAdaptableComponent<{ foo: string }, { bar: string }>({
|
||||
createSwappableComponent<{ foo: string }, { bar: string }>({
|
||||
id: 'foo',
|
||||
// @ts-expect-error - this should be an error as foo is not a string
|
||||
transformProps: props => ({ foo: 1 }),
|
||||
@@ -67,7 +67,7 @@ describe('createAdaptableComponent', () => {
|
||||
|
||||
describe('sync', () => {
|
||||
it('should create a component from a ref for sync component', () => {
|
||||
const Component = createAdaptableComponent({
|
||||
const Component = createSwappableComponent({
|
||||
id: 'random',
|
||||
loader: () => (props: { name: string }) => {
|
||||
return <div data-testid="test">{props.name}</div>;
|
||||
@@ -83,7 +83,7 @@ describe('createAdaptableComponent', () => {
|
||||
});
|
||||
|
||||
it('should render a fallback when theres no default implementation provided', () => {
|
||||
const Component = createAdaptableComponent({
|
||||
const Component = createSwappableComponent({
|
||||
id: 'random',
|
||||
});
|
||||
|
||||
@@ -93,7 +93,7 @@ describe('createAdaptableComponent', () => {
|
||||
});
|
||||
|
||||
it('should map props from external to internal', () => {
|
||||
const Component = createAdaptableComponent({
|
||||
const Component = createSwappableComponent({
|
||||
id: 'random',
|
||||
transformProps: (props: { name: string }) => ({
|
||||
uppercase: props.name.toUpperCase(),
|
||||
@@ -114,7 +114,7 @@ describe('createAdaptableComponent', () => {
|
||||
|
||||
describe('async', () => {
|
||||
it('should create a component from a ref for async component', async () => {
|
||||
const Component = createAdaptableComponent({
|
||||
const Component = createSwappableComponent({
|
||||
id: 'random',
|
||||
loader: async () => (props: { name: string }) => {
|
||||
return <div data-testid="test">{props.name}</div>;
|
||||
@@ -127,7 +127,7 @@ describe('createAdaptableComponent', () => {
|
||||
});
|
||||
|
||||
it('should render a fallback when theres no default implementation provided', async () => {
|
||||
const Component = createAdaptableComponent({
|
||||
const Component = createSwappableComponent({
|
||||
id: 'random',
|
||||
});
|
||||
|
||||
@@ -137,7 +137,7 @@ describe('createAdaptableComponent', () => {
|
||||
});
|
||||
|
||||
it('should map props from external to internal', async () => {
|
||||
const Component = createAdaptableComponent({
|
||||
const Component = createSwappableComponent({
|
||||
id: 'random',
|
||||
transformProps: (props: { name: string }) => ({
|
||||
uppercase: props.name.toUpperCase(),
|
||||
+5
-5
@@ -30,11 +30,11 @@ export type ComponentRef<
|
||||
};
|
||||
|
||||
/**
|
||||
* Options for creating an AdaptableComponent.
|
||||
* Options for creating an SwappableComponent.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export type CreateAdaptableComponentOptions<
|
||||
export type CreateSwappableComponentOptions<
|
||||
TInnerComponentProps extends {},
|
||||
TExternalComponentProps extends {} = TInnerComponentProps,
|
||||
> = {
|
||||
@@ -96,15 +96,15 @@ function makeComponentFromRef<
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a AdaptableComponent that can be used to render the component, optionally overriden by the app.
|
||||
* Creates a SwappableComponent that can be used to render the component, optionally overriden by the app.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export function createAdaptableComponent<
|
||||
export function createSwappableComponent<
|
||||
TInnerComponentProps extends {},
|
||||
TExternalComponentProps extends {} = TInnerComponentProps,
|
||||
>(
|
||||
options: CreateAdaptableComponentOptions<
|
||||
options: CreateSwappableComponentOptions<
|
||||
TInnerComponentProps,
|
||||
TExternalComponentProps
|
||||
>,
|
||||
@@ -19,9 +19,9 @@ export {
|
||||
type ExtensionBoundaryProps,
|
||||
} from './ExtensionBoundary';
|
||||
export {
|
||||
createAdaptableComponent,
|
||||
type CreateAdaptableComponentOptions,
|
||||
createSwappableComponent,
|
||||
type CreateSwappableComponentOptions,
|
||||
type ComponentRef,
|
||||
} from './createAdaptableComponent';
|
||||
} from './createSwappableComponent';
|
||||
export { useAppNode } from './AppNodeProvider';
|
||||
export * from './DefaultAdaptableComponents';
|
||||
export * from './DefaultSwappableComponents';
|
||||
|
||||
Reference in New Issue
Block a user