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(application-system): Possible to go back to hidden screens #17162

Merged
merged 13 commits into from
Dec 12, 2024

Conversation

HjorturJ
Copy link
Member

@HjorturJ HjorturJ commented Dec 6, 2024

Fixing: Possible to go back to a section that should not be navigable

Task link

What

Shouldnt be able to press the "Til baka" button and end up on a section that has its condition be false

Why

Because currently its possible for users to go back to screens they arent meant to see.

Screenshots / Gifs

Attach Screenshots / Gifs to help reviewers understand the scope of the pull request

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

    • Introduced a canGoBack property to enhance navigation capabilities, allowing users to determine if they can return to the previous screen.
    • Added a "Go Back" button that displays conditionally based on the new canGoBack logic.
  • Bug Fixes

    • Improved error handling for validation failures during application updates.
  • Chores

    • Added a utility function canGoBack to streamline navigation checks across screens.

Copy link
Contributor

coderabbitai bot commented Dec 6, 2024

Walkthrough

The changes introduce a new boolean property canGoBack to the ScreenProps and FooterProps interfaces, enhancing navigation control within the application. The Screen component utilizes this property to determine if the user can navigate back, while the ScreenFooter adjusts its rendering logic accordingly. Additionally, a new utility function canGoBack is added to evaluate the user's ability to navigate back based on the current screen index, integrating with existing components without altering their fundamental logic.

Changes

File Path Change Summary
libs/application/ui-shell/src/components/Screen.tsx Added property canGoBack: boolean to ScreenProps, integrated into the Screen component.
libs/application/ui-shell/src/components/ScreenFooter.tsx Added property canGoBack: boolean to FooterProps, modified rendering logic for the "Go Back" button.
libs/application/ui-shell/src/lib/FormShell.tsx Introduced utility function canGoBack to determine navigation capability, integrated into FormShell.
libs/application/ui-shell/src/reducer/reducerUtils.ts Added method canGoBack(screens: FormScreen[], screenIndex: number): boolean to evaluate backward navigation.

Suggested labels

automerge

Suggested reviewers

  • Toti91
  • sigruntg

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 generate docstrings to generate docstrings for this PR. (Experiment)
  • @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

codecov bot commented Dec 6, 2024

Codecov Report

Attention: Patch coverage is 55.55556% with 4 lines in your changes missing coverage. Please review.

Project coverage is 35.73%. Comparing base (04563fd) to head (339cf31).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...s/application/ui-shell/src/reducer/reducerUtils.ts 50.00% 4 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #17162      +/-   ##
==========================================
- Coverage   35.75%   35.73%   -0.02%     
==========================================
  Files        6935     6933       -2     
  Lines      148068   148273     +205     
  Branches    42212    42293      +81     
==========================================
+ Hits        52942    52989      +47     
- Misses      95126    95284     +158     
Flag Coverage Δ
api 3.33% <ø> (ø)
application-system-api 38.75% <ø> (+<0.01%) ⬆️
application-ui-shell 22.50% <55.55%> (+0.02%) ⬆️
judicial-system-web 27.88% <ø> (ø)

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

Files with missing lines Coverage Δ
...ibs/application/ui-shell/src/components/Screen.tsx 42.99% <ø> (ø)
...plication/ui-shell/src/components/ScreenFooter.tsx 26.19% <100.00%> (ø)
libs/application/ui-shell/src/lib/FormShell.tsx 69.44% <ø> (ø)
...s/application/ui-shell/src/reducer/reducerUtils.ts 87.56% <50.00%> (-1.70%) ⬇️

... and 34 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 04563fd...339cf31. Read the comment docs.

@datadog-island-is
Copy link

datadog-island-is bot commented Dec 6, 2024

Datadog Report

All test runs e078190 🔗

4 Total Test Services: 0 Failed, 4 Passed
⬆️ Test Sessions change in coverage: 1 increased (+0.02%), 7 no change

Test Services
Service Name Failed Known Flaky New Flaky Passed Skipped Total Time Code Coverage Change Test Service View
api 0 0 0 4 0 3.07s 1 no change Link
application-system-api 0 0 0 46 0 2m 24.73s 1 no change Link
application-ui-shell 0 0 0 74 0 31.46s 1 increased (+0.02%) Link
judicial-system-web 0 0 0 332 0 1m 16.81s 1 no change Link

Copy link
Member

@Toti91 Toti91 left a comment

Choose a reason for hiding this comment

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

Nice

@HjorturJ HjorturJ marked this pull request as ready for review December 11, 2024 14:52
@HjorturJ HjorturJ requested a review from a team as a code owner December 11, 2024 14:52
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 (2)
libs/application/ui-shell/src/reducer/reducerUtils.ts (1)

184-201: LGTM! Consider optimizing the implementation.

The canGoBack function is well-implemented with clear logic and proper TypeScript typing. However, it could be optimized for better readability and performance.

Consider using Array.prototype.findIndex for a more concise implementation:

 export const canGoBack = (
   screens: FormScreen[],
   screenIndex: number,
 ): boolean => {
   // Check if we're already at the start
   if (screenIndex <= 0) {
     return false
   }
 
-  // Look for any navigable screen behind where we are
-  for (let i = screenIndex - 1; i >= 0; i--) {
-    if (screens[i].isNavigable) {
-      return true
-    }
-  }
-
-  return false
+  // Find the last navigable screen before current index
+  return screens
+    .slice(0, screenIndex)
+    .findIndex((screen) => screen.isNavigable) !== -1
 }
libs/application/ui-shell/src/components/Screen.tsx (1)

79-79: Add JSDoc documentation for the canGoBack prop

To improve reusability and maintainability across different NextJS apps, please add JSDoc documentation explaining the purpose and behavior of this prop.

+  /** Determines if the back navigation should be enabled for this screen */
   canGoBack: boolean
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 5c8c1b9 and 99f3f17.

📒 Files selected for processing (4)
  • libs/application/ui-shell/src/components/Screen.tsx (3 hunks)
  • libs/application/ui-shell/src/components/ScreenFooter.tsx (2 hunks)
  • libs/application/ui-shell/src/lib/FormShell.tsx (2 hunks)
  • libs/application/ui-shell/src/reducer/reducerUtils.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
libs/application/ui-shell/src/components/ScreenFooter.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/application/ui-shell/src/lib/FormShell.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/application/ui-shell/src/components/Screen.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/application/ui-shell/src/reducer/reducerUtils.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 (6)
libs/application/ui-shell/src/components/ScreenFooter.tsx (2)

30-30: LGTM! Clean interface extension.

The addition of canGoBack to FooterProps interface is well-typed and properly integrated with existing navigation-related properties.


72-72: LGTM! Improved navigation control logic.

The canGoBack property is effectively utilized to enhance the navigation control, ensuring that back navigation is properly restricted based on the application state.

Also applies to: 78-78

libs/application/ui-shell/src/lib/FormShell.tsx (2)

28-28: LGTM! Clean import addition.

The canGoBack utility import is properly placed with other reducer-related imports.


146-146: LGTM! Well-integrated prop passing.

The canGoBack prop is properly passed to the Screen component, utilizing the utility function with the correct parameters.

libs/application/ui-shell/src/components/Screen.tsx (2)

Line range hint 421-425: LGTM: Proper integration with ScreenFooter

The canGoBack prop is correctly passed to ScreenFooter alongside other navigation-related props, effectively implementing the navigation control requirement.

✅ Verification successful

Verified: ScreenFooter properly implements canGoBack prop

The canGoBack prop is correctly implemented in the ScreenFooter component:

  • It's properly typed as a boolean in the component's props
  • It's used to control the visibility of the back button through showGoBack = canGoBack && (!isLastScreen || renderLastScreenBackButton)
  • The prop flows correctly from FormShell → Screen → ScreenFooter, with the value determined by the canGoBack utility function
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify ScreenFooter's handling of canGoBack prop
ast-grep --pattern 'const ScreenFooter: FC<$_> = ({ canGoBack, $_ }) => {
  $$$
}'

Length of output: 84


Script:

#!/bin/bash
# Let's try a broader search for ScreenFooter component and its props
rg -A 10 "ScreenFooter.*Props.*=.*{" --type typescript

# Also search for any usage of canGoBack prop in TypeScript files
rg "canGoBack.*=" --type typescript -A 3

Length of output: 248


Script:

#!/bin/bash
# Search for ScreenFooter component definition with fixed regex
rg -A 10 "ScreenFooter.*Props" 

# Search for files containing ScreenFooter
fd ScreenFooter

# Search for canGoBack usage
rg "canGoBack"

Length of output: 1866


111-111: Verify consistent usage of canGoBack across the application system

The addition of this prop affects navigation behavior. Let's verify its implementation across different screens.

✅ Verification successful

The canGoBack prop is properly integrated across the application system

Based on the code analysis:

  1. The canGoBack prop is properly defined in the Screen component's interface
  2. It's correctly implemented in the reducerUtils.ts with a dedicated function to determine navigation state
  3. It's properly passed through the component hierarchy: FormShell -> Screen -> ScreenFooter
  4. The prop controls navigation visibility through showGoBack logic in ScreenFooter
  5. The implementation follows a consistent pattern across the application system
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for Screen component usage to verify canGoBack prop implementation
rg -A 3 "<Screen\s" --type tsx

Length of output: 60


Script:

#!/bin/bash
# Search for Screen component usage with common TypeScript/JavaScript extensions
rg -t ts -t jsx -t tsx "<Screen\s" -A 3

# Also search for Screen imports to understand usage patterns
rg -t ts -t jsx -t tsx "import.*Screen.*from"

Length of output: 145


Script:

#!/bin/bash
# Search for Screen component usage and imports using ripgrep without file type filters
rg "<Screen\s" -A 3

# Search for Screen imports
rg "import.*Screen.*from"

# Find all potential Screen-related files
fd -e ts -e tsx -e js -e jsx Screen

Length of output: 44751


Script:

#!/bin/bash
# Let's examine the Screen component implementation and its usage of canGoBack
ast-grep --pattern 'interface $_Props {
  $$$
  canGoBack$_
  $$$
}'

# Also check the actual Screen component implementation
ast-grep --pattern 'const Screen = ({ $$$, canGoBack, $$$ }: $_Props) => {
  $$$
}'

Length of output: 156


Script:

#!/bin/bash
# Let's examine the Screen component file content
cat libs/application/ui-shell/src/components/Screen.tsx

# Also check for any direct references to canGoBack in the codebase
rg "canGoBack" -A 2 -B 2

Length of output: 16444

@HjorturJ HjorturJ added the automerge Merge this PR as soon as all checks pass label Dec 12, 2024
@kodiakhq kodiakhq bot merged commit 4241fe5 into main Dec 12, 2024
45 checks passed
@kodiakhq kodiakhq bot deleted the fix/back-to-hidden-section branch December 12, 2024 22:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Merge this PR as soon as all checks pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants