Skip to content

Conversation

@sastaachar
Copy link
Contributor

No description provided.

@sastaachar sastaachar requested a review from a team as a code owner March 11, 2025 15:44
@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 11, 2025

Open in Stackblitz

npm i https://pkg.pr.new/thoughtspot/visual-embed-sdk/@thoughtspot/visual-embed-sdk@152

commit: 949c1d5

const isInitCalledKey = 'isInitCalled';

const createAndSetInitPromise = (): void => {
const initPromise = new Promise<ReturnType<typeof init>>((resolve) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can upgarde ts libs with es2024 to use this but this is quite new .
Screenshot 2025-03-12 at 8 41 30 PM

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its in the baseline so supported in all browsers since 1 year, is there a concern ?

const initPromise = new Promise<ReturnType<typeof init>>((resolve) => {
storeValueInWindow(initPromiseResolveKey, resolve);
});
storeValueInWindow(isInitCalledKey, false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we store a single value in the window ? Store an object with these 3 properties

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

* @returns
*/
public async prerenderGeneric(): Promise<any> {
await this.isReadyForRender;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn;t readyForRender a boolean ?

*/
public async render(): Promise<TsEmbed> {
if (!getIsInitCalled()) {
logger.error(ERROR_MESSAGE.RENDER_CALLED_BEFORE_INIT);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.warn

Copy link
Contributor Author

@sastaachar sastaachar Mar 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cannot use warn here ,
If you have never done init , then loglevel by default is error. So warns will not be shown by logger.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should have loglevel by default to warn ?

Comment on lines 204 to 211
let readyForRenderResolve: (value?: boolean) => void;
let readyForRenderReject: (reason?: any) => void;

this.isReadyForRenderPromise = new Promise<boolean>((resolve, reject) => {
readyForRenderResolve = resolve;
readyForRenderReject = reject;
});

getInitPromise().then(async () => {
this.isReadyForRender = true;
// TODO: handle error
const embedConfig = getEmbedConfig();
this.embedConfig = embedConfig;
if (!embedConfig.authTriggerContainer && !embedConfig.useEventForSAMLPopup) {
this.embedConfig.authTriggerContainer = domSelector;
}
this.thoughtSpotHost = getThoughtSpotHost(embedConfig);
this.thoughtSpotV2Base = getV2BasePath(embedConfig);
this.shouldEncodeUrlQueryParams = embedConfig.shouldEncodeUrlQueryParams;

readyForRenderResolve();
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is far more complex than it needs to be.

this.isReadyForRenderPromise = getInitPromise().then(() => {
  const embedConfig = getEmbedConfig();
  this.embedConfig = embedConfig;
  if (!embedConfig.authTriggerContainer && !embedConfig.useEventForSAMLPopup) {
      this.embedConfig.authTriggerContainer = domSelector;
  }
  this.thoughtSpotHost = getThoughtSpotHost(embedConfig);
  this.thoughtSpotV2Base = getV2BasePath(embedConfig);
  this.shouldEncodeUrlQueryParams = embedConfig.shouldEncodeUrlQueryParams;
});

The isReadyForRender flag is not needed. We should just use the promise throughout

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup forgot to remove isReadyForRender its not used.
yeah this impl is much concise and clean, missed it .
will update

}

return renderInQueue((nextInQueue) => {
return renderInQueue(async (nextInQueue) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the throwInitError method above needed to be changed ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah we can remove that , i dont think that was ever called
cause if init is not done , code always failed in getIframeSrc it never reached here.
getThoughtSpotHost throws erorr while creating new instance itself
is there any other scenario ?

uploadMixpanelEvent(MIXPANEL_EVENT.VISUAL_SDK_RENDER_START);
return getAuthPromise()

return this.isReadyForRenderPromise.then(() => getAuthPromise()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't authPromise enough here ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah true , updated

ref.current = authEE;
}, [config]);

return ref.current;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since you are returning the current this will always be undefined. You have to return the ref

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missed that , updated

@sastaachar sastaachar requested a review from ashubham March 12, 2025 17:30
@sonar-community-ts
Copy link

SonarQube Quality Gate

Quality Gate failed

Failed condition 0.0% 0.0% Coverage on New Code (is less than 80%)
Failed condition 13.9% 13.9% Duplicated Lines (%) on New Code (is greater than 3%)

See analysis details on SonarQube

@sastaachar sastaachar merged commit 73ecab2 into main Mar 13, 2025
5 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants