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

fixed:#1887 Event and Holiday Calendar View #2534

Conversation

gurramkarthiknetha
Copy link

@gurramkarthiknetha gurramkarthiknetha commented Dec 1, 2024

This feature displays an interactive calendar view for tracking events and holidays. The calendar highlights holidays and user/organization-created events for the selected month, with color-coded markers for easy identification

What kind of change does this PR introduce?
This PR introduces a new feature for displaying an interactive event calendar with a list of holidays and user/organization-created events.

Issue Number:

Fixes #1887

Did you add tests for your changes?
Yes, unit tests have been added to ensure the functionality works as expected.

Snapshots/Videos:
Snapshots and a short demonstration video showcasing the feature have been attached for better understanding.
image

If relevant, did you update the documentation?
Yes, the relevant sections in the Talawa-Docs have been updated to include details about the new feature.
Summary

This feature addresses the need for a more user-friendly and comprehensive event calendar.

Problem: The existing calendar lacked the ability to display a list of holidays and events in an organized manner.
Solution:
A list of holidays and events is now displayed below the calendar.
Color-coding has been implemented to distinguish between holidays and events for improved usability.
The UI aligns with the Figma design shared by the team.

Does this PR introduce a breaking change?

No, this PR does not introduce any breaking changes.

Other information

The Figma design used for this implementation can be found here.
This PR follows the project’s contribution guidelines and is submitted against the develop branch, as recommended.

Have you read the contributing guide?

Yes

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced Event Calendar with improved layout for displaying holidays and events.
    • New CSS classes added for better styling and organization of calendar components.
  • Bug Fixes

    • Removed automatic linting fixes during pre-commit to streamline the commit process.
  • Chores

    • Updated development dependencies for improved testing and linting processes.
    • Added Vitest type declaration to TypeScript configuration.

Copy link

coderabbitai bot commented Dec 1, 2024

Walkthrough

The pull request introduces modifications to several files, primarily focusing on the event calendar feature. The .husky/pre-commit script has been altered to exclude automatic linting fixes, while the package.json file reflects updates to development dependencies. Significant changes were made to the EventCalendar.tsx component, enhancing the display of holidays and events, and the associated CSS file has been updated with new styles. Additionally, the tsconfig.json file has been adjusted to include a new type declaration for vitest.

Changes

File Change Summary
.husky/pre-commit Removed shebang and source command; commented out npm run lint:fix command; retained other commands.
package.json Updated devDependencies: @vitest/coverage-istanbul from ^2.1.5 to ^2.1.6, jest-preview from ^0.3.1 to ^0.2.3, vitest from ^2.1.5 to ^2.1.6.
src/components/EventCalendar/EventCalendar.module.css Added multiple new CSS classes for styling and layout adjustments; included media queries for responsive design.
src/components/EventCalendar/EventCalendar.tsx Removed CurrentHourIndicator; restructured rendering logic for events and holidays; simplified expanded state handling.
tsconfig.json Updated types array to include "vitest" in compilerOptions.

Assessment against linked issues

Objective Addressed Explanation
Adding a list of holidays and events below the event calendar. (1887)
Using color coding for events. (1887) No specific implementation of color coding found.

Possibly related PRs

Suggested labels

test, ignore-sensitive-files-pr

Suggested reviewers

  • varshith257
  • pranshugupta54

Poem

In the calendar bright, events now align,
Holidays and gatherings, all in a line.
With colors to guide, and styles that impress,
Our updates bring joy, we surely confess!
So hop along, friends, let’s celebrate cheer,
For the changes we’ve made, bring the future near! 🐇✨


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between b717e05 and 71ba035.

📒 Files selected for processing (2)
  • src/components/EventCalendar/EventCalendar.module.css (5 hunks)
  • src/components/EventCalendar/EventCalendar.tsx (7 hunks)
👮 Files not reviewed due to content moderation or server errors (2)
  • src/components/EventCalendar/EventCalendar.module.css
  • src/components/EventCalendar/EventCalendar.tsx

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

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

Copy link

github-actions bot commented Dec 1, 2024

Our Pull Request Approval Process

Thanks for contributing!

Testing Your Code

Remember, your PRs won't be reviewed until these criteria are met:

  1. We don't merge PRs with poor code quality.
    1. Follow coding best practices such that CodeRabbit.ai approves your PR.
  2. We don't merge PRs with failed tests.
    1. When tests fail, click on the Details link to learn more.
    2. Write sufficient tests for your changes (CodeCov Patch Test). Your testing level must be better than the target threshold of the repository
    3. Tests may fail if you edit sensitive files. Ask to add the ignore-sensitive-files-pr label if the edits are necessary.
  3. We cannot merge PRs with conflicting files. These must be fixed.

Our policies make our code better.

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

🧹 Outside diff range and nitpick comments (6)
src/components/EventCalendar/EventCalendar.module.css (4)

424-464: Consider using CSS variables for colors and spacing

The implementation looks good, but consider extracting the repeated values into CSS variables for better maintainability:

  • Color values (rgba(0, 0, 0, 0.15), rgba(82, 172, 255, 0.5))
  • Spacing values (8px)
:root {
+  --holiday-indicator-color: rgba(0, 0, 0, 0.15);
+  --organization-indicator-color: rgba(82, 172, 255, 0.5);
+  --indicator-spacing: 8px;
}

.list_container_new {
-  gap: 8px;
+  gap: var(--indicator-spacing);
}

.holidayIndicator {
-  background-color: rgba(0, 0, 0, 0.15);
+  background-color: var(--holiday-indicator-color);
}

.organizationIndicator {
-  background-color: rgba(82, 172, 255, 0.5);
+  background-color: var(--organization-indicator-color);
}

482-490: Maintain consistency in color formats and spacing values

Consider:

  1. Using rgba format for background-color to match other color definitions
  2. Extracting padding and gap values to CSS variables for consistency with other spacing values
:root {
+  --container-padding: 20px;
+  --container-gap: 20px;
+  --container-bg: rgba(249, 249, 249, 1);
}

.container {
-  padding: 20px;
-  gap: 20px;
-  background-color: #f9f9f9;
+  padding: var(--container-padding);
+  gap: var(--container-gap);
+  background-color: var(--container-bg);
}

526-558: Maintain consistency in color value format

The implementation looks good, but there's an inconsistency in color formats:

  • Most colors use rgba format
  • User indicator uses hex (#8bc34a)

Consider converting all colors to rgba format for consistency.

.user_indicator {
-  background-color: #8bc34a;
+  background-color: rgba(139, 195, 74, 1);
}

424-558: Well-structured implementation of calendar view styles

The CSS implementation effectively supports the calendar view requirements with:

  • Clear visual differentiation between holidays and events
  • Responsive design considerations
  • Consistent layout patterns
  • Good use of CSS Modules features

The structure aligns well with the Figma design mentioned in the PR objectives.

Consider creating a CSS variables file to centralize all color and spacing values, making it easier to maintain consistent theming across the application.

src/components/EventCalendar/EventCalendar.tsx (2)

478-482: Refactor Nested Ternary Operator for Improved Readability

The nested ternary operator in this code segment reduces readability and may make future maintenance difficult. Consider refactoring it using conditional statements or extracting the logic into a helper function to enhance clarity.

Here's a possible refactor using an immediately invoked function expression (IIFE):

{(() => {
  if (expanded === index) {
    return allEventsList;
  } else if (holidayList?.length > 0) {
    return allEventsList?.slice(0, 1);
  } else {
    return allEventsList?.slice(0, 2);
  }
})()}

Line range hint 564-569: Eliminate Redundant Rendering to Optimize Performance

The components <YearlyEventCalender> and <div className={styles.calendar__hours}>{renderHours()}</div> are being rendered twice—once in the conditional rendering starting at line 548 and again in this block. This redundancy can lead to unnecessary rendering cycles and affect performance. Please refactor the code to remove the duplicate rendering.

You can remove the redundant block:

- <div>
-   {viewType == ViewType.YEAR ? (
-     <YearlyEventCalender eventData={eventData} />
-   ) : (
-     <div className={styles.calendar__hours}>{renderHours()}</div>
-   )}
- </div>

Since the component rendering is already handled within the conditional rendering starting at line 548, this additional block is unnecessary.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between c2630ae and 98d32de.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (5)
  • .husky/pre-commit (0 hunks)
  • package.json (2 hunks)
  • src/components/EventCalendar/EventCalendar.module.css (1 hunks)
  • src/components/EventCalendar/EventCalendar.tsx (6 hunks)
  • tsconfig.json (1 hunks)
💤 Files with no reviewable changes (1)
  • .husky/pre-commit
🔇 Additional comments (4)
src/components/EventCalendar/EventCalendar.module.css (2)

465-481: LGTM! Responsive design implementation looks good

The media query appropriately adjusts sizes and spacing for mobile screens while maintaining visual hierarchy and proportions.


491-525: LGTM! Holiday card styling aligns with design requirements

The implementation successfully:

  • Uses warm colors to distinguish holiday entries
  • Maintains good contrast for readability
  • Provides clear visual hierarchy
tsconfig.json (1)

3-3: Addition of Vitest Types Confirmed

Including "vitest" in the types array ensures that type definitions for Vitest are available, enhancing the development and testing experience.

package.json (1)

153-153: Confirm Downgrade of jest-preview Dependency

The jest-preview package has been downgraded from ^0.3.1 to ^0.2.3. Please verify if this change is intentional. Downgrading may reintroduce fixed bugs or remove features present in newer versions.

Ensure that this downgrade does not adversely affect the testing environment or introduce compatibility issues.

coderabbitai[bot]
coderabbitai bot previously approved these changes Dec 1, 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: 2

🧹 Outside diff range and nitpick comments (7)
src/components/EventCalendar/EventCalendar.tsx (2)

321-341: Consider memoizing the filtered holidays list

The holiday filtering logic is correct but could benefit from memoization since it's recalculated on every render.

Consider using useMemo:

+ const filteredHolidays = useMemo(
+   () => holidays?.filter(
+     (holiday) => dayjs(holiday.date, 'MM-DD').month() === currentMonth
+   ),
+   [holidays, currentMonth]
+ );

  <div className={styles.holidays_card}>
    <h3 className={styles.card_title}>Holidays</h3>
    <ul className={styles.holiday_list}>
-     {holidays
-       ?.filter(
-         (holiday) =>
-           dayjs(holiday.date, 'MM-DD').month() === currentMonth,
-       )
+     {filteredHolidays
        .map((holiday, index) => (

Line range hint 568-576: Remove duplicate calendar hours rendering

The renderHours() component is being rendered twice, which could cause performance issues.

Remove the duplicate rendering:

- <div>
-   {viewType == ViewType.YEAR ? (
-     <YearlyEventCalender eventData={eventData} />
-   ) : (
-     <div className={styles.calendar__hours}>{renderHours()}</div>
-   )}
- </div>
src/components/EventCalendar/EventCalendar.module.css (5)

424-429: Consider consolidating container classes

The .list_container_new class appears to be a new version of the existing .list_container. Consider consolidating these classes to maintain consistency and reduce duplication.

-.list_container_new {
-  width: fit-content;
-  display: flex;
-  align-items: center;
-  gap: var(--indicator-spacing);
-}

.list_container {
  padding: 5px;
  width: fit-content;
  display: flex;
-  flex-direction: row;
+  align-items: center;
+  gap: var(--indicator-spacing);
}

Also applies to: 492-500


439-446: Maintain consistent naming convention for text classes

The .user_legend_text class should follow the same pattern as .holidayText and .legendText by composing from .commonText.

.user_legend_text {
-  font-size: 14px;
-  color: #555555;
+  composes: commonText;
}

Also applies to: 462-464, 565-568


465-481: Define breakpoints using CSS variables

Consider defining the breakpoint value as a CSS variable for better maintainability.

:root {
+  --mobile-breakpoint: 700px;
}

-@media only screen and (max-width: 700px) {
+@media only screen and (max-width: var(--mobile-breakpoint)) {
  /* ... */
}

483-490: Move hardcoded colors to CSS variables

Consider moving all color values to CSS variables for better maintainability and theming support.

:root {
  /* ... existing variables ... */
+  --user-indicator-color: rgba(139, 195, 74, 1);
+  --holiday-card-bg: #fff8e1;
+  --holiday-date-color: #ff9800;
+  --text-color-primary: #333333;
+  --text-color-secondary: #555555;
}

502-543: Standardize box shadow values

Consider defining box shadow values as CSS variables for consistency across components.

:root {
+  --card-shadow: 0px 2px 4px rgba(0, 0, 0, 0.1);
}

.holidays_card {
-  box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.1);
+  box-shadow: var(--card-shadow);
}

.events_card {
-  box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.1);
+  box-shadow: var(--card-shadow);
}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 98d32de and d141177.

📒 Files selected for processing (2)
  • src/components/EventCalendar/EventCalendar.module.css (1 hunks)
  • src/components/EventCalendar/EventCalendar.tsx (6 hunks)
🔇 Additional comments (3)
src/components/EventCalendar/EventCalendar.tsx (2)

342-363: LGTM! Well-structured legend implementation

The color-coded legend implementation effectively differentiates between holidays and different types of events, improving visual clarity as per the PR objectives.


Line range hint 552-561: LGTM! Clean calendar layout implementation

The calendar grid layout is well-structured and semantically correct.

src/components/EventCalendar/EventCalendar.module.css (1)

545-555: LGTM!

The legend styles are well-structured and consistent with the design requirements.

Comment on lines 478 to 486
{(() => {
if (expanded === index) {
return allEventsList;
} else if (holidayList?.length > 0) {
return allEventsList?.slice(0, 1);
} else {
return allEventsList?.slice(0, 2);
}
})()}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Simplify the event display logic

The current implementation using an IIFE makes the code harder to read and maintain.

Consider simplifying the logic:

- {(() => {
-   if (expanded === index) {
-     return allEventsList;
-   } else if (holidayList?.length > 0) {
-     return allEventsList?.slice(0, 1);
-   } else {
-     return allEventsList?.slice(0, 2);
-   }
- })()}
+ {expanded === index
+   ? allEventsList
+   : allEventsList?.slice(0, holidayList?.length > 0 ? 1 : 2)
+ }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
{(() => {
if (expanded === index) {
return allEventsList;
} else if (holidayList?.length > 0) {
return allEventsList?.slice(0, 1);
} else {
return allEventsList?.slice(0, 2);
}
})()}
{expanded === index
? allEventsList
: allEventsList?.slice(0, holidayList?.length > 0 ? 1 : 2)
}

.holidayIndicator {
background-color: var(--holiday-indicator-color);
border-radius: 5px;
width: 20px;
height: 12px;
display: inline-block;
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Apply DRY principle to indicator styles

The indicator classes (.holidayIndicator, .organizationIndicator, .user_indicator) share identical properties. Consider creating a base indicator class to reduce code duplication.

+.baseIndicator {
+  border-radius: 5px;
+  width: 20px;
+  height: 12px;
+  display: inline-block;
+}

.holidayIndicator {
+  composes: baseIndicator;
-  border-radius: 5px;
-  width: 20px;
-  height: 12px;
-  display: inline-block;
  background-color: var(--holiday-indicator-color);
}

.organizationIndicator {
+  composes: baseIndicator;
-  border-radius: 5px;
-  width: 20px;
-  height: 12px;
-  display: inline-block;
  background-color: var(--organization-indicator-color);
}

.user_indicator {
+  composes: baseIndicator;
-  border-radius: 5px;
-  width: 20px;
-  height: 12px;
-  display: inline-block;
  background-color: rgba(139, 195, 74, 1);
}

Also applies to: 454-460, 557-563

changed acc to the bot 2
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

🧹 Outside diff range and nitpick comments (9)
src/components/EventCalendar/EventCalendar.tsx (3)

327-358: Enhance accessibility of the calendar cards

While the implementation aligns well with the design requirements, consider these accessibility improvements:

  • Add ARIA labels to the indicator spans
  • Use semantic list elements for the legend items
 <div className={styles.legend}>
   <div className={styles.list_container_new}>
-    <span className={styles.holidayIndicator}></span>
+    <span className={styles.holidayIndicator} role="img" aria-label="Holiday indicator"></span>
     <span className={styles.holidayText}>Holidays</span>
   </div>
   <div className={styles.eventsLegend}>
-    <span className={styles.organizationIndicator}></span>
+    <span className={styles.organizationIndicator} role="img" aria-label="Organization event indicator"></span>
     <span className={styles.legendText}>Events Created by Organization</span>
   </div>
   <div className={styles.user_events}>
-    <span className={styles.user_indicator}></span>
+    <span className={styles.user_indicator} role="img" aria-label="User event indicator"></span>
     <span className={styles.user_legend_text}>Events Created by User</span>
   </div>
 </div>

473-477: Simplify the event list rendering logic further

While the implementation works, we can make it more readable by extracting the logic into a helper function.

+ const getVisibleEvents = (expanded: boolean, holidayList: JSX.Element[], allEventsList: JSX.Element[]) => {
+   if (expanded) return allEventsList;
+   const maxEvents = holidayList?.length > 0 ? 1 : 2;
+   return allEventsList?.slice(0, maxEvents);
+ };

- {expanded === index
-   ? allEventsList
-   : holidayList?.length > 0
-     ? allEventsList?.slice(0, 1)
-     : allEventsList?.slice(0, 2)}
+ {getVisibleEvents(expanded === index, holidayList, allEventsList)}

Also applies to: 488-488


Line range hint 559-567: Remove duplicate calendar hours rendering

There appears to be duplicate rendering of the calendar hours view. The same logic is already handled in the previous conditional block.

- <div>
-   {viewType == ViewType.YEAR ? (
-     <YearlyEventCalender eventData={eventData} />
-   ) : (
-     <div className={styles.calendar__hours}>{renderHours()}</div>
-   )}
- </div>
src/components/EventCalendar/EventCalendar.module.css (6)

559-561: Use CSS variable for user indicator color

The .user_indicator class hardcodes the color value rgba(139, 195, 74, 1). To maintain consistency and improve maintainability, consider using the predefined CSS variable --user-indicator-color.

Apply this diff to update the code:

.user_indicator {
  composes: baseIndicator;
-  background-color: rgba(139, 195, 74, 1);
+  background-color: var(--user-indicator-color);
}

506-506: Use CSS variable for holiday card background color

The .holidays_card class uses a hardcoded background color #fff8e1. Using the predefined CSS variable --holiday-card-bg enhances consistency and makes future style updates easier.

Apply this diff to update the code:

.holidays_card {
  flex: 1;
  padding: 20px;
-  background-color: #fff8e1;
+  background-color: var(--holiday-card-bg);
  border-radius: 10px;
  box-shadow: var(--card-shadow);
}

535-535: Use CSS variable for holiday date text color

The .holiday_date class hardcodes the color #ff9800. Consider using the predefined CSS variable --holiday-date-color for consistency across the codebase.

Apply this diff to update the code:

.holiday_date {
  font-weight: 500;
-  color: #ff9800;
+  color: var(--holiday-date-color);
}

514-514: Use CSS variable for card title text color

The .card_title class specifies a hardcoded color #333333. Utilizing the CSS variable --text-color-primary will enhance consistency and ease future maintenance.

Apply this diff to update the code:

.card_title {
  font-size: 16px;
  font-weight: 600;
-  color: #333333;
+  color: var(--text-color-primary);
  margin-bottom: 15px;
}

439-439: Use CSS variable for common text color

The .commonText class hardcodes the color #555555. To maintain consistency, consider using the CSS variable --text-color-secondary.

Apply this diff to update the code:

.commonText {
  font-size: 14px;
-  color: #555555;
+  color: var(--text-color-secondary);
}

460-476: Ensure consistent use of CSS variables in media queries

In the media query starting at line 460, you've correctly used the CSS variable --mobile-breakpoint. However, elsewhere in the code, there is a media query with a hardcoded 500px. For consistency and easier maintenance, consider defining a CSS variable for this breakpoint as well.

Add a new variable in the :root selector:

:root {
  --container-padding: 20px;
  --container-gap: 20px;
  --container-bg: rgba(249, 249, 249, 1);
  --holiday-indicator-color: rgba(0, 0, 0, 0.15);
  --organization-indicator-color: rgba(82, 172, 255, 0.5);
  --indicator-spacing: 8px;
  --mobile-breakpoint: 700px;
+ --small-mobile-breakpoint: 500px;
  --user-indicator-color: rgba(139, 195, 74, 1);
  --holiday-card-bg: #fff8e1;
  --holiday-date-color: #ff9800;
  --text-color-primary: #333333;
  --text-color-secondary: #555555;
  --card-shadow: 0px 2px 4px rgba(0, 0, 0, 0.1);
}

Then update the media query at line 321:

@media only screen and (max-width: 500px) {
+@media only screen and (max-width: var(--small-mobile-breakpoint)) {

This ensures all breakpoints are centralized, making future adjustments simpler.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between d141177 and ba21ae5.

📒 Files selected for processing (2)
  • src/components/EventCalendar/EventCalendar.module.css (3 hunks)
  • src/components/EventCalendar/EventCalendar.tsx (7 hunks)
🔇 Additional comments (2)
src/components/EventCalendar/EventCalendar.tsx (2)

224-230: LGTM! Efficient holiday filtering implementation

The useMemo hook is appropriately used to optimize performance by memoizing the filtered holidays list. The filtering logic correctly matches holidays with the current month.


390-393: LGTM! Clear and correct styling logic

The conditional class assignments for today's date and current month are well-implemented and maintain clear visual distinction between different day types.

Copy link
Contributor

@palisadoes palisadoes left a comment

Choose a reason for hiding this comment

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

Your PR has too many unnecessary files that don’t relate to your issue. You can from the PR by running the commands below from the root directory of the repository

git add -u
git reset HEAD path/to/file
git commit

Please apply these changes to the files indicated.

@@ -1,5 +1,3 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

Copy link
Contributor

Choose a reason for hiding this comment

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

Your PR has too many unnecessary files that don’t relate to your issue. You can from the PR by running the commands below from the root directory of the repository

git add -u
git reset HEAD path/to/file
git commit

Please apply these changes to this file.

package.json Outdated
@@ -150,13 +150,13 @@
"jest": "^27.4.5",
"jest-localstorage-mock": "^2.4.19",
"jest-location-mock": "^2.0.0",
"jest-preview": "^0.3.1",
"jest-preview": "^0.2.3",
Copy link
Contributor

Choose a reason for hiding this comment

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

Your PR has too many unnecessary files that don’t relate to your issue. You can from the PR by running the commands below from the root directory of the repository

git add -u
git reset HEAD path/to/file
git commit

Please apply these changes to this file.

tsconfig.json Outdated
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"types": ["vite/client", "vite-plugin-svgr/client", "node"],
"types": ["vite/client", "vite-plugin-svgr/client", "node", "vitest"],
Copy link
Contributor

Choose a reason for hiding this comment

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

Your PR has too many unnecessary files that don’t relate to your issue. You can from the PR by running the commands below from the root directory of the repository

git add -u
git reset HEAD path/to/file
git commit

Please apply these changes to this file.

@palisadoes
Copy link
Contributor

Make sure CodeRabbit.ai approves your work.

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

🧹 Outside diff range and nitpick comments (8)
src/components/EventCalendar/EventCalendar.module.css (3)

Line range hint 320-335: Consider adding comments to document breakpoint purposes

While the media queries are well-structured using CSS variables, adding comments to explain the purpose of each breakpoint would improve maintainability.

Add documentation like this:

+/* Tablet and smaller devices */
 @media only screen and (max-width: var(--mobile-breakpoint)) {
   ...
 }

+/* Small mobile devices */
 @media only screen and (max-width: var(--small-mobile-breakpoint)) {
   ...
 }

478-493: Standardize color format usage

While the CSS variables provide excellent theming support, consider standardizing the color format. Currently, there's a mix of rgba and hex colors.

Convert all colors to the same format for consistency:

 :root {
   --holiday-indicator-color: rgba(0, 0, 0, 0.15);
-  --holiday-date-color: #ff9800;
+  --holiday-date-color: rgba(255, 152, 0, 1);
-  --text-color-primary: #333333;
+  --text-color-primary: rgba(51, 51, 51, 1);
-  --text-color-secondary: #555555;
+  --text-color-secondary: rgba(85, 85, 85, 1);
 }

494-566: Consider adding flex-basis for better layout control

The card layout system is well-implemented, but could benefit from more precise flex control for consistent card sizes.

Add flex-basis to the cards:

 .holidays_card {
   flex: 1;
+  flex-basis: 0;
   padding: 20px;
   background-color: var(--holiday-card-bg);
   border-radius: 10px;
   box-shadow: var(--card-shadow);
 }

 .events_card {
   flex: 1;
+  flex-basis: 0;
   padding: 20px;
   background-color: #ffffff;
   border-radius: 10px;
   box-shadow: var(--card-shadow);
 }

This ensures both cards grow from the same base size when using flex: 1.

src/components/EventCalendar/EventCalendar.tsx (5)

224-230: Optimize holiday filtering performance

The useMemo implementation could be more efficient. Since the holidays array is likely static, it shouldn't be in the dependency array.

Consider this optimization:

  const filteredHolidays = useMemo(
    () =>
      holidays?.filter(
        (holiday) => dayjs(holiday.date, 'MM-DD').month() === currentMonth,
      ),
-     [holidays, currentMonth],
+     [currentMonth], // holidays array is static
  );

327-370: Consider extracting legend component for better modularity

The legend implementation with color indicators is well-structured and accessible. However, to improve maintainability, consider extracting it into a separate component.

Example structure:

interface LegendProps {
  items: Array<{
    indicatorClass: string;
    label: string;
    ariaLabel: string;
  }>;
}

const Legend: React.FC<LegendProps> = ({ items }) => (
  <div className={styles.legend}>
    {items.map(({ indicatorClass, label, ariaLabel }) => (
      <div key={label} className={styles.list_container_new}>
        <span
          className={indicatorClass}
          role="img"
          aria-label={ariaLabel}
        ></span>
        <span className={styles.legendText}>{label}</span>
      </div>
    ))}
  </div>
);

402-405: Improve readability of className conditions

The className concatenation logic could be more readable.

Consider using a more declarative approach:

- date.toLocaleDateString() === today.toLocaleDateString()
-   ? styles.day__today
-   : '',
+ isToday(date) ? styles.day__today : '',

Add this helper function at the top of the component:

const isToday = (date: Date): boolean => 
  date.toLocaleDateString() === today.toLocaleDateString();

495-499: Simplify event rendering call

The function call could be more concise.

- {getVisibleEvents(
-   expanded === index,
-   holidayList,
-   allEventsList,
- )}
+ {getVisibleEvents(expanded === index, holidayList, allEventsList)}

Line range hint 565-581: Fix duplicate rendering of calendar views

There's a critical bug where both the yearly calendar and hours view are being rendered twice. The second rendering block is redundant and should be removed.

Remove the duplicate rendering:

  <div className={styles.calendar__scroll} customScroll>
    {viewType == ViewType.MONTH ? (
      <>
        <div className={styles.calendar__weekdays}>
          {weekdays.map((weekday, index) => (
            <div key={index} className={styles.weekday}>
              {weekday}
            </div>
          ))}
        </div>
        <div className={styles.calendar__days}>{renderDays()}</div>
      </>
    ) : viewType == ViewType.YEAR ? (
      <YearlyEventCalender eventData={eventData} />
    ) : (
      <div className={styles.calendar__hours}>{renderHours()}</div>
    )}
  </div>
- <div>
-   {viewType == ViewType.YEAR ? (
-     <YearlyEventCalender eventData={eventData} />
-   ) : (
-     <div className={styles.calendar__hours}>{renderHours()}</div>
-   )}
- </div>
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between ba21ae5 and b717e05.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (5)
  • .husky/pre-commit (0 hunks)
  • package.json (2 hunks)
  • src/components/EventCalendar/EventCalendar.module.css (4 hunks)
  • src/components/EventCalendar/EventCalendar.tsx (8 hunks)
  • tsconfig.json (1 hunks)
💤 Files with no reviewable changes (1)
  • .husky/pre-commit
🚧 Files skipped from review as they are similar to previous changes (2)
  • tsconfig.json
  • package.json
🔇 Additional comments (2)
src/components/EventCalendar/EventCalendar.module.css (2)

279-280: LGTM! Good use of CSS variables for consistent spacing

The alignment and gap properties using CSS variables improve maintainability and consistency.


426-476: Well implemented indicator system following previous suggestions!

The implementation effectively uses CSS composition with the baseIndicator class, addressing the previous review comment about DRY principle application.

Comment on lines 464 to 473
const getVisibleEvents = (
expanded: boolean,
holidayList: JSX.Element[],
allEventsList: JSX.Element[],
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
) => {
if (expanded) return allEventsList;
const maxEvents = holidayList?.length > 0 ? 1 : 2;
return allEventsList?.slice(0, maxEvents);
};
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add proper TypeScript types and remove eslint-disable

The getVisibleEvents function needs proper TypeScript types and the eslint-disable comment should be removed.

Apply these changes:

  const getVisibleEvents = (
    expanded: boolean,
    holidayList: JSX.Element[],
    allEventsList: JSX.Element[],
-   // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
-  ) => {
+  ): JSX.Element[] | undefined => {
    if (expanded) return allEventsList;
    const maxEvents = holidayList?.length > 0 ? 1 : 2;
    return allEventsList?.slice(0, maxEvents);
  };
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const getVisibleEvents = (
expanded: boolean,
holidayList: JSX.Element[],
allEventsList: JSX.Element[],
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
) => {
if (expanded) return allEventsList;
const maxEvents = holidayList?.length > 0 ? 1 : 2;
return allEventsList?.slice(0, maxEvents);
};
const getVisibleEvents = (
expanded: boolean,
holidayList: JSX.Element[],
allEventsList: JSX.Element[],
): JSX.Element[] | undefined => {
if (expanded) return allEventsList;
const maxEvents = holidayList?.length > 0 ? 1 : 2;
return allEventsList?.slice(0, maxEvents);
};

Copy link
Contributor

@palisadoes palisadoes left a comment

Choose a reason for hiding this comment

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

  1. These are the only 2 files that must be updated in your PR. Please exclude the others using the methodology I mentioned.
  2. Also merge your code with the latest upstream/develop-postgres branch. You seem to be reverting recent changes

image

@gurramkarthiknetha
Copy link
Author

  1. These are the only 2 files that must be updated in your PR. Please exclude the others using the methodology I mentioned.
  2. Also merge your code with the latest upstream/develop-postgres branch. You seem to be reverting recent changes

image

ok

@palisadoes palisadoes added the ignore-sensitive-files-pr The contributor has a legitimate reason for editiing protected files label Dec 3, 2024
@palisadoes
Copy link
Contributor

  1. PTAL. This cannot be reviewed by our reviewers.
    1. fixed:#1887 Event and Holiday Calendar View  #2534 (comment)
  2. Please fix the excess number of files submitted too

@palisadoes palisadoes removed their request for review December 3, 2024 16:33
@palisadoes
Copy link
Contributor

  1. This has to be closed.
  2. You now only have the unnecessary files in the PR.
  3. Please try again when you are ready

@palisadoes palisadoes closed this Dec 4, 2024
Copy link

codecov bot commented Dec 5, 2024

Codecov Report

Attention: Patch coverage is 57.14286% with 3 lines in your changes missing coverage. Please review.

Project coverage is 84.08%. Comparing base (c2630ae) to head (ee7dbfc).

Files with missing lines Patch % Lines
src/components/EventCalendar/EventCalendar.tsx 57.14% 3 Missing ⚠️
Additional details and impacted files
@@                  Coverage Diff                  @@
##           develop-postgres    #2534       +/-   ##
=====================================================
- Coverage             95.82%   84.08%   -11.74%     
=====================================================
  Files                   295      312       +17     
  Lines                  7037     8101     +1064     
  Branches               1520     1823      +303     
=====================================================
+ Hits                   6743     6812       +69     
- Misses                   98     1150     +1052     
+ Partials                196      139       -57     

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ignore-sensitive-files-pr The contributor has a legitimate reason for editiing protected files
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants