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(regulations-admin): Add change appendix diff #15811

Merged
merged 12 commits into from
Sep 30, 2024

Conversation

thordurhhh
Copy link
Member

@thordurhhh thordurhhh commented Aug 29, 2024

What

Add diff for change appendixes.

Why

Addition requested.

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

    • Added an optional diff field to various models and input classes, enhancing the capability to track changes in appendices.
    • Introduced functions to better manage and display differences in regulation texts and appendices.
  • Bug Fixes

    • Improved handling of existing and new appendix entries to avoid duplication.
  • Documentation

    • Enhanced clarity in diff generation for both main regulation text and appendices.
  • Chores

    • Updated configurations to allow larger JSON request bodies for improved data handling.

Copy link
Contributor

coderabbitai bot commented Aug 29, 2024

Walkthrough

The changes introduce a new optional property diff of type HTMLText across several models and inputs related to draft regulations, enhancing their structure to accommodate differences in text. Additionally, modifications to the main.ts file increase the JSON body limit for requests. Various components and utility functions are updated to handle the new diff property, improving the management and formatting of appendixes and changes in regulations.

Changes

File Change Summary
.../appendix.model.ts Added optional property diff?: HTMLText to AppendixModel.
.../main.ts Updated jsonBodyLimit in bootstrap from '300kb' to '400kb'.
.../createDraftRegulationChange.input.ts Added optional field diff?: HTMLText to CreateChangeAppendixInput.
.../updateDraftRegulationChange.input.ts Added optional field diff?: HTMLText to UpdateChangeAppendixInput.
.../draftRegulationChange.model.ts Added optional field diff?: HTMLText to ChangeAppendix.
.../EditBasics.tsx Introduced state variable hasUpdatedAppendix and new function updateAppendixes.
.../impacts/EditChange.tsx Refactored getDiffHtml and added getAppendixDiffHtml for diff handling.
.../impacts/ReferenceText.tsx Updated class name for HTMLDump component for styling.
.../makeFields.ts Updated makeDraftAppendixForm to include optional diff property.
.../types.ts Added optional property diff?: HtmlDraftField to AppendixDraftForm.
.../formatAmendingRegulation.ts Updated formatAmendingRegBody to process optional appendixes parameter.
.../formatAmendingUtils.ts Added functions hasAnyChange and updateAppendixWording.

Possibly related PRs

Suggested labels

high priority

Suggested reviewers

  • osk
  • Valur

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 1068516 and a03fa3a.

📒 Files selected for processing (1)
  • libs/portals/admin/regulations-admin/src/components/impacts/EditChange.tsx (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • libs/portals/admin/regulations-admin/src/components/impacts/EditChange.tsx

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.

@thordurhhh thordurhhh added the deploy-feature Deploys features to dev label Aug 29, 2024
Copy link

codecov bot commented Aug 29, 2024

Codecov Report

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

Project coverage is 36.69%. Comparing base (23d2802) to head (a03fa3a).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...in/regulations-admin/src/components/EditBasics.tsx 0.00% 21 Missing ⚠️
...regulations-admin/src/utils/formatAmendingUtils.ts 0.00% 18 Missing ⚠️
...ations-admin/src/components/impacts/EditChange.tsx 0.00% 17 Missing ⚠️
...ations-admin/src/utils/formatAmendingRegulation.ts 0.00% 17 Missing ⚠️
...ls/admin/regulations-admin/src/state/makeFields.ts 0.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #15811      +/-   ##
==========================================
- Coverage   36.70%   36.69%   -0.02%     
==========================================
  Files        6778     6778              
  Lines      139605   139671      +66     
  Branches    39688    39719      +31     
==========================================
  Hits        51247    51247              
- Misses      88358    88424      +66     
Flag Coverage Δ
api 3.39% <ø> (ø)
portals-admin-regulations-admin 1.88% <0.00%> (-0.06%) ⬇️

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

Files with missing lines Coverage Δ
...ons-admin/src/components/impacts/ReferenceText.tsx 0.00% <ø> (ø)
...ls/admin/regulations-admin/src/state/makeFields.ts 0.00% <0.00%> (ø)
...ations-admin/src/components/impacts/EditChange.tsx 0.00% <0.00%> (ø)
...ations-admin/src/utils/formatAmendingRegulation.ts 0.00% <0.00%> (ø)
...regulations-admin/src/utils/formatAmendingUtils.ts 0.00% <0.00%> (ø)
...in/regulations-admin/src/components/EditBasics.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 23d2802...a03fa3a. Read the comment docs.

Copy link
Contributor

Affected services are: api,download-service,regulations-admin-backend,portals-admin,
Feature deployment of your services will begin shortly. Your feature will be accessible here:
https://regulations-adminappendix-diff-checker-api-catalogue.dev01.devland.is/api
https://regulations-adminappendix-diff-checker-api.dev01.devland.is/download
https://regulations-adminappendix-diff-checker-beta.dev01.devland.is/
https://regulations-adminappendix-diff-checker-beta.dev01.devland.is/api
https://regulations-adminappendix-diff-checker-beta.dev01.devland.is/samradsgatt
https://regulations-adminappendix-diff-checker-beta.dev01.devland.is/stjornbord

Deployed services: portals-admin,api,download-service,regulations-admin-backend,consultation-portal,web.
Excluded services: ``

@datadog-island-is
Copy link

datadog-island-is bot commented Aug 29, 2024

Datadog Report

All test runs ee7221c 🔗

3 Total Test Services: 0 Failed, 3 Passed
🔻 Test Sessions change in coverage: 1 decreased (-0.07%), 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.19s 1 no change Link
download-service 0 0 0 1 0 21.52s 1 no change Link
portals-admin-regulations-admin 0 0 0 24 0 14.49s 1 decreased (-0.07%) Link

🔻 Code Coverage Decreases vs Default Branch (1)

  • portals-admin-regulations-admin - jest 2.25% (-0.07%) - Details

@thordurhhh thordurhhh marked this pull request as ready for review September 29, 2024 19:17
@thordurhhh thordurhhh requested a review from a team as a code owner September 29, 2024 19:17
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: 4

🧹 Outside diff range and nitpick comments (13)
apps/services/regulations-admin-backend/src/app/modules/draft_regulation/models/appendix.model.ts (1)

Line range hint 1-12: LGTM! Consider grouping related properties.

The changes look good and align with NestJS best practices and the PR objectives. The new diff property is correctly implemented as an optional field with proper Swagger documentation.

A minor suggestion for improved code organization:

Consider grouping related properties together. You could move the diff property right after the text property since they are both of type HTMLText. This would improve readability and make the relationship between these properties more apparent.

export class AppendixModel {
  @ApiProperty()
  title!: PlainText

  @ApiProperty()
  text!: HTMLText

+  @ApiPropertyOptional()
+  diff?: HTMLText
-
-  @ApiPropertyOptional()
-  diff?: HTMLText
}
libs/api/domains/regulations-admin/src/lib/graphql/dto/updateDraftRegulationChange.input.ts (1)

11-13: LGTM! Consider grouping related fields.

The addition of the diff field is well-implemented and consistent with the existing structure. It adheres to TypeScript typing and NestJS/GraphQL conventions.

Consider grouping related fields together for better code organization. You could move the diff field right after the text field, as they are closely related:

@Field(() => String, { nullable: true })
text!: HTMLText

@Field(() => String, { nullable: true })
diff?: HTMLText

@Field(() => String, { nullable: true })
title!: PlainText

This arrangement might improve readability and make the relationship between text and diff more apparent.

libs/api/domains/regulations-admin/src/lib/graphql/dto/createDraftRegulationChange.input.ts (1)

11-13: LGTM! Consider adding a comment for the new diff field.

The addition of the diff field is well-implemented and aligns with the PR objectives. It correctly uses TypeScript and the @Field decorator, adhering to the coding guidelines for the libs directory.

For consistency and improved documentation, consider adding a brief comment explaining the purpose of the diff field, similar to how you might have comments for other fields in your codebase.

Example:

@Field(() => String, { nullable: true })
// Represents the difference in text for the appendix
diff?: HTMLText
libs/api/domains/regulations-admin/src/lib/graphql/models/draftRegulationChange.model.ts (1)

12-13: LGTM! Consider adding a comment for consistency.

The addition of the diff field is well-implemented and consistent with the existing codebase. It correctly uses TypeScript and the @Field decorator from @nestjs/graphql.

For consistency with the text field, consider adding a non-null assertion (!) to the diff field:

-  diff?: HTMLText
+  diff!: HTMLText

This change would make the field consistent with the text field above it, assuming that the behavior should be the same for both fields.

libs/portals/admin/regulations-admin/src/utils/formatAmendingUtils.ts (2)

91-97: LGTM! Consider a minor readability improvement.

The hasAnyChange function is well-implemented and efficiently checks for the presence of changes in the diff. It adheres to TypeScript usage and is exported for reusability across different NextJS apps.

For improved readability, consider using object shorthand notation:

-  return hasDeletion || hasInsert
+  return { hasDeletion, hasInsert }

This change would provide more detailed information about the specific types of changes present.


99-116: LGTM! Consider refactoring for improved conciseness.

The updateAppendixWording function correctly handles the replacement of "fylgiskjal" and "viðauki" with their appropriate forms. It's exported for reusability and adheres to TypeScript usage.

Consider refactoring the function for improved conciseness and maintainability:

export const updateAppendixWording = (input: string): string => {
  const replacements: { [key: string]: string } = {
    fylgiskjal: 'fylgiskjali',
    viðauki: 'viðauka',
  };

  return input.replace(/fylgiskjal|viðauki/gi, (match) => {
    const replacement = replacements[match.toLowerCase()];
    return match[0] === match[0].toUpperCase()
      ? replacement.charAt(0).toUpperCase() + replacement.slice(1)
      : replacement;
  });
};

This refactored version reduces repetition and improves maintainability by using a replacements object.

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

90-93: Approve changes with a minor suggestion for consistency

The addition of the s.diff class to the HTMLDump components is consistent with the PR objective of adding change appendix diff functionality. The use of the cn function for combining class names is a good practice.

For consistency, consider applying the same change to the HTMLDump component in the comments section (around line 110).

 <HTMLDump
-  className={ed.classes.editor}
+  className={cn(ed.classes.editor, s.diff)}
   html={comments as HTMLText}
 />
libs/portals/admin/regulations-admin/src/state/types.ts (1)

50-50: LGTM! Consider adding a brief comment for the diff property.

The addition of the optional diff property of type HtmlDraftField to the AppendixDraftForm type is well-structured and consistent with the existing codebase. It enhances the form to potentially include difference information.

Consider adding a brief comment explaining the purpose of the diff property, similar to the existing comment for the revoked property. This would improve code documentation and maintainability. For example:

/**
 * Represents the difference in the appendix content.
 * This is used to show changes between versions of the appendix.
 */
diff?: HtmlDraftField
libs/portals/admin/regulations-admin/src/components/EditBasics.tsx (2)

141-159: Use forEach instead of map when not using the returned array

In the updateAppendixes function, you're using map for side effects without utilizing the returned array. This can be misleading and may affect readability.

Consider replacing map with forEach to reflect the intent more clearly.

Apply this diff to make the change:

-  amendingArray.map((item) => {
-    item.appendixes.map((apx, idx) => {
+  amendingArray.forEach((item) => {
+    item.appendixes.forEach((apx, idx) => {
       // Rest of the code remains the same
     })
   })

144-144: Avoid hardcoding strings; use localization for internationalization

The default title Viðauki ${idx + 1} is hardcoded in Icelandic. To support internationalization and maintain consistency across locales, consider using a localization function like t to handle this string.

libs/portals/admin/regulations-admin/src/utils/formatAmendingRegulation.ts (1)

419-445: Use .forEach instead of .map when not using the returned array

The appendixes?.map function is used, but its return value is not utilized. For better readability and to indicate that the iteration is for side effects (modifying additionArray), consider using .forEach instead.

Apply this change:

- appendixes?.map((apx, idx) => {
+ appendixes?.forEach((apx, idx) => {
libs/portals/admin/regulations-admin/src/components/impacts/EditChange.tsx (2)

223-229: TypeScript Optional Parameters Clarification

In the getDiffHtml function, you're using optional parameters previous and current. Since these are optional, it's good practice to explicitly define their types as HTMLText | undefined for better type safety and clarity.


287-298: Improve Comment Placement for Readability

The multi-line comment within the appendixes mapping could affect code readability. Placing comments inside object literals may make the code harder to read and maintain.

Consider moving the comment above the mapping function to enhance clarity:

+                /**
+                 * These changes are needed to both display the diff in the regulation editor and
+                 * to display the appendix in the change regulation:
+                 *
+                 * IF DIFF => Show diff with something similar to getDiffHtml()
+                 * IF NO DIFF => Then 'diff' is undefined
+                 * IF NEW APPENDIX => 'diff' is <div data-diff="new"></div>
+                 */
                 appendixes: activeChange.appendixes.map((apx, i) => ({
                   title: apx.title.value,
                   text: apx.text.value,
-                  /**
-                   * These changes are needed to both display the diff in the regulation editor and
-                   * to display the appendix in the change regulation:
-                   *
-                   * IF DIFF => Show diff with something similar to getDiffHtml()
-                   * IF NO DIFF => Then 'diff' is undefined
-                   * IF NEW APPENDIX => 'diff' is <div data-diff="new"></div>
-                   */
                   diff: getAppendixDiffHtml(i),
                 })),
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between c14f868 and 4984cf0.

📒 Files selected for processing (12)
  • apps/services/regulations-admin-backend/src/app/modules/draft_regulation/models/appendix.model.ts (2 hunks)
  • apps/services/regulations-admin-backend/src/main.ts (1 hunks)
  • libs/api/domains/regulations-admin/src/lib/graphql/dto/createDraftRegulationChange.input.ts (1 hunks)
  • libs/api/domains/regulations-admin/src/lib/graphql/dto/updateDraftRegulationChange.input.ts (1 hunks)
  • libs/api/domains/regulations-admin/src/lib/graphql/models/draftRegulationChange.model.ts (1 hunks)
  • libs/portals/admin/regulations-admin/src/components/EditBasics.tsx (5 hunks)
  • libs/portals/admin/regulations-admin/src/components/impacts/EditChange.tsx (3 hunks)
  • libs/portals/admin/regulations-admin/src/components/impacts/ReferenceText.tsx (1 hunks)
  • libs/portals/admin/regulations-admin/src/state/makeFields.ts (1 hunks)
  • libs/portals/admin/regulations-admin/src/state/types.ts (1 hunks)
  • libs/portals/admin/regulations-admin/src/utils/formatAmendingRegulation.ts (5 hunks)
  • libs/portals/admin/regulations-admin/src/utils/formatAmendingUtils.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (12)
apps/services/regulations-admin-backend/src/app/modules/draft_regulation/models/appendix.model.ts (2)

Pattern apps/services/**/*: "Confirm that the code adheres to the following:

  • NestJS architecture, including modules, services, and controllers.
  • Dependency injection patterns and service encapsulation.
  • Integration and unit testing coverage and practices."

Pattern apps/**/*: "Confirm that the code adheres to the following:

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
apps/services/regulations-admin-backend/src/main.ts (2)

Pattern apps/services/**/*: "Confirm that the code adheres to the following:

  • NestJS architecture, including modules, services, and controllers.
  • Dependency injection patterns and service encapsulation.
  • Integration and unit testing coverage and practices."

Pattern apps/**/*: "Confirm that the code adheres to the following:

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
libs/api/domains/regulations-admin/src/lib/graphql/dto/createDraftRegulationChange.input.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/api/domains/regulations-admin/src/lib/graphql/dto/updateDraftRegulationChange.input.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/api/domains/regulations-admin/src/lib/graphql/models/draftRegulationChange.model.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/portals/admin/regulations-admin/src/components/EditBasics.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/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/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/state/makeFields.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/portals/admin/regulations-admin/src/state/types.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/portals/admin/regulations-admin/src/utils/formatAmendingRegulation.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/portals/admin/regulations-admin/src/utils/formatAmendingUtils.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 (18)
apps/services/regulations-admin-backend/src/main.ts (2)

Line range hint 1-11: Ensure comprehensive testing for the increased payload limit.

The changes adhere to the NestJS architecture and dependency injection patterns as required by the coding guidelines. However, it's crucial to:

  1. Update integration tests to cover scenarios with larger payloads (up to 400kb).
  2. Ensure that error handling for oversized payloads is still functioning correctly.
  3. Test the impact on API response times with larger payloads.

To verify the testing coverage, please run the following script:

#!/bin/bash
# Description: Check for tests related to payload size handling

# Search for tests related to payload size or JSON body limit
echo "Tests related to payload size or JSON body limit:"
rg --type typescript -e 'payload|body.*size|jsonBodyLimit' -g '*spec.ts' apps/services/regulations-admin-backend/src

# Check for any TODOs related to testing in the spec files
echo "TODOs in test files:"
rg --type typescript -e 'TODO' -g '*spec.ts' apps/services/regulations-admin-backend/src

This script will help identify existing tests related to payload handling and any TODOs that might need addressing in the test suite.


10-10: Consider the implications of increasing the JSON body limit.

The jsonBodyLimit has been increased from '300kb' to '400kb'. While this change allows for larger JSON payloads, it's important to consider the following:

  1. Performance: Larger payloads may impact server performance and response times.
  2. Security: Increased limit could potentially expose the server to larger malicious payloads.
  3. Scalability: Ensure that this change doesn't mask underlying issues with payload size management.

To understand the necessity of this change, please run the following script to check for any recent large payloads that might have triggered this increase:

This script will help verify if there have been issues with payload sizes that justify this increase.

Consider implementing a more dynamic approach to handle varying payload sizes:

  1. Use streaming for large payloads instead of increasing the limit.
  2. Implement pagination or chunking for large data sets.
  3. Optimize the data structure to reduce payload size.

These approaches can provide more scalable solutions without compromising security or performance.

libs/api/domains/regulations-admin/src/lib/graphql/dto/updateDraftRegulationChange.input.ts (2)

Line range hint 1-38: Adherence to coding guidelines confirmed.

The code in this file follows the specified guidelines for libs/**/* files:

  1. It uses TypeScript for defining props and exporting types.
  2. The input types are structured in a way that promotes reusability across different NextJS apps.
  3. There are no apparent issues with tree-shaking or bundling practices.

Line range hint 1-1: Clean up imports and verify consistency.

  1. The import statement includes unused types. Consider removing unused imports to keep the code clean:
- import { HTMLText, ISODate, PlainText } from '@island.is/regulations'
+ import { HTMLText } from '@island.is/regulations'
  1. The UpdateDraftRegulationChangeInput class also has a diff field (line 34), which wasn't mentioned in the AI summary. Please verify if this addition is intentional and consistent with the changes made to UpdateChangeAppendixInput.

Also applies to: 34-34

libs/api/domains/regulations-admin/src/lib/graphql/dto/createDraftRegulationChange.input.ts (2)

Line range hint 15-41: Good design allowing easy extension

The CreateDraftRegulationChangeInput class demonstrates good design principles. It uses CreateChangeAppendixInput in its appendixes field, allowing it to automatically incorporate the new diff field without requiring any changes. This approach promotes reusability and maintainability, aligning well with the coding guidelines for the libs directory.


Line range hint 1-41: Overall, excellent implementation adhering to coding guidelines

The changes in this file demonstrate a high-quality implementation that adheres to the coding guidelines for the libs directory:

  1. The code promotes reusability of components across different NextJS apps.
  2. TypeScript is effectively used for defining props and exporting types.
  3. The structure supports effective tree-shaking and bundling practices.

The minimal and focused changes to add the diff field show a good understanding of the existing codebase and maintain its overall design integrity.

libs/api/domains/regulations-admin/src/lib/graphql/models/draftRegulationChange.model.ts (1)

Line range hint 1-54: Overall assessment: The changes adhere to coding guidelines and best practices.

The addition of the diff field to the ChangeAppendix class is well-implemented and consistent with the existing codebase. The change:

  1. Maintains reusability across different NextJS apps.
  2. Correctly uses TypeScript for defining props and exporting types.
  3. Doesn't negatively impact tree-shaking or bundling practices.
  4. Adheres to the coding guidelines for files in the libs directory.
libs/portals/admin/regulations-admin/src/utils/formatAmendingUtils.ts (1)

Line range hint 1-116: Adherence to coding guidelines confirmed.

The file adheres to the coding guidelines for the libs/**/* pattern:

  1. The exported functions are reusable across different NextJS apps.
  2. TypeScript is used effectively for defining parameter types and return types.
  3. The file structure supports effective tree-shaking and bundling practices.
libs/portals/admin/regulations-admin/src/state/makeFields.ts (2)

Line range hint 1-224: Adherence to coding guidelines confirmed.

The changes and the overall file structure in makeFields.ts comply with the coding guidelines for libs/**/* files:

  1. The code maintains reusability across different NextJS apps.
  2. TypeScript is used effectively for defining props and exporting types.
  3. The changes preserve effective tree-shaking and bundling practices.

156-161: LGTM! Changes are consistent and well-implemented.

The modifications to the makeDraftAppendixForm function are correct and align with the PR objectives. The new diff property is properly handled, maintaining type safety and reusability. These changes adhere to the coding guidelines for files in the libs directory.

To ensure consistency across the codebase, let's verify the usage of the updated makeDraftAppendixForm function:

✅ Verification successful

Verified: All usages of makeDraftAppendixForm correctly handle the optional diff property.

The diff property is optional and is appropriately handled in all instances where makeDraftAppendixForm is called. No issues detected with the current implementation.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of makeDraftAppendixForm function
# Expected: All calls to makeDraftAppendixForm should include the possibility of a 'diff' property

rg --type typescript -A 5 'makeDraftAppendixForm\('

Length of output: 88


Script:

#!/bin/bash
# Description: Verify the usage of makeDraftAppendixForm function with correct file type
# Expected: All calls to makeDraftAppendixForm should include the possibility of a 'diff' property

rg --type ts -A 5 'makeDraftAppendixForm\('

Length of output: 3423

libs/portals/admin/regulations-admin/src/state/types.ts (1)

Line range hint 1-284: Excellent TypeScript usage and structure for reusability.

The file demonstrates proper use of TypeScript for defining and exporting types, which is crucial for reusability across different NextJS apps. The modular structure of types (e.g., AppendixDraftForm, RegDraftForm) promotes code reuse and maintainability.

Key points:

  1. Appropriate use of TypeScript features like union types, generics, and mapped types.
  2. Clear and consistent naming conventions.
  3. Proper export of types, enhancing modularity.
  4. No apparent issues with tree-shaking or bundling practices.
libs/portals/admin/regulations-admin/src/components/EditBasics.tsx (3)

42-42: State variable hasUpdatedAppendix initialized correctly

The state variable is properly initialized and follows naming conventions.


51-51: startTextExpanded constant correctly set

The startTextExpanded constant is set to true, simplifying the initial state logic as intended.


273-273: Properly accessing apx.diff?.value

The use of optional chaining to access apx.diff?.value ensures that the code safely handles cases where apx.diff may be undefined.

libs/portals/admin/regulations-admin/src/utils/formatAmendingRegulation.ts (3)

2-6: Imports updated appropriately

The necessary types AppendixDraftForm, GroupedDraftImpactForms, and RegDraftForm are imported, ensuring proper TypeScript type definitions.


17-20: Additional utility functions imported correctly

The utility functions hasAnyChange, isGildisTaka, removeRegPrefix, and updateAppendixWording are imported, which are used later in the code for text processing.


182-182: Function signature updated with optional appendixes parameter

The formatAmendingRegBody function now includes an optional appendixes parameter of type AppendixDraftForm[]. This allows the function to process appendixes when provided.

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

261-264: Validate Diff Generation for Appendixes

When mapping over activeChange.appendixes, you're generating diffs using getAppendixDiffHtml(i). It's important to ensure that the diffs are correctly generated, especially when appendixes have been added or removed.

Run the following script to verify that diffs are generated correctly for all appendixes:

Copy link
Member

@jonbjarnio jonbjarnio left a comment

Choose a reason for hiding this comment

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

😎

@thordurhhh thordurhhh added automerge Merge this PR as soon as all checks pass and removed deploy-feature Deploys features to dev labels Sep 30, 2024
@kodiakhq kodiakhq bot merged commit c23c6d6 into main Sep 30, 2024
41 checks passed
@kodiakhq kodiakhq bot deleted the regulations-admin/appendix-diff-checker branch September 30, 2024 11:23
thoreyjona pushed a commit that referenced this pull request Oct 2, 2024
* Add change appendix diff

* fix appendix type temp

* fix

* Fix appendix change update

* minor refactor

* Update EditChange.tsx

---------

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