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: ⚡ update task logs #3

Merged
merged 9 commits into from
Jun 21, 2024
Merged

feat: ⚡ update task logs #3

merged 9 commits into from
Jun 21, 2024

Conversation

lehuygiang28
Copy link
Owner

@lehuygiang28 lehuygiang28 commented Jun 21, 2024

Summary by CodeRabbit

  • New Features

    • Introduced a new HighlightCode component for formatting and syntax highlighting code snippets in various formats (json, markdown, html, xml, auto).
    • Added collapsible sections to display request and response details in the task logs.
  • Enhancements

    • Improved logging of response data length for more accurate insights.
    • Unified and normalized header handling across the app.
    • Enhanced task log creation to include detailed request and response information.
  • Bug Fixes

    • Addressed pagination issues by refining the handling of pagination parameters in repository methods.
  • UI Improvements

    • Updated the layout of descriptions and added collapsible components for better data visibility.
    • Integrated the ExportButton within header buttons for a more consistent user experience.
  • Chores

    • Refactored setting of default headers for Axios configuration.
    • Updated Redis connection configuration to improve connection stability.

Copy link

vercel bot commented Jun 21, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
tasktr ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 21, 2024 7:45pm
tasktr-be ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 21, 2024 7:45pm

Copy link

coderabbitai bot commented Jun 21, 2024

Warning

Review failed

The pull request is closed.

Walkthrough

The changes introduced encompass enhancements and additions across both the backend and frontend applications. Key modifications include updating default headers for Axios requests, adding pagination to repository methods, modifying Redis configurations, refining task logging structures, and normalizing header functions. On the frontend, new components for better code rendering and formatting have been introduced, along with adjustments to various UI components for improved usability and display.

Changes

Files/Paths Change Summaries
.../src/axios/index.ts Updated default headers for axiosConfig.
.../src/redis/redis.module.ts Introduced keepAlive parameter to Redis configurations.
.../src/utils/abstract/abstract.repository.ts Added pagination to repository methods.
.../src/utils/common.ts Added normalizeHeaders function.
.../src/utils/dtos/pagination-response.dto.ts Removed limit and page properties from PaginationResponseDto.
.../src/app/task-logs/dtos/task-log.dto.ts Added request and response object types to TaskLogDto.
.../src/app/task-logs/task-log.schema.ts Used RequestObject and ResponseObject in TaskLog schema.
.../src/app/task-logs/task-logs.service.ts Removed setting page and limit in returned objects.
.../src/app/tasks/processors/task.processor.ts Refined header normalization, improved logging, and updated task log creation.
.../src/app/tasks/tasks.service.ts Removed default settings for page and limit in methods.
.../tasks/logs/[id]/page.tsx Introduced functions for formatting, added collapsible sections for request and response details.
.../tasks/page.tsx Included ExportButton within headerButtons handling function.
.../tasks/show/[id]/page.tsx Used HighlightCode component, removed code formatting logic and ColorModeContext.
.../form/task-form.tsx Added setting 'isEnable' to false in useEffect.
.../components/show/highlight-code.tsx Introduced HighlightCode component for code formatting and highlighting.
.../components/show/index.ts Exported all from 'highlight-code' module.
.../libs/utils/common.ts Added camelCaseToCapitalizedWords function.

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant FE_Component as Frontend Component
  participant BE_API as Backend API
  participant DB as Database

  User->>FE_Component: Request to view task log
  FE_Component->>BE_API: Fetch task log data

  loop Fetching Records
    BE_API->>DB: Query with pagination
    DB->>BE_API: Return paginated records
  end

  BE_API->>FE_Component: Send task logs with request and response info
  FE_Component->>User: Display formatted task data with collapsible details
Loading

Poem

When headers shift, and tasks align,
With paginated trails so fine,
Logs now speak with clearer tone,
API calls no longer roam.
Frontend shines with formatted flair,
Highlighted code, with utmost care.
CodeRabbit smiles, paws in glee,
For change has come so beautifully! 🐰✨


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

nx-cloud bot commented Jun 21, 2024

☁️ Nx Cloud Report

CI is running/has finished running commands for commit b752ab3. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this CI Pipeline Execution


✅ Successfully ran 1 target

Sent with 💌 from NxCloud.

Copy link

@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: 5

Outside diff range comments (3)
apps/be/common/src/axios/index.ts (1)

Line range hint 21-21: Use Number.parseInt instead of the global parseInt.

To adhere to modern JavaScript standards and ensure consistency across environments, replace parseInt with Number.parseInt.

- port: url?.port ? parseInt(url.port) : url?.protocol === 'https:' ? 443 : 80,
+ port: url?.port ? Number.parseInt(url.port) : url?.protocol === 'https:' ? 443 : 80,
apps/be/src/app/tasks/tasks.service.ts (1)

Line range hint 26-27: Misplaced Decorators

The use of decorators on queue injections here is flagged as incorrect by the static analysis tool. Ensure that decorators are used in the correct context, typically directly above class properties or method declarations.

- @InjectQueue(BULLMQ_TASK_QUEUE) readonly taskQueue: Queue,
- @InjectQueue(BULLMQ_CLEAR_TASK_QUEUE)
+ readonly taskQueue: Queue = InjectQueue(BULLMQ_TASK_QUEUE),
+ readonly clearTaskQueue: Queue<unknown, unknown, ClearTasksJobName> = InjectQueue(BULLMQ_CLEAR_TASK_QUEUE),
apps/fe/src/app/(auth)/tasks/logs/[id]/page.tsx (1)

Line range hint 187-199: Optimize the RefreshButton implementation.

The RefreshButton is directly manipulating the invalidate function which is good for cache invalidation. However, consider using a more descriptive function name for the onClick handler to improve readability.

- <RefreshButton onClick={() => invalidate({resource: `tasks/logs/${id}`, invalidates: ['list'],})}/>
+ <RefreshButton onClick={handleRefresh}/>
+
+ // Somewhere in the component
+ function handleRefresh() {
+    invalidate({
+        resource: `tasks/logs/${id}`,
+        invalidates: ['list'],
+    });
+ }
Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between 604c2d6 and 56aa441.

Files selected for processing (17)
  • apps/be/common/src/axios/index.ts (1 hunks)
  • apps/be/common/src/redis/redis.module.ts (1 hunks)
  • apps/be/common/src/utils/abstract/abstract.repository.ts (2 hunks)
  • apps/be/common/src/utils/common.ts (1 hunks)
  • apps/be/common/src/utils/dtos/pagination-response.dto.ts (1 hunks)
  • apps/be/src/app/task-logs/dtos/task-log.dto.ts (2 hunks)
  • apps/be/src/app/task-logs/task-log.schema.ts (3 hunks)
  • apps/be/src/app/task-logs/task-logs.service.ts (1 hunks)
  • apps/be/src/app/tasks/processors/task.processor.ts (5 hunks)
  • apps/be/src/app/tasks/tasks.service.ts (1 hunks)
  • apps/fe/src/app/(auth)/tasks/logs/[id]/page.tsx (7 hunks)
  • apps/fe/src/app/(auth)/tasks/page.tsx (1 hunks)
  • apps/fe/src/app/(auth)/tasks/show/[id]/page.tsx (3 hunks)
  • apps/fe/src/components/form/task-form.tsx (1 hunks)
  • apps/fe/src/components/show/highlight-code.tsx (1 hunks)
  • apps/fe/src/components/show/index.ts (1 hunks)
  • apps/fe/src/libs/utils/common.ts (1 hunks)
Additional context used
Biome
apps/be/common/src/axios/index.ts

[error] 21-21: Use Number.parseInt instead of the equivalent global. (lint/style/useNumberNamespace)

ES2015 moved some globals into the Number namespace for consistency.
Safe fix: Use Number.parseInt instead.

apps/be/common/src/utils/common.ts

[error] 23-23: Template literals are preferred over string concatenation. (lint/style/useTemplate)

Unsafe fix: Use a template literal.


[error] 29-29: Template literals are preferred over string concatenation. (lint/style/useTemplate)

Unsafe fix: Use a template literal.


[error] 31-31: Template literals are preferred over string concatenation. (lint/style/useTemplate)

Unsafe fix: Use a template literal.


[error] 52-52: isNaN is unsafe. It attempts a type coercion. Use Number.isNaN instead. (lint/suspicious/noGlobalIsNan)

See the MDN documentation for more details.
Unsafe fix: Use Number.isNaN instead.


[error] 90-90: Avoid the use of spread (...) syntax on accumulators. (lint/performance/noAccumulatingSpread)

Spread syntax should be avoided on accumulators (like those in .reduce) because it causes a time complexity of O(n^2).
Consider methods such as .splice or .push instead.

apps/be/src/app/tasks/processors/task.processor.ts

[error] 24-24: Decorators are not valid here. (parse)

Decorators are only valid on class declarations, class expressions, and class methods.
You can enable parameter decorators by setting the unsafeParameterDecoratorsEnabled option to true in your configuration file.


[error] 70-70: Catch clause variable type annotation must be 'any' or 'unknown' if specified. (parse)


[error] 41-43: This else clause can be omitted because previous branches break early. (lint/style/noUselessElse)

Unsafe fix: Omit the else clause.


[error] 46-46: Excessive complexity detected. (lint/complexity/noExcessiveCognitiveComplexity)

Please refactor this function to reduce its complexity score from 19 to the max allowed complexity 15.

apps/fe/src/components/show/highlight-code.tsx

[error] 68-68: Useless case clause. (lint/complexity/noUselessSwitchCase)

because the default clause is present:

Unsafe fix: Remove the useless case.


[error] 26-26: Excessive complexity detected. (lint/complexity/noExcessiveCognitiveComplexity)

Please refactor this function to reduce its complexity score from 18 to the max allowed complexity 15.


[error] 99-99: Avoid using the index of an array as key property in an element. (lint/suspicious/noArrayIndexKey)

This is the source of the key value.

The order of the items may change, and this also affects performances and component state.
Check the React documentation.


[error] 101-101: Avoid using the index of an array as key property in an element. (lint/suspicious/noArrayIndexKey)

This is the source of the key value.

The order of the items may change, and this also affects performances and component state.
Check the React documentation.

apps/be/common/src/utils/abstract/abstract.repository.ts

[error] 99-99: Avoid the delete operator which can impact performance. (lint/performance/noDelete)


[error] 121-121: Avoid the delete operator which can impact performance. (lint/performance/noDelete)


[error] 138-138: Avoid the delete operator which can impact performance. (lint/performance/noDelete)

apps/be/src/app/tasks/tasks.service.ts

[error] 26-26: Decorators are not valid here. (parse)

Decorators are only valid on class declarations, class expressions, and class methods.
You can enable parameter decorators by setting the unsafeParameterDecoratorsEnabled option to true in your configuration file.


[error] 27-27: Decorators are not valid here. (parse)

Decorators are only valid on class declarations, class expressions, and class methods.
You can enable parameter decorators by setting the unsafeParameterDecoratorsEnabled option to true in your configuration file.

apps/fe/src/components/form/task-form.tsx

[error] 191-191: Use === instead of ==.
== is only allowed when comparing against null (lint/suspicious/noDoubleEquals)

== is only allowed when comparing against null

Using == may be unsafe if you are relying on type coercion
Unsafe fix: Use ===


[error] 191-191: Use === instead of ==.
== is only allowed when comparing against null (lint/suspicious/noDoubleEquals)

== is only allowed when comparing against null

Using == may be unsafe if you are relying on type coercion
Unsafe fix: Use ===


[error] 110-110: Avoid the use of spread (...) syntax on accumulators. (lint/performance/noAccumulatingSpread)

Spread syntax should be avoided on accumulators (like those in .reduce) because it causes a time complexity of O(n^2).
Consider methods such as .splice or .push instead.


[error] 142-142: Avoid using unnecessary Fragment. (lint/complexity/noUselessFragments)

A fragment is redundant if it contains only one child, or if it is the child of a html element, and is not a keyed fragment.
Unsafe fix: Remove the Fragment


[error] 162-162: Avoid using unnecessary Fragment. (lint/complexity/noUselessFragments)

A fragment is redundant if it contains only one child, or if it is the child of a html element, and is not a keyed fragment.
Unsafe fix: Remove the Fragment


[error] 188-188: Avoid using unnecessary Fragment. (lint/complexity/noUselessFragments)

A fragment is redundant if it contains only one child, or if it is the child of a html element, and is not a keyed fragment.
Unsafe fix: Remove the Fragment


[error] 209-209: Avoid using unnecessary Fragment. (lint/complexity/noUselessFragments)

A fragment is redundant if it contains only one child, or if it is the child of a html element, and is not a keyed fragment.
Unsafe fix: Remove the Fragment


[error] 232-232: Avoid using unnecessary Fragment. (lint/complexity/noUselessFragments)

A fragment is redundant if it contains only one child, or if it is the child of a html element, and is not a keyed fragment.
Unsafe fix: Remove the Fragment


[error] 268-268: Avoid using unnecessary Fragment. (lint/complexity/noUselessFragments)

A fragment is redundant if it contains only one child, or if it is the child of a html element, and is not a keyed fragment.
Unsafe fix: Remove the Fragment


[error] 313-313: Avoid using unnecessary Fragment. (lint/complexity/noUselessFragments)

A fragment is redundant if it contains only one child, or if it is the child of a html element, and is not a keyed fragment.
Unsafe fix: Remove the Fragment


[error] 375-375: Avoid using unnecessary Fragment. (lint/complexity/noUselessFragments)

A fragment is redundant if it contains only one child, or if it is the child of a html element, and is not a keyed fragment.
Unsafe fix: Remove the Fragment

Additional comments not posted (19)
apps/fe/src/components/show/index.ts (1)

1-1: Export statement looks good.

The export statement consolidates the HighlightCode component, making it accessible throughout the application.

apps/be/common/src/utils/dtos/pagination-response.dto.ts (1)

Line range hint 1-12: Simplified Pagination Response DTO.

The removal of limit and page from PaginationResponseDto simplifies the interface. Ensure that the frontend team is aware of these changes to adjust their data handling and UI components accordingly.

apps/be/common/src/axios/index.ts (2)

59-63: Define default headers for Axios requests.

The defaultHeaders object is well-defined with appropriate content types and a user agent. This setup ensures that all Axios requests will carry these headers unless specifically overridden, thus maintaining consistency across HTTP requests.


64-66: Configure Axios with default settings and a custom adapter.

The axiosConfig is properly set up to use the defaultHeaders, and both HTTP and HTTPS agents are configured with keepAlive: true, enhancing the connection's efficiency. The integration of the httpTimerAdapter is a good practice for performance monitoring.

apps/be/src/app/task-logs/task-log.schema.ts (2)

36-42: Define a schema for request objects in task logs.

The RequestObject class is well-defined with optional properties for headers and body. Using type: Object for headers and type: String for the body with sensible defaults aligns with typical HTTP request structures.


44-47: Define a schema for response objects in task logs.

The ResponseObject class, which extends RequestObject by picking headers and body, is a clever use of TypeScript's utility types to ensure DRY principles. This structure is efficient for logging responses that mirror the request structure.

apps/fe/src/app/(auth)/tasks/show/[id]/page.tsx (1)

66-66: Utilize the HighlightCode component for displaying formatted code.

The integration of the HighlightCode component to display headers and body in JSON and Markdown formats respectively enhances the readability of the task data. This use of specialized components for formatting promotes a cleaner and more maintainable codebase.

Also applies to: 69-69

apps/be/common/src/utils/common.ts (1)

72-92: Normalize HTTP headers by converting keys to lowercase and trimming whitespace.

The normalizeHeaders function is implemented correctly to ensure headers are normalized by converting all keys to lowercase and trimming whitespace. This function enhances the robustness of header handling across different parts of the application.

Tools
Biome

[error] 90-90: Avoid the use of spread (...) syntax on accumulators. (lint/performance/noAccumulatingSpread)

Spread syntax should be avoided on accumulators (like those in .reduce) because it causes a time complexity of O(n^2).
Consider methods such as .splice or .push instead.

apps/be/src/app/task-logs/dtos/task-log.dto.ts (1)

114-118: Addition of Request and Response Objects to TaskLogDto

The inclusion of RequestObject and ResponseObject in TaskLogDto enhances the logging capability by allowing detailed tracking of request and response data. This aligns with the PR's objective to update task logs with more detailed information.

apps/be/src/app/tasks/processors/task.processor.ts (2)

50-57: Enhanced Header Handling in Task Processing

The integration of defaultHeaders and normalizeHeaders ensures that headers are standardized across tasks. This helps in maintaining consistency and potentially avoids issues related to header case sensitivity.


Line range hint 68-106: Detailed Logging of Task Execution

The detailed logging of task execution, including response size and timings, is a significant improvement. It provides better insights into task performance and potential bottlenecks.

apps/be/common/src/utils/abstract/abstract.repository.ts (2)

18-18: Pagination DTO Import Added

The import of PaginationRequestDto enables the use of pagination functionality in repository methods, aligning with the PR objectives to enhance data handling with pagination.


182-201: Enhanced Error Handling in findOrThrow Method

The findOrThrow method now supports pagination and throws a NotFoundException if no documents are found. This improves the robustness of the method by ensuring that it handles empty result sets gracefully.

apps/fe/src/app/(auth)/tasks/page.tsx (1)

57-64: Enhanced Export Functionality in Task List

The inclusion of an ExportButton in the headerButtons of the List component enhances the functionality of the task list page by allowing users to export task data. This change is well-implemented and follows React best practices for component composition.

apps/fe/src/components/form/task-form.tsx (1)

63-63: Initial State Setting in useEffect

The addition of setValue('isEnable', false); in the useEffect hook sets a default state for the 'isEnable' field when the form loads. This ensures that the form state is correctly initialized, which is crucial for forms that might save state to a backend or depend on certain defaults for conditional rendering.

apps/fe/src/app/(auth)/tasks/logs/[id]/page.tsx (4)

27-31: Good use of utility functions for common tasks.

The import of multiple utility functions from common helps keep the component code clean and focused on presentation logic. This is a good practice in maintaining separation of concerns.


34-34: Proper use of the HighlightCode component.

Importing the HighlightCode component from ~/components/show aligns with the changes mentioned in the summary about replacing manual code formatting logic with this component. This should enhance maintainability and consistency across the application.


Line range hint 372-448: Enhanced task log details visualization.

The use of Descriptions, Collapse, and HighlightCode components in the modal for displaying detailed task log information is well implemented. It enhances user experience by providing a clear and interactive way to view detailed information. However, ensure that the formatType for HighlightCode is appropriately set for all use cases.


6-6: Consider using destructuring for imports from 'antd'.

To maintain consistency and reduce the line length, consider destructuring the imports from 'antd'.

- import { Breadcrumb, Space, Table, Modal, Typography, Descriptions, Collapse } from 'antd';
+ import { Breadcrumb, Space, Table, Modal, Descriptions, Collapse } from 'antd';
+ const { Title: TextTitle, Text } = Typography;

Likely invalid or redundant comment.

apps/fe/src/components/show/highlight-code.tsx Outdated Show resolved Hide resolved
apps/be/common/src/redis/redis.module.ts Show resolved Hide resolved
apps/fe/src/libs/utils/common.ts Show resolved Hide resolved
@lehuygiang28
Copy link
Owner Author

@coderabbitai review

Copy link

coderabbitai bot commented Jun 22, 2024

Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant