-
Notifications
You must be signed in to change notification settings - Fork 19
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
Visual Diff UI v1 #494
Conversation
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
There was a problem hiding this 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
// Same for FileTreeDiff. | ||
hotkeys.HotKeysAddon, | ||
docdiff.DocDiffAddon, | ||
filetreediff.FileTreeDiffAddon, | ||
|
||
linkpreviews.LinkPreviewsAddon, | ||
filetreediff.FileTreeDiffAddon, | ||
customscript.CustomScriptAddon, | ||
docdiff.DocDiffAddon, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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); | |
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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; |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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>
@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. |
There was a problem hiding this 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 👍🏼
Excited to test this out more! Always happy to update the code once we have patterns formalized. |
There was a problem hiding this 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 { |
There was a problem hiding this comment.
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.
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; |
There was a problem hiding this comment.
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}> |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
This adds a v1 Visual Diff UI.
It does the following:
Fixes https://github.com/readthedocs/meta/issues/171
Demo
Screenshare.-.2025-01-14.12_27_53.PM.mp4