-
Notifications
You must be signed in to change notification settings - Fork 61
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): add Cases in progress screen for OJOI #16492
Conversation
c1dcd91
to
85b8123
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🚀
Datadog ReportAll test runs ✅ 5 Total Test Services: 0 Failed, 5 Passed Test Services
|
WalkthroughThe pull request introduces several changes across multiple components related to the Official Journal of Iceland. Key modifications include updates to type declarations, the addition of new properties and methods, the introduction of new GraphQL queries and response types, and enhancements to the API specifications. Notably, a new page component for "mal-i-vinnslu" is created, and various utility functions and localized messages are added to support the new features. Changes
Possibly related PRs
Suggested reviewers
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 6
🧹 Outside diff range and nitpick comments (15)
libs/api/domains/official-journal-of-iceland/src/lib/models/cases.response.ts (1)
6-13
: LGTM: Well-structured GraphQL response type with a minor suggestion.The
CasesInProgressResponse
class is well-defined using appropriate decorators and TypeScript types. This structure ensures type safety and adheres to NestJS and GraphQL best practices.Consider using TypeScript's strict null checks and avoiding the non-null assertion operator (!). Instead, you could explicitly define the fields as non-nullable in the GraphQL schema:
@Field(() => [CaseInProgress], { nullable: false }) cases: CaseInProgress[]; @Field(() => AdvertPaging, { nullable: false }) paging: AdvertPaging;This approach maintains type safety without relying on the non-null assertion operator.
apps/web/pages/stjornartidindi/mal-i-vinnslu/index.ts (2)
1-4
: LGTM! Consider using named imports for clarity.The imports are appropriate for a NextJS page component, covering GraphQL integration, internationalization, and server-side rendering. However, for better readability and maintainability, consider using named imports for
withApollo
andwithLocale
.Here's a suggested improvement:
-import withApollo from '@island.is/web/graphql/withApollo' -import { withLocale } from '@island.is/web/i18n' +import { withApollo } from '@island.is/web/graphql/withApollo' +import { withLocale } from '@island.is/web/i18n'
9-11
: LGTM! Consider adding type annotations for improved clarity.The exports are correctly set up for a NextJS page component. The default export of
Screen
and the named export ofgetServerSideProps
are appropriate. The use ofgetServerSidePropsWrapper
suggests proper setup for server-side rendering.For improved type safety and clarity, consider adding type annotations:
-export default Screen +export default Screen as React.ComponentType -export const getServerSideProps = getServerSidePropsWrapper(Screen) +export const getServerSideProps: GetServerSideProps = getServerSidePropsWrapper(Screen)Don't forget to import the
GetServerSideProps
type from 'next' if you implement this suggestion.libs/api/domains/official-journal-of-iceland/src/lib/models/case.model.ts (2)
5-24
: Field definitions look good, with a minor suggestion for improvement.The field definitions are well-structured with appropriate types and nullability. The use of
@Field
decorators is correct for GraphQL schema generation.For consistency, consider using the non-null assertion operator (
!
) for all fields, including those that are nullable in GraphQL. This maintains TypeScript type safety while allowing GraphQL nullability. For example:@Field(() => String, { nullable: true }) title!: string | null;This approach ensures that the field is always defined in TypeScript, even if it can be null in GraphQL.
1-25
: Code adheres to coding guidelines forlibs/**/*
files.The code follows the guidelines by using TypeScript for defining props and exporting types. The
CaseInProgress
class is potentially reusable across different NextJS apps.To enhance reusability, consider adding a brief comment describing the purpose and usage of the
CaseInProgress
class. This will help developers understand how to use this model in different contexts.apps/web/components/OfficialJournalOfIceland/OJOIHomeIntro.tsx (3)
Line range hint
1-11
: Consider using more specific imports for GraphQL typesWhile the current imports are functional, consider using a more specific import for the
Organization
type from the GraphQL schema. This can help reduce bundle size and improve performance in larger applications.You could update the import like this:
import { Organization } from '@island.is/web/graphql/schema'to:
import type { Organization } from '@island.is/web/graphql/schema'This ensures that only the type information is imported, which can be beneficial for tree-shaking in the build process.
Line range hint
24-93
: Consider destructuring props for improved readabilityThe component's structure and prop usage are generally good, with appropriate handling of optional props. To further enhance readability and maintainability, consider destructuring the props at the beginning of the component.
You could update the component like this:
export const OJOIHomeIntro = ({ organization, breadCrumbs, searchPlaceholder, quickLinks, searchUrl, shortcutsTitle, featuredImage, }: OJOIHomeIntroProps) => { if (!organization) { return null } // Rest of the component... }This approach can make it clearer which props are being used and can slightly simplify the JSX.
Line range hint
24-24
: Consider memoizing the component for potential performance gainsThe
OJOIHomeIntro
component follows React best practices and is implemented as a functional component. To potentially optimize performance, especially if this component is used in a context where its props change frequently but the component itself doesn't need to re-render, consider memoizing it.You could update the component export like this:
export const OJOIHomeIntro = React.memo((props: OJOIHomeIntroProps) => { // Component implementation... })This optimization can help prevent unnecessary re-renders if the parent component updates frequently but the props passed to
OJOIHomeIntro
remain the same. However, make sure to benchmark the performance impact, as memoization isn't always beneficial for every scenario.libs/api/domains/official-journal-of-iceland/src/lib/officialJournalOfIceland.resolver.ts (1)
96-101
: LGTM: New query method is well-implemented.The
getCasesInProgress
method is correctly implemented as a GraphQL query. It uses TypeScript for type definitions, follows naming conventions, and properly delegates to the service method.For consistency with other query methods in this file, consider adding a description to the
@Query
decorator:@Query(() => CasesInProgressResponse, { name: 'officialJournalOfIcelandCasesInProgress', description: 'Get cases in progress for the Official Journal of Iceland', })apps/web/screens/queries/OfficialJournalOfIceland.ts (1)
192-216
: LGTM! Consider adding a comment for consistency.The new
CASES_IN_PROGRESS_QUERY
is well-structured and consistent with other queries in the file. It adheres to GraphQL and Apollo Client best practices, and the use of TypeScript ensures type safety.For consistency with other queries in the file, consider adding a brief comment above the query explaining its purpose. For example:
// Query to fetch cases in progress for the Official Journal of Iceland export const CASES_IN_PROGRESS_QUERY = gql` // ... (existing query code) `apps/web/components/OfficialJournalOfIceland/OJOIWrapper.tsx (3)
34-34
: LGTM! Consider adding JSDoc for the new prop.The addition of the
isHomePage
prop is well-typed and maintains backward compatibility. Great job!Consider adding a JSDoc comment to explain the purpose of this prop:
/** Indicates whether the current page is the home page. */ isHomePage?: boolean;Also applies to: 47-47
141-178
: LGTM! Consider extracting the grid content into a separate component.The new conditional rendering for non-sidebar, non-homepage content is well-structured and follows NextJS and React best practices. The use of Grid components provides a consistent layout.
To improve readability and maintainability, consider extracting the grid content into a separate component:
const NonHomepageContent: React.FC<{ breadcrumbItems?: BreadCrumbItem[]; pageTitle: string; hideTitle?: boolean; pageDescription?: string; children: ReactNode; }> = ({ breadcrumbItems, pageTitle, hideTitle, pageDescription, children }) => ( <GridContainer> <GridRow> <GridColumn span="12/12"> {/* Breadcrumbs, title, description, and children */} </GridColumn> </GridRow> </GridContainer> ); // Usage in OJOIWrapper {!sidebarContent && !isHomePage && ( <NonHomepageContent breadcrumbItems={breadcrumbItems} pageTitle={pageTitle} hideTitle={hideTitle} pageDescription={pageDescription} > {children} </NonHomepageContent> )}
180-180
: LGTM! Consider wrapping homepage content for consistency.The conditional rendering for homepage content is clear and allows for flexible content. Good job!
For consistency with the non-homepage rendering, consider wrapping the homepage content in a similar structure:
{!sidebarContent && isHomePage && ( <GridContainer> <GridRow> <GridColumn span="12/12"> {children} </GridColumn> </GridRow> </GridContainer> )}This would provide a consistent structure across all pages while still allowing for flexible content on the homepage.
apps/web/screens/OfficialJournalOfIceland/OJOIHome.tsx (1)
96-96
: LGTM! Consider adding type definition forisHomePage
.The addition of the
isHomePage
prop to theOJOIWrapper
component is a good practice for explicitly declaring the page type. This change adheres to React best practices and doesn't violate any NextJS conventions.For improved type safety, consider updating the
OJOIWrapper
component's prop types to include theisHomePage
property:interface OJOIWrapperProps { // ... existing props isHomePage?: boolean; }This will ensure type checking for the
isHomePage
prop and make the component's API more explicit.apps/web/screens/OfficialJournalOfIceland/messages.ts (1)
266-299
: LGTM! Consider adding a comment for clarity.The new
casesInProgress
object is well-structured and consistent with the existing code. It provides a comprehensive set of localized messages for the new "Mál í vinnslu" (Cases in progress) feature, aligning with the PR objectives.For consistency with other sections in this file, consider adding a comment above the
casesInProgress
object to briefly describe its purpose. For example:// Messages for the Cases in Progress page casesInProgress: defineMessages({ // ... existing code }),
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 Files selected for processing (15)
- apps/web/components/OfficialJournalOfIceland/OJOIHomeIntro.tsx (1 hunks)
- apps/web/components/OfficialJournalOfIceland/OJOISearchListView.tsx (2 hunks)
- apps/web/components/OfficialJournalOfIceland/OJOIWrapper.tsx (4 hunks)
- apps/web/pages/stjornartidindi/mal-i-vinnslu/index.ts (1 hunks)
- apps/web/screens/OfficialJournalOfIceland/OJOICasesInProgress.tsx (1 hunks)
- apps/web/screens/OfficialJournalOfIceland/OJOIHome.tsx (1 hunks)
- apps/web/screens/OfficialJournalOfIceland/messages.ts (1 hunks)
- apps/web/screens/queries/OfficialJournalOfIceland.ts (1 hunks)
- libs/api/domains/official-journal-of-iceland/src/lib/models/advert.input.ts (1 hunks)
- libs/api/domains/official-journal-of-iceland/src/lib/models/case.model.ts (1 hunks)
- libs/api/domains/official-journal-of-iceland/src/lib/models/cases.response.ts (1 hunks)
- libs/api/domains/official-journal-of-iceland/src/lib/officialJournalOfIceland.resolver.ts (2 hunks)
- libs/api/domains/official-journal-of-iceland/src/lib/officialJournalOfIceland.service.ts (3 hunks)
- libs/clients/official-journal-of-iceland/public/src/clientConfig.json (3 hunks)
- libs/clients/official-journal-of-iceland/public/src/lib/officialJournalOfIcelandClient.service.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (15)
apps/web/components/OfficialJournalOfIceland/OJOIHomeIntro.tsx (1)
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/web/components/OfficialJournalOfIceland/OJOISearchListView.tsx (1)
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/web/components/OfficialJournalOfIceland/OJOIWrapper.tsx (1)
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/web/pages/stjornartidindi/mal-i-vinnslu/index.ts (1)
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/web/screens/OfficialJournalOfIceland/OJOICasesInProgress.tsx (1)
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/web/screens/OfficialJournalOfIceland/OJOIHome.tsx (1)
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/web/screens/OfficialJournalOfIceland/messages.ts (1)
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/web/screens/queries/OfficialJournalOfIceland.ts (1)
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/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/api/domains/official-journal-of-iceland/src/lib/models/case.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/api/domains/official-journal-of-iceland/src/lib/models/cases.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/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/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/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/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."
🔇 Additional comments (20)
libs/api/domains/official-journal-of-iceland/src/lib/models/cases.response.ts (2)
1-4
: LGTM: Imports are well-structured and necessary.The imports are correctly defined and include only the necessary components from external and local modules. This adheres to good practices for modularity and tree-shaking.
1-13
: Excellent adherence to coding guidelines for libs//* files.**This file successfully meets the specified guidelines:
- The
CasesInProgressResponse
class is a reusable component that can be utilized across different NextJS apps.- TypeScript is effectively used for defining props and exporting types, enhancing type safety and developer experience.
- The structure of the file, with its focused imports and clear type definitions, supports effective tree-shaking and bundling practices.
libs/api/domains/official-journal-of-iceland/src/lib/models/case.model.ts (1)
1-4
: LGTM: Imports and class definition are well-structured.The imports are appropriate for defining a GraphQL object type, and the class definition with the
@ObjectType
decorator is correctly implemented.libs/clients/official-journal-of-iceland/public/src/lib/officialJournalOfIcelandClient.service.ts (3)
13-13
: LGTM: Import addition is correct and follows guidelines.The addition of
GetCasesInProgressRequest
to the import statement is appropriate and aligns with TypeScript usage for defining types. This import supports the new method being added to the service.
56-58
: LGTM: New method adheres to coding guidelines and maintains consistency.The
getCasesInProgress
method is well-implemented and follows the established patterns in the service:
- It uses TypeScript for parameter typing, enhancing type safety.
- The method is public and async, consistent with other methods in the class.
- It directly calls the corresponding API method, maintaining the service's role as a thin wrapper around the API.
This addition enhances the reusability of the service across different NextJS apps by providing a standardized way to fetch cases in progress.
Line range hint
1-58
: Excellent adherence to coding guidelines forlibs/**/*
files.The
OfficialJournalOfIcelandClientService
demonstrates strong compliance with the specified coding guidelines:
- Reusability: The service is designed as a modular component, enhancing its potential for reuse across different NextJS apps.
- TypeScript usage: The code consistently uses TypeScript for defining types and method signatures, improving type safety and developer experience.
- Tree-shaking and bundling: The modular structure of the service, with clear method definitions and imports, supports effective tree-shaking and bundling practices.
These characteristics contribute to maintaining a high-quality, reusable codebase.
apps/web/components/OfficialJournalOfIceland/OJOISearchListView.tsx (2)
6-6
: LGTM: Good modularization of utility functionThe import of
formatDate
from a separate utility file adheres to NextJS best practices for code organization and improves maintainability.
33-33
: Verify date formatting for all possible input formatsThe use of the
formatDate
utility function improves code readability and maintainability. However, please ensure thatformatDate
can handle all possible date formats thatad.publicationDate
might have, including potential edge cases like null or invalid dates.To verify the robustness of the
formatDate
function, please run the following script:libs/api/domains/official-journal-of-iceland/src/lib/officialJournalOfIceland.service.ts (2)
3-3
: LGTM: Import statement updated correctly.The addition of
GetCasesInProgressRequest
to the import statement is consistent with the existing code style and supports the new functionality being added to the service. This change aligns with the guideline for reusability across different NextJS apps.
71-75
: LGTM: New method adheres to coding guidelines and best practices.The
getCasesInProgress
method is well-implemented:
- It uses TypeScript for input and return type definitions, aligning with the coding guidelines.
- The method structure and naming convention are consistent with other methods in the class.
- It properly uses async/await for handling the Promise.
- The method delegates work to the injected service, promoting good separation of concerns.
- As part of the exported class, it supports reusability across different NextJS apps.
These aspects contribute to maintainable and reusable code, which is crucial for components in the
libs
directory.apps/web/components/OfficialJournalOfIceland/OJOIHomeIntro.tsx (1)
18-18
: Approved: Improved type clarity forbreadCrumbs
The change from
ReactNode
toReact.ReactNode
enhances type clarity by explicitly referencing the React namespace. This adheres to TypeScript best practices and improves consistency within the React ecosystem.libs/api/domains/official-journal-of-iceland/src/lib/models/advert.input.ts (2)
35-35
:⚠️ Potential issueUpdate @field decorator to match the new type
Similar to the
dateFrom
field, the type ofdateTo
has been changed fromDate
tostring
, but the@Field
decorator still specifiesDate
as the type. This inconsistency could lead to issues with GraphQL schema generation and type safety.Please update the
@Field
decorator to match the new type:- @Field(() => Date, { nullable: true }) + @Field(() => String, { nullable: true }) dateTo?: stringAlso, consider the impact of this change on type checking and validation in other parts of the codebase that may expect a
Date
object.To ensure this change doesn't break existing queries or mutations, please run the following command to check for usages:
32-32
:⚠️ Potential issueUpdate @field decorator to match the new type
The type of
dateFrom
has been changed fromDate
tostring
, but the@Field
decorator still specifiesDate
as the type. This inconsistency could lead to issues with GraphQL schema generation and type safety.Please update the
@Field
decorator to match the new type:- @Field(() => Date, { nullable: true }) + @Field(() => String, { nullable: true }) dateFrom?: stringAlso, consider the impact of this change on type checking and validation in other parts of the codebase that may expect a
Date
object.To ensure this change doesn't break existing queries or mutations, please run the following command to check for usages:
libs/api/domains/official-journal-of-iceland/src/lib/officialJournalOfIceland.resolver.ts (2)
25-25
: LGTM: Import statement is correct and follows best practices.The import statement is properly using a relative path and importing only the necessary type. This approach supports effective tree-shaking and follows TypeScript best practices.
25-25
: Confirm: Code adheres to coding guidelines forlibs/**/*
files.The new code in this file complies with the specified guidelines:
- It uses TypeScript for defining types (e.g.,
CasesInProgressResponse
,QueryParams
).- The new query method can be reused across different NextJS apps that need to interact with the Official Journal of Iceland API.
- The specific import of
CasesInProgressResponse
supports effective tree-shaking.Also applies to: 96-101
apps/web/components/OfficialJournalOfIceland/OJOIWrapper.tsx (1)
Line range hint
1-190
: Excellent use of TypeScript and adherence to NextJS best practices!The overall structure of the OJOIWrapper component is well-organized and follows React and NextJS best practices. The use of TypeScript for prop types and hooks is optimal, providing good type safety. The state management using useState and useEffect is efficient and appropriate for the component's needs.
Great job on maintaining a clean and well-structured component!
apps/web/screens/OfficialJournalOfIceland/OJOIHome.tsx (1)
Line range hint
1-300
: Great job on component structure and NextJS implementation!The overall structure and implementation of the
OJOIHomePage
component adhere to NextJS best practices and make efficient use of React and TypeScript features:
- Proper use of NextJS's
withMainLayout
andwithCustomPageWrapper
HOCs for layout management.- Efficient state management using Apollo Client's
useQuery
hook for client-side data fetching.- Effective use of TypeScript for prop types and GraphQL query responses, enhancing type safety.
- Correct implementation of server-side data fetching with the
getProps
static method, following NextJS conventions.- Well-organized component structure following React best practices.
The code demonstrates a good understanding of NextJS, React, and TypeScript best practices, resulting in a maintainable and type-safe implementation.
libs/clients/official-journal-of-iceland/public/src/clientConfig.json (2)
1060-1130
: New schemas added: CaseInProgress and GetCasesInProgressReponseThe new schemas for
CaseInProgress
andGetCasesInProgressReponse
have been added to support the new/api/v1/cases
endpoint. The schemas look well-defined and consistent with other schemas in the API.To ensure the new schemas are properly utilized and consistent with other parts of the codebase, please run the following verification:
#!/bin/bash # Description: Verify the usage and consistency of the new CaseInProgress and GetCasesInProgressReponse schemas # Check for proper usage of CaseInProgress in TypeScript files rg -i 'CaseInProgress' -g '*.ts' # Check for proper usage of GetCasesInProgressReponse in TypeScript files rg -i 'GetCasesInProgressReponse' -g '*.ts' # Check for any potential typos in the schema names (note the misspelling of "Response") rg -i 'GetCasesInProgressRe[sp]onse' -g '*.ts'
413-452
: New endpoint added: GET /api/v1/casesA new endpoint for retrieving cases in progress has been added. The implementation looks correct and follows the existing patterns in the API.
To ensure consistency with other endpoints and proper implementation, please run the following verification:
apps/web/screens/OfficialJournalOfIceland/OJOICasesInProgress.tsx (1)
122-167
: Confirm customgetProps
method aligns with Next.js data fetching conventionsThe use of a custom
getProps
method is unconventional in Next.js, which typically usesgetStaticProps
orgetServerSideProps
for data fetching. Verify thatgetProps
integrates correctly with Next.js and supports the intended server-side rendering or static generation behavior.
libs/api/domains/official-journal-of-iceland/src/lib/models/advert.input.ts
Show resolved
Hide resolved
apps/web/screens/OfficialJournalOfIceland/OJOICasesInProgress.tsx
Outdated
Show resolved
Hide resolved
apps/web/screens/OfficialJournalOfIceland/OJOICasesInProgress.tsx
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Codeowned files look good 🚀
apps/web/screens/OfficialJournalOfIceland/OJOICasesInProgress.tsx
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
🧹 Outside diff range and nitpick comments (6)
apps/web/screens/OfficialJournalOfIceland/messages.ts (1)
280-313
: LGTM: Cases in progress messages added correctly.The addition of messages for the new "Mál í vinnslu" (Cases in progress) page aligns with the PR objectives. The implementation follows the existing pattern in the file and uses
defineMessages
for type safety.Consider adding a comment above the
casesInProgress
object to briefly explain its purpose, similar to other sections in this file. This would improve code readability and maintainability.apps/web/screens/OfficialJournalOfIceland/OJOISearch.tsx (5)
235-243
: Localization improvement for breadcrumbsGood job on updating the breadcrumb titles to use
formatMessage
for localization. This change enhances the internationalization of the component and aligns with NextJS best practices.Consider extracting the
formatMessage
calls to a separateuseMemo
hook to optimize performance, especially if these messages are used in multiple places within the component.const localizedMessages = useMemo(() => ({ frontpage: formatMessage(m.breadcrumb.frontpage), searchTitle: formatMessage(m.search.breadcrumbTitle), }), [formatMessage]); // Then use localizedMessages.frontpage and localizedMessages.searchTitle in the breadcrumbItems array
Line range hint
91-137
: Improved search state managementThe modifications to
updateSearchStateHandler
enhance the robustness of the search state management. Good job on ensuring consistent handling of Date objects and updating the URL to reflect the current search state.Consider using TypeScript's discriminated unions to improve type safety when handling different value types:
type SearchStateValue = string | number | Date | undefined; type ParsedSearchStateValue = | { type: 'string', value: string } | { type: 'number', value: number } | { type: 'date', value: Date } | { type: 'undefined', value: undefined }; const parseSearchStateValue = (value: SearchStateValue): ParsedSearchStateValue => { if (typeof value === 'string') return { type: 'string', value: value.trim() }; if (typeof value === 'number') return { type: 'number', value }; if (value instanceof Date) return { type: 'date', value }; return { type: 'undefined', value: undefined }; }; // Then use this in updateSearchStateHandler const parsed = parseSearchStateValue(value); // Handle each case based on parsed.typeThis approach can make the code more maintainable and less prone to type-related bugs.
Line range hint
139-166
: Enhanced reset filter functionalityThe improvements to the
resetFilter
function provide a better user experience by offering a clear way to reset all search parameters. Updating the URL to reflect the cleared state is a good practice.Consider extracting the initial state values to a constant object at the top of the file. This would improve code organization and make it easier to maintain the initial state:
const INITIAL_SEARCH_STATE = { q: '', deild: '', tegund: '', timabil: '', malaflokkur: '', stofnun: '', dagsFra: undefined, dagsTil: undefined, sida: 1, staerd: 20, }; // In resetFilter function setSearchState(INITIAL_SEARCH_STATE); // When initializing searchState const [searchState, setSearchState] = useState(INITIAL_SEARCH_STATE);This approach centralizes the definition of the initial state, making it easier to update and maintain.
Line range hint
368-405
: Improved DatePicker handlingThe updates to the DatePicker components ensure better consistency between the UI and the search state. Directly updating the search state with the selected date is a good approach.
To improve code readability and maintainability, consider extracting the common DatePicker props into a separate object:
const commonDatePickerProps = { size: "xs", locale: "is", }; const dateFromPickerProps = { ...commonDatePickerProps, name: "dagsFra", label: formatMessage(m.search.dateFromLabel), placeholderText: formatMessage(m.search.dateFromPlaceholder), minDate: new Date('1950-01-01'), maxDate: searchState.dagsTil ? new Date(searchState.dagsTil) : undefined, selected: searchState.dagsFra ? new Date(searchState.dagsFra) : undefined, handleChange: (date) => updateSearchStateHandler('dagsFra', date), }; // Then use <DatePicker {...dateFromPickerProps} /> in your JSXThis approach reduces duplication and makes it easier to manage common properties across multiple DatePicker components.
Line range hint
1-728
: Consider component decomposition for improved maintainabilityWhile the current implementation works well, the size and complexity of the
OJOISearchPage
component might make it challenging to maintain as the feature set grows.Consider breaking down this large component into smaller, more focused components:
- Create a separate
SearchForm
component to handle the form inputs and filters.- Extract the search results display logic into a
SearchResults
component.- Move the search state management logic into a custom hook, e.g.,
useOJOISearch
.This decomposition would improve:
- Readability: Smaller components are easier to understand and reason about.
- Maintainability: Changes to one aspect (e.g., form layout) won't affect unrelated parts.
- Reusability: Smaller components can potentially be reused in other parts of the application.
- Testing: Smaller, focused components are generally easier to unit test.
Example structure:
// useOJOISearch.ts const useOJOISearch = (initialState) => { // Search state management logic here return { searchState, updateSearchState, resetFilter, /* ... */ }; }; // SearchForm.tsx const SearchForm = ({ searchState, updateSearchState, resetFilter }) => { // Render form inputs and filters }; // SearchResults.tsx const SearchResults = ({ adverts, loading, error }) => { // Render search results or loading/error states }; // OJOISearchPage.tsx const OJOISearchPage = (props) => { const { searchState, updateSearchState, /* ... */ } = useOJOISearch(props.defaultSearchParams); return ( <OJOIWrapper {...wrapperProps}> <SearchForm searchState={searchState} updateSearchState={updateSearchState} /* ... */ /> <SearchResults adverts={adverts} loading={loading} error={error} /> </OJOIWrapper> ); };This structure would make the code more modular and easier to maintain in the long run.
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 Files selected for processing (6)
- apps/web/screens/OfficialJournalOfIceland/OJOIAdvert.tsx (1 hunks)
- apps/web/screens/OfficialJournalOfIceland/OJOICasesInProgress.tsx (1 hunks)
- apps/web/screens/OfficialJournalOfIceland/OJOICategories.tsx (1 hunks)
- apps/web/screens/OfficialJournalOfIceland/OJOIHome.tsx (2 hunks)
- apps/web/screens/OfficialJournalOfIceland/OJOISearch.tsx (1 hunks)
- apps/web/screens/OfficialJournalOfIceland/messages.ts (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- apps/web/screens/OfficialJournalOfIceland/OJOIHome.tsx
🧰 Additional context used
📓 Path-based instructions (5)
apps/web/screens/OfficialJournalOfIceland/OJOIAdvert.tsx (1)
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/web/screens/OfficialJournalOfIceland/OJOICasesInProgress.tsx (1)
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/web/screens/OfficialJournalOfIceland/OJOICategories.tsx (1)
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/web/screens/OfficialJournalOfIceland/OJOISearch.tsx (1)
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/web/screens/OfficialJournalOfIceland/messages.ts (1)
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."
🔇 Additional comments (8)
apps/web/screens/OfficialJournalOfIceland/OJOIAdvert.tsx (1)
43-43
: Excellent localization improvement!The change from a static string to
formatMessage(m.breadcrumb.frontpage)
enhances the component's internationalization. This approach aligns well with NextJS best practices for localization and maintains type safety. It also contributes to a more consistent and maintainable user interface across different locales.apps/web/screens/OfficialJournalOfIceland/messages.ts (3)
4-9
: LGTM: New breadcrumb messages added correctly.The addition of breadcrumb messages is a good practice for improving navigation. The implementation follows the existing pattern in the file and uses
defineMessages
for type safety.
68-71
: LGTM: Search breadcrumb title added.The addition of a breadcrumb title for search results enhances navigation consistency. The implementation follows the existing pattern and naming convention in the file.
180-183
: LGTM: Categories breadcrumb title added.The addition of a breadcrumb title for categories enhances navigation consistency. The implementation follows the existing pattern and naming convention in the file.
apps/web/screens/OfficialJournalOfIceland/OJOICategories.tsx (3)
165-173
: Improved localization for breadcrumb titlesThe use of
formatMessage
for breadcrumb titles enhances the localization capabilities of the component. This change aligns with NextJS best practices for internationalization.
Line range hint
176-186
: Efficient state management with memoized search params updateThe memoization of
updateSearchParams
usinguseMemo
and the implementation ofdebounce
demonstrate efficient state management and performance optimization. This approach prevents unnecessary re-renders and reduces the frequency of URL updates, aligning with React and NextJS best practices.
Line range hint
365-374
: Enhanced type safety and flexibility in OJOICategories componentThe
OJOICategories
component has been updated to includecustomPageData
in its props, improving its flexibility. The use of TypeScript for defining props enhances type safety. This change aligns with NextJS best practices for custom pages and demonstrates optimal use of TypeScript for component type safety.apps/web/screens/OfficialJournalOfIceland/OJOISearch.tsx (1)
Line range hint
1-728
: Overall assessment: Good improvements with room for optimizationThe changes made to this component enhance its functionality, particularly in terms of localization and search state management. The code is generally well-structured and follows NextJS best practices.
Key points:
- Localization improvements enhance the internationalization of the component.
- Search state management is more robust and consistent.
- The reset filter functionality provides a better user experience.
- DatePicker handling ensures better state consistency.
Suggestions for further improvement:
- Consider extracting repeated logic and common properties into separate functions or constants.
- Enhance type safety using TypeScript features like discriminated unions.
- Decompose the large component into smaller, more focused components for better maintainability and potential reusability.
Overall, good job on the improvements. Implementing the suggested optimizations will further enhance the code quality and maintainability of this component.
apps/web/screens/OfficialJournalOfIceland/OJOICasesInProgress.tsx
Outdated
Show resolved
Hide resolved
4c5d24f
to
eb59f3f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Outside diff range and nitpick comments (2)
apps/web/components/OfficialJournalOfIceland/OJOIUtils.ts (1)
84-87
: Approved with a minor suggestion for consistencyThe changes to the
formatDate
function improve its flexibility and robustness by handling cases where no date is provided. This aligns well with TypeScript best practices and enhances type safety.For consistency with the rest of the codebase, consider using a ternary operator for the conditional return:
export const formatDate = (date?: string, df = 'dd.MM.yyyy') => { if (!date) return '-'; // ... rest of the function }This minor change would make the code more concise and align with modern JavaScript practices.
apps/web/screens/OfficialJournalOfIceland/OJOICasesInProgress.tsx (1)
138-138
: Consider implementing pagination for scalabilityThe
pageSize
for fetching cases is currently set to a fixed value of 30. If the number of cases grows beyond this limit or if there is a need to display more cases, fetching them all at once may lead to performance issues and longer load times. Implementing pagination or infinite scrolling would enhance scalability and improve the user experience by loading data in manageable chunks.
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 Files selected for processing (2)
- apps/web/components/OfficialJournalOfIceland/OJOIUtils.ts (1 hunks)
- apps/web/screens/OfficialJournalOfIceland/OJOICasesInProgress.tsx (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
apps/web/components/OfficialJournalOfIceland/OJOIUtils.ts (1)
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/web/screens/OfficialJournalOfIceland/OJOICasesInProgress.tsx (1)
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."
* feat(ojoi): add Cases in progress screen for OJOI * fix: add status to cases * fix: cleanup CaseInProgress * fix: add translations for breadcrumbs * fix: handle null/empty data --------- Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
What
Add Mál í vinnslu page for Stjórnartíðindi
Checklist:
Summary by CodeRabbit
New Features
Improvements
Localization