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

Changes to supervisor start flow #1654

Merged
merged 1 commit into from
Oct 24, 2024
Merged

Changes to supervisor start flow #1654

merged 1 commit into from
Oct 24, 2024

Conversation

nipunarora-eGov
Copy link
Contributor

@nipunarora-eGov nipunarora-eGov commented Oct 23, 2024

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced ActivityHomeCard to support click actions with a new onClickCard prop for improved interactivity.
    • Introduced optionKey in ChooseActivity for better identification of activity actions.
    • Added asynchronous updatePlan function to facilitate plan updates based on user interactions.
  • Improvements

    • Conditional rendering of module names in MicroplanCard based on user roles.
    • Enhanced error handling in ChooseActivity for improved user experience during updates.
  • Bug Fixes

    • Improved control flow and URL parameter handling in various components.

@nipunarora-eGov nipunarora-eGov requested a review from a team as a code owner October 23, 2024 19:16
Copy link
Contributor

coderabbitai bot commented Oct 23, 2024

📝 Walkthrough

Walkthrough

The pull request introduces several modifications across multiple components in the microplan module. Key changes include the addition of an onClickCard prop to the ActivityHomeCard component, enhancing its interactivity. The MicroplanCard component now conditionally displays module names based on user roles. The createUpdatePlanProject function has been updated with new logic for handling various cases, improving control flow and error handling. Additionally, the ChooseActivity component has been enhanced with an optionKey for activity cards and new functions for updating plans and handling card clicks.

Changes

File Change Summary
.../ActivityCard.js Added onClickCard prop to ActivityHomeCard, enabling callback execution on card click.
.../MicroplanCard.js Introduced userInfo and isSupervisorLoggedIn to conditionally render module names based on roles.
.../createUpdatePlanProject.js Updated createUpdatePlanProject function with new logic for handling various cases in the switch statement.
.../ChooseActivity.js Added optionKey to activity cards, introduced updatePlan and onClickCard functions for handling card interactions.

Possibly related PRs

🐰 In the meadow, we hop and play,
New cards to click, hip-hip-hooray!
With roles and plans, we dance around,
In our micro world, joy is found!
So click away, let actions flow,
A rabbit's cheer for changes that glow! 🌼


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

🧹 Outside diff range comments (2)
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/ActivityCard.js (1)

Line range hint 12-36: Consider extracting styles and improving grid responsiveness.

While the component structure is good, there are some improvements that could enhance maintainability and user experience:

  1. Move inline styles to CSS modules
  2. Enhance grid layout for better responsiveness
  3. Consider adding aria-labels for accessibility

Example implementation:

+ import styles from './ActivityCard.module.css'
  // ...
- <Card className="fsm" style={{ backgroundColor: "transparent", boxShadow: "none", paddingTop: "0" }}>
+ <Card className={`fsm ${styles.transparentCard}`}>
  // ...
- <div style={{ display: "grid", gridTemplateColumns: "33.3% 33.3% 33.3%", textAlign: "-webkit-center", gap: "10px" }}>
+ <div className={styles.cardGrid}>
  // ...
  <Card
    key={i.name}
-   style={{ minWidth: "100px", cursor: i.disable ? "not-allowed" : "pointer", opacity: i.disable ? 0.6 : 1, margin: "10px" }}
+   className={`${styles.actionCard} ${i.disable ? styles.disabled : ''}`}
+   aria-disabled={i.disable}
+   aria-label={t(i.name)}

Create a CSS module file:

.transparentCard {
  background-color: transparent;
  box-shadow: none;
  padding-top: 0;
}

.cardGrid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  text-align: center;
}

.actionCard {
  min-width: 100px;
  margin: 10px;
  cursor: pointer;
}

.disabled {
  cursor: not-allowed;
  opacity: 0.6;
}
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/MicroplanCard.js (1)

Line range hint 5-13: Consider moving ROLES configuration to a central location

The ROLES configuration should be maintained in a central configuration file rather than being defined within this component. This would:

  • Improve maintainability
  • Enable reuse across components
  • Make role management more consistent

Consider:

  1. Moving ROLES to a separate configuration file (e.g., config/roles.js)
  2. Creating a custom hook for role-based checks (e.g., useUserRoles)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between a0eb114 and ac758c4.

📒 Files selected for processing (4)
  • health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/ActivityCard.js (2 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/MicroplanCard.js (2 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/hooks/services/createUpdatePlanProject.js (4 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/pages/employee/ChooseActivity.js (1 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/ActivityCard.js (1)

Pattern **/*.js: check

health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/MicroplanCard.js (1)

Pattern **/*.js: check

health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/hooks/services/createUpdatePlanProject.js (1)

Pattern **/*.js: check

health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/pages/employee/ChooseActivity.js (1)

Pattern **/*.js: check

📓 Learnings (1)
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/ActivityCard.js (1)
Learnt from: Ramkrishna-egov
PR: egovernments/DIGIT-Frontend#1545
File: health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/ActivityCard.js:30-35
Timestamp: 2024-10-17T12:00:51.749Z
Learning: In our codebase, the 'Card' component is commonly used by passing children via the 'children' prop.
🔇 Additional comments (7)
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/ActivityCard.js (1)

6-6: LGTM! Props destructuring follows best practices.

The implementation correctly provides a default empty function for onClickCard and uses rest operator for remaining props.

health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/MicroplanCard.js (1)

42-42: Verify translation key usage and role-checking patterns

Let's verify the consistency of translation keys and role-checking patterns across the codebase.

✅ Verification successful

Based on the results, I can now generate the final response since we have clear evidence about the usage of these translation keys and role-checking patterns.

Translation keys and role-checking implementation are properly scoped

The verification shows that:

  • The translation keys MICROPLAN_MODULE_PROCESS and MICROPLAN_MODULE_SETUP are only used in this specific component, indicating they are properly scoped for this feature.
  • The supervisor role check (isSupervisorLoggedIn) is consistently implemented within the same file, along with proper role-based link generation using ROLES.SUPERVISOR.
  • The conditional rendering based on the supervisor role is self-contained within this component and follows a clear pattern.
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for translation key usage
echo "Checking translation key usage..."
rg "MICROPLAN_MODULE_PROCESS|MICROPLAN_MODULE_SETUP" -t js

# Check for similar role-checking patterns
echo "Checking role-checking patterns..."
rg "isSupervisorLoggedIn|ROLES\.SUPERVISOR" -t js

Length of output: 1014

health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/pages/employee/ChooseActivity.js (2)

131-131: Verify onClickCard prop handling in ActivityHomeCard.

The addition of onClickCard prop looks good, but we should verify its implementation in the ActivityHomeCard component.

Let's verify the prop handling:

#!/bin/bash
# Description: Check ActivityHomeCard implementation
# Expected: Find onClickCard prop handling in ActivityCard component

ast-grep --pattern 'const ActivityHomeCard = ({ $$$, onClickCard, $$$ }) => {
  $$$
}'

69-98: LGTM! Verify role-status combinations.

The addition of optionKeys and role-based disable conditions looks good. The status checks are appropriately mapped to each activity's workflow stage.

Let's verify the role-status combinations are correctly configured:

✅ Verification successful

Let me try a different approach to verify the role configurations and workflow states.


Let me try one final verification to check the isCardDisabled function implementation to ensure the role-status combinations are properly validated.


Based on the gathered evidence, I can now provide a final response:

Role-status combinations are correctly implemented

The verification shows that:

  1. The workflow states (EXECUTION_TO_BE_DONE, CENSUS_DATA_APPROVAL_IN_PROGRESS, etc.) are properly defined in the UI configurations and consistently used across the application.
  2. The isCardDisabled function implementation correctly validates:
    • User roles against the required roles for each action
    • Current plan status against the valid statuses for each action
  3. The role-status combinations in the activity cards align with the workflow stages defined in UICustomizations.js

The disable logic is robust and follows proper role-based access control patterns:

  • Population data approval requires POPULATION_DATA_APPROVER or ROOT_POPULATION_DATA_APPROVER roles during EXECUTION_TO_BE_DONE or CENSUS_DATA_APPROVAL_IN_PROGRESS states
  • Facility assignment requires FACILITY_CATCHMENT_MAPPER or ROOT_FACILITY_CATCHMENT_MAPPER roles during CENSUS_DATA_APPROVED state
  • Plan estimation approval requires PLAN_ESTIMATION_APPROVER or ROOT_PLAN_ESTIMATION_APPROVER roles during RESOURCE_ESTIMATION_IN_PROGRESS state
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify role definitions exist in MDMS
# Expected: Find role definitions matching those used in the code

rg -A 2 '"code":.*("POPULATION_DATA_APPROVER"|"ROOT_POPULATION_DATA_APPROVER"|"FACILITY_CATCHMENT_MAPPER"|"ROOT_FACILITY_CATCHMENT_MAPPER"|"PLAN_ESTIMATION_APPROVER"|"ROOT_PLAN_ESTIMATION_APPROVER"|"MICROPLAN_VIEWER")'

Length of output: 182


Script:

#!/bin/bash
# Search for role definitions in JSON files
fd -e json -x rg -l "POPULATION_DATA_APPROVER|ROOT_POPULATION_DATA_APPROVER|FACILITY_CATCHMENT_MAPPER|ROOT_FACILITY_CATCHMENT_MAPPER|PLAN_ESTIMATION_APPROVER|ROOT_PLAN_ESTIMATION_APPROVER|MICROPLAN_VIEWER" {}

# Search for workflow states in the codebase
rg "EXECUTION_TO_BE_DONE|CENSUS_DATA_APPROVAL_IN_PROGRESS|CENSUS_DATA_APPROVED|RESOURCE_ESTIMATION_IN_PROGRESS" -A 2

Length of output: 7620


Script:

#!/bin/bash
# Search for isCardDisabled function implementation
ast-grep --pattern 'const isCardDisabled = ($$$) => {
  $$$
}'

# Also search with ripgrep as fallback
rg "function isCardDisabled|const isCardDisabled" -A 10

Length of output: 4292

health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/hooks/services/createUpdatePlanProject.js (3)

310-311: Verify that setting URL parameters to null removes them

At lines 310-311, you are updating URL parameters isLastVerticalStep and internalKey by setting them to null. Please confirm that setting these parameters to null effectively removes them from the URL or behaves as intended, ensuring no unintended null values are introduced in the query string.


387-388: Verify that setting URL parameters to null removes them

At lines 387-388, you set isFormulaLastVerticalStep and formulaInternalKey in the URL parameters to null. Please ensure that this action removes the parameters from the URL as expected and does not result in null strings appearing in the URL.


544-545: Verify that setting URL parameters to null removes them

At lines 544-545, you again set isLastVerticalStep and internalKey URL parameters to null. Please confirm that this effectively removes these parameters from the URL and doesn't introduce unintended behavior due to null values.

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.

2 participants