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

[FC-0036] feat: Sort taxonomies #949

Conversation

ChrisChV
Copy link
Contributor

Description

Describe what this pull request changes, and why. Include implications for people using this change.
Design decisions and their rationales should be documented in the repo (docstring / ADR), per

Useful information to include:

  • Which edX user roles will this change impact? Common user roles are "Learner", "Course Author",
    "Developer", and "Operator".
  • Include screenshots for changes to the UI (ideally, both "before" and "after" screenshots, if applicable).
  • Provide links to the description of corresponding configuration changes. Remember to correctly annotate these
    changes.

Supporting information

Link to other information about the change, such as Jira issues, GitHub issues, or Discourse discussions.
Be sure to check they are publicly readable, or if not, repeat the information here.

Testing instructions

Please provide detailed step-by-step instructions for testing this change.

Other information

Include anything else that will help reviewers and consumers understand the change.

  • Does this change depend on other changes elsewhere?
  • Any special concerns or limitations? For example: deprecations, migrations, security, or accessibility.

@ChrisChV ChrisChV requested a review from a team as a code owner April 11, 2024 17:56
@openedx-webhooks
Copy link

openedx-webhooks commented Apr 11, 2024

Thanks for the pull request, @ChrisChV! Please note that it may take us up to several weeks or months to complete a review and merge your PR.

Feel free to add as much of the following information to the ticket as you can:

  • supporting documentation
  • Open edX discussion forum threads
  • timeline information ("this must be merged by XX date", and why that is)
  • partner information ("this is a course on edx.org")
  • any other information that can help Product understand the context for the PR

All technical communication about the code itself will be done via the GitHub pull request interface. As a reminder, our process documentation is here.

Please let us know once your PR is ready for our review and all tests are green.

@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Apr 11, 2024
@ChrisChV ChrisChV changed the title feat: Sort taxonomies [FC-0036] feat: Sort taxonomies Apr 11, 2024
@ChrisChV ChrisChV marked this pull request as draft April 11, 2024 18:06
@ChrisChV ChrisChV marked this pull request as ready for review April 11, 2024 19:11
Copy link
Member

@yusuf-musleh yusuf-musleh left a comment

Choose a reason for hiding this comment

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

👍 @ChrisChV Looks good to me!

  • I tested this: I confirmed that the implicit tags are now also including when sorting
  • I read through the code
  • I checked for accessibility issues
  • Includes documentation

Copy link
Contributor

@xitij2000 xitij2000 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 working as is, but I feel there can be some optimisation done here. I feel that the tag count is being calculated twice and can be avoided once, and some of the sorting code can be simplified.

Comment on lines 113 to 144
const taxonomiesWithData = taxonomiesList.filter(
(t) => t.contentTags.length !== 0,
);

// Count implicit tags per taxonomy
const tagsCountBytaxonomy = {};
taxonomiesWithData.forEach((tax) => {
const countedTags = [];
let tagsCounter = 0;
tax.contentTags.forEach((tag) => {
tag.lineage.forEach((value) => {
if (!countedTags.includes(value)) {
countedTags.push(value);
tagsCounter += 1;
}
});
});
tagsCountBytaxonomy[tax.id] = tagsCounter;
});

// Sort taxonomies with data by implicit count
const sortedTaxonomiesWithData = taxonomiesWithData.sort(
(a, b) => tagsCountBytaxonomy[b.id] - tagsCountBytaxonomy[a.id],
);

// Sort empty taxonomies by name
const emptyTaxonomies = taxonomiesList.filter(
(t) => t.contentTags.length === 0,
).sort((a, b) => a.name.localeCompare(b.name));

return [...sortedTaxonomiesWithData, ...emptyTaxonomies];
};
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 this code can be simplified quite a bit. If I understand correctly, you want to sort first by the tag count and then by the name? The complication being that all implicit tags need to be counted as well.

I see that this value is being displayed in the UI, so can't that value be cached and reused? Why is it being recalculated for the sorting here?

I think javascript sorting is stable, so if the API response is already sorted by name you can just sort by tag count here, and it should sort the whole list by tags while retaining the order of the other elements.

So the whole tag count code can be replaced with roughly:

taxonomiesList.map(item => (new Set(item.contentTags.flatMap(item=>item.lineage))).size)

This will create a flat list of all lineage items, convert that to a set, so that duplicates are removed an then get the size. You then have a list of tag counts and can sort by this list.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the feedback! I updated the code here 9ded66e

I see that this value is being displayed in the UI, so can't that value be cached and reused? Why is it being recalculated for the sorting here?

Yes, you are right, that calculation is done individually here: https://github.com/openedx/frontend-app-course-authoring/blob/08140226c3d3601378f36215f366826557b9023e/src/content-tags-drawer/ContentTagsCollapsibleHelper.jsx#L140-L176

For reasons of complexity and budget I have left a comment about this, to do it in the future. The good thing is that with or without the counting the function will be executed so it does not affect performance.

Copy link

codecov bot commented Apr 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.10%. Comparing base (99a144a) to head (9ded66e).
Report is 15 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #949      +/-   ##
==========================================
+ Coverage   92.00%   92.10%   +0.09%     
==========================================
  Files         612      634      +22     
  Lines       10746    11091     +345     
  Branches     2305     2387      +82     
==========================================
+ Hits         9887    10215     +328     
- Misses        830      847      +17     
  Partials       29       29              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@xitij2000 xitij2000 merged commit 422a5db into openedx:master Apr 18, 2024
6 checks passed
@openedx-webhooks
Copy link

@ChrisChV 🎉 Your pull request was merged! Please take a moment to answer a two question survey so we can improve your experience in the future.

@xitij2000 xitij2000 deleted the chris/FAL-3645-refined-tag-drawer-sort-taxonomies branch April 18, 2024 03:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
open-source-contribution PR author is not from Axim or 2U
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants