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(app): update UI and fix bugs for credit hours and assignment restrictions #3055

Conversation

FussuChalice
Copy link
Contributor

Description

  • Added "Report credit hours" field with a tooltip for inactive publishers: Only available for pioneers.
  • Fixed bug where parent "Ministry" field remained active when child items were inactive.
  • Updated UI to disable certain assignments for female persons, with tooltip: Applies only to brothers.

Fixes # (issue)

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • Any dependent changes have been merged and published in downstream modules

@rhahao
Copy link
Member

rhahao commented Nov 27, 2024

Task linked: CU-86c11k555 Add tooltips – Person page

Copy link

vercel bot commented Nov 27, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
organized-app ✅ Ready (Inspect) Visit Preview Nov 28, 2024 8:57pm

Copy link
Contributor

coderabbitai bot commented Nov 27, 2024

Important

Review skipped

Review was skipped due to path filters

⛔ Files ignored due to path filters (2)
  • package-lock.json is excluded by !**/package-lock.json, !**/*.json
  • src/locales/en/ministry.json is excluded by !**/*.json

CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including **/dist/** will override the default block on the dist directory, by removing the pattern from both the lists.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The pull request modifies the AssignmentGroup component in src/features/persons/assignment_group/index.tsx by integrating a Tooltip component and enhancing the logic related to assignment conditions. The useAssignmentGroup hook now returns additional boolean variables: isMinistryDisabled and isDisabledByGender, which are used to determine if assignments should be disabled based on ministry and gender criteria. The rendering logic is updated to wrap the AssignmentsCheckList component within the Tooltip, which displays when either condition is met.

Changes

File Path Change Summary
src/features/persons/assignment_group/index.tsx - Added Tooltip component.
- Integrated useAppTranslation hook.
- Introduced isMinistryDisabled and isDisabledByGender variables.
- Added getTooltipsForAssignmentTitles method.
- Modified rendering logic to wrap AssignmentsCheckList in Tooltip and updated disabled prop.
src/features/persons/assignment_group/useAssignmentGroup.tsx - Added methods: isMinistryDisabled, isDisabledByGender, and getTooltipsForAssignmentTitles.
- Updated return statement to include new methods.

Possibly related PRs

Suggested reviewers

  • rhahao

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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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: 0

🧹 Outside diff range and nitpick comments (1)
src/features/persons/assignment_group/index.tsx (1)

25-28: Consider extracting string literals and improving readability

While the logic is correct, there are a few potential improvements:

  1. Extract 'ministry' and 'applyFieldMinistryPart' as constants to avoid magic strings
  2. Consider using a positive condition for gender check for better readability (e.g., isMale or isFemale)
+const MINISTRY_ID = 'ministry';
+const FIELD_MINISTRY_PART_ID = 'applyFieldMinistryPart';

-  const isMinistryDisabled: boolean =
-    id == 'ministry' && checkAssignmentDisabled(items[0].code);
+  const isMinistryDisabled: boolean =
+    id === MINISTRY_ID && checkAssignmentDisabled(items[0].code);

-  const isDisabledByGender: boolean = !male && id != 'applyFieldMinistryPart';
+  const isFemale = !male;
+  const isDisabledByGender: boolean = isFemale && id !== FIELD_MINISTRY_PART_ID;
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between de72f12 and 5041b25.

⛔ Files ignored due to path filters (3)
  • package-lock.json is excluded by !**/package-lock.json, !**/*.json
  • src/locales/en/general.json is excluded by !**/*.json
  • src/locales/en/ministry.json is excluded by !**/*.json
📒 Files selected for processing (1)
  • src/features/persons/assignment_group/index.tsx (2 hunks)
🔇 Additional comments (5)
src/features/persons/assignment_group/index.tsx (5)

5-6: LGTM: Import statements are properly organized

The new imports follow the project's conventions and are appropriately placed.


23-24: LGTM: Translation hook is properly initialized

The translation hook is correctly set up for internationalizing the tooltip messages.


41-78: Consider accessibility improvements for tooltip

While the tooltip implementation is functional, consider adding ARIA attributes for better accessibility:

   <Tooltip
     followCursor
     title={getTooltipTitle()}
     show={isMinistryDisabled || isDisabledByGender}
+    aria-label={getTooltipTitle()}
+    role="tooltip"
   >

Also, verify that the tooltip is keyboard accessible when users navigate through the assignments.


30-38: Verify translation key availability

The tooltip messages use translation keys that need to be verified in the translation files.

✅ Verification successful

Translation keys are properly defined

Both translation keys tr_onlyAvailableForPioneers and tr_appliesOnlyToBrothers are correctly defined in the English locale files:

  • tr_appliesOnlyToBrothers in src/locales/en/general.json
  • tr_onlyAvailableForPioneers in src/locales/en/ministry.json
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for the translation keys in the codebase
echo "Searching for translation keys..."
rg "tr_onlyAvailableForPioneers|tr_appliesOnlyToBrothers" --type json

Length of output: 325


Line range hint 1-81: Verify completeness of PR objectives

The PR description mentions a "Report credit hours" field with a tooltip for inactive publishers who are pioneers, but this feature is not visible in the current file. Please verify if this feature is implemented in another file or if it's missing from the implementation.

coderabbitai[bot]
coderabbitai bot previously approved these changes Nov 27, 2024
Copy link
Member

Choose a reason for hiding this comment

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

Hi @FussuChalice, could you please move the added logic inside the hooks for this component? Thank you.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, of course. No problem.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

inside the hooks

What do you mean by this?

Copy link
Member

Choose a reason for hiding this comment

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

@FussuChalice, I mean to move theme inside useAssignmentGroup.tsx file. Thanks.

Copy link
Member

Choose a reason for hiding this comment

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

@FussuChalice, I mean to move theme inside useAssignmentGroup.tsx file. Thanks.

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 (2)
src/features/persons/assignment_group/useAssignmentGroup.tsx (2)

56-58: Improve function naming and documentation

The current name isDisabledByGender doesn't fully convey that it specifically checks for non-male restrictions with a special case for field ministry.

Consider renaming and adding documentation:

+ /**
+  * Checks if an assignment should be disabled for non-male persons
+  * @param id - The assignment ID
+  * @returns true if the assignment should be disabled (except for field ministry)
+  */
- const isDisabledByGender = (id: string) => {
+ const isRestrictedForNonMalePersons = (id: string) => {
    return !male && id !== 'applyFieldMinistryPart';
  };

60-71: Enhance type safety and maintainability

Consider extracting translation keys to constants and adding return type annotation.

+ const TRANSLATION_KEYS = {
+   PIONEER_ONLY: 'tr_onlyAvailableForPioneers',
+   BROTHERS_ONLY: 'tr_appliesOnlyToBrothers'
+ } as const;

  const getTooltipsForAssignmentTitles = (
    id: string,
    items: { code: AssignmentCode }[]
-  ) => {
+  ): string => {
    if (isMinistryDisabled(id, items)) {
-     return t('tr_onlyAvailableForPioneers');
+     return t(TRANSLATION_KEYS.PIONEER_ONLY);
    }
    if (isDisabledByGender(id)) {
-     return t('tr_appliesOnlyToBrothers');
+     return t(TRANSLATION_KEYS.BROTHERS_ONLY);
    }
    return '';
  };
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 5041b25 and a72181e.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json, !**/*.json
📒 Files selected for processing (2)
  • src/features/persons/assignment_group/index.tsx (2 hunks)
  • src/features/persons/assignment_group/useAssignmentGroup.tsx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/features/persons/assignment_group/index.tsx
🔇 Additional comments (3)
src/features/persons/assignment_group/useAssignmentGroup.tsx (3)

2-2: LGTM: Translation setup is properly implemented

The translation hook is correctly imported and initialized.

Also applies to: 9-9


73-79: LGTM: Clean interface export

The return object properly exposes all necessary functions in a logical order.


Line range hint 1-79: Verify alignment with business requirements

The implementation introduces gender-based and ministry-based restrictions. Please ensure these align with the organization's policies and requirements.

✅ Verification successful

Let me gather more specific information about the business requirements by searching for related test files and implementation details.


Let me try one more search with corrected commands to find the business requirements.


Based on the extensive search results, I can now verify the business requirements. The translations and implementation across multiple languages consistently show that:

  1. Gender-based restrictions are a standard requirement, with specific assignments limited to males ("brothers") as shown by the tooltip message "tr_appliesOnlyToBrothers"
  2. Ministry-based restrictions are tied to publisher and pioneer roles, with certain assignments requiring pioneer status as shown by the tooltip "tr_onlyAvailableForPioneers"
  3. The restrictions are part of the core functionality across all supported languages and regions
  4. The implementation aligns with the form S-89 requirements and service committee guidelines found in the localization files

Let me verify one final aspect about the assignment codes:


Based on the extensive code analysis, I can now provide a definitive verification of the gender and ministry-based restrictions:

The implementation aligns with established business requirements

The code shows clear evidence that:

  1. Gender restrictions are properly implemented:
  • Male-only assignments are explicitly defined with maleOnly: true flag
  • Brother-specific assignments are grouped in BROTHER_ASSIGNMENT constant
  • Female-accessible assignments are clearly defined for ministry roles like MM_StartingConversation, MM_FollowingUp, etc.
  1. Ministry-based restrictions follow organizational policies:
  • Pioneer-specific assignments require proper status checks (e.g., personIsFR)
  • Publisher status verification for ministry assignments
  • Proper handling of ministry hours credit (MINISTRY_HOURS_CREDIT) based on role
  1. The implementation is consistent across all supported languages and regions as shown in the localization files, with proper tooltips and error messages for restricted assignments.

The code structure and validation logic demonstrate a robust implementation that correctly enforces these organizational requirements while maintaining flexibility for authorized roles.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for related test files to verify business requirements
fd -e test.tsx -e spec.tsx -e test.ts -e spec.ts . | grep -i "assignment"

# Search for documentation of these restrictions
fd -e md . | xargs rg -i "gender|ministry|restriction"

Length of output: 1580


Script:

#!/bin/bash
# Search for test files specifically related to assignment groups and gender/ministry restrictions
ast-grep --pattern 'describe($_, () => { $$$ checkAssignmentDisabled $$$ })'

# Search for related implementation files to understand the business logic
rg -l "AssignmentCode" --type ts --type tsx

# Look for any comments or documentation in the implementation files
rg -i "gender|ministry|restriction" --type ts --type tsx -C 2

Length of output: 242


Script:

#!/bin/bash
# Search for files containing AssignmentCode
rg -l "AssignmentCode"

# Search for test files and implementation files related to assignments with context
rg -i "gender|ministry|restriction" -C 2

# Look for any enum or type definitions related to assignments
ast-grep --pattern 'enum AssignmentCode {
  $$$
}'

Length of output: 113970


Script:

# Look for assignment code definitions
rg "AssignmentCode\." -B 2 -A 2

# Search for any configuration or validation files related to assignments
fd -e ts -e tsx -e json | rg -l "assignment.*config|assignment.*valid"

Length of output: 92954

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@FussuChalice FussuChalice requested a review from rhahao November 28, 2024 07:04
coderabbitai[bot]
coderabbitai bot previously approved these changes Nov 28, 2024
@@ -122,6 +122,7 @@
"tr_pioneers": "Pioneers",
"tr_reminderPublisherReport": "Submit your monthly field service report",
"tr_reminderPublisherReportDesc": "It should be submitted to the secretary no later than the 6th day of the month.",
"tr_reminderBranchReport": "The Congregation Field Service and Meeting Attendance (S-1) report hasn’t been submitted yet",
"tr_reminderBranchReportDesc": "It should be submitted to the branch office no later than the 20th day of the month."
"tr_reminderBranchReport": "The Congregation Field Service and Meeting Attendance (S-1) report is not yet ready",
Copy link
Member

Choose a reason for hiding this comment

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

@FussuChalice: one last change please: could you update your local file in this line? It has been changed but it seems like yours is still the old one and this will overwrite the last update if not changed. Thanks.

@rhahao rhahao merged commit d3eeab6 into sws2apps:main Nov 29, 2024
10 checks passed
Copy link

cypress bot commented Nov 29, 2024

organized-app    Run #1659

Run Properties:  status check passed Passed #1659  •  git commit d3eeab6722: feat(app): update UI and fix bugs for credit hours and assignment restrictions
Project organized-app
Branch Review main
Run status status check passed Passed #1659
Run duration 00m 17s
Commit git commit d3eeab6722: feat(app): update UI and fix bugs for credit hours and assignment restrictions
Committer Max Makaluk
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 0
Tests that did not run due to a developer annotating a test with .skip  Pending 0
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 1
View all changes introduced in this branch ↗︎

@rhahao
Copy link
Member

rhahao commented Nov 30, 2024

🎉 This PR is included in version 2.130.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

2 participants