Skip to content
This repository has been archived by the owner on Apr 18, 2024. It is now read-only.

fix: LSDV-5256: Stop automatically scrolling if current Paragraph is not on the screen #1502

Merged
merged 21 commits into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
ee8516a
fix: LSDV-5256: Stop automatically scrolling if current Paragraph is …
juliosgarbi Jul 16, 2023
578b8f8
remove leftover console log
juliosgarbi Jul 16, 2023
bc154b3
start get the padding element and stop using magic numbers
juliosgarbi Jul 17, 2023
6f876ff
remove leftover console log
juliosgarbi Jul 17, 2023
e27acc6
fix audio seek sync with scroll
juliosgarbi Jul 20, 2023
ace2f80
small fixies about scroll position and scroll validation
juliosgarbi Jul 21, 2023
75bb1be
fix regression with auto scroll if Phrase is annotated
juliosgarbi Jul 24, 2023
e458e5a
fix the auto scroll position
juliosgarbi Jul 24, 2023
d5883dc
merge conflcits
juliosgarbi Jul 24, 2023
180e500
remove unecessary comment
juliosgarbi Jul 24, 2023
3c07f88
changing the scroll position to stop breaking the UI
juliosgarbi Jul 24, 2023
3c8e1f2
roll back the changes
juliosgarbi Jul 24, 2023
6dd1832
fix the way that the reading line is rendering to influence the Parag…
juliosgarbi Jul 24, 2023
52103a4
removing the double FF validation
juliosgarbi Jul 24, 2023
c4c042e
trigger the auto scroll when user changes the author filter
juliosgarbi Jul 25, 2023
8ef04aa
change the timeout delay to get automatically from css
juliosgarbi Jul 25, 2023
778d60c
fix the overlap timing
juliosgarbi Jul 25, 2023
16fe11f
fix playingId calc and reuse intersection observer
bmartel Jul 26, 2023
dd30aac
fix tests
juliosgarbi Jul 26, 2023
995ea52
revert observer change
juliosgarbi Jul 27, 2023
d9b4888
fix tests
juliosgarbi Jul 27, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions e2e/tests/sync/audio-paragraphs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,5 +352,56 @@ FFlagMatrix(['fflag_feat_front_lsdv_e_278_contextual_scrolling_short'], function

await assert.equal(scrollPosition.scrollTop, 0);
});

FFlagScenario('Paragraph shouldnt automatically scroll if user manually scroll and the current paragraph is not in the screen', async function({ I, LabelStudio, AtAudioView }) {
LabelStudio.setFeatureFlags({
ff_front_dev_2715_audio_3_280722_short: true,
ff_front_1170_outliner_030222_short: true,
...flags,
});

params.config = configWithScroll;

I.amOnPage('/');

LabelStudio.init(params);

await AtAudioView.waitForAudio();
await AtAudioView.lookForStage();

const [{ currentTime: startingAudioTime }, { currentTime: startingParagraphAudioTime }] = await AtAudioView.getCurrentAudio();

assert.equal(startingAudioTime, startingParagraphAudioTime);
assert.equal(startingParagraphAudioTime, 0);

AtAudioView.clickPlayButton();

I.wait(2);

I.executeScript( () => {
document.querySelector('[data-testid="phrases-wrapper"]').scrollTo(0, 1000);

const wheelEvt = document.createEvent('MouseEvents');

wheelEvt.initEvent('wheel', true, true);

wheelEvt.deltaY = 1200;

document.querySelector('[data-testid="phrases-wrapper"]').dispatchEvent(wheelEvt);
});

I.wait(5);

const scrollPosition = await I.executeScript(function(selector) {
const element = document.querySelector(selector);

return {
scrollTop: element.scrollTop,
scrollLeft: element.scrollLeft,
};
}, '[data-testid="phrases-wrapper"]');

await assert(scrollPosition.scrollTop > 400, 'Scroll position should be greater than 200');
});
}
});
4 changes: 3 additions & 1 deletion src/tags/object/Paragraphs/AuthorFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const renderMultipleSelected = (selected) => {
);
};

export const AuthorFilter = observer(({ item }) => {
export const AuthorFilter = observer(({ item, onChange }) => {
const placeholder = useMemo(() => (<span className={styles.authorFilter__placeholder}>Show all authors</span>), []);
const value = item.filterByAuthor;
const options = useMemo(() => item._value.reduce((all, v) => all.includes(v[item.namekey]) ? all : [...all, v[item.namekey]], []).sort(), [item._value, item.namekey]);
Expand All @@ -33,6 +33,8 @@ export const AuthorFilter = observer(({ item }) => {
} else {
item.setAuthorFilter(next);
}

onChange?.();
}, [item.setAuthorFilter]);

return (
Expand Down
69 changes: 45 additions & 24 deletions src/tags/object/Paragraphs/HtxParagraphs.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class HtxParagraphsView extends Component {
this.isPlaying = false;
this.state = {
canScroll: true,
inViewport: true,
};
}

Expand Down Expand Up @@ -417,42 +418,56 @@ class HtxParagraphsView extends Component {


if (isFF(FF_LSDV_E_278) && this.props.item.contextscroll && item.playingId >= 0 && this.lastPlayingId !== item.playingId && this.state.canScroll) {
const _padding = 8; // 8 is the padding between the phrases, so it will keep aligned with the top of the phrase
const _padding = parseInt(window.getComputedStyle(this.myRef.current)?.getPropertyValue('padding-top')) || 0;
const _playingItem = this.props.item._value[item.playingId];
const _start = _playingItem.start;
const _end = _playingItem.end;
const _phaseHeight = this.activeRef.current?.offsetHeight || 0;
const _duration = this.props.item._value[item.playingId].duration || _end - _start;
const _wrapperHeight = root.offsetHeight;
const _wrapperOffsetTop = this.activeRef.current?.offsetTop - _padding;
const _splittedText = 10; // it will be from 0 to 100% of the text height, going 10% by 10%
const _splittedText = Math.ceil(this.activeRef.current?.offsetHeight / this.myRef.current?.offsetHeight) + 1; // +1 to make sure the last line is scrolled to the top

this._disposeTimeout();

if (_phaseHeight > _wrapperHeight) {
for (let i = 0; i < _splittedText; i++) {
this.scrollTimeout.push(
setTimeout(() => {
const _pos = (_wrapperOffsetTop) + ((_phaseHeight - (_wrapperHeight / 3)) * (i * .1)); // 1/3 of the wrapper height is the offset to keep the text aligned with the middle of the wrapper
const _pos = (_wrapperOffsetTop) + ((_phaseHeight) * (i * (1 / _splittedText)));

root.scrollTo({
top: _pos,
behavior: 'smooth',
});
if (this.state.inViewPort && this.state.canScroll) {
root.scrollTo({
top: _pos,
behavior: 'smooth',
});
}
}, ((_duration / _splittedText) * i) * 1000),
);
}
} else {
root.scrollTo({
top: _wrapperOffsetTop,
behavior: 'smooth',
});
if (this.state.inViewPort) {
root.scrollTo({
top: _wrapperOffsetTop,
behavior: 'smooth',
});
}
}

this.lastPlayingId = item.playingId;
}
}

_handleScrollToPhrase() {
const _padding = parseInt(window.getComputedStyle(this.myRef.current)?.getPropertyValue('padding-top')) || 0;
const _wrapperOffsetTop = this.activeRef.current?.offsetTop - _padding;

this.myRef.current.scrollTo({
top: _wrapperOffsetTop,
behavior: 'smooth',
});
}

_handleScrollContainerHeight() {
const container = this.myRef.current;
const mainContentView = document.querySelector('.lsf-main-content');
Expand All @@ -470,10 +485,6 @@ class HtxParagraphsView extends Component {

}

_handleScrollRoot() {
this._disposeTimeout();
}

_resizeObserver = new ResizeObserver(() => this._handleScrollContainerHeight());

componentDidUpdate() {
Expand All @@ -483,35 +494,45 @@ class HtxParagraphsView extends Component {
componentDidMount() {
if(isFF(FF_LSDV_E_278) && this.props.item.contextscroll) this._resizeObserver.observe(document.querySelector('.lsf-main-content'));
this._handleUpdate();

if(isFF(FF_LSDV_E_278))
this.myRef.current.addEventListener('wheel', this._handleScrollRoot.bind(this));
}

componentWillUnmount() {
const target = document.querySelector('.lsf-main-content');

if(isFF(FF_LSDV_E_278))
this.myRef.current.removeEventListener('wheel', this._handleScrollRoot);

if (target) this._resizeObserver?.unobserve(target);
this._resizeObserver?.disconnect();
}

setIsInViewPort(isInViewPort) {
this.setState({ inViewPort: isInViewPort });
}

renderWrapperHeader() {
const { item } = this.props;

return (
<div className={styles.wrapper_header}>
{isFF(FF_DEV_2669) && (
<AuthorFilter item={item} />
<AuthorFilter item={item} onChange={() => {
if (!this.activeRef.current) return;
const _timeoutDelay = parseFloat(window.getComputedStyle(this.activeRef.current).transitionDuration) * 1000;

setTimeout(() => {
this._handleScrollToPhrase();
}, _timeoutDelay);
}} />
)}
<div className={styles.wrapper_header__buttons}>
<Toggle
data-testid={'auto-scroll-toggle'}
checked={this.state.canScroll}
onChange={() => {
this.setState({ canScroll: !this.state.canScroll });
if (!this.state.canScroll)
this._handleScrollToPhrase();

this.setState({
canScroll: !this.state.canScroll,
});
}}
label={'Auto-scroll'}
/>
Expand Down Expand Up @@ -560,7 +581,7 @@ class HtxParagraphsView extends Component {
className={contextScroll ? styles.scroll_container : styles.container}
onMouseUp={this.onMouseUp.bind(this)}
>
<Phrases item={item} playingId={item.playingId} {...(isFF(FF_LSDV_E_278) ? { activeRef: this.activeRef }: {})} />
<Phrases setIsInViewport={this.setIsInViewPort.bind(this)} item={item} playingId={item.playingId} {...(isFF(FF_LSDV_E_278) ? { activeRef: this.activeRef }: {})} />
</div>
</ObjectTag>
);
Expand Down
13 changes: 13 additions & 0 deletions src/tags/object/Paragraphs/Paragraphs.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -257,4 +257,17 @@ $border-thin: 1px solid rgba(137, 128, 152, 0.16);
color: #898098;
}
}

.wrapperText {
position: relative;

.readingLine {
position: absolute;
bottom: 0;
left: 0;
width: 100%;
height: 20px;
pointer-events: none;
}
}
}
Loading
Loading