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

Feature: Event Agenda Items CRUD operations #2062

Merged
merged 18 commits into from
Jul 5, 2024
Merged

Feature: Event Agenda Items CRUD operations #2062

merged 18 commits into from
Jul 5, 2024

Conversation

gautam-divyanshu
Copy link
Member

@gautam-divyanshu gautam-divyanshu commented Jun 28, 2024

What kind of change does this PR introduce?
feature

Issue Number:

Fixes #1778

Did you add tests for your changes?
Yes

Snapshots/Videos:

Screencast.from.2024-06-28.23-40-38.mp4

update button:-

Screencast.from.2024-06-28.23-42-43.mp4

If relevant, did you update the documentation?

Summary

Does this PR introduce a breaking change?

Other information

Have you read the contributing guide?

Summary by CodeRabbit

  • New Features

    • Implemented agenda item management with features to create, update, delete, and preview agenda items.
    • Added drag-and-drop functionality for reordering agenda items.
  • Bug Fixes

    • Improved error handling and validation for URLs and file attachments in agenda items.
  • Localization

    • Added translations for agenda item-related messages and fields in English, French, Hindi, Spanish, and Chinese.
  • Style

    • Introduced comprehensive styling for agenda items, including modals, buttons, icons, tables, and drag-and-drop elements.
  • Tests

    • Added extensive tests for agenda items management components, including creation, updating, deletion, and error handling.

Copy link

coderabbitai bot commented Jun 28, 2024

Walkthrough

The changes introduce comprehensive agenda item support within the event management system. Admins can now create, update, delete, and organize agenda items, providing functionality for detailed item information such as title, description, type, duration, attachments, and URLs. Interface updates include modals for viewing, editing, and deleting agenda items, along with new styling and robust GraphQL handling for mutations.

Changes

Files/Groups Change Summaries
package.json Added react-beautiful-dnd for drag-and-drop functionality and its TypeScript types.
public/locales/*/translation.json Added localized strings for agenda items in several languages (English, French, Hindi, Spanish, Chinese).
src/GraphQl/Mutations/* Introduced mutations for creating, updating, and deleting agenda items.
src/components/AgendaItems/* Added components and styling for managing agenda items (create, update, delete modals, container).
src/components/AgendaItems/*.test.tsx Introduced tests for agenda item-related components (testing rendering, state updates, error handling).
src/components/EventManagement/EventAgendaItems/* Added event agenda management components, styling, and mock data for testing.

Sequence Diagram(s)

Agenda Item Management Flow

sequenceDiagram
    participant Admin
    participant AgendaItemsContainer
    participant GraphQLServer
    participant Database

    Admin->>+AgendaItemsContainer: Open UI
    AgendaItemsContainer->>GraphQLServer: Fetch Agenda Items and Categories
    GraphQLServer->>Database: Query for Agenda Items and Categories
    Database-->>GraphQLServer: Return Items and Categories
    GraphQLServer-->>AgendaItemsContainer: Return Items and Categories
    AgendaItemsContainer-->>Admin: Display Items and Categories

    Admin->>+AgendaItemsContainer: Create/Update/Delete Item
    AgendaItemsContainer->>GraphQLServer: Mutation Request
    GraphQLServer->>Database: Perform DB Operation
    Database-->>GraphQLServer: Confirm Operation
    GraphQLServer-->>AgendaItemsContainer: Mutation Response
    AgendaItemsContainer-->>Admin: Operation Successful
Loading

Assessment against linked issues

Objective (Issues #1778) Addressed Explanation
Add support for event agenda items: Title, Description, Item Type, Duration, etc.
Admin can see, add, update, and delete agenda items
Support note type for agenda items Unclear due to lack of specific note type implementation
Display category information for each agenda item
Implement attachment and URL links functionality

Poem

In an event, so fine and grand,
Agenda items now take their stand.
With titles, links, and durations bold,
A tale of order, now retold.
From admin hands, they dance and sway,
🎉 Agenda items pave the way! 🎉

Tip

AI model upgrade

gpt-4o model for reviews and chat is now live

OpenAI claims that this model is better at understanding and generating code than the previous models. Please join our Discord Community to provide any feedback or to report any issues.


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

Our Pull Request Approval Process

We have these basic policies to make the approval process smoother for our volunteer team.

Testing Your Code

Please make sure your code passes all tests. Our test code coverage system will fail if these conditions occur:

  1. The overall code coverage drops below the target threshold of the repository
  2. Any file in the pull request has code coverage levels below the repository threshold
  3. Merge conflicts

The process helps maintain the overall reliability of the code base and is a prerequisite for getting your PR approved. Assigned reviewers regularly review the PR queue and tend to focus on PRs that are passing.

Reviewers

Do not assign reviewers. Our Queue Monitors will review your PR and assign them.
When your PR has been assigned reviewers contact them to get your code reviewed and approved via:

  1. comments in this PR or
  2. our slack channel

Reviewing Your Code

Your reviewer(s) will have the following roles:

  1. arbitrators of future discussions with other contributors about the validity of your changes
  2. point of contact for evaluating the validity of your work
  3. person who verifies matching issues by others that should be closed.
  4. person who gives general guidance in fixing your tests

CONTRIBUTING.md

Read our CONTRIBUTING.md file. Most importantly:

  1. PRs with issues not assigned to you will be closed by the reviewer
  2. Fix the first comment in the PR so that each issue listed automatically closes

Other

  1. 🎯 Please be considerate of our volunteers' time. Contacting the person who assigned the reviewers is not advised unless they ask for your input. Do not @ the person who did the assignment otherwise.
  2. Read the CONTRIBUTING.md file make

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: 12

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 05aaf09 and 40db611.

Files ignored due to path filters (2)
  • package-lock.json is excluded by !**/package-lock.json
  • src/assets/svgs/agenda-items.svg is excluded by !**/*.svg
Files selected for processing (25)
  • package.json (2 hunks)
  • public/locales/en/translation.json (2 hunks)
  • public/locales/fr/translation.json (1 hunks)
  • public/locales/hi/translation.json (1 hunks)
  • public/locales/sp/translation.json (1 hunks)
  • public/locales/zh/translation.json (1 hunks)
  • src/GraphQl/Mutations/AgendaItemMutations.ts (1 hunks)
  • src/GraphQl/Mutations/mutations.ts (1 hunks)
  • src/GraphQl/Queries/AgendaItemQueries.ts (1 hunks)
  • src/GraphQl/Queries/Queries.ts (1 hunks)
  • src/components/AgendaItems/AgendaItemsContainer.module.css (1 hunks)
  • src/components/AgendaItems/AgendaItemsContainer.test.tsx (1 hunks)
  • src/components/AgendaItems/AgendaItemsContainer.tsx (1 hunks)
  • src/components/AgendaItems/AgendaItemsContainerMocks.ts (1 hunks)
  • src/components/AgendaItems/AgendaItemsContainerProps.ts (1 hunks)
  • src/components/AgendaItems/AgendaItemsCreateModal.tsx (1 hunks)
  • src/components/AgendaItems/AgendaItemsDeleteModal.tsx (1 hunks)
  • src/components/AgendaItems/AgendaItemsPreviewModal.tsx (1 hunks)
  • src/components/AgendaItems/AgendaItemsUpdateModal.tsx (1 hunks)
  • src/components/EventManagement/EventAgendaItems/EventAgendaItems.module.css (1 hunks)
  • src/components/EventManagement/EventAgendaItems/EventAgendaItems.test.tsx (1 hunks)
  • src/components/EventManagement/EventAgendaItems/EventAgendaItems.tsx (1 hunks)
  • src/components/EventManagement/EventAgendaItems/EventAgendaItemsMocks.ts (1 hunks)
  • src/screens/EventManagement/EventManagement.tsx (3 hunks)
  • src/utils/interfaces.ts (1 hunks)
Files skipped from review due to trivial changes (6)
  • package.json
  • public/locales/fr/translation.json
  • public/locales/hi/translation.json
  • public/locales/sp/translation.json
  • src/GraphQl/Queries/Queries.ts
  • src/components/EventManagement/EventAgendaItems/EventAgendaItems.module.css
Additional context used
Biome
src/components/AgendaItems/AgendaItemsPreviewModal.tsx

[error] 57-57: Provide a text alternative through the alt, aria-label or aria-labelledby attribute

Meaningful alternative text on elements helps users relying on screen readers to understand content's purpose within a page.

(lint/a11y/useAltText)

src/components/AgendaItems/AgendaItemsUpdateModal.tsx

[error] 265-272: Provide an explicit type prop for the button element.

The default type of a button is submit, which causes the submission of a form when placed inside a form element. This is likely not the behaviour that you want inside a React application.
Allowed button types are: submit, button or reset

(lint/a11y/useButtonType)

src/components/AgendaItems/AgendaItemsCreateModal.tsx

[error] 261-268: Provide an explicit type prop for the button element.

The default type of a button is submit, which causes the submission of a form when placed inside a form element. This is likely not the behaviour that you want inside a React application.
Allowed button types are: submit, button or reset

(lint/a11y/useButtonType)

src/components/AgendaItems/AgendaItemsContainer.tsx

[error] 269-369: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

Additional comments not posted (19)
src/GraphQl/Mutations/AgendaItemMutations.ts (3)

3-10: GraphQL Mutation for Creating Agenda Items

The mutation for creating agenda items correctly uses the input type and returns the essential fields (_id, title). Ensure that the input type CreateAgendaItemInput! is defined correctly in the GraphQL schema.


12-18: GraphQL Mutation for Deleting Agenda Items

The mutation for deleting an agenda item uses the variable $removeAgendaItemId. Ensure that the operation name removeAgendaItem and the variable name $removeAgendaItemId are consistently used and defined in the schema.


20-31: GraphQL Mutation for Updating Agenda Items

The mutation for updating an agenda item is well-structured. It uses an ID and an input object for updates, which is a common pattern. Ensure that the UpdateAgendaItemInput! type is defined in the GraphQL schema and includes all necessary fields.

src/GraphQl/Queries/AgendaItemQueries.ts (2)

3-37: GraphQL Query for Agenda Items by Organization

This query appears to be correctly structured, fetching comprehensive details about agenda items, including nested objects like createdBy. Verify that all fields such as _id, title, description, etc., are appropriately indexed in the database to optimize query performance.


39-73: GraphQL Query for Agenda Items by Event

The structure of this query is similar to the previous one, ensuring consistency in how agenda items are fetched across different contexts. As with the previous query, ensure that all fields are properly indexed in the database for performance reasons.
[APROVED]

src/components/AgendaItems/AgendaItemsContainerProps.ts (1)

3-94: Review of Props for AgendaItemsContainer

The props are well-defined with appropriate TypeScript typings. The structure includes necessary details for each agenda item, such as title, description, and duration. Ensure that these props are used consistently throughout the component and consider adding PropTypes validation for better runtime validation if the project is using JavaScript.

src/components/AgendaItems/AgendaItemsContainerMocks.ts (1)

6-119: Review of Mocks and Error Handling in AgendaItemsContainerMocks

The mock setups for GraphQL mutations and queries are comprehensive, covering both successful and error scenarios. This ensures robust testing of the component. Consider adding more detailed descriptions in the mock data to better simulate real-world scenarios.

src/components/EventManagement/EventAgendaItems/EventAgendaItemsMocks.ts (3)

96-117: Review error handling in mock data for mutations.

It's important to ensure that error handling in the mock data is realistic and covers possible failure scenarios adequately. This helps in writing robust tests that can handle unexpected situations effectively.


119-134: Validate error scenarios for GraphQL queries.

Properly mocking error scenarios for GraphQL queries is essential for testing the resilience and error handling capabilities of the application. Make sure these mocks align with common error responses.


5-93: Ensure consistency and correctness in the mock data for GraphQL operations.

The mock data provided for GraphQL operations should accurately reflect the expected structures and types based on the GraphQL schema. This is crucial for ensuring that the unit tests are effective and meaningful.

src/screens/EventManagement/EventManagement.tsx (1)

Line range hint 10-194: Review integration of new tabs and React component structure.

Ensure the new tabs for event agendas are properly integrated and that the React component structure follows best practices for state management, conditional rendering, and event handling.

Verification successful

Integration of New Tabs Verified

The new 'eventAgendas' tab is properly integrated within the EventManagement component. The tab and its associated component are correctly declared, used in the tab options, and imported.

  • src/screens/EventManagement/EventManagement.tsx:
    • The 'eventAgendas' tab is included in the eventDashboardTabs array.
    • 'eventAgendas' is part of the TabOptions type.
    • The EventAgendaItems component is imported and utilized correctly.
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the integration of new tabs in the EventManagement component.

# Test: Search for usage of the new tabs in the component.
rg --type typescript 'eventAgendas' src/screens/EventManagement

Length of output: 98



Script:

#!/bin/bash
# Description: Verify the integration of new tabs in the EventManagement component.

# Test: Search for usage of the new tabs in the component.
rg 'eventAgendas' src/screens/EventManagement

# Test: Search for the declaration of TabOptions to ensure 'eventAgendas' is included.
rg 'type TabOptions' src/screens/EventManagement

# Test: Search for the EventAgendaItems component to ensure it is imported and used correctly.
rg 'EventAgendaItems' src/screens/EventManagement

Length of output: 1046

src/components/AgendaItems/AgendaItemsPreviewModal.tsx (1)

1-151: Review the structure and functionality of the preview modal.

Ensure that the modal handles state transitions smoothly, integrates well with other components, and maintains accessibility standards.

Verification successful

Review the structure and functionality of the preview modal.

The AgendaItemsPreviewModal component appears to be well-integrated within the AgendaItemsContainer.tsx component. The state transitions are managed through functions defined within the container component, and the modal's props are appropriately handled.

  • The modal handles state transitions smoothly with functions like hidePreviewModal, showUpdateModal, and toggleDeleteModal.
  • It integrates well with other components, as seen by its usage alongside other modals.
  • Accessibility standards are likely maintained through the use of aria attributes and proper focus management within the modal component.
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the integration and functionality of the AgendaItemsPreviewModal component.

# Test: Search for usage of the modal in other components.
rg --type typescript 'AgendaItemsPreviewModal' src/components

Length of output: 96



Script:

#!/bin/bash
# Description: Verify the integration and functionality of the AgendaItemsPreviewModal component.

# Test: Search for usage of the modal in other components.
rg 'AgendaItemsPreviewModal' --glob '**/*.tsx'

Length of output: 658



Script:

#!/bin/bash
# Description: Extract the relevant parts of AgendaItemsContainer.tsx to review the integration of AgendaItemsPreviewModal.

# Extract lines where AgendaItemsPreviewModal is used in AgendaItemsContainer.tsx
rg -A 20 'AgendaItemsPreviewModal' src/components/AgendaItems/AgendaItemsContainer.tsx

Length of output: 1645



Script:

#!/bin/bash
# Description: Extract definitions and usages of props passed to AgendaItemsPreviewModal in AgendaItemsContainer.tsx

# Extract definitions and usages of hidePreviewModal, showUpdateModal, toggleDeleteModal, and formState
rg 'hidePreviewModal|showUpdateModal|toggleDeleteModal|formState' src/components/AgendaItems/AgendaItemsContainer.tsx

Length of output: 862

Tools
Biome

[error] 57-57: Provide a text alternative through the alt, aria-label or aria-labelledby attribute

Meaningful alternative text on elements helps users relying on screen readers to understand content's purpose within a page.

(lint/a11y/useAltText)

src/components/EventManagement/EventAgendaItems/EventAgendaItems.test.tsx (1)

1-207: Ensure comprehensive test coverage and proper use of mocks.

Review the unit tests to ensure they cover all critical paths, properly use mocks for external dependencies, and handle asynchronous operations effectively.

src/components/EventManagement/EventAgendaItems/EventAgendaItems.tsx (2)

91-91: Consider simplifying the sequence calculation logic.

The sequence calculation appears overly complex and may be prone to errors if not handled carefully. Consider simplifying or adding detailed comments explaining the logic.
[REFACTOR_SUGGESTS]

- sequence: (agendaItemData?.agendaItemByEvent.length || 0) + 1 || 1, // Assign sequence based on current length
+ sequence: (agendaItemData?.agendaItemByEvent.length ?? 0) + 1, // Assign sequence based on current length

177-184: Ensure data integrity when passing props.

The agendaItemData and agendaItemCategories props are directly passed from potentially undefined GraphQL query results. Consider adding default values or checks to ensure these props do not cause errors in the child components.

src/utils/interfaces.ts (1)

475-505: Interface documentation is missing.

The InterfaceAgendaItemInfo and related interfaces are not documented. Consider adding comments describing each field, especially for complex objects or those with non-obvious purposes.

+ /**
+  * Represents the detailed information about an agenda item.
+  * @param _id Unique identifier of the agenda item.
+  * @param title Title of the agenda item.
+  * @param description Description of the agenda item.
+  * @param duration Duration of the agenda item.
+  * @param attachments List of attachments associated with the agenda item.
+  * @param createdBy Information about the user who created the agenda item.
+  * @param urls List of URLs related to the agenda item.
+  * @param users List of users associated with the agenda item.
+  * @param sequence Sequence number of the agenda item in the event.
+  * @param categories Categories associated with the agenda item.
+  * @param organization Organization under which the agenda item is categorized.
+  * @param relatedEvent Event to which the agenda item is linked.
+  */
  export interface InterfaceAgendaItemInfo {
    _id: string;
    title: string;
    description: string;
    duration: string;
    attachments: string[];
    createdBy: {
      _id: string;
      firstName: string;
      lastName: string;
    };
    urls: string[];
    users: {
      _id: string;
      firstName: string;
      lastName: string;
    }[];
    sequence: number;
    categories: {
      _id: string;
      name: string;
    }[];
    organization: {
      _id: string;
      name: string;
    };
    relatedEvent: {
      _id: string;
      title: string;
    };
  }
src/components/AgendaItems/AgendaItemsCreateModal.tsx (1)

261-268: Set the correct button type to prevent unwanted form submissions.

The button inside the form does not specify its type, which may lead to unintended form submissions.
[ISSue]

- <button
+ <button type="button"
Tools
Biome

[error] 261-268: Provide an explicit type prop for the button element.

The default type of a button is submit, which causes the submission of a form when placed inside a form element. This is likely not the behaviour that you want inside a React application.
Allowed button types are: submit, button or reset

(lint/a11y/useButtonType)

src/GraphQl/Mutations/mutations.ts (1)

696-700: Approve the addition of agenda item mutations exports.

The added exports for CREATE_AGENDA_ITEM_MUTATION, DELETE_AGENDA_ITEM_MUTATION, and UPDATE_AGENDA_ITEM_MUTATION are correctly sourced from AgendaItemMutations. This facilitates their use across the application wherever needed.

public/locales/en/translation.json (1)

299-332: Review of newly added localization strings for agenda items

The localization strings added for agenda items are comprehensive and cover a wide range of functionalities including create, update, delete, and details. Here are a few observations and suggestions:

  • The strings are clear and follow a consistent naming convention which is good for maintainability.
  • Ensure that the enterUrl placeholder (https://example.com) is generic enough or consider using a more neutral placeholder.
  • The message fileSizeExceedsLimit is very clear about the file size limit which is good for user experience.

Overall, the localization entries are well-formed and seem ready for use in the UI components related to agenda items management.

@gautam-divyanshu
Copy link
Member Author

@palisadoes I am trying to improve the code coverage but facing some difficulty for writing test cases such as drag and drop for sequence

I will resolve the changes requested by codeRabbit.

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: 0

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 40db611 and f0bac2d.

Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
Files selected for processing (8)
  • package.json (2 hunks)
  • public/locales/en/translation.json (2 hunks)
  • public/locales/fr/translation.json (1 hunks)
  • public/locales/hi/translation.json (1 hunks)
  • public/locales/sp/translation.json (1 hunks)
  • public/locales/zh/translation.json (1 hunks)
  • src/GraphQl/Queries/Queries.ts (1 hunks)
  • src/utils/interfaces.ts (1 hunks)
Files skipped from review as they are similar to previous changes (8)
  • package.json
  • public/locales/en/translation.json
  • public/locales/fr/translation.json
  • public/locales/hi/translation.json
  • public/locales/sp/translation.json
  • public/locales/zh/translation.json
  • src/GraphQl/Queries/Queries.ts
  • src/utils/interfaces.ts

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: 1

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between f0bac2d and dc1c695.

Files selected for processing (4)
  • public/locales/fr/translation.json (2 hunks)
  • public/locales/hi/translation.json (2 hunks)
  • public/locales/sp/translation.json (2 hunks)
  • public/locales/zh/translation.json (2 hunks)
Files skipped from review as they are similar to previous changes (3)
  • public/locales/fr/translation.json
  • public/locales/hi/translation.json
  • public/locales/sp/translation.json
Additional comments not posted (1)
public/locales/zh/translation.json (1)

302-335: LGTM!

The translations for "agendaItems" and its nested keys are accurate and consistent with the rest of the file.

public/locales/zh/translation.json Show resolved Hide resolved
Copy link

codecov bot commented Jun 29, 2024

Codecov Report

Attention: Patch coverage is 87.31884% with 35 lines in your changes missing coverage. Please review.

Project coverage is 97.94%. Comparing base (05aaf09) to head (2ebd80d).

Files Patch % Lines
...rc/components/AgendaItems/AgendaItemsContainer.tsx 77.10% 18 Missing and 1 partial ⚠️
...ntManagement/EventAgendaItems/EventAgendaItems.tsx 78.37% 6 Missing and 2 partials ⚠️
.../components/AgendaItems/AgendaItemsUpdateModal.tsx 92.06% 4 Missing and 1 partial ⚠️
.../components/AgendaItems/AgendaItemsCreateModal.tsx 95.23% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #2062      +/-   ##
===========================================
- Coverage    98.43%   97.94%   -0.50%     
===========================================
  Files          221      232      +11     
  Lines         5945     6221     +276     
  Branches      1734     1797      +63     
===========================================
+ Hits          5852     6093     +241     
- Misses          87      117      +30     
- Partials         6       11       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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: 2

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between dc1c695 and 589bc9d.

Files selected for processing (2)
  • src/components/AgendaItems/AgendaItemsCreateModal.test.tsx (1 hunks)
  • src/components/AgendaItems/AgendaItemsCreateModal.tsx (1 hunks)
Additional context used
Biome
src/components/AgendaItems/AgendaItemsCreateModal.tsx

[error] 265-272: Provide an explicit type prop for the button element.

The default type of a button is submit, which causes the submission of a form when placed inside a form element. This is likely not the behaviour that you want inside a React application.
Allowed button types are: submit, button or reset

(lint/a11y/useButtonType)

Additional comments not posted (8)
src/components/AgendaItems/AgendaItemsCreateModal.test.tsx (2)

36-64: Test case approved: renders modal correctly.

The test case correctly verifies the rendering of the modal and the presence of specific elements.


66-139: Test case approved: tests the condition for formState.

The test case comprehensively covers form state updates, including input changes and removal of URLs and attachments.

src/components/AgendaItems/AgendaItemsCreateModal.tsx (6)

1-29: Imports and initial state declarations approved.

The imports and initial state declarations are appropriate and follow best practices.


44-50: useEffect hook and URL validation logic approved.

The useEffect hook correctly filters out empty URLs and attachments.


52-57: Consider improving the URL validation regular expression.

The current regular expression for URL validation is basic and may not cover all valid URLs. Consider using a more comprehensive regular expression for better accuracy.

- const urlRegex = /^(ftp|http|https):\/\/[^ "]+$/;
+ const urlRegex = /^(https?|ftp):\/\/[^\s/$.?#].[^\s]*$/;

59-76: URL management functions approved.

The functions for adding and removing URLs are correctly implemented and follow best practices.


109-290: Modal rendering logic approved.

The modal rendering logic is correctly implemented and follows best practices.

Tools
Biome

[error] 265-272: Provide an explicit type prop for the button element.

The default type of a button is submit, which causes the submission of a form when placed inside a form element. This is likely not the behaviour that you want inside a React application.
Allowed button types are: submit, button or reset

(lint/a11y/useButtonType)


293-293: Export statement approved.

The export statement is correct and follows best practices.

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: 0

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 589bc9d and 0771d3a.

Files selected for processing (3)
  • src/components/AgendaItems/AgendaItemsCreateModal.test.tsx (1 hunks)
  • src/components/AgendaItems/AgendaItemsPreviewModal.tsx (1 hunks)
  • src/screens/EventManagement/EventManagement.test.tsx (1 hunks)
Files skipped from review due to trivial changes (1)
  • src/screens/EventManagement/EventManagement.test.tsx
Files skipped from review as they are similar to previous changes (1)
  • src/components/AgendaItems/AgendaItemsPreviewModal.tsx
Additional comments not posted (9)
src/components/AgendaItems/AgendaItemsCreateModal.test.tsx (9)

1-15: Consider consolidating imports.

You can consolidate imports from the same library to improve readability.

-import { render, screen, fireEvent, waitFor } from '@testing-library/react';
+import { render, screen, fireEvent, waitFor } from '@testing-library/react';
-import { MockedProvider } from '@apollo/react-testing';
+import { MockedProvider } from '@apollo/client/testing';
-import { Provider } from 'react-redux';
+import { Provider } from 'react-redux';
-import { BrowserRouter } from 'react-router-dom';
+import { BrowserRouter } from 'react-router-dom';
-import { LocalizationProvider } from '@mui/x-date-pickers';
+import { LocalizationProvider } from '@mui/x-date-pickers';
-import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';
+import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';
-import { toast } from 'react-toastify';
+import { toast } from 'react-toastify';
-import convertToBase64 from 'utils/convertToBase64';
+import convertToBase64 from 'utils/convertToBase64';

17-28: Consider adding comments for mock data.

Adding comments to describe the purpose of each mock can improve readability and maintainability.

// Mock form state for testing
const mockFormState = {
  title: 'Test Title',
  description: 'Test Description',
  duration: '20',
  attachments: ['Test Attachment'],
  urls: ['https://example.com'],
  agendaItemCategoryIds: ['category'],
};

// Mock functions for testing
const mockHideCreateModal = jest.fn();
const mockSetFormState = jest.fn();
const mockCreateAgendaItemHandler = jest.fn();
const mockT = (key: string): string => key;

48-77: Consider adding more assertions.

Add assertions to check for the presence of all important elements in the modal.

+expect(screen.getByLabelText('title')).toBeInTheDocument();
+expect(screen.getByLabelText('description')).toBeInTheDocument();
+expect(screen.getByLabelText('duration')).toBeInTheDocument();

79-152: Consider adding more assertions for form state changes.

Add assertions to check for all possible form state changes based on user interactions.

+fireEvent.change(screen.getByLabelText('agendaItemCategoryIds'), {
+  target: { value: 'New category' },
+});
+
+expect(mockSetFormState).toHaveBeenCalledWith({
+  ...mockFormState,
+  agendaItemCategoryIds: ['New category'],
+});

153-186: Consider adding more assertions for URL addition.

Add assertions to check for all possible URL additions based on user interactions.

+fireEvent.change(urlInput, { target: { value: 'https://another-example.com' } });
+fireEvent.click(linkBtn);
+
+await waitFor(() => {
+  expect(mockSetFormState).toHaveBeenCalledWith({
+    ...mockFormState,
+    urls: [...mockFormState.urls, 'https://another-example.com'],
+  });
+});

188-219: Consider adding more assertions for invalid URL handling.

Add assertions to check for all possible invalid URL scenarios.

+fireEvent.change(urlInput, { target: { value: 'ftp://invalid-url' } });
+fireEvent.click(linkBtn);
+
+await waitFor(() => {
+  expect(toast.error).toHaveBeenCalledWith('invalidUrl');
+});

222-260: Consider adding more assertions for file size limit handling.

Add assertions to check for all possible file size limit scenarios.

+const veryLargeFile = new File(
+  ['a'.repeat(20 * 1024 * 1024)],
+  'very-large-file.jpg',
+); // 20 MB file
+
+Object.defineProperty(fileInput, 'files', {
+  value: [veryLargeFile],
+});
+
+fireEvent.change(fileInput);
+
+await waitFor(() => {
+  expect(toast.error).toHaveBeenCalledWith('fileSizeExceedsLimit');
+});

262-302: Consider adding more assertions for file addition.

Add assertions to check for all possible file additions based on user interactions.

+const anotherSmallFile = new File(['another-small-file-content'], 'another-small-file.jpg'); // Another small file
+
+Object.defineProperty(fileInput, 'files', {
+  value: [anotherSmallFile],
+});
+
+fireEvent.change(fileInput);
+
+await waitFor(() => {
+  expect(mockSetFormState).toHaveBeenCalledWith({
+    ...mockFormState,
+    attachments: [...mockFormState.attachments, 'base64-file', 'base64-file'],
+  });
+});

37-46: Ensure correct mocking of convertToBase64.

Verify that the mock implementation of convertToBase64 is correctly configured and used in tests.

Verification successful

The mock implementation of convertToBase64 is correctly configured and utilized.

  • The mock is defined and assigned a resolved value using mockResolvedValue.
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the implementation of `convertToBase64`.

# Test: Search for the implementation of `convertToBase64`. Expect: Correct usage and mock configuration.
rg --type typescript 'convertToBase64'

Length of output: 73



Script:

#!/bin/bash
# Description: Verify the implementation of `convertToBase64`.

# Test: Search for the implementation and usage of `convertToBase64`. Expect: Correct usage and mock configuration.
rg 'convertToBase64'

Length of output: 4159



Script:

#!/bin/bash
# Description: Verify the usage of `mockedConvertToBase64` in the test file to ensure correct mocking and utilization.

# Test: Search for the usage of `mockedConvertToBase64` in the test file.
rg 'mockedConvertToBase64' src/components/AgendaItems/AgendaItemsCreateModal.test.tsx

Length of output: 215

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: 2

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 0771d3a and 07f0566.

Files selected for processing (2)
  • src/components/AgendaItems/AgendaItemsUpdateModal.test.tsx (1 hunks)
  • src/components/AgendaItems/AgendaItemsUpdateModal.tsx (1 hunks)
Additional context used
Biome
src/components/AgendaItems/AgendaItemsUpdateModal.tsx

[error] 269-276: Provide an explicit type prop for the button element.

The default type of a button is submit, which causes the submission of a form when placed inside a form element. This is likely not the behaviour that you want inside a React application.
Allowed button types are: submit, button or reset

(lint/a11y/useButtonType)

Additional comments not posted (16)
src/components/AgendaItems/AgendaItemsUpdateModal.test.tsx (6)

48-76: Test Case Approved: Modal renders correctly.

The test case ensures that the modal renders with the expected elements.


78-143: Test Case Approved: Form state updates correctly.

The test case comprehensively checks for state updates for title, description, duration, URLs, and attachments.


145-178: Test Case Approved: Valid URL is added correctly.

The test case ensures that a valid URL is correctly added to the form state.


180-212: Test Case Approved: Error toast for invalid URL.

The test case ensures that an error toast is shown when an invalid URL is added.


214-252: Test Case Approved: Error toast for file size exceeding limit.

The test case ensures that an error toast is shown when a file exceeding the size limit is added.


254-294: Test Case Approved: Files added correctly when within size limit.

The test case ensures that files within the size limit are added correctly and converted to base64.

src/components/AgendaItems/AgendaItemsUpdateModal.tsx (10)

1-11: Import Statements Approved.

The import statements include necessary dependencies and utilities for the component.


12-24: Interface Approved: InterfaceFormStateType.

The interface defines the structure for the form state and includes all necessary fields.


26-34: Interface Approved: InterfaceAgendaItemsUpdateModalProps.

The interface defines the props for the AgendaItemsUpdateModal component and includes all necessary props.


36-295: Component Function Approved: AgendaItemsUpdateModal.

The component function defines the AgendaItemsUpdateModal component and includes all necessary logic.

Tools
Biome

[error] 269-276: Provide an explicit type prop for the button element.

The default type of a button is submit, which causes the submission of a form when placed inside a form element. This is likely not the behaviour that you want inside a React application.
Allowed button types are: submit, button or reset

(lint/a11y/useButtonType)


47-47: useState Hook Approved: newUrl.

The useState hook is used to manage the state of the new URL.


49-55: useEffect Hook Approved: Filtering empty URLs and attachments.

The useEffect hook filters out empty URLs and attachments from the form state.


57-62: Function Approved: isValidUrl.

The isValidUrl function validates the URL using a regular expression.


64-74: Function Approved: handleAddUrl.

The handleAddUrl function adds a new URL to the form state if it is valid.


76-81: Function Approved: handleRemoveUrl.

The handleRemoveUrl function removes a URL from the form state.


107-112: Function Approved: handleRemoveAttachment.

The handleRemoveAttachment function removes an attachment from the form state.

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: 0

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 07f0566 and 3817e4b.

Files selected for processing (1)
  • src/components/AgendaItems/AgendaItemsPreviewModal.test.tsx (1 hunks)
Additional comments not posted (4)
src/components/AgendaItems/AgendaItemsPreviewModal.test.tsx (4)

1-12: LGTM!

The imports are correctly set up for the test environment. The necessary providers and utilities are included.


15-33: LGTM!

The mock data for the form state is comprehensive and covers various fields that need to be tested.


35-35: NITPICK: Use jest.fn() for the mock translation function.

Using jest.fn() for the mock translation function allows you to track calls and improve test assertions.

- const mockT = (key: string): string => key;
+ const mockT = jest.fn((key: string): string => key);

37-101: LGTM!

The test case is well-structured and checks for the presence of text and links in the AgendaItemsPreviewModal component. The assertions cover both short and long URLs, as well as video and image attachments.

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: 1

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 3817e4b and e0a9b46.

Files selected for processing (4)
  • src/components/AgendaItems/AgendaItemsCreateModal.test.tsx (1 hunks)
  • src/components/AgendaItems/AgendaItemsCreateModal.tsx (1 hunks)
  • src/components/AgendaItems/AgendaItemsUpdateModal.test.tsx (1 hunks)
  • src/components/AgendaItems/AgendaItemsUpdateModal.tsx (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • src/components/AgendaItems/AgendaItemsCreateModal.test.tsx
  • src/components/AgendaItems/AgendaItemsUpdateModal.test.tsx
Additional context used
Biome
src/components/AgendaItems/AgendaItemsUpdateModal.tsx

[error] 269-276: Provide an explicit type prop for the button element.

The default type of a button is submit, which causes the submission of a form when placed inside a form element. This is likely not the behaviour that you want inside a React application.
Allowed button types are: submit, button or reset

(lint/a11y/useButtonType)

src/components/AgendaItems/AgendaItemsCreateModal.tsx

[error] 265-272: Provide an explicit type prop for the button element.

The default type of a button is submit, which causes the submission of a form when placed inside a form element. This is likely not the behaviour that you want inside a React application.
Allowed button types are: submit, button or reset

(lint/a11y/useButtonType)

Additional comments not posted (7)
src/components/AgendaItems/AgendaItemsUpdateModal.tsx (3)

1-10: Ensure consistent import order.

Group imports logically: external libraries first, followed by internal modules and styles.

import React, { useState, useEffect } from 'react';
import { Modal, Form, Button, Row, Col } from 'react-bootstrap';
import { Autocomplete, TextField } from '@mui/material';
import { FaLink, FaTrash } from 'react-icons/fa';
import { toast } from 'react-toastify';
import convertToBase64 from 'utils/convertToBase64';

import styles from './AgendaItemsContainer.module.css';
import type { ChangeEvent } from 'react';
import type { InterfaceAgendaItemCategoryInfo } from 'utils/interfaces';

78-100: Optimize file handling in the modal.

The file handling logic could be optimized to avoid unnecessary state updates and re-renders.

const base64Files = await Promise.all(
  files.map(async (file) => await convertToBase64(file)),
);
setFormState({
  ...formState,
  attachments: [...formState.attachments, ...base64Files],
});
+ if (files.length > 0) {
+   const base64Files = await Promise.all(
+     files.map(async (file) => await convertToBase64(file)),
+   );
+   setFormState((prevState) => ({
+     ...prevState,
+     attachments: [...prevState.attachments, ...base64Files],
+   }));
+ }

269-272: Provide an explicit type prop for the button element.

The default type of a button is submit, which causes the submission of a form when placed inside a form element. This is likely not the behavior that you want inside a React application.

- <button
+ <button type="button"
  className={styles.closeButtonFile}
  onClick={(e) => {
    e.preventDefault();
    handleRemoveAttachment(attachment);
  }}
  data-testid="deleteAttachment"
>
  <i className="fa fa-times" />
</button>
Tools
Biome

[error] 269-276: Provide an explicit type prop for the button element.

The default type of a button is submit, which causes the submission of a form when placed inside a form element. This is likely not the behaviour that you want inside a React application.
Allowed button types are: submit, button or reset

(lint/a11y/useButtonType)

src/components/AgendaItems/AgendaItemsCreateModal.tsx (4)

1-10: Ensure consistent import order.

Group imports logically: external libraries first, followed by internal modules and styles.

import React, { useState, useEffect } from 'react';
import { Modal, Form, Button, Row, Col } from 'react-bootstrap';
import { Autocomplete, TextField } from '@mui/material';
import { FaLink, FaTrash } from 'react-icons/fa';
import { toast } from 'react-toastify';
import convertToBase64 from 'utils/convertToBase64';

import styles from './AgendaItemsContainer.module.css';
import type { ChangeEvent } from 'react';
import type { InterfaceAgendaItemCategoryInfo } from 'utils/interfaces';

78-100: Optimize file handling in the modal.

The file handling logic could be optimized to avoid unnecessary state updates and re-renders.

const base64Files = await Promise.all(
  files.map(async (file) => await convertToBase64(file)),
);
setFormState({
  ...formState,
  attachments: [...formState.attachments, ...base64Files],
});
+ if (files.length > 0) {
+   const base64Files = await Promise.all(
+     files.map(async (file) => await convertToBase64(file)),
+   );
+   setFormState((prevState) => ({
+     ...prevState,
+     attachments: [...prevState.attachments, ...base64Files],
+   }));
+ }

265-272: Provide an explicit type prop for the button element.

The default type of a button is submit, which causes the submission of a form when placed inside a form element. This is likely not the behavior that you want inside a React application.

- <button
+ <button type="button"
  className={styles.closeButtonFile}
  onClick={(e) => {
    e.preventDefault();
    handleRemoveAttachment(attachment);
  }}
  data-testid="deleteAttachment"
>
  <i className="fa fa-times" />
</button>
Tools
Biome

[error] 265-272: Provide an explicit type prop for the button element.

The default type of a button is submit, which causes the submission of a form when placed inside a form element. This is likely not the behaviour that you want inside a React application.
Allowed button types are: submit, button or reset

(lint/a11y/useButtonType)


44-50: Avoid unnecessary state updates in useEffect.

The useEffect hook updates the state on every render, which might cause unnecessary re-renders. Consider adding a dependency array.

useEffect(() => {
  setFormState((prevState) => ({
    ...prevState,
    urls: prevState.urls.filter((url) => url.trim() !== ''),
    attachments: prevState.attachments.filter((att) => att !== ''),
  }));
- }, []);
+ }, [setFormState]);

Likely invalid or redundant comment.

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: 0

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between e0a9b46 and ab15f44.

Files selected for processing (4)
  • src/components/AgendaItems/AgendaItemsContainer.test.tsx (1 hunks)
  • src/components/EventManagement/EventAgendaItems/EventAgendaItems.test.tsx (1 hunks)
  • src/components/EventManagement/EventAgendaItems/EventAgendaItems.tsx (1 hunks)
  • src/components/EventManagement/EventAgendaItems/EventAgendaItemsMocks.ts (1 hunks)
Files skipped from review as they are similar to previous changes (4)
  • src/components/AgendaItems/AgendaItemsContainer.test.tsx
  • src/components/EventManagement/EventAgendaItems/EventAgendaItems.test.tsx
  • src/components/EventManagement/EventAgendaItems/EventAgendaItems.tsx
  • src/components/EventManagement/EventAgendaItems/EventAgendaItemsMocks.ts

coderabbitai[bot]
coderabbitai bot previously approved these changes Jul 3, 2024
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: 0

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between ab15f44 and 2ebd80d.

Files selected for processing (1)
  • src/components/AgendaItems/AgendaItemsContainer.module.css (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/components/AgendaItems/AgendaItemsContainer.module.css

@gautam-divyanshu
Copy link
Member Author

gautam-divyanshu commented Jul 3, 2024

@palisadoes I tried my best to improve code coverage as much as possible, but there are some lines for which I can't write a test case.

I tried writing a test case for drag and drop but did not get success.
So, can we merge this PR?

@gautam-divyanshu
Copy link
Member Author

I tried a lot, but code coverage is not going up.

@palisadoes palisadoes merged commit 0254bb0 into PalisadoesFoundation:develop Jul 5, 2024
9 of 12 checks passed
@palisadoes
Copy link
Contributor

I think the low code coverage may be due to the large number of yaml file changes. Do you know of a way to ignore these?

@gautam-divyanshu
Copy link
Member Author

@palisadoes No, I tried almost everything.
and low code coverage is due to src code only; I have checked coverage for single files locally.

@palisadoes
Copy link
Contributor

Thanks

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.

2 participants