Skip to content

Visual Diff UI v1 #494

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

Merged
merged 4 commits into from
Jan 23, 2025
Merged

Visual Diff UI v1 #494

merged 4 commits into from
Jan 23, 2025

Conversation

ericholscher
Copy link
Member

@ericholscher ericholscher commented Jan 14, 2025

This adds a v1 Visual Diff UI.
It does the following:

  • Adds a UI element to track Docdiff state, and exposes filetreediff as a dropdown
  • Updates the URL to track diff state
  • Updates the UI element to show state based on events (eg. hotkeys)
  • Shows the current file in the dropdown if it's open, otherwise a generic message

Fixes https://github.com/readthedocs/meta/issues/171

Demo

Screenshot 2025-01-14 at 12 28 49 PM

Screenshare.-.2025-01-14.12_27_53.PM.mp4

This adds a v1 Visual Diff UI.
It does the following:

* Adds a UI element to track Docdiff state, and exposes filetreediff as a dropdown
* Updates the URL to track diff state
* Updates the UI element to show state based on events (eg. hotkeys)
* Shows the current file in the dropdown if it's open, otherwise a generic message
Copy link
Member

@humitos humitos left a comment

Choose a reason for hiding this comment

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

This is, without any doubt, a lot better than what we had 😄 . It's tiny, simple, and usable.

src/index.js Outdated
Comment on lines 32 to 38
// Same for FileTreeDiff.
hotkeys.HotKeysAddon,
docdiff.DocDiffAddon,
filetreediff.FileTreeDiffAddon,

linkpreviews.LinkPreviewsAddon,
filetreediff.FileTreeDiffAddon,
customscript.CustomScriptAddon,
docdiff.DocDiffAddon,
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure to understand this change. It seems that hotkeys addon was already initialized before filetreediff. Is there any other reason why you needed to re-order them here?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it's actually docdiff that needs to run last, because it's triggering the event based on the URL param and filetreediff is now listening to that to keep state. It's messy keeping state in multiple places with events like this, and I'm not convinced it's a good long term solution vs. having the docdiff addon keep the "enabled/disabled" state that other addons can query.

Copy link
Member Author

Choose a reason for hiding this comment

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

addons/src/docdiff.js

Lines 105 to 111 in 47645b0

// Enable DocDiff if the URL parameter is present
if (hasQueryParam(DOCDIFF_URL_PARAM)) {
const event = new CustomEvent(
EVENT_READTHEDOCS_DOCDIFF_ADDED_REMOVED_SHOW,
);
document.dispatchEvent(event);
}

Copy link
Member

@humitos humitos Jan 16, 2025

Choose a reason for hiding this comment

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

docdiff addon keep the "enabled/disabled" state that other addons can query.

This will have similar problems. If the state changes on docdiff, you need to communicate this somehow to the other addons to update their UI as well. I don't think you can have a "reactive property" based on other web-component property.

Copy link
Member

Choose a reason for hiding this comment

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

Probably, what we need to share state is to use a ContextRoot, similar to what we are implementing in #491. That way, every time that any addons update the state all the other addons will be notified and act in consequence.

Comment on lines +5 to +9
background-color: #f8f9fa;
padding: 0.25rem 0.75rem;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
z-index: 2000;
border-radius: 0 0 6px 6px;
Copy link
Member

Choose a reason for hiding this comment

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

@agjohnson what would be the pattern here to add --readthedocs-* CSS variables? what are the correct/required ones to add? All of those with *color* on its name? Should all the "spacing" values be calculated from --readthedocs-filetreediff-font-size?

Copy link
Contributor

Choose a reason for hiding this comment

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

Whatever we're doing in other addons right now is fine. There isn't any issue with adding CSS variables that we'll change later especially if we aren't documenting them.

}

:host(.toast) > div {
.file-dropdown {
Copy link
Member

Choose a reason for hiding this comment

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

I understand we are not using CSS classes for this, but more strict selectors instead. Example: :host > div > div > label and similars. I'm not 100% about the benefits, but just mentioning what's the pattern we have been following for other addons -- cc @agjohnson

Copy link
Member Author

@ericholscher ericholscher Jan 15, 2025

Choose a reason for hiding this comment

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

Yea, I didn't have any understanding of the current pattern, so just went with something that worked. If we have a doc explaining the approach we're taking, happy to follow it.

Looking at the current CSS files, some have :host selectors and some don't, so wasn't sure what was best.

Copy link
Contributor

Choose a reason for hiding this comment

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

The classes just aren't usually necessary for such a sparse element, so class name is overly verbose. We know the structure is :host > div and :host > div > div, and there aren't any competing elements like div.directory-dropdown that make it necessary to name the elements.

This should follow what the other elements do at least and use more specificity, especially scoping the selector to start at :host (:host > div > div). This rules out any possibility of a deeper nested element to match the selector.

Co-authored-by: Manuel Kaufmann <humitos@gmail.com>
@ericholscher
Copy link
Member Author

ericholscher commented Jan 22, 2025

@humitos if you're happy with the overall concept here, I think we 👍 it and ship it, and we can iterate in dev. I'd like to start using visual diff more on WTD, and this UI makes it not a blocker :)

Can always add another issue for variables and CSS rules.

@ericholscher ericholscher marked this pull request as ready for review January 23, 2025 16:28
@ericholscher ericholscher requested a review from a team as a code owner January 23, 2025 16:28
Copy link
Member

@humitos humitos left a comment

Choose a reason for hiding this comment

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

I re-reviewed this and I don't seeing anything blocking us to deploy this work. It's better to what we currently have and it has to be enabled per-project -- which looks safe.

Once it's deployed, we can ping some users so they can start testing it and give us some feedback (e.g. CPython folks are waiting for this, actually).

Let's ship it and iterate over it with the feedback we receive and our own as well 👍🏼

@ericholscher ericholscher merged commit 4af0887 into main Jan 23, 2025
4 checks passed
@ericholscher ericholscher deleted the ftd-dropdown branch January 23, 2025 17:42
@ericholscher
Copy link
Member Author

Excited to test this out more! Always happy to update the code once we have patterns formalized.

Copy link
Contributor

@agjohnson agjohnson left a comment

Choose a reason for hiding this comment

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

Just noting some general patterns to follow, otherwise this PR looks great. I'm glad to have the update to replace the notification UI.

}

:host(.toast) > div {
.file-dropdown {
Copy link
Contributor

Choose a reason for hiding this comment

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

The classes just aren't usually necessary for such a sparse element, so class name is overly verbose. We know the structure is :host > div and :host > div > div, and there aren't any competing elements like div.directory-dropdown that make it necessary to name the elements.

This should follow what the other elements do at least and use more specificity, especially scoping the selector to start at :host (:host > div > div). This rules out any possibility of a deeper nested element to match the selector.

Comment on lines +5 to +9
background-color: #f8f9fa;
padding: 0.25rem 0.75rem;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
z-index: 2000;
border-radius: 0 0 6px 6px;
Copy link
Contributor

Choose a reason for hiding this comment

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

Whatever we're doing in other addons right now is fine. There isn't any issue with adding CSS variables that we'll change later especially if we aren't documenting them.

/>
Show diff
</label>
<select id="file-select" @change=${this.handleFileChange}>
Copy link
Contributor

Choose a reason for hiding this comment

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

file-select seems unused, are we doing something with this?

If this needs to be targeted with an event, use Lit @[event] attributes instead. It doesn't look like this is the case though.

flex: 1;
padding: 0.25rem 0.5rem;
border: 1px solid #ddd;
border-radius: 4px;
Copy link
Contributor

Choose a reason for hiding this comment

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

Generally, all units should be em/rem to avoid breaking scaling of these elements with font size -- px won't scale up if users override the font-size larger.

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