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

fix(openchallenges): create pipe to map enum values of challenge properties to labels #2612

Merged
merged 13 commits into from
Apr 3, 2024

Conversation

rrchai
Copy link
Contributor

@rrchai rrchai commented Apr 1, 2024

Changelog

  • Create a pipe in util lib to convert the enum value of a challenge property into a label name based on the mapping file located in the challenge-search component stored locally.

@rrchai
Copy link
Contributor Author

rrchai commented Apr 1, 2024

I realize the challenge card has incentive information. To avoid calling the function hundreds of times to get incentive label for each challenge card, I will change to create a separate mapping file for label-value.

@rrchai
Copy link
Contributor Author

rrchai commented Apr 1, 2024

When I was trying to update the incentive in the challenge card component, all pages displayed blank with an error indicating that loading the footer failed. Here is the error message.

statistics-viewer.component.ts:13 Uncaught TypeError: Cannot read properties of undefined (reading 'FooterComponent')
    at Module.FooterComponent (statistics-viewer.component.ts:13:72)
    at 72716 (challenge-search.component.ts:83:5)
    at __webpack_require__ (bootstrap:19:1)
    at 17844 (challenge-search.component.ts:87:34)
    at __webpack_require__ (bootstrap:19:1)
    at 15392 (variables.ts:9:2)
    at __webpack_require__ (bootstrap:19:1)
    at 71604 (mock-avatars.ts:14:2)
    at __webpack_require__ (bootstrap:19:1)
    at 65488 (statistics-viewer.component.ts:13:72)

I noticed this issue when I shared the mapping file in the challenge-search library via index.ts. However, the error disappears if I share it in the ui library. I'm not sure if it's related to a recurring module loading issue.

@rrchai rrchai changed the title fix(openchallenges): add functionality to retrieve label for challenge property from mapping file fix(openchallenges): add mapping file to retrieve label for challenge property Apr 1, 2024
@rrchai rrchai marked this pull request as ready for review April 1, 2024 21:30
@rrchai rrchai marked this pull request as draft April 2, 2024 15:41
@rrchai
Copy link
Contributor Author

rrchai commented Apr 2, 2024

I noticed this issue when I shared the mapping file in the challenge-search library via index.ts. However, the error disappears if I share it in the ui library. I'm not sure if it's related to a recurring module loading issue.

Potential circular dependency, if creating a new mapping file stored in challenge-search/challenge:

  • challenge-search/challenge depends on ui (which includes challenge-card).
  • challenge-card depends on challenge-search/challenge for mappings.

The new mapping file cannot be in the challenge/challenge-search lib to avoid the error.

Potential circular dependency, If using a function to retrieve the labels from an existing mapping file in challenge-search:

  • the reusable function depends on challenge-search for mappings.
  • challenge-search depends on ui (which includes challenge-card).
  • challenge-card depends on the reusable function for mappings.

This approach is not doable, as the reusable function needs to be isolated from challenge-search to avoid the error, unless creating/moving a mapping file. Or directly import the mapping file from challenge-search, see this comment.


I am creating a pipe directly importing the existing mapping file from challenge-search.

@rrchai rrchai changed the title fix(openchallenges): add mapping file to retrieve label for challenge property fix(openchallenges): create pipe to map challenge property enums to labels Apr 2, 2024
@rrchai rrchai changed the title fix(openchallenges): create pipe to map challenge property enums to labels fix(openchallenges): create pipe to map challenge's incentive and submission type enums to labels Apr 2, 2024
@rrchai rrchai marked this pull request as ready for review April 2, 2024 21:39
@rrchai rrchai changed the title fix(openchallenges): create pipe to map challenge's incentive and submission type enums to labels fix(openchallenges): create pipe to map enum values of challenge properties to labels Apr 2, 2024
@rrchai rrchai requested a review from tschaffter April 2, 2024 23:38
Copy link
Member

@tschaffter tschaffter left a comment

Choose a reason for hiding this comment

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

This fix works as expected, thanks! I like how developer-friendly using Angular pipes to convert constant to human-readable text is.

There are two improvements I can see for the future:

  • use the constant from the API client as keys in a dictionary and set the localization strings as the values. This approach has the benefit of defining the content of the dictionary once and they have one "implementation" for each languages.
  • extract the localization code from the util library and place it into a "localization" library.

@tschaffter tschaffter merged commit ef0a030 into Sage-Bionetworks:main Apr 3, 2024
13 checks passed
Copy link

sonarcloud bot commented Apr 5, 2024

Quality Gate Passed Quality Gate passed for 'openchallenges-app'

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarCloud

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] Fix MLCube casing typo
2 participants