Skip to content

Commit 3c77cc7

Browse files
shubham-builderShubhamsamijaber
authored
chore[gen-1]: ENG-8050 send modal-name and api-key from sdk (BuilderIO#3877)
## Description Sending "modalName" and "apiKey" from sdk. These data are added to the event "builder.sdkInjected". --------- Co-authored-by: Shubham <[email protected]> Co-authored-by: Sami Jaber <[email protected]>
1 parent 4bc82ec commit 3c77cc7

File tree

5 files changed

+37
-4
lines changed

5 files changed

+37
-4
lines changed

.changeset/giant-flies-punch.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@builder.io/react": patch
3+
---
4+
5+
chore: send `apiKey` to Visual Editor to improve editing experience.

packages/react-tests/react-vite/src/App.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,10 @@ function App() {
8080
Builder.trustedHosts = props.trustedHosts;
8181
}
8282

83-
return props || PAGES[window.location.pathname]?.isGen1VisualEditingTest ? (
84-
<BuilderComponent {...props} />
83+
return PAGES[window.location.pathname]?.isGen1VisualEditingTest ? (
84+
<BuilderComponent model='page' {...props} />
8585
) : (
86+
props ? <BuilderComponent {...props} /> :
8687
<div>Content Not Found</div>
8788
);
8889
}

packages/react/src/components/builder-component.component.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ export class BuilderComponent extends React.Component<
734734

735735
if (Builder.isIframe) {
736736
window.parent?.postMessage(
737-
{ type: 'builder.sdkInjected', data: { modelName: this.name } },
737+
{ type: 'builder.sdkInjected', data: { modelName: this.name, apiKey: this.props.apiKey || builder.apiKey } },
738738
'*'
739739
);
740740
}

packages/sdks-tests/embedder/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ const server = (req, res) => {
3232
switch (event.data.type) {
3333
case 'builder.registerComponent':
3434
return 'Component name: ' + event.data.data.name;
35+
case 'builder.sdkInjected':
36+
return 'modelName: ' + event.data.data.modelName + ' apiKey: ' + event.data.data.apiKey;
3537
default:
3638
return '';
3739
}

packages/sdks-tests/src/e2e-tests/editing.spec.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
} from '../specs/columns.js';
77
import { NEW_TEXT } from '../specs/helpers.js';
88
import { HOMEPAGE } from '../specs/homepage.js';
9-
import { checkIsRN, test } from '../helpers/index.js';
9+
import { checkIsRN, test ,excludeGen2} from '../helpers/index.js';
1010
import {
1111
cloneContent,
1212
launchEmbedderAndWaitForSdk,
@@ -345,4 +345,29 @@ test.describe('Visual Editing', () => {
345345
await page.frameLocator('iframe').getByText('coffee info: Another coffee brand.').waitFor();
346346
});
347347
});
348+
349+
test.describe('SDK', () => {
350+
test('should inject correct SDK data into iframe', async ({ page, basePort, sdk }) => {
351+
test.skip(excludeGen2(sdk));
352+
let consoleMsg = '';
353+
const msgPromise = page.waitForEvent('console', msg => {
354+
if(msg.text().includes('BUILDER_EVENT: builder.sdkInjected')){
355+
consoleMsg = msg.text();
356+
return true;
357+
}
358+
return false;
359+
});
360+
await launchEmbedderAndWaitForSdk({
361+
page,
362+
basePort,
363+
path: '/editing',
364+
sdk,
365+
});
366+
await msgPromise;
367+
368+
expect(consoleMsg).toContain('modelName: page');
369+
expect(consoleMsg).toContain('apiKey: abcd');
370+
});
371+
});
372+
348373
});

0 commit comments

Comments
 (0)