diff --git a/packages/frontend-plugin-api/src/wiring/createExtensionBlueprint.test.tsx b/packages/frontend-plugin-api/src/wiring/createExtensionBlueprint.test.tsx index 79ccce31ff..16786f9757 100644 --- a/packages/frontend-plugin-api/src/wiring/createExtensionBlueprint.test.tsx +++ b/packages/frontend-plugin-api/src/wiring/createExtensionBlueprint.test.tsx @@ -949,4 +949,119 @@ describe('createExtensionBlueprint', () => { ), ).toThrow('Refused to override params and factory at the same time'); }); + + it('should be possible to override extensions resulting from .makeWithOverrides', () => { + const testDataRef1 = createExtensionDataRef().with({ id: 'test1' }); + const testDataRef2 = createExtensionDataRef().with({ id: 'test2' }); + + function getOutputs(ext: ExtensionDefinition) { + const tester = createExtensionTester(ext); + return { + test1: tester.get(testDataRef1), + test2: tester.get(testDataRef2), + }; + } + + const blueprint = createExtensionBlueprint({ + kind: 'test-extension', + attachTo: { id: 'test', input: 'default' }, + output: [testDataRef1, testDataRef2], + *factory(params: { test1: string; test2: string }) { + yield testDataRef1(params.test1); + yield testDataRef2(params.test2); + }, + }); + + const extension = blueprint.makeWithOverrides({ + factory(origFactory) { + return origFactory({ + test1: 'orig-1', + test2: 'orig-2', + }); + }, + }); + + expect(getOutputs(extension)).toEqual({ + test1: 'orig-1', + test2: 'orig-2', + }); + + expect( + getOutputs( + extension.override({ + params: { + test1: 'override-1', + test2: 'override-2', + }, + }), + ), + ).toEqual({ + test1: 'override-1', + test2: 'override-2', + }); + + // Partial override + expect( + getOutputs( + extension.override({ + params: { + test2: 'override-2', + }, + }), + ), + ).toEqual({ + test1: 'orig-1', + test2: 'override-2', + }); + + expect( + getOutputs( + extension.override({ + factory(origFactory) { + return origFactory({ + params: { + test1: 'override-1', + test2: 'override-2', + }, + }); + }, + }), + ), + ).toEqual({ + test1: 'override-1', + test2: 'override-2', + }); + + // Partial override via factory + expect( + getOutputs( + extension.override({ + factory(origFactory) { + return origFactory({ + params: { + test2: 'override-2', + }, + }); + }, + }), + ), + ).toEqual({ + test1: 'orig-1', + test2: 'override-2', + }); + + expect(() => + getOutputs( + extension.override({ + params: { + test1: 'override-1', + test2: 'override-2', + }, + factory(origFactory) { + return origFactory(); + }, + }), + ), + ).toThrow('Refused to override params and factory at the same time'); + }); }); diff --git a/packages/frontend-plugin-api/src/wiring/createExtensionBlueprint.ts b/packages/frontend-plugin-api/src/wiring/createExtensionBlueprint.ts index fb9a4de830..3436464711 100644 --- a/packages/frontend-plugin-api/src/wiring/createExtensionBlueprint.ts +++ b/packages/frontend-plugin-api/src/wiring/createExtensionBlueprint.ts @@ -508,20 +508,25 @@ export function createExtensionBlueprint< }, } : undefined, - factory: ({ node, config, inputs, apis }) => { + factory: ctx => { + const { node, config, inputs, apis } = ctx; return args.factory( (innerParams, innerContext) => { return createExtensionDataContainer( - options.factory(innerParams, { - apis, - node, - config: (innerContext?.config ?? config) as any, - inputs: resolveInputOverrides( - options.inputs, - inputs, - innerContext?.inputs, - ) as any, - }) as Iterable, + options.factory( + // TODO(Rugvip): Same as ctx.params from .make + { ...innerParams, ...(ctx as any).params }, + { + apis, + node, + config: (innerContext?.config ?? config) as any, + inputs: resolveInputOverrides( + options.inputs, + inputs, + innerContext?.inputs, + ) as any, + }, + ) as Iterable, options.output, ); },