SCAL-334772 Extract full-height support into a shared module - #641
SCAL-334772 Extract full-height support into a shared module#641shivam-kumar-ts wants to merge 5 commits into
Conversation
commit: |
There was a problem hiding this comment.
Code Review
This pull request refactors the full-height and lazy-loading logic for AppEmbed and LiveboardEmbed by extracting it into a new, dedicated FullHeightController class. This centralizes height negotiation, query parameter additions, and viewport listeners for lazy loading, improving code modularity and testability. Corresponding tests have been updated, and a new test suite src/full-height.spec.ts has been added. Additionally, the inline iframe center calculation in TsEmbed has been replaced with a helper function calculateElementCenter in utils.ts.
Feedback is provided regarding a style guide violation in src/types.ts, where the non-standard @type tag is used in TSDoc comments.
1fa4c7f to
9c61e12
Compare
f3163cf to
87e4b46
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request refactors the full-height functionality for App and Liveboard embeds by introducing a dedicated FullHeightController class, centralizing the logic for height negotiation, lazy loading, and coordinate tracking. It also introduces a shared FullHeightViewConfig interface to improve type safety and maintainability. The review feedback includes several style guide enforcements regarding American English spelling and documentation tag formatting, as well as a defensive programming suggestion to verify coordinate availability before triggering events.
There was a problem hiding this comment.
Code Review
This pull request refactors the full-height and lazy-loading logic for AppEmbed and LiveboardEmbed by extracting it into a shared FullHeightController class, reducing code duplication. Feedback on the changes focuses on adhering to the repository style guide, specifically: correcting British English spellings ('behaviour', 'honours') to American English, moving imports to the top of the test file, and replacing invalid placeholder tags like <EmbedComponent> with concrete component names in JSDoc code examples to ensure syntactically valid TypeScript.
There was a problem hiding this comment.
Code Review
This pull request refactors the full-height and lazy-loading logic for AppEmbed and LiveboardEmbed by extracting it into a dedicated FullHeightController class, improving modularity and testability. The review feedback points out several style guide violations in src/types.ts regarding the spelling of 'behavior' and the formatting of the @Version tag to use 'ThoughtSpot Cloud'. Additionally, it recommends shallow-copying the viewConfig object in FullHeightController to prevent potential runtime errors when mutating frozen configuration objects.
What
The full-height feature was implemented twice, verbatim — once in
LiveboardEmbedand once inAppEmbed. This PR extracts it into a singleFullHeightControllerinsrc/full-height.ts, backed by a sharedFullHeightViewConfigtype, and deletes ~470 lines of duplication from the embed classes.No change to the public API surface:
fullHeight,minimumHeight,defaultHeight,lazyLoadingForFullHeight,lazyLoadingMarginandenableScrollableContainerLazyLoadingare accepted by exactly the same embeds as before, with the same semantics.Why
Both embeds carried identical copies of
sendFullHeightLazyLoadData,requestVisibleEmbedCoordinatesHandler,updateIFrameHeight,embedIframeCenter,setIframeHeightForNonEmbedLiveboard,registerLazyLoadEventsandunregisterLazyLoadEvents, plus the same three state fields, the same constructor wiring and the same query-param block. TheliveboardRelatedRouteslist was duplicated character-for-character. A third copy of the viewport math lived inTsEmbed.getIframeCenter().Every fix to this feature had to land in two or three places, and the two copies had already drifted (
AppEmbedsilently ignoreddefaultHeight).How
src/full-height.ts(new) —FullHeightControllerowns all full-height state, event handlers, query params and listener lifecycle. It talks to the embed through a 4-methodFullHeightEmbedHostcontract (getIframe/setFrameHeight/on/trigger), so it needs nothing from the embed class hierarchy. Inert unlessfullHeightis enabled.src/types.ts—FullHeightViewConfigholds the six full-height props;LiveboardViewConfigandAppViewConfigextend it and drop their duplicated declarations.src/utils.ts—calculateElementCenter(element)generalises the viewport math that was inlined inTsEmbed.src/embed/{app,liveboard}.ts— reduced to constructing the controller and forwarding four lifecycle calls.src/embed/ts-embed.ts—getIframeCenter()is now a thin delegate tocalculateElementCenter.The
defaultHeightmutation that used to happen as a side effect ofgetEmbedParamsObject()is now aminimumHeightgetter derived from the view config, removing the ordering dependency between param building and height events.src/embed/app.tssrc/embed/liveboard.tssrc/embed/ts-embed.tssrc/full-height.tssrc/types.tssrc/utils.tsBehavior change⚠️
AppEmbednow honoursdefaultHeight. It previously resolvedminimumHeight || 500and ignoreddefaultHeightentirely;LiveboardEmbedresolvedminimumHeight || defaultHeight || 500. The shared getter applies the Liveboard rule to both.This is additive and non-breaking — passing
defaultHeighttoAppEmbedwas a TypeScript excess-property error before, so no typed consumer can regress.minimumHeightstill wins where both are set.