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(regulations-admin): Update strings, fix impactname #17041

Merged
merged 3 commits into from
Nov 27, 2024

Conversation

thordurhhh
Copy link
Member

@thordurhhh thordurhhh commented Nov 27, 2024

What

Update strings, fix impactname

Why

Bugfixes 🐛
and
Improvement 🧹

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 new prop asBase in the ReferenceText component for enhanced draft type rendering.
    • Added a new message descriptor for effective date guidance in regulatory changes.
  • Improvements

    • Enhanced state management in the EditChange and ImpactDate components for better user experience.
    • Updated labels in the ReferenceText component to clarify terminology between amending and base regulations.
  • User Interface

    • Improved context and control flow related to custom date selection in the ImpactDate component.

@thordurhhh thordurhhh added the automerge Merge this PR as soon as all checks pass label Nov 27, 2024
@thordurhhh thordurhhh requested a review from a team as a code owner November 27, 2024 11:10
@thordurhhh thordurhhh removed the automerge Merge this PR as soon as all checks pass label Nov 27, 2024
Copy link
Contributor

coderabbitai bot commented Nov 27, 2024

Caution

Review failed

The pull request is closed.

Walkthrough

The pull request introduces several modifications across multiple components related to the regulation editing interface. Key changes include the addition of a new prop asBase in the EditChange component, enhancements to state management, and updates to the saveChange function for better API interaction. The ImpactDate component sees adjustments in state handling and UI elements, while the ReferenceText component updates text constants to reflect new terminology. Additionally, a new message descriptor is added to improve user guidance regarding effective dates in the messages.ts file.

Changes

File Path Change Summary
libs/portals/admin/regulations-admin/src/components/impacts/EditChange.tsx Added asBase prop to ReferenceText, refined state management for regulation data, updated saveChange function, and enhanced localActions for appendixes.
libs/portals/admin/regulations-admin/src/components/impacts/ImpactDate.tsx Adjusted internal state management, modified button behavior for resetting custom date, and improved UI with additional text details.
libs/portals/admin/regulations-admin/src/components/impacts/ReferenceText.tsx Updated text constants for referenceLegend and referenceBaseLegend to reflect new terminology.
libs/portals/admin/regulations-admin/src/lib/messages.ts Added new message descriptor specificDateApplyTextDetails to clarify effective date guidance.

Possibly related PRs

Suggested reviewers

  • thorkellmani
  • Valur

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
Member

@thorkellmani thorkellmani left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link

codecov bot commented Nov 27, 2024

Codecov Report

Attention: Patch coverage is 0% with 8 lines in your changes missing coverage. Please review.

Project coverage is 35.60%. Comparing base (9fa6dc7) to head (ce147fe).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...ations-admin/src/components/impacts/ImpactDate.tsx 0.00% 8 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #17041      +/-   ##
==========================================
- Coverage   35.61%   35.60%   -0.01%     
==========================================
  Files        6934     6934              
  Lines      146857   146863       +6     
  Branches    41755    41755              
==========================================
  Hits        52297    52297              
- Misses      94560    94566       +6     
Flag Coverage Δ
portals-admin-regulations-admin 1.80% <0.00%> (-0.01%) ⬇️

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

Files with missing lines Coverage Δ
...ations-admin/src/components/impacts/EditChange.tsx 0.00% <ø> (ø)
...ons-admin/src/components/impacts/ReferenceText.tsx 0.00% <ø> (ø)
...ortals/admin/regulations-admin/src/lib/messages.ts 0.00% <ø> (ø)
...ations-admin/src/components/impacts/ImpactDate.tsx 0.00% <0.00%> (ø)

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 9fa6dc7...ce147fe. Read the comment docs.

@datadog-island-is
Copy link

datadog-island-is bot commented Nov 27, 2024

Datadog Report

Branch report: regulations-admin/strings-date-and-impactname
Commit report: e16d1b8
Test service: portals-admin-regulations-admin

✅ 0 Failed, 24 Passed, 0 Skipped, 15.56s Total Time
➡️ Test Sessions change in coverage: 1 no change

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 (7)
libs/portals/admin/regulations-admin/src/components/impacts/ImpactDate.tsx (2)

45-58: Consider adding aria-description for better accessibility

While the explanatory text provides good context visually, consider linking it to the checkbox using aria-describedby for better screen reader support.

 <Box marginBottom={2}>
   <Checkbox
     label={t(impactMsgs.specificDateApply)}
     labelVariant="default"
     checked={hasCustomDate}
     onChange={() => setHasCustomDate(!hasCustomDate)}
+    aria-describedby="date-details"
   />
 </Box>

 <Box marginBottom={3}>
-  <Text variant="small" color="dark400">
+  <Text variant="small" color="dark400" id="date-details">
     {t(impactMsgs.specificDateApplyTextDetails)}
   </Text>
 </Box>

Line range hint 24-24: Add explicit return type for better type safety

Consider adding an explicit return type to the component for better type safety and documentation.

-export const ImpactDate = (props: ImpactDateProps) => {
+export const ImpactDate = (props: ImpactDateProps): JSX.Element => {
libs/portals/admin/regulations-admin/src/components/impacts/ReferenceText.tsx (1)

Line range hint 14-18: Enhance TypeScript type definitions

While the component follows TypeScript best practices, consider these improvements:

  1. Add JSDoc documentation for the asBase prop to explain its purpose
  2. Explicitly type the comments field in the component's usage of Regulation type
 type ReferenceTextProps = {
   baseName: RegName
   regulation: Regulation
+  /** When true, displays the component in base regulation mode */
   asBase?: boolean
 }
libs/portals/admin/regulations-admin/src/components/impacts/EditChange.tsx (3)

Line range hint 282-321: Enhance error handling in mutation responses

The error handling in the mutations could be improved. Currently, it only checks for multiple errors (res.errors.length > 1), which might miss single error cases.

Consider updating the error handling logic:

- if (res.errors && res.errors.length > 1) {
+ if (res.errors?.length > 0) {
    throw res.errors[0]
  }

Line range hint 424-433: Consider enhancing validation logic

The current validation checks for presence but could benefit from additional validation rules:

  • Length limits for title and text
  • Format validation for specific fields
  • Type checking for critical fields

Consider adding more comprehensive validation:

 const isValidImpact = () => {
+  const MAX_TITLE_LENGTH = 255;
   return (
     activeChange.date?.value &&
-    activeChange.title?.value &&
+    activeChange.title?.value &&
+    activeChange.title.value.length <= MAX_TITLE_LENGTH &&
     activeChange.text?.value &&
     activeChange.appendixes.every(
       (apx) => apx.title?.value && apx.text?.value,
     )
   )
 }

Line range hint 1-50: Consider improving component reusability

As this component resides in a library folder, it should be designed for reuse across different NextJS apps. Consider:

  1. Extracting regulation-specific logic into custom hooks
  2. Making the component more generic by accepting customizable validation and transformation functions

Example approach:

// Custom hook for regulation logic
const useRegulationChange = (draft, change) => {
  // Move regulation-specific logic here
  return {
    activeChange,
    setActiveChange,
    isValid,
    save,
    // ... other regulation-specific logic
  }
}

// More generic component
const EditChange = ({ 
  draft, 
  change, 
  validate = defaultValidate,
  transform = defaultTransform,
  ...props 
}) => {
  const { 
    activeChange, 
    setActiveChange, 
    isValid, 
    save 
  } = useRegulationChange(draft, change)
  // ... rest of the component
}
libs/portals/admin/regulations-admin/src/lib/messages.ts (1)

428-432: LGTM! Consider adding a description field for consistency.

The new message descriptor follows the established patterns and provides clear guidance. The implementation is type-safe and maintains the file's structure.

Consider adding an optional description field to provide additional context for translators, following the pattern used in other complex messages in this file:

 specificDateApplyTextDetails: {
   id: 'ap.regulations-admin:change-applied-on-specific-date-text-details',
   defaultMessage:
     'Sjálfgefið er að breytingar taki gildi þegar í stað, daginn eftir útgáfudag. Veljið dagsetningu úr dagatali ef gildistaka er á ákveðinni dagsetningu.',
+  description: 'Explanatory text shown when selecting a specific effective date for regulation changes',
 },
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between c33e7a2 and 79b513d.

📒 Files selected for processing (4)
  • libs/portals/admin/regulations-admin/src/components/impacts/EditChange.tsx (1 hunks)
  • libs/portals/admin/regulations-admin/src/components/impacts/ImpactDate.tsx (3 hunks)
  • libs/portals/admin/regulations-admin/src/components/impacts/ReferenceText.tsx (1 hunks)
  • libs/portals/admin/regulations-admin/src/lib/messages.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
libs/portals/admin/regulations-admin/src/components/impacts/EditChange.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/portals/admin/regulations-admin/src/components/impacts/ImpactDate.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/portals/admin/regulations-admin/src/components/impacts/ReferenceText.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/portals/admin/regulations-admin/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."
🔇 Additional comments (4)
libs/portals/admin/regulations-admin/src/components/impacts/ImpactDate.tsx (2)

1-7: LGTM! Imports follow best practices

The imports are well-organized and maintain effective tree-shaking by importing specific components from the UI library.


80-83: LGTM! Improved state management

The button handler now properly resets both the date value and the custom date flag, ensuring consistent state management.

libs/portals/admin/regulations-admin/src/components/impacts/ReferenceText.tsx (1)

29-30: LGTM! Text constant updates are consistent

The terminology changes align well with the mapping function mapRegulationTypeToDisplayString and maintain consistent string templating.

libs/portals/admin/regulations-admin/src/components/impacts/EditChange.tsx (1)

449-449: LGTM: Clear and meaningful prop addition

The new asBase prop effectively distinguishes between base and non-base regulation types.

@thordurhhh thordurhhh added the automerge Merge this PR as soon as all checks pass label Nov 27, 2024
@thordurhhh thordurhhh removed the automerge Merge this PR as soon as all checks pass label Nov 27, 2024
@thordurhhh thordurhhh added the automerge Merge this PR as soon as all checks pass label Nov 27, 2024
@kodiakhq kodiakhq bot merged commit 4b7b30e into main Nov 27, 2024
40 of 41 checks passed
@kodiakhq kodiakhq bot deleted the regulations-admin/strings-date-and-impactname branch November 27, 2024 11:59
thordurhhh added a commit that referenced this pull request Nov 27, 2024
* Fix strings date and impact name

* Radio buttons

---------

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
automerge Merge this PR as soon as all checks pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants