Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make plots ribbon sticky on scroll #2759

Merged
merged 2 commits into from
Nov 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 13 additions & 1 deletion webview/src/plots/components/ribbon/Ribbon.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import cx from 'classnames'
import { MessageFromWebviewType } from 'dvc/src/webview/contract'
import React, { useEffect, useState } from 'react'
import { useSelector } from 'react-redux'
import { performOrderedUpdate, reorderObjectList } from 'dvc/src/util/array'
import { useInView } from 'react-intersection-observer'
import styles from './styles.module.scss'
import { RibbonBlock } from './RibbonBlock'
import { sendMessage } from '../../../shared/vscode'
Expand All @@ -12,6 +14,12 @@ import { Lines, Refresh } from '../../../shared/components/icons'
const MAX_NB_EXP = 7

export const Ribbon: React.FC = () => {
const [ref, needsShadow] = useInView({
root: document.querySelector('#webview-wrapper'),
rootMargin: '-5px',
threshold: 0.95
})

const revisions = useSelector(
(state: PlotsState) => state.webview.selectedRevisions
)
Expand Down Expand Up @@ -42,7 +50,11 @@ export const Ribbon: React.FC = () => {
}

return (
<ul className={styles.list} data-testid="ribbon">
<ul
ref={ref}
data-testid="ribbon"
className={cx(styles.list, needsShadow && styles.withShadow)}
>
<li className={styles.buttonWrapper}>
<IconButton
onClick={selectRevisions}
Expand Down
10 changes: 10 additions & 0 deletions webview/src/plots/components/ribbon/styles.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,22 @@

.list {
display: flex;
position: sticky;
align-items: center;
gap: 6px;
border-bottom: 1px solid $border-color;
padding: 10px 15px;
margin: 0;
flex-wrap: wrap;
top: 0;
width: 100%;
z-index: 100;
background-color: $bg-color;
transition: box-shadow 0.25s;

&.withShadow {
box-shadow: 0 5px 8px -2px $shadow;
}
}

.buttonWrapper {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const WebviewWrapper = ({

return (
<div
id="webview-wrapper"
className={cx(styles.webviewWrapper, className)}
style={themeVariables}
onContextMenu={e => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.webviewWrapper {
width: 100%;
Copy link
Contributor

Choose a reason for hiding this comment

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

Changing this to min-content would solve the following bug:

Screen.Recording.2022-11-14.at.8.58.31.AM.mov

Copy link
Contributor

Choose a reason for hiding this comment

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

Technically, this bug is in main and not part of this pr. Could be fixed separately :)

Copy link
Contributor

Choose a reason for hiding this comment

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

It is more apparent with a sticky banner though

Copy link
Member Author

Choose a reason for hiding this comment

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

thanks @sroy3, good catch. The fix proposed changes the whole UX in a way that we probably don't want. Instead of the ribbon taking always size of the viewport only and overflowing items, it's now taking the whole space (defined by the most wide plot). I'm not sure this is a good idea. Also, plots size control will move to the edge if we do it this way

I can find a way to fill the space with something, but the whole layout might change after the #2747 and further changes?

Copy link
Contributor

@sroy3 sroy3 Nov 15, 2022

Choose a reason for hiding this comment

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

You are right, it is not as simple as that a change. What I'd do is make the ribbon 100% and create a div inside (ribbon-content or something else) and give it a width of 100vw (might have to calculate padding in there).

But yeah once #2585 is completely done, we shouldn't have horizontal scrollbars for the whole webview.

Copy link
Member Author

Choose a reason for hiding this comment

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

let's skip it for now and get back to it after #2585 is done then

height: 100%;
height: auto;
min-height: 100%;
}