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

Added team filter support #195

Merged

Conversation

GurinderRawala
Copy link

@GurinderRawala GurinderRawala commented Mar 22, 2025

Summary by CodeRabbit

  • New Features

    • Introduced team filtering options in variable selection to enable a more tailored filtering experience.
    • Enhanced dashboard navigation for more consistent location and history tracking.
  • Refactor

    • Streamlined global state management by incorporating team metadata.
    • Simplified dashboard configuration for a cleaner and more efficient interface.

Copy link

coderabbitai bot commented Mar 22, 2025

📝 Walkthrough

Walkthrough

This pull request updates the global state data model to include a new metadata property with a teams array, and modifies components to leverage this new data. The changes impact state initialization, dispatch actions, and component logic. In the OptionsPicker component, team filtering logic is incorporated, and the event handling for variable input is refactored. Additionally, the code updates the location service in the FN dashboard for consistent external export and usage, and simplifies the dashboard properties interface by extending the global state.

Changes

File(s) Change Summary
public/app/core/reducers/fn-slice.ts, public/app/fn-app/create-mfe.ts, public/app/fn-app/types.ts - Introduced a new metadata property with a teams array in the global state interface.
- Updated INITIAL_FN_STATE to initialize metadata.
- Modified dispatch in updateFnApp to include metadata.
- Updated FNDashboardProps to extend the updated global state, and removed several now redundant properties.
public/app/features/variables/pickers/OptionsPicker/OptionsPicker.tsx - Added conditional logic to handle team filtering by checking the active dashboard state and available teams.
- Mapped teams to a teamFilter array that is merged with existing picker options.
- Changed the onChange handler to an inline arrow function calling this.onFilterOrSearchOptions.
public/app/fn-app/fn-dashboard-page/render-fn-dashboard.tsx - Replaced the local locationService with an exported mfeLocationService.
- Updated method calls to use mfeLocationService for retrieving history, location, and handling pathname changes.

Sequence Diagram(s)

Loading
sequenceDiagram
  participant U as User
  participant O as OptionsPicker
  participant F as optionPickerFactory
  participant G as Global State
  U->>O: Initiates onChange event
  O->>F: Call optionPickerFactory()
  F->>G: Read teams from FnGlobalState
  G-->>F: Return teams array
  F->>F: Map teams to teamFilter
  F-->>O: Return picker with teamFilter & mfeState
  O->>O: Inline onChange calls onFilterOrSearchOptions
Loading
sequenceDiagram
  participant R as RenderFNDashboard
  participant M as mfeLocationService
  R->>M: getHistory()
  M-->>R: Return history
  R->>M: getLocation()
  M-->>R: Return location
  Note over R, M: useEffect triggers pathname change
  R->>M: fnPathnameChange()
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
  • @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

@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

🧹 Nitpick comments (1)
public/app/features/variables/pickers/OptionsPicker/OptionsPicker.tsx (1)

56-70: Implemented team filtering logic

The code now checks if the FN Dashboard is active and if there are teams in the metadata, then creates filter options based on those teams. This implementation correctly merges team filter options with existing options when teams are present.

However, the selected state for all team filters is initially set to false. Consider if there should be a way to persist selected team filters across component re-renders.

You might consider adding a mechanism to save and restore selected team filters, especially if users would expect their filter selections to persist across different interactions with the dashboard.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9f51b61 and 61e15e6.

📒 Files selected for processing (5)
  • public/app/core/reducers/fn-slice.ts (2 hunks)
  • public/app/features/variables/pickers/OptionsPicker/OptionsPicker.tsx (2 hunks)
  • public/app/fn-app/create-mfe.ts (2 hunks)
  • public/app/fn-app/fn-dashboard-page/render-fn-dashboard.tsx (4 hunks)
  • public/app/fn-app/types.ts (2 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
public/app/fn-app/types.ts (1)
public/app/core/reducers/fn-slice.ts (1) (1)
  • FnGlobalState (7-21)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build-and-test
🔇 Additional comments (12)
public/app/core/reducers/fn-slice.ts (2)

18-20: Added metadata for team filtering support

The addition of the metadata property with a teams array provides a structured way to store team-related information in the global state, enabling team filtering functionality across the application.


63-65: Properly initialized the metadata property

The initialization of the metadata property with an empty teams array in the INITIAL_FN_STATE ensures that the state is properly structured from the start, preventing potential null/undefined errors when accessing this property.

public/app/fn-app/create-mfe.ts (2)

208-208: Code formatting adjustment

This change appears to be a simple reformatting of the code, maintaining the same functionality while potentially improving readability or consistency.


283-283: Added metadata support to state updates

The inclusion of the metadata property in the updatePartialFnStates dispatch ensures that team information persists during app updates, which is essential for the team filtering functionality to work correctly.

public/app/features/variables/pickers/OptionsPicker/OptionsPicker.tsx (1)

165-167: Refactored event handler for improved readability

The onChange handler now uses an inline arrow function instead of directly referencing the method. This approach is more explicit about what happens when the input changes and follows modern React patterns.

public/app/fn-app/fn-dashboard-page/render-fn-dashboard.tsx (4)

10-10: Exported location service for external use

Exporting the location service as mfeLocationService makes it available to be imported and used in other components, promoting better code organization and reuse.


20-20: Updated history property to use mfeLocationService

This change ensures consistency with the exported location service, maintaining the same behavior while using the newly exported service.


53-53: Updated function call to use mfeLocationService

This change maintains consistency with the location service renaming, ensuring that the pathname change functionality continues to work as expected.


65-65: Updated location access to use mfeLocationService

This change ensures consistency with the location service renaming and makes the code more maintainable by using the exported service throughout the component.

public/app/fn-app/types.ts (3)

3-3: Import updated to support team filtering.

The import change from GrafanaThemeType to FnGlobalState supports the team filtering feature by bringing in the necessary state interface that contains the new metadata.teams property.


19-19: Good refactoring to extend FnGlobalState.

This is a clean approach that reduces duplication by having FNDashboardProps extend FnGlobalState rather than redefining the same properties. This change consolidates the dashboard properties and allows the component to access the new metadata.teams array needed for team filtering.

The interface now inherits several properties from FnGlobalState including:

  • uid, slug, version (dashboard identifiers)
  • mode, controlsContainer, pageTitle (UI elements)
  • queryParams (navigation)
  • metadata.teams (new team filtering capability)

19-26:

❓ Verification inconclusive

Verify compatibility with existing component usages.

While this inheritance-based approach is cleaner, it represents a structural change to the interface. Ensure that all components using FNDashboardProps expect these additional properties.


🏁 Script executed:

#!/bin/bash
# Find all files that import and use FNDashboardProps
rg "FNDashboardProps" --type ts --type tsx -A 3 -B 3

Length of output: 80


I'll need to gather more information on the usages of FNDashboardProps since the initial search failed due to an issue with the file type flag. Let's re-run the search with a revised command that explicitly targets both .ts and .tsx files:

Please run this updated script and share the output so we can verify all component usages before finalizing the review comment.


🏁 Script executed:

#!/bin/bash
# Searching for FNDashboardProps usage in .ts and .tsx files using glob patterns
echo "Searching for FNDashboardProps usage in .ts and .tsx files..."
rg "FNDashboardProps" -g "*.ts" -g "*.tsx" -A 3 -B 3

Length of output: 11382


Action: Verify compatibility with new FNDashboardProps structure across component usages

The interface now extends FnGlobalState and includes additional properties. Please ensure that every component importing or referencing FNDashboardProps is updated to supply and handle the inherited properties correctly. Notable files using this interface include:

  • public/app/fn-app/fn-app-provider.tsx – where a subset of properties is picked.
  • public/app/fn-app/create-mfe.ts – which references properties like mode via FNDashboardProps['mode'].
  • public/app/fn-dashboard-page (fn-dashboard.tsx and render-fn-dashboard.tsx) – that directly utilize the properties from the interface.
  • public/app/features/dashboard/containers/DashboardPage.tsx – which accesses properties like version and isLoading from the interface.

Please confirm (ideally via manual verification or targeted tests) that existing component usages account for the structural change introduced by the inherited properties.

@GurinderRawala GurinderRawala self-assigned this Mar 24, 2025
@GurinderRawala GurinderRawala merged commit 874cb7a into coderabbit_micro_frontend Mar 24, 2025
1 of 2 checks passed
@GurinderRawala GurinderRawala deleted the adding-team-filter-support branch March 24, 2025 02:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant