Skip to content

Conversation

@Haz3-jolt
Copy link
Member

@Haz3-jolt Haz3-jolt commented Jan 11, 2025

Purpose / Description

Adds two JS API functions [set/replace]NoteTags and getTagsFromNote which act similar to PUT and GET from a REST API

Fixes

Approach

Adds two methods to allow the caller to get Tags and update/set tags.

How Has This Been Tested?

Added two unit tests both verified and passing.

Checklist

Please, go through these checks before submitting the PR.

  • You have a descriptive commit message with a short title (first line, max 50 chars).
  • You have commented your code, particularly in hard-to-understand areas
  • You have performed a self-review of your own code
  • UI changes: include screenshots of all affected screens (in particular showing any new or changed strings)
  • UI Changes: You have tested your change using the Google Accessibility Scanner

@Haz3-jolt
Copy link
Member Author

@david-allison Do you think we should deprecate addTagToNote? Also [set/replace]NoteTags triggers lint failure

Copy link
Member

@mikehardy mikehardy left a comment

Choose a reason for hiding this comment

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

Do you think we should deprecate addTagToNote

Yes - haven't done our deprecation strategy in a while, not sure exactly how. Is it documented anywhere? May not be, but we should be able to mark something as deprecated and have it emit a warning in console or similar

Mizokuiam

This comment was marked as spam.

@Mizokuiam

This comment was marked as spam.

@Haz3-jolt Haz3-jolt force-pushed the setTags branch 2 times, most recently from 783f9fa to 36e8da6 Compare January 11, 2025 16:02
@Haz3-jolt
Copy link
Member Author

Do you think we should deprecate addTagToNote

Yes - haven't done our deprecation strategy in a while, not sure exactly how. Is it documented anywhere? May not be, but we should be able to mark something as deprecated and have it emit a warning in console or similar

From some searching, the most I can find is the deprecated decorator on Kotlin side, I dunno how we would approach on js. Is there official documentation for JS api? if not we can just have a comment?

@Haz3-jolt
Copy link
Member Author

Thanks for bringing this up. Here's my perspective...

Hey! Can you you elaborate further?

@mikehardy
Copy link
Member

@Mizokuiam please stop. You are wasting everyone's time.

@Haz3-jolt
Copy link
Member Author

@Mizokuiam please stop. You are wasting everyone's time.

Spammer? :(

@mikehardy
Copy link
Member

@Haz3-jolt I assume so. Negative value contributions, banned at organization level by me now.

@Haz3-jolt
Copy link
Member Author

@mikehardy How is this for a deprecation warning? Since people mainly interact on Js side

Subject: [PATCH] JS function to setTags and getTags
---
Index: AnkiDroid/src/main/assets/scripts/js-api.js
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/AnkiDroid/src/main/assets/scripts/js-api.js b/AnkiDroid/src/main/assets/scripts/js-api.js
--- a/AnkiDroid/src/main/assets/scripts/js-api.js	(revision 6d3d270e9067fbad4797f25b0f3060adc60e41cd)
+++ b/AnkiDroid/src/main/assets/scripts/js-api.js	(date 1736620228061)
@@ -121,6 +121,7 @@
 Object.keys(jsApiList).forEach(method => {
     if (method === "ankiAddTagToNote") {
         AnkiDroidJS.prototype[method] = async function (noteId, tag) {
+            console.warn("ankiAddTagToNote is deprecated. Use ankiSetNoteTags instead.");
             const endpoint = jsApiList[method];
             const data = JSON.stringify({ noteId, tag });
             return await this.handleRequest(endpoint, data);

@mikehardy
Copy link
Member

@Haz3-jolt I believe that deprecation in javascript console is the correctly location for it

@Haz3-jolt
Copy link
Member Author

@Haz3-jolt I believe that deprecation in javascript console is the correctly location for it

Amend the current commit or separate commit?

@mikehardy
Copy link
Member

amend I think, the deprecation of the old is part of adding the new to me, it's all one piece

@Haz3-jolt
Copy link
Member Author

amend I think, the deprecation of the old is part of adding the new to me, it's all one piece

Cool!

@david-allison david-allison added Needs Second Approval Has one approval, one more approval to merge and removed Needs Review labels Jan 11, 2025
@Haz3-jolt Haz3-jolt requested a review from mikehardy January 12, 2025 12:31
@Haz3-jolt

This comment was marked as outdated.

@david-allison

This comment has been minimized.

@Haz3-jolt

This comment has been minimized.

@Haz3-jolt Haz3-jolt force-pushed the setTags branch 3 times, most recently from 4b7ec2b to 5b2f5bc Compare January 28, 2025 08:12
Copy link
Member

@david-allison david-allison left a comment

Choose a reason for hiding this comment

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

Should be the last one!

@Haz3-jolt
Copy link
Member Author

@david-allison Any other changes? Ive double checked that both functions are working.

@Haz3-jolt
Copy link
Member Author

@david-allison although I don't think I can do it rn, any idea on how a integration test for the setTags can be done? Perhaps setting a note with the Js function in the note, and using espresso to find the button or something?

@Haz3-jolt
Copy link
Member Author

@david-allison should I re base and force push to check if any conflicts are there? its been a while since this PR has been open

@Haz3-jolt
Copy link
Member Author

@david-allison should I re base and force push to check if any conflicts are there? its been a while since this PR has been open

Okay so looks like no conflicts

@david-allison
Copy link
Member

david-allison commented Feb 14, 2025

The PR will display conflicts if there are any (and it'll have Has Conflicts )

If it's sat for a while, a rebase saves a little time on our end

Copy link
Member

@david-allison david-allison left a comment

Choose a reason for hiding this comment

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

Cheers!

@david-allison david-allison added Needs Second Approval Has one approval, one more approval to merge and removed Needs Review labels Feb 14, 2025
Copy link
Member

@lukstbit lukstbit left a comment

Choose a reason for hiding this comment

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

Thanks, LGTM. Please squash the two commits into one and then this can be merged.

@lukstbit lukstbit added Pending Merge Things with approval that are waiting future merge (e.g. targets a future release, CI wait, etc) squash-merge A squash & force push is required. The PR author may do this to speed up the merge process. and removed Needs Second Approval Has one approval, one more approval to merge labels Feb 27, 2025
@Haz3-jolt
Copy link
Member Author

Thanks, LGTM. Please squash the two commits into one and then this can be merged.

Iirc @mikehardy and @david-allison agreed seprate commits might be better because it's adding the calls and unit tests for it in a seperate commit. But yeah I'm fine with squash merge as well.

@lukstbit lukstbit added this pull request to the merge queue Feb 27, 2025
@lukstbit lukstbit removed the squash-merge A squash & force push is required. The PR author may do this to speed up the merge process. label Feb 27, 2025
Merged via the queue into ankidroid:main with commit b64a565 Feb 27, 2025
9 checks passed
@github-actions github-actions bot removed the Pending Merge Things with approval that are waiting future merge (e.g. targets a future release, CI wait, etc) label Feb 27, 2025
@github-actions github-actions bot added this to the 2.21 release milestone Feb 27, 2025
@Haz3-jolt Haz3-jolt deleted the setTags branch June 17, 2025 08:57
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.

FR: JS API function to remove a specific tag

5 participants