Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat]: Functionalize TeamDashboardFilter component with optimized state management #3576

Merged
merged 5 commits into from
Feb 3, 2025

Conversation

Innocent-Akim
Copy link
Contributor

@Innocent-Akim Innocent-Akim commented Feb 3, 2025

Description

Please include a summary of the changes and the related issues.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented on my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings

Previous screenshots

Please add here videos or images of the previous status

Current screenshots

Please add here videos or images of the current (new) status

Summary by CodeRabbit

  • New Features
    • Introduced an interactive filter component for team dashboards, allowing users to easily refine teams and employee data.
    • Expanded timelog filtering options with additional team and user selection capabilities.
  • Improvements
    • Enhanced the dashboard header filtering for a smoother and more intuitive experience.
    • Refined the layout and styling of timesheet filters for improved visual consistency.
    • Increased the reliability of team selection to prevent potential display issues.
    • Added new terms to the spell checker for improved text accuracy.
    • Improved safety in property access for team selection to prevent runtime errors.

Copy link
Contributor

coderabbitai bot commented Feb 3, 2025

Caution

Review failed

The pull request is closed.

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

apps/web/app/[locale]/dashboard/team-dashboard/[teamId]/components/team-dashboard-filter.tsx

Oops! Something went wrong! :(

ESLint: 8.46.0

ESLint couldn't find the config "next/core-web-vitals" to extend from. Please check that the name of the config is correct.

The config "next/core-web-vitals" was referenced from the config file in "/apps/web/.eslintrc.json".

If you still have problems, please stop by https://eslint.org/chat/help to chat with the team.

Walkthrough

This pull request introduces several changes across the codebase. Two new words have been added in the spell-check configuration file. The team dashboard filtering functionality has been refactored by extracting filter logic into a new TeamDashboardFilter component and updating the header component accordingly. Additionally, new state atoms and hook enhancements have been added to support global states for users and teams. Minor cosmetic adjustments were performed on the timesheet filter popover, and safe access via optional chaining was introduced in the teams dropdown.

Changes

File(s) Change Summary
.cspell.json Added two new words "alluser" and "allteams" to the "words" array.
apps/web/app/[locale]/…/dashboard/team-dashboard/[teamId]/components/dashboard-header.tsx
apps/web/app/[locale]/…/dashboard/team-dashboard/[teamId]/components/team-dashboard-filter.tsx
Removed the handleFilterChange function and integrated the new TeamDashboardFilter component to encapsulate filtering logic. A new TeamDashboardFilter component was introduced.
apps/web/app/[locale]/timesheet/[memberId]/components/TimeSheetFilterPopover.tsx Cosmetic formatting adjustments: changed quotation marks and reordered class names.
apps/web/app/hooks/features/useTimelogFilterOptions.ts
apps/web/app/stores/time-logs.ts
Added new state variables and corresponding atoms for alluser and allteams using Jotai. Updated the return object in the hook to include these new states.
apps/web/lib/features/team/teams-dropdown.tsx Updated conditional checks by applying optional chaining for safe access of properties in timerStatus.lastLog.

Sequence Diagram(s)

sequenceDiagram
  participant U as User
  participant DH as DashboardHeader
  participant TF as TeamDashboardFilter
  participant H as useTimelogFilterOptions
  participant S as State Store

  U->>DH: Clicks filter button
  DH->>TF: Loads new TeamDashboardFilter
  TF->>U: Displays popover with multi-select options
  U->>TF: Selects teams/employees and applies filter
  TF->>H: Triggers update with new filter selections
  H->>S: Updates alluser/allteams state atoms
  S-->>H: Returns updated state
  H-->>TF: Confirms filter update
Loading

Possibly related PRs

  • [Feat]: Timesheet-Duration-Display #3352: The changes in the main PR are related to the modifications in the useTimelogFilterOptions function within the retrieved PR, as both involve updates to state management related to user and team data in the same file.

Suggested labels

feature, WEB, Improvement, Ever Teams

Suggested reviewers

  • evereq

Poem

I'm a rabbit with hops so fleet,
Code carrots fresh and ever so neat.
Filters bloom like springtime cheer,
New states and atoms, all so clear.
I nibble on patches of code with glee,
Celebrating changes wildly, just like me!
🥕🐇 Happy coding and hop on free!


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 67cb3e6 and 72cfa80.

📒 Files selected for processing (1)
  • apps/web/app/[locale]/dashboard/team-dashboard/[teamId]/components/team-dashboard-filter.tsx (1 hunks)

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

CodeRabbit Configuration 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
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🔭 Outside diff range comments (1)
apps/web/app/[locale]/dashboard/team-dashboard/[teamId]/components/dashboard-header.tsx (1)

9-12: Remove unused prop onUpdateFilters.

The onUpdateFilters prop is no longer used after moving the filter functionality to the TeamDashboardFilter component.

Apply this diff to remove the unused prop:

 interface DashboardHeaderProps {
 	onUpdateDateRange: (startDate: Date, endDate: Date) => void;
-	onUpdateFilters: (filters: Partial<Omit<ITimeLogReportDailyChartProps, 'organizationId' | 'tenantId'>>) => void;
 }

-export function DashboardHeader({ onUpdateDateRange, onUpdateFilters }: DashboardHeaderProps) {
+export function DashboardHeader({ onUpdateDateRange }: DashboardHeaderProps) {
🧹 Nitpick comments (5)
apps/web/app/stores/time-logs.ts (1)

28-29: Fix inconsistent spacing around equals signs.

The spacing around equals signs in the new atoms is inconsistent with the rest of the file.

Apply this diff to maintain consistent spacing:

-export const allTeamsState=atom<IOrganizationTeamList[]>([]);
-export const allUserState=atom<OT_Member[]>([]);
+export const allTeamsState = atom<IOrganizationTeamList[]>([]);
+export const allUserState = atom<OT_Member[]>([]);
apps/web/lib/features/team/teams-dropdown.tsx (1)

28-37: Simplify the timer status condition.

The condition checking timer status has multiple redundant checks and could be simplified for better readability.

Apply this diff to simplify the condition:

 if (
 	timerStatus &&
 	timerStatus?.running &&
-	timerStatus?.lastLog &&
-	timerStatus?.lastLog?.organizationTeamId &&
-	timerStatus?.lastLog?.source === 'TEAMS' &&
 	activeTeam &&
 	activeTeam?.id &&
-	timerStatus?.lastLog?.organizationTeamId === activeTeam?.id
+	timerStatus?.lastLog?.source === 'TEAMS' &&
+	timerStatus?.lastLog?.organizationTeamId === activeTeam.id
 ) {
🧰 Tools
🪛 Biome (1.9.4)

[error] 29-30: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

apps/web/app/hooks/features/useTimelogFilterOptions.ts (2)

9-10: Fix missing semicolons.

Maintain consistent semicolon usage throughout the file.

Apply this diff:

-    const [alluserState, setAllUserState] = useAtom(allUserState)
-    const [allteamsState, setAllTeamsState] = useAtom(allTeamsState)
+    const [alluserState, setAllUserState] = useAtom(allUserState);
+    const [allteamsState, setAllTeamsState] = useAtom(allTeamsState);

18-18: Remove commented code.

Remove the commented-out code as it's no longer needed and can cause confusion.

Apply this diff:

-    // const [selectTimesheetId, setSelectTimesheetId] = React.useState<TimesheetLog[]>([])
apps/web/app/[locale]/dashboard/team-dashboard/[teamId]/components/team-dashboard-filter.tsx (1)

70-101: Improve type safety in MultiSelect components.

The type casting with 'as any' in onValueChange handlers should be replaced with proper types.

Consider defining proper types and updating the handlers:

interface Team {
  id: string;
  name: string;
  members?: Member[];
}

interface Member {
  id: string;
  employee?: {
    fullName: string;
  };
}

// Update handlers
onValueChange={(selectedItems: Team[]) => setAllTeamsState(selectedItems)}
onValueChange={(selectedItems: Member[]) => setAllUserState(selectedItems)}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e60c210 and e36d32c.

📒 Files selected for processing (7)
  • .cspell.json (1 hunks)
  • apps/web/app/[locale]/dashboard/team-dashboard/[teamId]/components/dashboard-header.tsx (2 hunks)
  • apps/web/app/[locale]/dashboard/team-dashboard/[teamId]/components/team-dashboard-filter.tsx (1 hunks)
  • apps/web/app/[locale]/timesheet/[memberId]/components/TimeSheetFilterPopover.tsx (2 hunks)
  • apps/web/app/hooks/features/useTimelogFilterOptions.ts (2 hunks)
  • apps/web/app/stores/time-logs.ts (2 hunks)
  • apps/web/lib/features/team/teams-dropdown.tsx (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • apps/web/app/[locale]/timesheet/[memberId]/components/TimeSheetFilterPopover.tsx
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: deploy
🔇 Additional comments (3)
apps/web/app/[locale]/dashboard/team-dashboard/[teamId]/components/team-dashboard-filter.tsx (2)

1-14: LGTM! Well-structured imports and component declaration.

The component is properly optimized with React.memo and imports all necessary dependencies.


30-50: LGTM! Well-implemented filter button with accessibility support.

The button implementation includes proper accessibility attributes and responsive styling.

.cspell.json (1)

17-18: LGTM! Spell-check dictionary updated.

The new words "alluser" and "allteams" are correctly added to support the state management variables.

@Innocent-Akim Innocent-Akim self-assigned this Feb 3, 2025
@evereq
Copy link
Member

evereq commented Feb 3, 2025

@Innocent-Akim merge conflict :)

@Innocent-Akim Innocent-Akim force-pushed the feat/team-dashboard-filter-functionalization branch from e571ca6 to 67cb3e6 Compare February 3, 2025 19:03
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🔭 Outside diff range comments (1)
apps/web/app/[locale]/dashboard/team-dashboard/[teamId]/components/dashboard-header.tsx (1)

10-11: Unused onUpdateFilters Prop in DashboardHeaderProps
Our investigation confirms that while onUpdateFilters is declared in the DashboardHeaderProps interface and passed from the parent (page.tsx), it isn’t used anywhere within the DashboardHeader component or forwarded to the TeamDashboardFilter component. This indicates that the prop is likely redundant since filter handling has been moved to TeamDashboardFilter.
• Remove onUpdateFilters from the interface (and corresponding props in parent components) if it’s no longer needed, or
• Pass the callback to TeamDashboardFilter if it is intended to handle filter updates.

🔗 Analysis chain

Consider updating interface to reflect new filter handling.

The onUpdateFilters prop is still in the interface but appears unused after moving filter logic to TeamDashboardFilter component.

Consider either:

  1. Removing unused props and their types if filtering is now fully handled by TeamDashboardFilter
  2. Passing the callback to TeamDashboardFilter if it's still needed
interface DashboardHeaderProps {
  onUpdateDateRange: (startDate: Date, endDate: Date) => void;
-  onUpdateFilters: (filters: Partial<Omit<ITimeLogReportDailyChartProps, 'organizationId' | 'tenantId'>>) => void;
}
🏁 Scripts executed

The following scripts were executed for the analysis:

Error: No shell scripts found


Script:

#!/bin/bash
# Searching for occurrences of "onUpdateFilters" across the repository to verify its usage.
rg -n "onUpdateFilters" .

Length of output: 531


Script:

#!/bin/bash
# Displaying the contents of dashboard-header.tsx to see how onUpdateFilters is used.
sed -n '1,150p' apps/web/app/[locale]/dashboard/team-dashboard/[teamId]/components/dashboard-header.tsx

Length of output: 1731

🧹 Nitpick comments (3)
apps/web/app/[locale]/dashboard/team-dashboard/[teamId]/components/team-dashboard-filter.tsx (3)

15-20: Simplify state reset logic.

The current implementation using useEffect to reset shouldRemoveItems can be simplified.

Consider using a callback instead:

- const [shouldRemoveItems, setShouldRemoveItems] = React.useState(false);
- React.useEffect(() => {
-   if (shouldRemoveItems) {
-     setShouldRemoveItems(false);
-   }
- }, [shouldRemoveItems]);

+ const handleClearFilter = React.useCallback(() => {
+   setShouldRemoveItems(true);
+   // Reset immediately after MultiSelect processes it
+   setTimeout(() => setShouldRemoveItems(false), 0);
+ }, []);

32-32: Add aria-label to Popover for better accessibility.

The Popover component lacks an accessible label.

- <Popover modal>
+ <Popover modal aria-label={t('common.FILTER_OPTIONS')}>

104-115: Add keyboard navigation support for filter actions.

The filter actions section lacks keyboard navigation support.

Add keyboard support for better accessibility:

- <div className="flex gap-x-4 justify-end items-center w-full">
+ <div 
+   className="flex gap-x-4 justify-end items-center w-full"
+   role="group"
+   aria-label={t('common.FILTER_ACTIONS')}
+ >
    <Button
      onClick={() => setShouldRemoveItems(true)}
      variant={'outline'}
      className="flex justify-center items-center h-10 text-sm rounded-lg dark:text-gray-300"
+     onKeyDown={(e) => e.key === 'Enter' && setShouldRemoveItems(true)}
    >
      <span className="text-sm">{t('common.CLEAR_FILTER')}</span>
    </Button>
    <Button 
      className="flex justify-center items-center h-10 text-sm rounded-lg bg-primary dark:bg-primary-light dark:text-gray-300"
+     onKeyDown={(e) => e.key === 'Enter' && handleApplyFilter()}
    >
      <span className="text-sm">{t('common.APPLY_FILTER')}</span>
    </Button>
  </div>
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e36d32c and 67cb3e6.

📒 Files selected for processing (7)
  • .cspell.json (1 hunks)
  • apps/web/app/[locale]/dashboard/team-dashboard/[teamId]/components/dashboard-header.tsx (2 hunks)
  • apps/web/app/[locale]/dashboard/team-dashboard/[teamId]/components/team-dashboard-filter.tsx (1 hunks)
  • apps/web/app/[locale]/timesheet/[memberId]/components/TimeSheetFilterPopover.tsx (2 hunks)
  • apps/web/app/hooks/features/useTimelogFilterOptions.ts (2 hunks)
  • apps/web/app/stores/time-logs.ts (2 hunks)
  • apps/web/lib/features/team/teams-dropdown.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (5)
  • .cspell.json
  • apps/web/app/[locale]/timesheet/[memberId]/components/TimeSheetFilterPopover.tsx
  • apps/web/lib/features/team/teams-dropdown.tsx
  • apps/web/app/stores/time-logs.ts
  • apps/web/app/hooks/features/useTimelogFilterOptions.ts
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: deploy
🔇 Additional comments (1)
apps/web/app/[locale]/dashboard/team-dashboard/[teamId]/components/dashboard-header.tsx (1)

27-27: Pass onUpdateFilters to TeamDashboardFilter if still needed.

The onUpdateFilters prop is not being passed to TeamDashboardFilter, which may indicate a loss of functionality.

If filtering updates should still be propagated to the parent:

- <TeamDashboardFilter />
+ <TeamDashboardFilter onUpdateFilters={onUpdateFilters} />

@Innocent-Akim Innocent-Akim requested a review from evereq February 3, 2025 19:18
@evereq evereq merged commit de88e2d into develop Feb 3, 2025
11 of 13 checks passed
@evereq evereq deleted the feat/team-dashboard-filter-functionalization branch February 3, 2025 19:19
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