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(ojoi): Advert main types #17275

Merged
merged 13 commits into from
Dec 19, 2024
Merged

feat(ojoi): Advert main types #17275

merged 13 commits into from
Dec 19, 2024

Conversation

jonbjarnio
Copy link
Member

@jonbjarnio jonbjarnio commented Dec 18, 2024

What

  • Updated the public client to allow fetching main types
  • Updated the application to use these main types
  • Fixed minor UI bugs

Why

To allow users to better search / filter types when creating application

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 GraphQL query for fetching main types related to the official journal of Iceland.
    • Added a new input type for querying main types and enhanced pagination fields.
    • New constants for department identifiers have been defined.
    • Added a new utility function for cleaning object properties.
  • Improvements

    • Enhanced the responsiveness and layout management in various components.
    • Improved loading state handling in the OJOISelectController.
  • Bug Fixes

    • Updated input labels and placeholders for clarity in the advert object.
  • API Changes

    • Significant restructuring of API endpoints for better clarity and functionality.

Copy link
Contributor

coderabbitai bot commented Dec 18, 2024

Walkthrough

This pull request introduces comprehensive changes to the Official Journal of Iceland (OJOI) application, focusing on enhancing type definitions, input handling, and GraphQL schema for advertisement-related functionalities. The modifications span multiple files across different layers of the application, including input models, GraphQL resolvers, services, and frontend components. The changes primarily revolve around introducing main types, improving pagination handling, and refactoring type-related queries and components.

Changes

File Path Change Summary
libs/api/domains/official-journal-of-iceland/src/lib/models/advert.input.ts - Replaced Number with Int for pagination fields
- Added new MainTypesQueryParams input type
libs/api/domains/official-journal-of-iceland/src/lib/models/advert.model.ts - Added new AdvertMainType class with fields for main type representation
libs/api/domains/official-journal-of-iceland/src/lib/models/advert.response.ts - Introduced MainTypesResponse for main types query results
libs/api/domains/official-journal-of-iceland/src/lib/officialJournalOfIceland.resolver.ts - Added getAdvertMainTypes GraphQL query method
libs/api/domains/official-journal-of-iceland/src/lib/officialJournalOfIceland.service.ts - Introduced getMainTypes method to fetch main types
libs/application/templates/official-journal-of-iceland/src/hooks/useTypes.ts - Updated to manage main types alongside existing types
libs/application/templates/official-journal-of-iceland/src/lib/constants.ts - Added new department constants
libs/application/templates/official-journal-of-iceland/src/lib/dataSchema.ts - Added mainType property to advertSchema
libs/application/templates/official-journal-of-iceland/src/lib/messages/advert.ts - Added mainType entry to the advert inputs
libs/application/templates/official-journal-of-iceland/src/lib/types.ts - Added mainType property to InputFields
libs/application/templates/official-journal-of-iceland/src/graphql/queries.ts - Added MAIN_TYPES_QUERY for fetching main types
libs/clients/official-journal-of-iceland/public/src/clientConfig.json - Updated API endpoint structure for main types and categories
libs/clients/official-journal-of-iceland/public/src/lib/officialJournalOfIcelandClient.service.ts - Updated methods to accommodate new request types for main types

Suggested labels

deploy-feature

Suggested reviewers

  • RunarVestmann
  • Toti91
  • fjandakornid

Possibly related PRs


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.

@jonbjarnio jonbjarnio changed the title Fix/advert types feat(ojoi): Advert main types Dec 18, 2024
Copy link

codecov bot commented Dec 18, 2024

Codecov Report

Attention: Patch coverage is 39.47368% with 23 lines in your changes missing coverage. Please review.

Project coverage is 35.69%. Comparing base (1712305) to head (38c539c).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...-journal-of-iceland/src/lib/models/advert.input.ts 35.71% 9 Missing ⚠️
.../src/lib/officialJournalOfIcelandClient.service.ts 0.00% 6 Missing ⚠️
...-journal-of-iceland/src/lib/models/advert.model.ts 75.00% 2 Missing ⚠️
...urnal-of-iceland/src/lib/models/advert.response.ts 60.00% 2 Missing ⚠️
...eland/src/lib/officialJournalOfIceland.resolver.ts 33.33% 2 Missing ⚠️
...celand/src/lib/officialJournalOfIceland.service.ts 0.00% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main   #17275   +/-   ##
=======================================
  Coverage   35.68%   35.69%           
=======================================
  Files        6922     6922           
  Lines      148527   148554   +27     
  Branches    42420    42422    +2     
=======================================
+ Hits        53008    53022   +14     
- Misses      95519    95532   +13     
Flag Coverage Δ
api 3.33% <ø> (ø)
application-system-api 38.74% <39.47%> (-0.01%) ⬇️
application-template-api-modules 27.70% <ø> (+<0.01%) ⬆️
application-ui-shell 22.31% <ø> (ø)
judicial-system-web 27.77% <ø> (ø)

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

Files with missing lines Coverage Δ
...-journal-of-iceland/src/lib/models/advert.model.ts 57.60% <75.00%> (+1.65%) ⬆️
...urnal-of-iceland/src/lib/models/advert.response.ts 63.82% <60.00%> (-0.46%) ⬇️
...eland/src/lib/officialJournalOfIceland.resolver.ts 50.00% <33.33%> (-1.22%) ⬇️
...celand/src/lib/officialJournalOfIceland.service.ts 15.38% <0.00%> (-1.29%) ⬇️
.../src/lib/officialJournalOfIcelandClient.service.ts 15.38% <0.00%> (-1.29%) ⬇️
...-journal-of-iceland/src/lib/models/advert.input.ts 56.66% <35.71%> (+0.04%) ⬆️

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 1712305...38c539c. Read the comment docs.

@datadog-island-is
Copy link

Datadog Report

All test runs c147c76 🔗

4 Total Test Services: 0 Failed, 4 Passed
🔻 Test Sessions change in coverage: 1 decreased (-0.02%), 9 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.2s 1 no change Link
application-system-api 0 0 0 46 0 2m 12.98s 1 decreased (-0.02%) Link
application-template-api-modules 0 0 0 118 0 2m 6.42s 1 no change Link
application-ui-shell 0 0 0 74 0 31.13s 1 no change Link

🔻 Code Coverage Decreases vs Default Branch (1)

  • application-system-api - jest 35.59% (-0.02%) - Details

@jonbjarnio jonbjarnio marked this pull request as ready for review December 19, 2024 10:14
@jonbjarnio jonbjarnio requested a review from a team as a code owner December 19, 2024 10:14
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

🧹 Nitpick comments (13)
libs/application/templates/official-journal-of-iceland/src/components/htmlEditor/HTMLEditor.tsx (1)

78-78: Consider using island-ui/core components for error display

For better consistency and reusability, consider replacing the plain div for error display with island-ui/core components.

Replace the error div with Text component:

-      {error && <div className={errorStyle}>{error}</div>}
+      {error && <Text variant="small" color="red600">{error}</Text>}
libs/application/templates/official-journal-of-iceland/src/fields/Advert.tsx (2)

125-125: Title input.
The max length of 600 is a practical choice. Ensure there's a clear error message or truncation approach for user feedback if exceeded.


145-145: Disabled template select.
Having a disabled field is useful for clarity, but ensure the user understands why it’s disabled.

libs/clients/official-journal-of-iceland/public/src/lib/officialJournalOfIcelandClient.service.ts (1)

38-39: Updated getAdvertTypeById method.
Replacing 'getAdvertTypeById' with 'getTypeById' is more semantically aligned. Make sure the removal of the old method is covered in existing tests.

libs/application/templates/official-journal-of-iceland/src/hooks/useTypes.ts (3)

60-68: Consider implementing error retry strategy

The main types query could benefit from Apollo Client's retry policies for better error handling and resilience.

   } = useQuery<MainTypesResponse, TypesVariables>(MAIN_TYPES_QUERY, {
     variables: {
       params: params,
     },
+    retry: (count, error) => {
+      return count < 3 && !error.message.includes('NOT_FOUND');
+    },
+    retryDelay: (attempt) => Math.min(1000 * 2 ** attempt, 30000),
   })

77-86: Consider implementing request deduplication

The lazy query for main types could benefit from request deduplication to prevent unnecessary network requests.

   ] = useLazyQuery<MainTypesResponse, TypesVariables>(MAIN_TYPES_QUERY, {
     fetchPolicy: 'network-only',
+    dedupingInterval: 1000, // Deduplicate identical requests within 1 second
   })

92-94: Consider memoizing derived state

The current implementation recalculates currentMainTypes on every render. Consider using useMemo to optimize performance.

+  const currentMainTypes = useMemo(() => 
+    lazyMainTypes
+      ? lazyMainTypes.officialJournalOfIcelandMainTypes.mainTypes
+      : mainTypesData?.officialJournalOfIcelandMainTypes.mainTypes,
+    [lazyMainTypes, mainTypesData]
+  );

Also applies to: 97-103

libs/api/domains/official-journal-of-iceland/src/lib/models/advert.model.ts (1)

140-156: LGTM! Consider adding field descriptions.

The AdvertMainType class is well-structured and consistent with other models. The field types and relationships are appropriate for the domain model.

Consider adding @Field descriptions to document the purpose of each field, similar to this:

 @ObjectType('OfficialJournalOfIcelandAdvertsMainType')
 export class AdvertMainType {
-  @Field()
+  @Field({ description: 'Unique identifier for the main type' })
   id!: string

-  @Field()
+  @Field({ description: 'Display title of the main type' })
   title!: string
   // ... similar for other fields
libs/api/domains/official-journal-of-iceland/src/lib/models/advert.input.ts (1)

138-148: Consider adding input validation for pagination params.

The MainTypesQueryParams class is well-structured, but could benefit from input validation to ensure positive page numbers and reasonable page sizes.

Consider adding validation decorators:

 @InputType('OfficialJournalOfIcelandMainTypesInput')
 export class MainTypesQueryParams {
   @Field(() => String, { nullable: true })
   department?: string

   @Field(() => Int, { nullable: true })
+  @Min(1)
   page?: number

   @Field(() => Int, { nullable: true })
+  @Min(1)
+  @Max(100)
   pageSize?: number
 }
libs/application/templates/official-journal-of-iceland/src/graphql/queries.ts (1)

120-150: LGTM: Well-structured GraphQL query for main types.

The query follows established patterns and includes all necessary fields including pagination.

Consider extracting common fields (department, paging) into reusable fragments to improve maintainability. Example:

+ const DEPARTMENT_FIELDS = gql`
+   fragment DepartmentFields on Department {
+     id
+     title
+     slug
+   }
+ `
+ 
+ const PAGING_FIELDS = gql`
+   fragment PagingFields on Paging {
+     page
+     pageSize
+     totalPages
+     totalItems
+     hasNextPage
+     hasPreviousPage
+     nextPage
+     previousPage
+   }
+ `

  export const MAIN_TYPES_QUERY = gql`
+   ${DEPARTMENT_FIELDS}
+   ${PAGING_FIELDS}
    query AdvertMainTypes($params: OfficialJournalOfIcelandMainTypesInput!) {
      officialJournalOfIcelandMainTypes(params: $params) {
        mainTypes {
          id
          title
          slug
          department {
-           id
-           title
-           slug
+           ...DepartmentFields
          }
          types {
            id
            title
            slug
          }
        }
        paging {
-         page
-         pageSize
-         totalPages
-         totalItems
-         hasNextPage
-         hasPreviousPage
-         nextPage
-         previousPage
+         ...PagingFields
        }
      }
    }
  `
libs/application/templates/official-journal-of-iceland/src/lib/utils.ts (1)

392-400: Consider making the function more generic

The function works correctly for the current use case, but could be made more reusable.

Consider this more generic implementation using TypeScript's utility types:

-export const cleanTypename = (obj: {
-  __typename?: string
-  id: string
-  title: string
-  slug: string
-}) => {
+export const cleanTypename = <T extends { __typename?: string }>(obj: T): Omit<T, '__typename'> => {
   const { __typename: _, ...rest } = obj
   return rest
 }
libs/application/templates/official-journal-of-iceland/src/components/input/OJOISelectController.tsx (1)

85-108: LGTM: Clean conditional rendering with a minor enhancement opportunity

The Box wrapper and loading state implementation are well-structured. Consider extracting the loading state into a separate component for better reusability across the application.

+ const LoadingState = () => (
+   <SkeletonLoader
+     borderRadius="standard"
+     display="block"
+     height={OJOI_INPUT_HEIGHT}
+   />
+ )

  return (
    <Box width={half && isSmOrSmaller ? 'full' : 'half'}>
-     {loading ? (
-       <SkeletonLoader
-         borderRadius="standard"
-         display="block"
-         height={OJOI_INPUT_HEIGHT}
-       />
-     ) : (
+     {loading ? <LoadingState /> : (
libs/application/templates/official-journal-of-iceland/src/screens/InvolvedPartyScreen.tsx (1)

93-106: Clean implementation with minor enhancement opportunities

The OJOISelectController implementation looks good, but there are two minor improvements possible:

  1. Consider using optional chaining as suggested by static analysis
  2. Consider making the half prop value dynamic based on screen size if needed
  <OJOISelectController
    half={true}
    disabled={disableSelect}
    loading={loading}
    name={InputFields.advert.involvedPartyId}
    label={f(involvedParty.general.section)}
    options={options}
    applicationId={application.id}
    defaultValue={defaultValue}
    placeholder={involvedParty.inputs.select.placeholder}
    onChange={() => {
-     setSubmitButtonDisabled && setSubmitButtonDisabled(false)
+     setSubmitButtonDisabled?.(false)
    }}
  />
🧰 Tools
🪛 Biome (1.9.4)

[error] 104-104: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 62ed00f and 07b7531.

📒 Files selected for processing (19)
  • libs/api/domains/official-journal-of-iceland/src/lib/models/advert.input.ts (5 hunks)
  • libs/api/domains/official-journal-of-iceland/src/lib/models/advert.model.ts (1 hunks)
  • libs/api/domains/official-journal-of-iceland/src/lib/models/advert.response.ts (2 hunks)
  • libs/api/domains/official-journal-of-iceland/src/lib/officialJournalOfIceland.resolver.ts (3 hunks)
  • libs/api/domains/official-journal-of-iceland/src/lib/officialJournalOfIceland.service.ts (3 hunks)
  • libs/application/templates/official-journal-of-iceland/src/components/htmlEditor/HTMLEditor.tsx (3 hunks)
  • libs/application/templates/official-journal-of-iceland/src/components/input/OJOISelectController.tsx (5 hunks)
  • libs/application/templates/official-journal-of-iceland/src/fields/Advert.tsx (7 hunks)
  • libs/application/templates/official-journal-of-iceland/src/fields/AdvertModal.tsx (2 hunks)
  • libs/application/templates/official-journal-of-iceland/src/graphql/queries.ts (1 hunks)
  • libs/application/templates/official-journal-of-iceland/src/hooks/useTypes.ts (3 hunks)
  • libs/application/templates/official-journal-of-iceland/src/lib/constants.ts (1 hunks)
  • libs/application/templates/official-journal-of-iceland/src/lib/dataSchema.ts (1 hunks)
  • libs/application/templates/official-journal-of-iceland/src/lib/messages/advert.ts (1 hunks)
  • libs/application/templates/official-journal-of-iceland/src/lib/types.ts (1 hunks)
  • libs/application/templates/official-journal-of-iceland/src/lib/utils.ts (1 hunks)
  • libs/application/templates/official-journal-of-iceland/src/screens/InvolvedPartyScreen.tsx (1 hunks)
  • libs/clients/official-journal-of-iceland/public/src/clientConfig.json (9 hunks)
  • libs/clients/official-journal-of-iceland/public/src/lib/officialJournalOfIcelandClient.service.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (19)
libs/application/templates/official-journal-of-iceland/src/components/htmlEditor/HTMLEditor.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/templates/official-journal-of-iceland/src/graphql/queries.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/templates/official-journal-of-iceland/src/lib/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/application/templates/official-journal-of-iceland/src/lib/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."
libs/application/templates/official-journal-of-iceland/src/fields/AdvertModal.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/api/domains/official-journal-of-iceland/src/lib/officialJournalOfIceland.service.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/templates/official-journal-of-iceland/src/lib/constants.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/official-journal-of-iceland/src/lib/models/advert.response.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/official-journal-of-iceland/src/lib/models/advert.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/application/templates/official-journal-of-iceland/src/components/input/OJOISelectController.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/api/domains/official-journal-of-iceland/src/lib/officialJournalOfIceland.resolver.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/templates/official-journal-of-iceland/src/lib/dataSchema.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/templates/official-journal-of-iceland/src/hooks/useTypes.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/templates/official-journal-of-iceland/src/fields/Advert.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/templates/official-journal-of-iceland/src/lib/messages/advert.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/clients/official-journal-of-iceland/public/src/lib/officialJournalOfIcelandClient.service.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/clients/official-journal-of-iceland/public/src/clientConfig.json (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/official-journal-of-iceland/src/lib/models/advert.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/application/templates/official-journal-of-iceland/src/screens/InvolvedPartyScreen.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."
🪛 Biome (1.9.4)
libs/application/templates/official-journal-of-iceland/src/screens/InvolvedPartyScreen.tsx

[error] 104-104: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

🔇 Additional comments (44)
libs/application/templates/official-journal-of-iceland/src/components/htmlEditor/HTMLEditor.tsx (1)

6-6: LGTM! Good choice using Stack for layout management

The addition of Stack from island-ui/core aligns with best practices for consistent spacing and layout management across components.

libs/application/templates/official-journal-of-iceland/src/fields/Advert.tsx (19)

2-2: Use of Stack for layout is appropriate.
This change improves consistency within the codebase by relying on the reusable layout primitives from the Island UI library. Good job.


14-14: Utility imports recognized.
Bringing in 'cleanTypename' and 'getAdvertMarkup' indicates well-structured utility usage. No issues found here.


15-15: Department constant import.
Using a default department constant enhances readability and consistency.


22-22: Maintain clarity in naming.
The variable name 'currentApplication' is descriptive. Consider verifying if it differs from 'application' to reduce confusion.


25-26: Default department logic.
Setting a default department ID is essential for a better user experience when no department is provided. This looks correct and aligns with the new constants.


28-30: Increasing pageSize to 300.
Confirm that this higher page size doesn't cause performance issues. This might be acceptable if the data is not too large.


42-44: Naming consistency for mainTypeOptions.
Transition from 'types' to 'mainTypes' is clear. Ensure all references across the codebase are updated accordingly.
[approve]


47-52: Constructing currentTypes array.
Mapping on 'currentApplication.answers.advert?.mainType?.types' for conditional rendering is a good approach. Ensure that the field 'types' always exists or is handled properly if undefined.


53-57: Title preview logic.
Using 'getAdvertMarkup' to generate a preview is a nice touch. Confirm that removing or refactoring 'type' references aligns with the new 'mainType' approach to avoid confusion.


59-59: Stack usage clarity.
Adopting consistent spacing ensures a coherent visual layout.


Line range hint 61-76: Department SelectController onChange callback.
The callback sets 'type' to null whenever the department changes, which appears consistent with the new mainType design. This is a logical reset.


86-86: Additional form group spacing.
No issues found. The spacing is consistent with the existing layout strategy.


88-102: Main Type OJOISelectController.
• Properly sets the placeholder and loading status.
• The 'onBeforeChange' logic is invaluable. It cleans up the single nested type or nullifies it otherwise, which aligns with the new design.


105-114: Conditional rendering if multiple types.
Great use of a conditional to show a second dropdown only when there are multiple type options. This enhances usability.


127-127: HTMLEditor key property.
Using a dynamic key will force a re-render as expected. This is a pragmatic solution to handle changing values in the editor.


133-133: Closing bracket for Stack.
No actionable issue detected.


137-137: New FormGroup structure.
Enhances clarity by logically grouping related form elements.


154-154: OJOIHtmlController onChange.
The usage of 'setValue' from 'react-hook-form' ensures form state consistency.


156-156: Overall stacking.
Well-structured layout, no issues found.

libs/clients/official-journal-of-iceland/public/src/lib/officialJournalOfIcelandClient.service.ts (4)

12-14: New request types.
Swapping out request imports for 'GetTypeByIdRequest', 'GetTypesRequest', and 'GetMainTypesRequest' is consistent with the updated domain model. Ensure any references to the deprecated request types are removed globally.
[approve]


16-16: Import for GetAdvertMainTypes.
Matches the newly introduced GraphQL endpoint. Confirm that the import path remains up-to-date.


42-46: New getAdvertMainTypes method.
Provides essential fetch capability for main types. Returning 'Promise' clarifies the method's interface. This is a strong addition for modular code.
[approve]


48-49: Refactored getAdvertTypes.
Uses 'GetTypesRequest' for uniform naming. This ensures consistency with the updated API signature.

libs/api/domains/official-journal-of-iceland/src/lib/models/advert.response.ts (3)

8-8: AdvertMainType import.
Necessary import. Confirm that references to 'AdvertMainType' are correct and fully tested.


84-84: New MainTypesResponse class declaration.
Appropriately introduced to handle main types results.


85-91: MainTypesResponse fields.
• The 'mainTypes' array is properly typed with 'AdvertMainType[]'.
• The 'paging' field leverages the existing 'AdvertPaging'.
Though minimal, this implementation is aligned with existing patterns in this file.

libs/application/templates/official-journal-of-iceland/src/lib/constants.ts (1)

17-19: New department constants introduced.
Clear naming of 'DEPARTMENT_A', 'DEPARTMENT_B', and 'DEPARTMENT_C' helps maintain consistency across the codebase. Ensure these are sufficiently documented so that developers know what each corresponds to.

libs/api/domains/official-journal-of-iceland/src/lib/officialJournalOfIceland.service.ts (2)

11-11: LGTM! Clean import additions

The new type imports are properly organized with related types.

Also applies to: 21-21


59-61: LGTM! Method implementation follows service patterns

The new getMainTypes method:

  • Follows the established pattern of other service methods
  • Properly uses async/await
  • Correctly passes through the params to the underlying service
libs/application/templates/official-journal-of-iceland/src/lib/types.ts (1)

15-15: Consider adding mainType to RequiredInputFieldsNames

The mainType field has been added to InputFields but not to RequiredInputFieldsNames. If this field is required for advertisement creation, consider adding it to RequiredInputFieldsNames with an appropriate label.

libs/application/templates/official-journal-of-iceland/src/hooks/useTypes.ts (1)

20-22: LGTM! Clean type definition

The MainTypesResponse type follows TypeScript best practices and matches the GraphQL schema.

libs/api/domains/official-journal-of-iceland/src/lib/officialJournalOfIceland.resolver.ts (1)

77-82: LGTM! Query implementation follows established patterns.

The new query method is well-structured and consistent with other queries in the resolver. It's properly protected by scopes and feature flags.

libs/api/domains/official-journal-of-iceland/src/lib/models/advert.input.ts (1)

13-16: LGTM! Better type precision for pagination fields.

The change from Number to Int type for pagination fields is a good improvement, making the schema more precise and aligned with GraphQL best practices.

Also applies to: 46-49, 64-67

libs/application/templates/official-journal-of-iceland/src/lib/messages/advert.ts (2)

66-77: LGTM: New message block for main type selection.

The new message block follows the established pattern and provides clear translations for the main type input field.


81-81: LGTM: Updated type messages to reflect hierarchy.

The messages have been appropriately updated to indicate that this is now a subtype selection, maintaining clarity in the UI.

Also applies to: 86-86

libs/application/templates/official-journal-of-iceland/src/fields/AdvertModal.tsx (1)

79-84: LGTM: Improved code maintainability with cleanTypename utility.

The refactoring centralizes the typename cleaning logic and applies it consistently across all objects.

libs/application/templates/official-journal-of-iceland/src/lib/dataSchema.ts (1)

72-74: LGTM: Schema extension is well-structured

The mainType property is correctly implemented as an extension of baseEntitySchema with an optional types array, maintaining consistency with the existing schema patterns.

libs/clients/official-journal-of-iceland/public/src/clientConfig.json (3)

437-616: Well-structured API endpoints for advert types

The new endpoints /api/v1/advert-types/types and /api/v1/advert-types/main-types are well-designed with:

  • Comprehensive query parameters
  • Proper pagination support
  • Clear error responses

1475-1487: Comprehensive error handling schema

The AdvertTypeError schema is well-defined with:

  • Clear error types
  • Severity levels
  • Required fields for proper error reporting

1460-1474: Verify pagination implementation for advert types responses

The response schemas for advert types include pagination, but we should verify the implementation handles edge cases correctly.

Also applies to: 1488-1529

✅ Verification successful

Based on the search results, I can see that pagination is well-implemented across the codebase with proper handling of edge cases:

  1. The advert types implementation in useTypes hook (libs/application/templates/official-journal-of-iceland/src/hooks/useTypes.ts) has a safe default pageSize of 1000 to handle all items.

  2. The pagination logic is consistently implemented across queries with proper handling of:

    • pageSize
    • totalPages
    • hasNextPage/hasPreviousPage
    • nextPage/previousPage
  3. The GraphQL queries in libs/application/templates/official-journal-of-iceland/src/graphql/queries.ts show proper pagination fields being requested.

  4. No risky division operations were found in the totalPages calculations.

Pagination implementation for advert types is properly handled

The implementation includes all necessary pagination fields and has appropriate defaults to handle edge cases. No issues found.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check pagination implementation in the codebase
# Look for pagination handling in the related files

# Search for pagination logic
rg -A 5 "pageSize|totalPages|nextPage|previousPage" --type ts

# Search for potential division operations that might cause issues
ast-grep --pattern 'totalPages = $$$'

Length of output: 68144

libs/application/templates/official-journal-of-iceland/src/components/input/OJOISelectController.tsx (3)

7-12: LGTM: Clean import organization and proper type definitions

The new imports and type definitions are well-structured and follow TypeScript best practices.

Also applies to: 31-31


45-45: LGTM: Clean responsive design implementation

The breakpoint logic is well-implemented with clear variable naming and proper default prop value.

Also applies to: 56-57


81-81: Verify the impact of defaultOpt return value change

The change from returning false to undefined is semantically more correct but could affect consumers.

✅ Verification successful

Change from false to undefined is safe

The change is safe because:

  1. The defaultOpt is only used as the defaultValue prop for the Select component
  2. The undefined return is more semantically correct as it represents "no match found"
  3. Both false and undefined would result in no default selection in the Select component
  4. The component's consumers are not directly using the defaultOpt value
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for usages of this component where defaultOpt might be checked
rg -A 3 "OJOISelectController.*defaultValue" --type typescript

Length of output: 99


Script:

#!/bin/bash
# Search for usages of OJOISelectController
rg -A 5 "OJOISelectController"

# Search for the implementation to understand the context
ast-grep --pattern 'const defaultOpt = $_'

Length of output: 7120


Script:

#!/bin/bash
# Let's look at how the defaultOpt is used in the component
ast-grep --pattern 'const OJOISelectController = $_ => {
  $$$
}'

Length of output: 67


Script:

#!/bin/bash
# Get the full component implementation
cat libs/application/templates/official-journal-of-iceland/src/components/input/OJOISelectController.tsx

Length of output: 2915

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.

Mostly good, one comment

@jonbjarnio jonbjarnio added the deprecated:automerge (Disabled) Merge this PR as soon as all checks pass label Dec 19, 2024
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

🧹 Nitpick comments (4)
libs/application/templates/official-journal-of-iceland/src/components/input/OJOISelectController.tsx (1)

81-81: Simplify the return statement.

The explicit return of undefined is unnecessary as it's the default return value when no return statement is present.

-    return undefined
+    return
libs/application/templates/official-journal-of-iceland/src/screens/InvolvedPartyScreen.tsx (1)

93-106: LGTM with minor optimization suggestion.

The width prop is correctly used, improving the component's layout control. Consider optimizing the onChange callback.

-          onChange={() => {
-            setSubmitButtonDisabled && setSubmitButtonDisabled(false)
-          }}
+          onChange={() => setSubmitButtonDisabled?.(false)}
🧰 Tools
🪛 Biome (1.9.4)

[error] 104-104: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

libs/application/templates/official-journal-of-iceland/src/fields/Advert.tsx (2)

95-102: Consider extracting type handling logic.

The type handling logic in onBeforeChange could be moved to a separate function for better maintainability.

+const handleTypeChange = (answers, value) => {
+  if (value.types.length === 1) {
+    const cleaned = cleanTypename(value.types[0])
+    set(answers, InputFields.advert.type, cleaned)
+  } else {
+    set(answers, InputFields.advert.type, null)
+  }
+}

-            onBeforeChange={(answers, value) => {
-              if (value.types.length === 1) {
-                const cleaned = cleanTypename(value.types[0])
-                set(answers, InputFields.advert.type, cleaned)
-              } else {
-                set(answers, InputFields.advert.type, null)
-              }
-            }}
+            onBeforeChange={handleTypeChange}

125-133: Document the key prop usage.

The key prop's purpose in forcing re-renders when type or title changes should be documented for better maintainability.

          <HTMLEditor
+            // Force re-render when type or title changes to update preview
            key={`${currentApplication.answers.advert?.type?.title}-${currentApplication.answers.advert?.title}`}
            name="preview.title"
            config={{ toolbar: false }}
            readOnly={true}
            value={titlePreview}
          />
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 07b7531 and 0561363.

📒 Files selected for processing (3)
  • libs/application/templates/official-journal-of-iceland/src/components/input/OJOISelectController.tsx (5 hunks)
  • libs/application/templates/official-journal-of-iceland/src/fields/Advert.tsx (7 hunks)
  • libs/application/templates/official-journal-of-iceland/src/screens/InvolvedPartyScreen.tsx (1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
libs/application/templates/official-journal-of-iceland/src/components/input/OJOISelectController.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/templates/official-journal-of-iceland/src/fields/Advert.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/templates/official-journal-of-iceland/src/screens/InvolvedPartyScreen.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."
🪛 Biome (1.9.4)
libs/application/templates/official-journal-of-iceland/src/screens/InvolvedPartyScreen.tsx

[error] 104-104: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

🔇 Additional comments (5)
libs/application/templates/official-journal-of-iceland/src/components/input/OJOISelectController.tsx (3)

31-31: LGTM! Well-defined type for the width prop.

The new width prop enhances the component's reusability across different layouts.


56-57: LGTM! Good responsive design implementation.

The breakpoint logic effectively handles different screen sizes, making the component more adaptable.


85-108: LGTM! Well-structured responsive layout with proper loading state.

The component effectively handles both responsive layout and loading states, providing a consistent user experience.

libs/application/templates/official-journal-of-iceland/src/fields/Advert.tsx (2)

25-30: LGTM! Improved initialization with fallback.

The default department handling with fallback to DEPARTMENT_A and the addition of pageSize parameter enhance the component's robustness.


47-56: LGTM! Well-structured type handling.

The separation of mainTypes and currentTypes provides clear data management, and the preview calculation is appropriately placed.

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