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

feat(Tags): Allow users to favorite Tags on CRUD Listview page #24701

Merged
merged 19 commits into from
Jul 27, 2023

Conversation

hughhhh
Copy link
Member

@hughhhh hughhhh commented Jul 14, 2023

SUMMARY

Update CRUD Tag Page to have favorites stars, and filter dropdowns from @kasiazjc designs. The main change is now allowing users to favorite tags

Screen Shot 2023-07-19 at 2 49 08 PM

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

TESTING INSTRUCTIONS

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

@hughhhh hughhhh requested a review from a team as a code owner July 14, 2023 20:05
@hughhhh hughhhh changed the title feat: allow users to favorite Tags feat(Tags): Allow users to favorite Tags on CRUD Listview page Jul 14, 2023
@codecov
Copy link

codecov bot commented Jul 14, 2023

Codecov Report

Merging #24701 (ef55538) into master (165afee) will increase coverage by 0.14%.
Report is 5 commits behind head on master.
The diff coverage is 79.72%.

❗ Current head ef55538 differs from pull request most recent head c1a6082. Consider uploading reports for the commit c1a6082 to get more accurate results

@@            Coverage Diff             @@
##           master   #24701      +/-   ##
==========================================
+ Coverage   68.84%   68.98%   +0.14%     
==========================================
  Files        1902     1903       +1     
  Lines       73997    74086      +89     
  Branches     8195     8194       -1     
==========================================
+ Hits        50944    51110     +166     
+ Misses      20934    20860      -74     
+ Partials     2119     2116       -3     
Flag Coverage Δ
hive 54.14% <46.83%> (?)
javascript 55.81% <73.91%> (+0.01%) ⬆️
mysql 79.21% <84.81%> (+0.01%) ⬆️
postgres 79.31% <84.81%> (+0.01%) ⬆️
presto 54.04% <46.83%> (-0.02%) ⬇️
python 83.36% <84.81%> (+0.24%) ⬆️
sqlite 77.88% <84.81%> (?)
unit 54.97% <64.55%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Changed Coverage Δ
superset-frontend/src/SqlLab/App.jsx 0.00% <ø> (ø)
...tersConfigModal/Footer/CancelConfirmationAlert.tsx 100.00% <ø> (ø)
superset-frontend/src/hooks/apiResources/tables.ts 73.80% <ø> (ø)
superset-frontend/src/pages/Tags/index.tsx 0.00% <0.00%> (ø)
superset-frontend/src/views/CRUD/hooks.ts 52.38% <ø> (ø)
...eFilters/FiltersConfigModal/FiltersConfigModal.tsx 71.09% <50.00%> (+0.13%) ⬆️
...t-frontend/src/components/AsyncAceEditor/index.tsx 91.66% <63.63%> (+0.55%) ⬆️
superset/tags/api.py 75.16% <77.27%> (+0.85%) ⬆️
.../SqlLab/components/AceEditorWrapper/useKeywords.ts 80.00% <80.00%> (ø)
superset/daos/tag.py 95.41% <93.10%> (-0.89%) ⬇️
... and 4 more

... and 11 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more


if tag and user:
tag.users_favorited.append(user)
db.session.add(tag)
Copy link
Contributor

Choose a reason for hiding this comment

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

should we use session.merge as this tag object is returned object from the DAO?

Copy link
Member Author

Choose a reason for hiding this comment

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

whats the difference between just doing add/commit?

Copy link
Contributor

Choose a reason for hiding this comment

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

see https://docs.sqlalchemy.org/en/20/orm/session_state_management.html
and https://stackoverflow.com/questions/1849567/can-sqlalchemys-session-merge-update-its-result-with-newer-data-from-the-data

I believe since you get tag from the TagDAO the tag object is already in the session.
Calling add here is redundant.
But I am not sure about that g.user if that's returning a user object in the same session or if it's in a different session.
If it's in different sqla session, you will want to call merge() here so that it merges the user object to current session by matching the user.id.

Regardless, I think merge() is safer.

Copy link
Member

Choose a reason for hiding this comment

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

Agree. We should pass the user as a param as opposed to using the global

@@ -257,3 +266,90 @@ def get_tagged_objects_for_tags(
for obj in saved_queries
)
return results

@staticmethod
def user_favorite_tag(tag_id: int) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

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

naming: maybe favor_tag_by_id_for_current_user

Copy link
Contributor

Choose a reason for hiding this comment

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

or you can pass in user_id as param so it will be like def favor_tag_by_id(tag_id: int, user_id: int) -> None

Copy link
Contributor

Choose a reason for hiding this comment

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

is there any authorization that you need to check or any user can favor any tag?

Copy link
Member Author

Choose a reason for hiding this comment

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

right now any user can favorite a tag and matches the current functionality for other resources

db.session.commit()

@staticmethod
def favorited_ids(tags: list[Tag]) -> list[int]:
Copy link
Contributor

Choose a reason for hiding this comment

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

naming: favorited_tag_ids

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's better to just pass in tag IDs instead of the tag objects

Copy link
Member Author

Choose a reason for hiding this comment

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

$ref: '#/components/responses/500'
"""
requested_ids = kwargs["rison"]
tags = TagDAO.find_by_ids(requested_ids)

This comment was marked as outdated.

Returns:
None.
"""
tag = TagDAO.find_by_id(tag_id)
Copy link
Contributor

Choose a reason for hiding this comment

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

we should check tag is None here and throw.
Then in the controller you catch the TagNotFoundException and return 404 http code

@john-bodley
Copy link
Member

@hughhhh would you mind including screenshots (or the designs) to help provide more context.


# Remove the tag from the user's favorites
if tag and user:
tag.users_favorited.remove(user)
Copy link
Member

Choose a reason for hiding this comment

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

What's the TL;DR between tags and favoriting? It seems like we're doing double bookkeeping here which is likely suboptimal.

Copy link
Member Author

Choose a reason for hiding this comment

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

tags will become the defacto for managing favorites moving forward, i have a ticket to manage migration and handle the cleanup.

This table is needed becuase we can leverage tags to favorite tags with the circuliar dependency

Returns:
None.
"""
# Find the tag
Copy link
Member

Choose a reason for hiding this comment

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

This comment seems superfluous. Well named methods FTW!

tag = TagDAO.find_by_id(tag_id)
user = g.user

# Remove the tag from the user's favorites
Copy link
Member

Choose a reason for hiding this comment

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

See previous comment.

500:
$ref: '#/components/responses/500'
"""
TagDAO.favorite_tag_by_id_for_current_user(pk)
Copy link
Contributor

Choose a reason for hiding this comment

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

do you need to handle UserNotFound and TagNotFound exception here?

if not TagDAO.find_by_id(pk):
return self.response_404()

TagDAO.remove_user_favorite_tag(pk)
Copy link
Contributor

Choose a reason for hiding this comment

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

do you need to handle UserNotFound and TagNotFound exception here? You can remove line 516 then

@@ -372,3 +372,47 @@ def test_delete_tags(self):
# check that tags are all gone
tags = db.session.query(Tag).filter(Tag.name.in_(example_tag_names))
self.assertEqual(tags.count(), 0)

@pytest.mark.usefixtures("create_tags")
def test_add_delete_favorite_tag(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

add some negative tests for bad tag id

mock_session.commit.assert_called_once()


def test_remove_user_favorite_tag(mocker):

This comment was marked as outdated.

@pytest.mark.usefixtures("create_tags")
def test_add_tag_not_found(self):
self.login(username="admin")
user_id = self.get_user(username="admin").get_id()
Copy link
Contributor

Choose a reason for hiding this comment

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

user_id is not used

@hughhhh hughhhh force-pushed the hxgh-update-tags-page branch 5 times, most recently from 88fd3a4 to 4e01884 Compare July 26, 2023 21:31
Copy link
Member

@Antonio-RiveroMartnez Antonio-RiveroMartnez left a comment

Choose a reason for hiding this comment

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

lgtm

@hughhhh hughhhh merged commit 3b46511 into apache:master Jul 27, 2023
29 checks passed
@hughhhh hughhhh deleted the hxgh-update-tags-page branch July 27, 2023 17:17
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 3.1.0 labels Mar 8, 2024
vinothkumar66 pushed a commit to vinothkumar66/superset that referenced this pull request Nov 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels size/XL 🚢 3.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants