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): TableRepeater cancel option #16929

Merged
merged 3 commits into from
Nov 19, 2024

Conversation

Toti91
Copy link
Member

@Toti91 Toti91 commented Nov 18, 2024

TableRepeater cancel option

Attach a link to issue if relevant

What

Add an option to cancel active insertion in TableRepeater

Also add better support for nationalIdWithName in repeater, by providing default table header and row support for name and nationalId

Why

Better UX and DX

Screenshots / Gifs

image

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

Release Notes

  • New Features

    • Introduced new messages for localization: buttonCancel, nationalId, and name.
    • Added cancelButtonText property to enhance the TableRepeaterField interface.
    • Implemented a cancel button in the UI for better item management.
  • Enhancements

    • Improved table header and row generation with new utility functions.
    • Enhanced user interface by grouping the cancel and save buttons together.

These updates aim to improve usability and localization within the application.

@Toti91 Toti91 added the deprecated:automerge (Disabled) Merge this PR as soon as all checks pass label Nov 18, 2024
@Toti91 Toti91 requested a review from a team as a code owner November 18, 2024 17:19
Copy link
Contributor

coderabbitai bot commented Nov 18, 2024

Caution

Review failed

The pull request is closed.

Walkthrough

This pull request introduces new message definitions for localization in the messages.ts file, adds a cancelButtonText property to the TableRepeaterField interface, and enhances the TableRepeaterFormField component. The component now includes a cancel button, which utilizes the newly defined messages. Utility functions for generating table headers and rows are also added, improving the structure and usability of the table within the form.

Changes

File Change Summary
libs/application/core/src/lib/messages.ts Added new messages: buttonCancel, nationalId, and name to coreMessages with respective IDs, default messages, and descriptions.
libs/application/types/src/lib/Fields.ts Added new property cancelButtonText?: StaticText to the TableRepeaterField interface.
libs/application/ui-fields/src/lib/TableRepeaterFormField/TableRepeaterFormField.tsx Introduced handleCancelItem method, added cancelButtonText variable, and modified button layout to include a cancel button using the new text.
libs/application/ui-fields/src/lib/TableRepeaterFormField/utils.ts Added buildDefaultTableHeader and buildDefaultTableRows functions for structured table header and row generation.

Possibly related PRs

Suggested reviewers

  • Toti91
  • kksteini
  • jonnigs

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

codecov bot commented Nov 18, 2024

Codecov Report

Attention: Patch coverage is 10.52632% with 17 lines in your changes missing coverage. Please review.

Project coverage is 36.46%. Comparing base (d743d2e) to head (6888a7c).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
.../ui-fields/src/lib/TableRepeaterFormField/utils.ts 18.18% 9 Missing ⚠️
.../TableRepeaterFormField/TableRepeaterFormField.tsx 0.00% 8 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main   #16929   +/-   ##
=======================================
  Coverage   36.46%   36.46%           
=======================================
  Files        6903     6903           
  Lines      144583   144555   -28     
  Branches    41283    41285    +2     
=======================================
- Hits        52718    52716    -2     
+ Misses      91865    91839   -26     
Flag Coverage Δ
air-discount-scheme-web 0.00% <ø> (ø)
api 3.34% <ø> (ø)
application-api-files 62.35% <ø> (ø)
application-core 70.98% <ø> (ø)
application-system-api 41.02% <ø> (ø)
application-template-api-modules 27.72% <ø> (+0.01%) ⬆️
application-templates-accident-notification 28.98% <ø> (ø)
application-templates-car-recycling 3.12% <ø> (ø)
application-templates-criminal-record 25.87% <ø> (ø)
application-templates-driving-license 18.14% <ø> (ø)
application-templates-estate 12.14% <ø> (ø)
application-templates-example-payment 24.80% <ø> (ø)
application-templates-financial-aid 15.48% <ø> (ø)
application-templates-general-petition 23.07% <ø> (ø)
application-templates-inheritance-report 6.52% <ø> (ø)
application-templates-marriage-conditions 15.04% <ø> (ø)
application-templates-mortgage-certificate 43.36% <ø> (ø)
application-templates-parental-leave 29.86% <ø> (ø)
application-types 6.60% <ø> (ø)
application-ui-components 1.27% <ø> (ø)
application-ui-shell 20.82% <10.52%> (-0.02%) ⬇️
clients-charge-fjs-v2 24.11% <ø> (ø)
services-endorsements-api 53.21% <ø> (ø)

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

Files with missing lines Coverage Δ
libs/application/core/src/lib/messages.ts 100.00% <ø> (ø)
libs/application/types/src/lib/Fields.ts 100.00% <ø> (ø)
.../TableRepeaterFormField/TableRepeaterFormField.tsx 1.26% <0.00%> (-0.09%) ⬇️
.../ui-fields/src/lib/TableRepeaterFormField/utils.ts 15.38% <18.18%> (+2.88%) ⬆️

... and 8 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 d743d2e...6888a7c. Read the comment docs.

---- 🚨 Try these New Features:

@datadog-island-is
Copy link

datadog-island-is bot commented Nov 18, 2024

Datadog Report

All test runs 815da17 🔗

22 Total Test Services: 0 Failed, 21 Passed
➡️ Test Sessions change in coverage: 94 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
air-discount-scheme-web 0 0 0 2 0 7.56s 1 no change Link
api 0 0 0 4 0 2.73s 1 no change Link
application-api-files 0 0 0 2 0 4.62s 1 no change Link
application-core 0 0 0 97 0 18.49s 1 no change Link
application-system-api 0 0 0 112 2 3m 16.14s 1 no change Link
application-template-api-modules 0 0 0 116 0 2m 21.38s 1 no change Link
application-templates-accident-notification 0 0 0 148 0 19.35s 1 no change Link
application-templates-criminal-record 0 0 0 2 0 10.65s 1 no change Link
application-templates-driving-license 0 0 0 13 0 16.13s 1 no change Link
application-templates-example-payment 0 0 0 2 0 11.15s 1 no change Link

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 (7)
libs/application/ui-fields/src/lib/TableRepeaterFormField/utils.ts (3)

35-35: Consider enhancing error handling and function naming

While the added truthiness check improves safety, consider:

  1. Adding comprehensive error handling for edge cases
  2. Renaming the function to better reflect its specific handling of nationalIdWithName
-export const handleCustomMappedValues = <T>(
+export const handleNationalIdWithNameValues = <T>(
   tableItems: Array<Item>,
   values: Array<Value<T>>,
 ) => {
+  if (!tableItems?.length) {
+    return []
+  }
   // Rest of the function...
 }

45-54: Consider adding input validation and improving clarity

The function is well-structured but could benefit from:

  1. Input validation for the items array
  2. A named constant for the flatten depth
  3. JSDoc documentation explaining the special handling of nationalIdWithName
+const FLATTEN_DEPTH = 2
+
+/**
+ * Builds table headers with special handling for nationalIdWithName components
+ * @param items Array of TableRepeaterItem to generate headers from
+ * @returns Array of header labels
+ */
 export const buildDefaultTableHeader = (items: Array<TableRepeaterItem>) => {
+  if (!items?.length) {
+    return []
+  }
   return items
     .map((item) =>
       item.component === 'nationalIdWithName'
         ? [coreMessages.name, coreMessages.nationalId]
         : item.label,
     )
-    .flat(2)
+    .flat(FLATTEN_DEPTH)
 }

Line range hint 1-65: Add unit tests for the new utility functions

As mentioned in the PR objectives, tests are missing. These utility functions are critical for table functionality and should be thoroughly tested.

Would you like me to help generate unit tests for these utility functions? I can create test cases covering:

  • Normal cases for both header and row generation
  • Special handling of nationalIdWithName components
  • Edge cases and error handling
libs/application/ui-fields/src/lib/TableRepeaterFormField/TableRepeaterFormField.tsx (3)

97-101: Consider adding a confirmation dialog.

While the cancel functionality is correctly implemented, consider adding a confirmation dialog to prevent accidental data loss when canceling an active insertion.

  const handleCancelItem = (index: number) => {
+   if (window.confirm(formatText(confirmCancelMessage, application, formatMessage))) {
      setActiveIndex(-1)
      remove(index)
+   }
  }

252-269: Fix typo in justifyContent prop.

The button layout looks good, but there's a typo in the justifyContent prop value.

-<Box display="flex" alignItems="center" justifyContent="flexEnd">
+<Box display="flex" alignItems="center" justifyContent="flex-end">

Line range hint 1-297: Add tests for the new cancel functionality.

The PR objectives mention that tests haven't been added yet. Please add tests to verify:

  1. Cancel button visibility and functionality
  2. State management during cancel operation
  3. Integration with nationalIdWithName feature

Would you like me to help create a test suite for these scenarios?

libs/application/types/src/lib/Fields.ts (1)

627-627: LGTM! Consider adding JSDoc comments.

The addition of the optional cancelButtonText property is well-typed and properly integrated with the existing interface. The change aligns perfectly with the PR objectives to add a cancel option for active insertions.

Consider adding JSDoc comments to document the purpose and usage of this property:

+ /** Text to display on the cancel button for active insertions */
  cancelButtonText?: StaticText
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 6e102a0 and a3729da.

📒 Files selected for processing (4)
  • libs/application/core/src/lib/messages.ts (2 hunks)
  • libs/application/types/src/lib/Fields.ts (1 hunks)
  • libs/application/ui-fields/src/lib/TableRepeaterFormField/TableRepeaterFormField.tsx (5 hunks)
  • libs/application/ui-fields/src/lib/TableRepeaterFormField/utils.ts (3 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
libs/application/core/src/lib/messages.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."
libs/application/types/src/lib/Fields.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."
libs/application/ui-fields/src/lib/TableRepeaterFormField/TableRepeaterFormField.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-fields/src/lib/TableRepeaterFormField/utils.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-fields/src/lib/TableRepeaterFormField/utils.ts (1)

Line range hint 1-7: LGTM! Types and imports are well-structured

The type definitions and imports follow TypeScript best practices and support effective tree-shaking.

libs/application/ui-fields/src/lib/TableRepeaterFormField/TableRepeaterFormField.tsx (3)

25-29: LGTM! Well-structured imports.

The new utility imports follow best practices for modularity and tree-shaking support.


54-54: LGTM! Well-defined prop with default value.

The cancelButtonText prop is properly typed and defaults to a core message, maintaining backward compatibility.


79-80: Verify default table implementations for nationalIdWithName.

The fallback mechanism looks good, but let's verify the utility functions properly handle the nationalIdWithName case.

✅ Verification successful

Default table implementations correctly handle nationalIdWithName

The utility functions properly handle the nationalIdWithName case:

  • buildDefaultTableHeader splits it into name and nationalId columns using coreMessages
  • buildDefaultTableRows correctly maps the component to corresponding 'name' and 'nationalId' fields
  • Special case handling is properly documented in the code
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of buildDefaultTableHeader and buildDefaultTableRows for nationalIdWithName

# Search for the utility function implementations
ast-grep --pattern 'export const buildDefaultTableHeader = $_' -f ts,tsx
ast-grep --pattern 'export const buildDefaultTableRows = $_' -f ts,tsx

# Search for nationalIdWithName usage
rg -A 5 'nationalIdWithName' -t ts -t tsx

Length of output: 573


Script:

#!/bin/bash
# Search for the utility function implementations
ast-grep --pattern 'export const buildDefaultTableHeader'
ast-grep --pattern 'export const buildDefaultTableRows'

# Search for nationalIdWithName usage with ripgrep
rg "nationalIdWithName"

# Find relevant TypeScript/TSX files
fd "\.(ts|tsx)$" libs/application/ui-fields/src/lib/TableRepeaterFormField/

Length of output: 3758

libs/application/core/src/lib/messages.ts (2)

44-48: LGTM! Cancel button message follows consistent pattern.

The buttonCancel message is well-structured and aligns with the PR objective of adding a cancel option.


144-153: LGTM! National ID and name messages support the nationalIdWithName feature.

The nationalId and name messages are well-structured and align with the PR objective of improving support for the nationalIdWithName feature.

Copy link
Member

@obmagnusson obmagnusson left a comment

Choose a reason for hiding this comment

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

Nice one!

@kodiakhq kodiakhq bot merged commit 910627c into main Nov 19, 2024
88 checks passed
@kodiakhq kodiakhq bot deleted the fix/table-repeater-cancel branch November 19, 2024 10:30
jonnigs pushed a commit that referenced this pull request Nov 26, 2024
* cancel active item functionality

* setup default row and header support for nationalidWithname

---------

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