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(service-portal-education): Fix typing #16148

Merged
merged 3 commits into from
Sep 30, 2024
Merged

fix(service-portal-education): Fix typing #16148

merged 3 commits into from
Sep 30, 2024

Conversation

thorkellmani
Copy link
Member

@thorkellmani thorkellmani commented Sep 25, 2024

What

  • Use english letters of object keys

Why

  • Breaking my build

Checklist:

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • Formatting passes locally with my changes
  • I have rebased against main before asking for a review

Summary by CodeRabbit

  • New Features

    • Updated labels in the Secondary School Career and Graduation Detail components for improved clarity and consistency, using English terms.
  • Bug Fixes

    • Enhanced the tagSelector functionality for more reliable color mapping based on input strings.

@thorkellmani thorkellmani requested review from a team as code owners September 25, 2024 10:55
@thorkellmani thorkellmani added the deploy-feature Deploys features to dev label Sep 25, 2024
Copy link
Contributor

coderabbitai bot commented Sep 25, 2024

Walkthrough

The changes involve renaming keys in the EducationGraduationDetail component across two files, SecondarySchoolCareer.tsx and SecondarySchoolGraduationDetail.tsx, to replace Icelandic terms with their English equivalents for improved consistency. Additionally, the tagSelector function in tagSelector.ts has been refactored to use a switch statement instead of an object for color mapping, modifying the control flow of the function.

Changes

File Path Change Summary
libs/service-portal/education/src/screens/SecondarySchoolCareer/SecondarySchoolCareer.tsx
libs/service-portal/education/src/screens/SecondarySchoolGraduationDetail/SecondarySchoolGraduationDetail.tsx
Renamed keys in labels and items from Icelandic to English: brautarheiti to course, einingar to units, einkunn to grade, dags to date, and Staða to status. Updated footer object accordingly.
libs/service-portal/education/src/utils/tagSelector.ts Changed the implementation of the tagSelector function from an object-based mapping to a switch statement for color selection, while updating the function signature to specify the return type.

Possibly related PRs

Suggested labels

automerge, high priority


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (6)
libs/service-portal/education/src/screens/SecondarySchoolCareer/SecondarySchoolCareer.tsx (4)

80-84: Approved: Consistent use of English keys

The changes from Icelandic to English keys in the labels object improve consistency and align with the PR objective. This modification should help prevent build issues related to non-English characters.

For even better consistency, consider using camelCase for multi-word keys:

-  course: formatMessage(edMessage.courseId),
+  courseId: formatMessage(edMessage.courseId),

This change would make the key naming consistent with JavaScript conventions and the courseName key used elsewhere in the code.


90-94: Approved: Consistent key renaming in items mapping

The changes in the items mapping correctly align with the modifications made to the labels object. This consistency ensures that the SortableTable component will continue to function as expected with the new English key names.

To maintain consistency with the previous suggestion:

-  course: course?.courseId ?? '',
+  courseId: course?.courseId ?? '',

This change would align with the suggested camelCase naming convention for multi-word keys.


100-101: Approved: Consistent key renaming in footer object

The renaming of the brautarheiti key to course in the footer object is consistent with the previous changes and contributes to the overall goal of using English keys throughout the component.

For consistency with the previous suggestions:

-  course: '',
+  courseId: '',

This change would align the footer object with the suggested camelCase naming convention for multi-word keys used in the labels and items objects.


Line range hint 1-108: Overall assessment: Improved consistency and maintainability

The changes in this file successfully address the PR objective of replacing non-English letters in object keys. The consistent renaming of keys from Icelandic to English across the EducationGraduationDetail component improves code readability and maintainability.

Key points:

  1. The changes align with the coding guidelines for library files.
  2. TypeScript usage is maintained, ensuring type safety.
  3. The component's reusability is preserved.
  4. The modifications should help prevent build issues related to non-English characters.

Consider implementing the suggested minor improvements for even better consistency in naming conventions.

To further enhance the component's reusability across different NextJS apps, consider extracting the label messages into a separate, importable constant object. This would allow for easier localization and potential reuse in other components or applications.

libs/service-portal/education/src/screens/SecondarySchoolGraduationDetail/SecondarySchoolGraduationDetail.tsx (2)

118-122: Approved: Improved naming consistency

The renaming of object keys from Icelandic to English improves code consistency and readability. This change aligns well with the PR objective of addressing issues related to non-English letters in object keys.

Consider using an interface or type alias for the labels object to enhance type safety and documentation. For example:

interface TableLabels {
  name: string;
  course: string;
  units: string;
  grade: string;
  date: string;
  status: string;
}

const labels: TableLabels = {
  name: formatMessage(edMessage.courseName),
  course: formatMessage(edMessage.courseId),
  units: formatMessage(edMessage.units),
  grade: formatMessage(edMessage.grade),
  date: formatMessage(edMessage.dateShort),
  status: formatMessage(edMessage.status),
};

This would improve type checking and make the code more self-documenting.


128-132: Approved: Consistent naming in items mapping

The renaming of object keys in the items mapping is consistent with the changes in the labels object, improving overall code consistency and readability.

To enhance type safety and make the code more robust, consider defining an interface for the course object and using it in the mapping. For example:

interface Course {
  courseId: string;
  courseName: string;
  units: string;
  finalgrade: string;
  date: string;
  status: string;
}

// In the items mapping
items={
  item.courses?.map((course: Course, i) => ({
    id: course.courseId ?? `${i}`,
    name: course.courseName ?? '',
    course: course.courseId ?? '',
    units: course.units ?? '',
    grade: course.finalgrade ?? '',
    date: formatDate(course.date ?? ''),
    status: course.status ?? '',
    tag: tagSelector(course.status ?? ''),
  })) ?? []
}

This would provide better type checking and make the code more self-documenting.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 621b5bb and 9a0b8d1.

📒 Files selected for processing (3)
  • libs/service-portal/education/src/screens/SecondarySchoolCareer/SecondarySchoolCareer.tsx (1 hunks)
  • libs/service-portal/education/src/screens/SecondarySchoolGraduationDetail/SecondarySchoolGraduationDetail.tsx (1 hunks)
  • libs/service-portal/education/src/utils/tagSelector.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
libs/service-portal/education/src/screens/SecondarySchoolCareer/SecondarySchoolCareer.tsx (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/service-portal/education/src/screens/SecondarySchoolGraduationDetail/SecondarySchoolGraduationDetail.tsx (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/service-portal/education/src/utils/tagSelector.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
🔇 Additional comments not posted (1)
libs/service-portal/education/src/screens/SecondarySchoolGraduationDetail/SecondarySchoolGraduationDetail.tsx (1)

138-139: Approved: Consistent naming in footer object

The renaming of the key from brautarheiti to course in the footer object is consistent with the previous changes, maintaining overall code consistency and readability.

Copy link
Contributor

Affected services are: service-portal,
Feature deployment of your services will begin shortly. Your feature will be accessible here:
https://fixeducatoin-errors-beta.dev01.devland.is/minarsidur

Deployed services: service-portal.
Excluded services: ``

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 9a0b8d1 and 147c300.

📒 Files selected for processing (1)
  • libs/service-portal/education/src/utils/tagSelector.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
libs/service-portal/education/src/utils/tagSelector.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
📓 Learnings (1)
libs/service-portal/education/src/utils/tagSelector.ts (1)
Learnt from: thordurhhh
PR: island-is/island.is#16078
File: libs/service-portal/education/src/utils/tagSelector.ts:3-7
Timestamp: 2024-09-23T14:05:19.772Z
Learning: The `tagSelector` function maps the Icelandic strings returned from the API to matching colors, and the service currently returns Icelandic strings.
🔇 Additional comments (3)
libs/service-portal/education/src/utils/tagSelector.ts (3)

1-1: Good addition of the ColorValue type

The introduction of the ColorValue type enhances type safety and aligns with TypeScript best practices. It clearly defines the possible return values of the tagSelector function, which aids in code clarity and maintainability.


3-3: Improved function signature with explicit return type

The addition of the explicit return type ColorValue to the tagSelector function signature enhances type safety and code readability. This change aligns well with TypeScript best practices and improves the overall quality of the code.


4-17: Approved refactoring to switch statement

The refactoring from an object-based mapping to a switch statement improves code readability and maintainability. The implementation correctly handles all cases, including a default case.

However, keep in mind that if the number of cases grows significantly in the future, an object lookup might be more performant. Consider benchmarking and potentially refactoring back to an object-based approach if the number of cases increases substantially.

Copy link

codecov bot commented Sep 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 36.68%. Comparing base (621b5bb) to head (147c300).
Report is 47 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #16148      +/-   ##
==========================================
+ Coverage   36.67%   36.68%   +0.01%     
==========================================
  Files        6766     6767       +1     
  Lines      139340   139393      +53     
  Branches    39614    39621       +7     
==========================================
+ Hits        51099    51134      +35     
- Misses      88241    88259      +18     
Flag Coverage Δ
api 3.39% <ø> (ø)
api-domains-auth-admin 48.77% <ø> (-0.10%) ⬇️
api-domains-communications 39.96% <ø> (-0.03%) ⬇️
application-system-api 41.62% <ø> (+0.06%) ⬆️
application-template-api-modules 23.72% <ø> (+0.10%) ⬆️
cms 0.43% <ø> (-0.01%) ⬇️
cms-translations 39.08% <ø> (-0.04%) ⬇️
judicial-system-api 18.46% <ø> (-0.12%) ⬇️
judicial-system-backend 54.82% <ø> (-0.05%) ⬇️
services-user-notification 47.13% <ø> (-0.04%) ⬇️

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

see 32 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 621b5bb...147c300. Read the comment docs.

@datadog-island-is
Copy link

Datadog Report

All test runs d4d7942 🔗

10 Total Test Services: 0 Failed, 9 Passed
➡️ Test Sessions change in coverage: 28 no change

Test Services
This report shows up to 10 services
Service Name Failed Known Flaky New Flaky Passed Skipped Total Time Code Coverage Change Test Service View
api 0 0 0 4 0 2.81s 1 no change Link
api-domains-auth-admin 0 0 0 18 0 12.51s 1 no change Link
api-domains-communications 0 0 0 5 0 33.03s 1 no change Link
api-domains-license-service 0 0 0 0 0 535.83ms 1 no change Link
application-system-api 0 0 0 122 2 3m 15.1s 1 no change Link
application-template-api-modules 0 0 0 109 0 2m 1.76s 1 no change Link
cms-translations 0 0 0 3 0 27.42s 1 no change Link
judicial-system-api 0 0 0 57 0 5.99s 1 no change Link
judicial-system-backend 0 0 0 21185 0 21m 8.05s 1 no change Link
services-user-notification 0 0 0 51 0 1m 29.19s 1 no change Link

@thorkellmani thorkellmani added the deprecated:automerge (Disabled) Merge this PR as soon as all checks pass label Sep 30, 2024
@kodiakhq kodiakhq bot merged commit e86af21 into main Sep 30, 2024
17 of 20 checks passed
@kodiakhq kodiakhq bot deleted the fix/educatoin-errors branch September 30, 2024 10:19
thoreyjona pushed a commit that referenced this pull request Oct 2, 2024
* fix/init

* chore: typed

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deploy-feature Deploys features to dev deprecated:automerge (Disabled) Merge this PR as soon as all checks pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants