frontend-plugin-api: no longer require factory for extension overrides
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/frontend-test-utils': patch
|
||||
---
|
||||
|
||||
The extension tester will no longer unconditionally enable any additional extensions that have been added.
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/frontend-plugin-api': patch
|
||||
---
|
||||
|
||||
The `factory` option is no longer required when overriding an extension.
|
||||
@@ -1108,7 +1108,7 @@ export type ExtensionDefinition<
|
||||
string}' is already defined in parent schema`;
|
||||
};
|
||||
};
|
||||
factory(
|
||||
factory?(
|
||||
originalFactory: (context?: {
|
||||
config?: T['config'];
|
||||
inputs?: ResolveInputValueOverrides<NonNullable<T['inputs']>>;
|
||||
|
||||
@@ -705,6 +705,41 @@ describe('createExtension', () => {
|
||||
).toBe('foo-hello-override-world');
|
||||
});
|
||||
|
||||
it('should be able to disable extension with override', () => {
|
||||
const subject = createExtension({
|
||||
name: 'root',
|
||||
attachTo: { id: 'ignored', input: 'ignored' },
|
||||
inputs: {
|
||||
input: createExtensionInput([stringDataRef], {
|
||||
singleton: true,
|
||||
optional: true,
|
||||
}),
|
||||
},
|
||||
output: [stringDataRef.optional()],
|
||||
factory({ inputs }) {
|
||||
return inputs.input ?? [];
|
||||
},
|
||||
});
|
||||
|
||||
const attached = createExtension({
|
||||
attachTo: { id: 'root', input: 'input' },
|
||||
output: [stringDataRef],
|
||||
factory() {
|
||||
return [stringDataRef('test')];
|
||||
},
|
||||
});
|
||||
|
||||
expect(
|
||||
createExtensionTester(subject).add(attached).get(stringDataRef),
|
||||
).toBe('test');
|
||||
|
||||
expect(
|
||||
createExtensionTester(subject)
|
||||
.add(attached.override({ disabled: true }))
|
||||
.get(stringDataRef),
|
||||
).toBe(undefined);
|
||||
});
|
||||
|
||||
it('should be able to override input values', () => {
|
||||
const outputRef = createExtensionDataRef<unknown>().with({
|
||||
id: 'output',
|
||||
|
||||
@@ -191,7 +191,7 @@ export type ExtensionDefinition<
|
||||
string}' is already defined in parent schema`;
|
||||
};
|
||||
};
|
||||
factory(
|
||||
factory?(
|
||||
originalFactory: (context?: {
|
||||
config?: T['config'];
|
||||
inputs?: ResolveInputValueOverrides<NonNullable<T['inputs']>>;
|
||||
|
||||
@@ -213,11 +213,17 @@ export class ExtensionTester<UOutput extends AnyExtensionDataRef> {
|
||||
const [subject, ...rest] = this.#extensions;
|
||||
|
||||
const extensionsConfig: JsonArray = [
|
||||
...rest.map(extension => ({
|
||||
[extension.id]: {
|
||||
config: extension.config,
|
||||
},
|
||||
})),
|
||||
...rest.flatMap(extension =>
|
||||
extension.config
|
||||
? [
|
||||
{
|
||||
[extension.id]: {
|
||||
config: extension.config,
|
||||
},
|
||||
},
|
||||
]
|
||||
: [],
|
||||
),
|
||||
{
|
||||
[subject.id]: {
|
||||
config: subject.config,
|
||||
|
||||
Reference in New Issue
Block a user