Skip to content
New issue

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

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

Already on GitHub? # to your account

[Feat]: Add role-based access control for team dashboard #3601

Merged
merged 2 commits into from
Feb 9, 2025

Conversation

Innocent-Akim
Copy link
Contributor

@Innocent-Akim Innocent-Akim commented Feb 8, 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
    • Enhanced the team dashboard with a management mode that conditionally reveals additional filtering options.
    • Introduced a tailored employee selection section for users with management access, providing a dynamic and personalized dashboard experience.
    • Updated report activity displays based on access rights, ensuring the interface adapts according to your permissions.

Copy link
Contributor

coderabbitai bot commented Feb 8, 2025

Walkthrough

The changes add an optional boolean property "isManage" to several components in the team dashboard. The DashboardHeader and TeamDashboardFilter interfaces and function signatures are updated to accept this new property. Additionally, the useReportActivity hook now computes and returns the "isManage" flag based on user access, allowing conditional rendering (such as showing an employee selection section) throughout the dashboard.

Changes

File(s) Change Summary
apps/web/app/…/team-dashboard/[teamId]/components/dashboard-header.tsx
apps/web/app/…/team-dashboard/[teamId]/components/team-dashboard-filter.tsx
apps/web/app/…/team-dashboard/[teamId]/page.tsx
Added optional "isManage" property to component interfaces and updated function signatures; modified TeamDashboardFilter to conditionally render the employee selection section based on "isManage".
apps/web/app/hooks/features/useReportActivity.ts Introduced "isManage" by checking user access (via useTimelogFilterOptions), updated employeeIds logic and dependency arrays, and included "isManage" in the hook's return.

Sequence Diagram(s)

sequenceDiagram
  participant P as TeamDashboard Page
  participant H as useReportActivity Hook
  participant DH as DashboardHeader
  participant TF as TeamDashboardFilter

  P->>H: Invoke useReportActivity()
  H-->>P: Return data including isManage
  P->>DH: Render DashboardHeader(isManage)
  DH->>TF: Pass isManage prop
  alt isManage true
    TF->>TF: Render employee selection component
  else isManage false
    TF->>TF: Skip employee selection component
  end
Loading

Possibly related PRs

  • [Feat]: Improve timesheet and Activity reporting #3590: The changes in the main PR are related to the modifications in the TeamDashboardFilter component found in the retrieved PR, as both introduce the isManage prop and update the component signatures accordingly.
  • [Fea]: Activity Modal #3551: The changes in the main PR are related to the modifications in the TeamDashboardFilter component, as both introduce the isManage prop and update their respective component signatures to utilize it.
  • [Feat]: Implement report activity filters and loading state #3536: The changes in the main PR are related to the modifications made to the DashboardHeader component in the retrieved PR, as both PRs involve updates to the DashboardHeaderProps interface and the function signature of the DashboardHeader component.

Suggested labels

feature, WEB, Improvement, Ever Teams

Suggested reviewers

  • evereq
  • Cedric921

Poem

I'm a little rabbit, hopping along the code,
With changes in my step and a merry, bouncy mode.
"isManage" now leads the way through every view,
Conditional paths clear, fresh as morning dew.
CodeRabbit cheers with whiskers all a-flutter – hip, hip, hooray!
🥕🐰

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/hooks/features/useReportActivity.ts

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.


📜 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 6122dff and 93a143b.

📒 Files selected for processing (1)
  • apps/web/app/hooks/features/useReportActivity.ts (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/web/app/hooks/features/useReportActivity.ts
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: deploy

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

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

83-113: Consider UX improvements for employee filtering.

While the implementation correctly implements role-based access control, consider these improvements:

  1. Add a helper text to indicate that employee options are filtered based on selected teams.
  2. Memoize the filtered members list to optimize performance.

Here's how you could implement these improvements:

+const memoizedFilteredMembers = React.useMemo(
+  () => allteamsState.flatMap((team) => {
+    const members = team.members ?? [];
+    return members.filter((member) => member && member.employee);
+  }),
+  [allteamsState]
+);

{isManage && (
  <div className="">
    <label className="flex justify-between mb-1 text-sm text-gray-600">
      <span className="text-[12px]">{t('manualTime.EMPLOYEE')}</span>
+     <span className="text-xs text-gray-400">
+       {t('common.FILTERED_BY_SELECTED_TEAMS')}
+     </span>
      <span
        className={cn(
          'text-primary/10',
          alluserState.length > 0 && 'text-primary dark:text-primary-light'
        )}
      >
        {t('common.CLEAR')} ({alluserState.length})
      </span>
    </label>
    <MultiSelect
      localStorageKey="team-dashboard-select-filter-employee"
      removeItems={shouldRemoveItems}
-     items={allteamsState.flatMap((team) => {
-       const members = team.members ?? [];
-       return members.filter((member) => member && member.employee);
-     })}
+     items={memoizedFilteredMembers}
      itemToString={(member) => {
        if (!member?.employee) return '';
        return member.employee.fullName || t('manualTime.EMPLOYEE');
      }}
      itemId={(item) => item.id}
      onValueChange={(selectedItems) => setAllUserState(selectedItems as any)}
      multiSelect={true}
      triggerClassName="dark:border-gray-700"
    />
  </div>
)}
🧰 Tools
🪛 Biome (1.9.4)

[error] 101-101: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


99-102: Use optional chaining for safer member access.

Consider using optional chaining for a more concise and safer member access.

items={allteamsState.flatMap((team) => {
-  const members = team.members ?? [];
+  const members = team?.members ?? [];
  return members.filter((member) => member && member.employee);
})}
🧰 Tools
🪛 Biome (1.9.4)

[error] 101-101: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

apps/web/app/hooks/features/useReportActivity.ts (1)

96-99: Consider adding error handling for edge cases.

While the implementation is correct, consider handling edge cases where:

  • alluserState is undefined/null
  • user.employee.id is undefined
-employeeIds: isManage
-  ? alluserState?.map(({ employee: { id } }) => id).filter(Boolean)
-  : [user.employee.id],
+employeeIds: isManage && alluserState
+  ? alluserState.map(({ employee: { id } }) => id).filter(Boolean)
+  : user?.employee?.id ? [user.employee.id] : [],
apps/web/app/[locale]/dashboard/team-dashboard/[teamId]/page.tsx (1)

24-24: Consider breaking down destructured properties for better readability.

The line is quite long with many destructured properties. Consider grouping related properties.

-const { rapportChartActivity, updateDateRange, updateFilters, loadingTimeLogReportDailyChart, rapportDailyActivity, loadingTimeLogReportDaily, statisticsCounts,loadingTimesheetStatisticsCounts, isManage} = useReportActivity();
+const {
+  // Report data
+  rapportChartActivity,
+  rapportDailyActivity,
+  statisticsCounts,
+  // Loading states
+  loadingTimeLogReportDailyChart,
+  loadingTimeLogReportDaily,
+  loadingTimesheetStatisticsCounts,
+  // Actions
+  updateDateRange,
+  updateFilters,
+  // Access control
+  isManage
+} = useReportActivity();
apps/web/app/[locale]/dashboard/team-dashboard/[teamId]/components/dashboard-header.tsx (1)

8-12: Consider adding JSDoc documentation for the interface.

Adding documentation would help explain the purpose of the isManage flag and its impact on component behavior.

+/**
+ * Props for the DashboardHeader component
+ * @property {Function} onUpdateDateRange - Callback for date range updates
+ * @property {Function} onUpdateFilters - Callback for filter updates
+ * @property {boolean} [isManage] - Flag indicating if user has management access
+ */
interface DashboardHeaderProps {
  onUpdateDateRange: (startDate: Date, endDate: Date) => void;
  onUpdateFilters: (filters: Partial<Omit<ITimeLogReportDailyChartProps, 'organizationId' | 'tenantId'>>) => void;
  isManage?: boolean;
}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e71a27c and 6122dff.

📒 Files selected for processing (4)
  • apps/web/app/[locale]/dashboard/team-dashboard/[teamId]/components/dashboard-header.tsx (1 hunks)
  • apps/web/app/[locale]/dashboard/team-dashboard/[teamId]/components/team-dashboard-filter.tsx (3 hunks)
  • apps/web/app/[locale]/dashboard/team-dashboard/[teamId]/page.tsx (2 hunks)
  • apps/web/app/hooks/features/useReportActivity.ts (5 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
apps/web/app/[locale]/dashboard/team-dashboard/[teamId]/components/team-dashboard-filter.tsx

[error] 101-101: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: deploy
🔇 Additional comments (4)
apps/web/app/[locale]/dashboard/team-dashboard/[teamId]/components/team-dashboard-filter.tsx (1)

10-13: LGTM! Clean interface definition for role-based access control.

The interface and component signature changes are well-structured and align with the PR objectives.

apps/web/app/hooks/features/useReportActivity.ts (1)

64-64: LGTM! Role-based access control is properly implemented.

The implementation correctly determines management access by:

  1. Using isUserAllowedToAccess from the useTimelogFilterOptions hook
  2. Checking both user existence and access rights

Also applies to: 73-73

apps/web/app/[locale]/dashboard/team-dashboard/[teamId]/page.tsx (1)

57-61: LGTM! Props are correctly passed to DashboardHeader.

The isManage prop is properly passed down to the DashboardHeader component.

apps/web/app/[locale]/dashboard/team-dashboard/[teamId]/components/dashboard-header.tsx (1)

14-14: LGTM! Component properly handles and forwards the isManage prop.

The implementation correctly:

  1. Accepts isManage in the component signature
  2. Forwards it to TeamDashboardFilter

Also applies to: 26-26

…Either include it or remove the dependency array.
@Innocent-Akim Innocent-Akim self-assigned this Feb 8, 2025
@evereq evereq merged commit 85a822d into develop Feb 9, 2025
13 checks passed
@evereq evereq deleted the feat/team-dashboard-role-access branch February 9, 2025 05:20
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants