Skip to content

Addons: resolve URLs for file tree diff API response #11749

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 8 commits into from
Nov 12, 2024

Conversation

humitos
Copy link
Member

@humitos humitos commented Nov 7, 2024

Resolve all the filename into URLs, so the frontend can use these links without manipulating them. We don't want re-implement the resolver in the frontend.

Now, we return the filename, the URL for the current version, and the URL for the source version of the filename changed.

Closes readthedocs/addons#409

@humitos humitos marked this pull request as ready for review November 7, 2024 11:51
@humitos humitos requested a review from a team as a code owner November 7, 2024 11:51
@humitos humitos requested a review from stsewd November 7, 2024 11:51
This works for now, but we also want to sort them alphabetically as well.
Comment on lines 651 to 660
"current": resolver.resolve(
project=project,
filename=filename,
version_slug=version.slug,
),
"source": resolver.resolve(
project=project,
filename=filename,
version_slug=latest_version.slug,
),
Copy link
Member

Choose a reason for hiding this comment

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

A couple of notes:

  • We are using version_a and version_b as naming (similar to diff), not current/source.
  • Maybe just have two fields (version_a_base_url and version_b_base_url) at the top level response, and the client can use that information to build the final URL (similar to what we do in search). This will also make it easier to link to the top level pages of both versions.
  • Even if we prefer to have this information per file, you can just resolve both base urls once in the backend, and then concatenate to each filename (resolver.resolve_version will give you this information, and that method should be used when you already have access to the version object to avoid hitting the DB again).

Copy link
Member Author

Choose a reason for hiding this comment

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

We are using version_a and version_b as naming (similar to diff), not current/source.

I would like to use a name with more semantic meaning that communicates what's the source version and what's the current version. version_a and version_b does not communicate that in a clear way --I find them confusing.

I'm happy to change source/current name for something different that conveys the semantic meaning I'm looking for if we have something better here, tho. cc @ericholscher

Maybe just have two fields (version_a_base_url and version_b_base_url) at the top level response, and the client can use that information to build the final URL.

I want to avoid manipulating URLs in the frontend as much as possible. The backend resolver is the source of truth here and I expect we will be making changes to it in the future. So, I want to stick to it.

resolver.resolve_version will give you this information

I used this method and it reduced 5 queries in total 👍🏼 . We are at 30 DB queries when FTD is enabled, which is pretty similar to when it's not, so we are good here. We can concentrate more in the performance later if we notice it's needed, tho.

Copy link
Member

Choose a reason for hiding this comment

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

I thought about this for a bit, and came up with some other options (current and original) which imply changes a bit more explicitly. I'm not 100% sure the best approach here. I agree a/b is an odd thing to surface for folks who aren't familiar with diff, but I agree we want it to be consistent, and if there's existing ways to discuss this it's not a bad idea to reuse them. I know git diff's expose a/b as a concept, so it's probably fine to reuse existing patterns here, instead of reinventing our own?

Copy link
Member Author

Choose a reason for hiding this comment

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

OK, I don't like version_a and version_b, but it seems there is consensus to move forward with that. So, I will move forward with those names.

@humitos humitos requested a review from ericholscher November 11, 2024 10:23
Comment on lines 651 to 660
"current": resolver.resolve(
project=project,
filename=filename,
version_slug=version.slug,
),
"source": resolver.resolve(
project=project,
filename=filename,
version_slug=latest_version.slug,
),
Copy link
Member

Choose a reason for hiding this comment

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

I thought about this for a bit, and came up with some other options (current and original) which imply changes a bit more explicitly. I'm not 100% sure the best approach here. I agree a/b is an odd thing to surface for folks who aren't familiar with diff, but I agree we want it to be consistent, and if there's existing ways to discuss this it's not a bad idea to reuse them. I know git diff's expose a/b as a concept, so it's probably fine to reuse existing patterns here, instead of reinventing our own?

@ericholscher ericholscher merged commit 9a14ae9 into main Nov 12, 2024
8 checks passed
@ericholscher ericholscher deleted the humitos/file-tree-diff-api branch November 12, 2024 15:27
humitos added a commit to readthedocs/addons that referenced this pull request Nov 12, 2024
Added a new addon to show all the filenames and URLs that were added,
deleted or modified in the current PR compared to the LATEST version.


![Screenshot_2024-11-07_12-44-02](https://github.com/user-attachments/assets/dfdba906-1eb1-4755-a1e6-eaddbfa51144)

I'm rendering this data in a new notification decoupled from the
existing one on purpose. I don't want to entangle the code of these two
different addons for now, in particular while we are under
development/testing. I also see that in the future they may have
different UI elements, or the data will be integrated in a more bigger
UI element (eg. toolbar) or similar.

We can discuss more how this addon will grow and where is a good place
to add this data and make that work in a following PR. For now, I want
something that we can start testing internally in our own projects.

### Examples


![Screenshot_2024-11-07_14-15-37](https://github.com/user-attachments/assets/d0265b34-8ade-4348-bc8e-e6a3ff8ae0d1)



![Screenshot_2024-11-07_14-35-41](https://github.com/user-attachments/assets/403b6860-60c1-468e-ae5d-2491f6f47b38)



![Screenshot_2024-11-07_14-51-06](https://github.com/user-attachments/assets/0e24664d-672f-40c0-9be4-bd76b2cf4f04)


Closes #409
Requires readthedocs/readthedocs.org#11749
humitos added a commit that referenced this pull request Nov 13, 2024
Instead of using `version_a` and `version_b`, we are using `current` and `base`
for these field names. These names are standard GitHub/Git names, for example
when creating pull requests and you have to select the "base branch".

* Refs: #11762 (comment)
* Refs: #11749 (comment)
humitos added a commit that referenced this pull request Nov 18, 2024
Instead of using `version_a` and `version_b`, we are using `current` and
`base` for these field names. These names are standard GitHub/Git names,
for example when creating pull requests and you have to select the "base
branch".

* Refs:
#11762 (comment)
* Refs:
#11749 (comment)
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.

File tree diff client
3 participants