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(19622): add mcda search to search bar v1 #844

Merged
merged 3 commits into from
Sep 20, 2024

Conversation

Natallia-Harshunova
Copy link
Contributor

@Natallia-Harshunova Natallia-Harshunova commented Sep 20, 2024

https://kontur.fibery.io/Tasks/Task/dn-fe-handle-mcda-suggestion-19622

Summary by CodeRabbit

  • New Features

    • Introduced a new MCDA search functionality, allowing users to fetch and display MCDA suggestions.
    • Added a new MCDASearchResult component to show loading, error, and result messages for MCDA analysis.
    • Integrated conditional rendering of the MCDASearchResult based on feature flags in the SearchBar component.
    • Enhanced search functionality with the searchQueryAction, which now includes MCDA data fetching capabilities.
  • Bug Fixes

    • Updated action handling in the SearchBar to reflect the new search query logic.
  • Chores

    • Enhanced the API structure for better data management and retrieval related to MCDA.

Copy link
Contributor

coderabbitai bot commented Sep 20, 2024

Walkthrough

The changes introduce new functionality for Multi-Criteria Decision Analysis (MCDA) within the application. A new interface MCDASearchDTO and a function getMCDA are added to handle MCDA-related API requests. Additionally, a new React component MCDASearchResult is created to display the results of these requests. The SearchBar component is updated to integrate the new MCDA features, and several atoms are introduced for managing MCDA data asynchronously. Feature flags are implemented to conditionally render components based on the availability of the new MCDA functionality.

Changes

Files Change Summary
src/core/api/search.ts Added interface MCDASearchDTO and function getMCDA(query: string, abortController?: AbortController).
src/core/app/types.ts Introduced constant LLM_MCDA: 'llm_mcda' in AppFeature.
src/features/search/componets/MCDASearch/MCDASearchResult.tsx Created MCDASearchResult component to display loading, error, and result messages based on MCDA data state.
src/features/search/componets/SearchBar/SearchBar.tsx Updated action to searchQueryAction, added conditional rendering for MCDASearchResult based on feature flags.
src/features/search/searchLocationAtoms.ts Renamed searchLocationsAction to searchQueryAction, modified imports, and added feature flag checks.
src/features/search/searchMcdaAtoms.ts Introduced fetchMCDAAsyncResource, MCDAAtom, and showAnalysis action for managing MCDA data asynchronously.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant SearchBar
    participant MCDAAtom
    participant MCDASearchResult

    User->>SearchBar: Initiate search
    SearchBar->>MCDAAtom: Trigger searchQueryAction
    MCDAAtom->>MCDAAtom: Check LLM_MCDA feature flag
    alt If LLM_MCDA is enabled
        MCDAAtom->>MCDAAtom: Fetch MCDA data
        MCDAAtom->>MCDASearchResult: Update state with fetched data
    end
    MCDASearchResult->>User: Display results or loading/error messages
Loading

Poem

🐰 In a world of choices, vast and wide,
New paths for analysis we now can ride.
With MCDA's wisdom, our queries take flight,
A search for solutions, both clear and bright.
So hop along, dear friends, let's explore,
For every decision, there's always more! 🌟


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.

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

Language To Recheck Fuzzy Untranslated Total
ar 3 24 101 128
de 2 24 101 127
es 3 24 101 128
id 2 24 101 127
ko 3 24 101 128
uk 0 7 8 15

Copy link

github-actions bot commented Sep 20, 2024

Bundle size diff

Old size New size Diff
5.13 MB 5.12 MB -4.29 KB (-0.08%)

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

Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between f63d415 and fbc470e.

Files selected for processing (6)
  • src/core/api/search.ts (2 hunks)
  • src/core/app/types.ts (1 hunks)
  • src/features/search/componets/MCDASerach/MCDASearchResult.tsx (1 hunks)
  • src/features/search/componets/SearchBar/SearchBar.tsx (3 hunks)
  • src/features/search/searchLocationAtoms.ts (2 hunks)
  • src/features/search/searchMcdaAtoms.ts (1 hunks)
Additional comments not posted (14)
src/features/search/searchMcdaAtoms.ts (4)

1-13: LGTM!

The imports are well-organized, follow a consistent pattern, and are sourced from appropriate locations within the codebase. The MCDAConfig type import suggests that it will be used in the code, which is a good practice.


14-18: LGTM!

The fetchMCDAAsyncResource is well-defined using reatomAsync and follows a clean and readable structure. The piped operators handle various aspects of the asynchronous resource, such as data, error, statuses, and abort functionality.


19-25: LGTM!

The MCDAAtom atom provides a clean and convenient way to access MCDA-related data, loading state, and error. It efficiently uses ctx.spy to access the required atoms from fetchMCDAAsyncResource. The returned object has a clear structure with meaningful property names.


27-32: LGTM!

The showAnalysis action is well-defined and handles the creation of an MCDA layer when the required data is available. It safely checks for the existence of data and its config property before dispatching the action using mcdaLayerAtom.createMCDALayer.

src/core/api/search.ts (2)

4-4: LGTM!

The import statement is syntactically correct and the imported type is likely used in the subsequent code changes.


31-47: Excellent work!

The code segment introduces a new interface MCDASearchDTO and a new function getMCDA to retrieve MCDA suggestions from the API. Here are the key points:

  • The interface provides a structured format for the API response.
  • The function performs the API request correctly, handling optional abort controller.
  • It sets the language header for localization, which is a good practice.
  • The return type aligns with the defined interface.

Overall, the changes enhance the API layer of the application by introducing new functionality to retrieve MCDA suggestions, encapsulated in a well-defined data structure.

src/features/search/componets/MCDASerach/MCDASearchResult.tsx (4)

1-3: LGTM!

The import statements are relevant and necessary for the component's functionality.


5-55: Component structure and functionality look good!

The MCDASearchResult component effectively handles the rendering of the MCDA search result based on the state of the MCDAAtom. It provides appropriate feedback to the user for different states (error, loading, data) and triggers the showAnalysis action when the user clicks on the "Create analysis" message. The component is relatively small and focused, which is good for maintainability.


9-21: Message rendering logic is clear and effective!

The loadingMessage, errorMessage, and renderShowResultsMessage provide clear feedback to the user about the state of the MCDA search. The renderShowResultsMessage appropriately triggers the onShowResults action when clicked, while the other messages have empty onClick handlers since they don't require user interaction. Extracting the messages into separate variables/functions improves readability and maintainability.

Also applies to: 23-35, 37-49


51-54: Conditional rendering logic handles different states effectively!

The conditional rendering logic in the MCDASearchResult component correctly handles the different states of the MCDA search. It prioritizes rendering the error message first, then the loading message, and finally the data message. Returning null if none of the conditions are met is a good fallback to prevent rendering anything if the state is unexpected.

src/core/app/types.ts (1)

52-52: LGTM!

The new constant LLM_MCDA is added correctly to the AppFeature object. It follows the existing naming convention and does not break any existing code. The AppFeatureType type will automatically include the new constant due to its definition.

src/features/search/searchLocationAtoms.ts (1)

9-13: Imports updated to support MCDA feature integration

The import statements have been correctly updated to reflect the new API structure and include the necessary modules for MCDA functionality.

src/features/search/componets/SearchBar/SearchBar.tsx (2)

96-101: Conditional rendering of MCDASearchResult component looks good.

The use of feature flags to conditionally render <MCDASearchResult /> integrates the MCDA feature appropriately.


21-21: Ensure searchQueryAction is correctly replacing searchLocationsAction.

Verify that searchQueryAction provides the intended functionality and that all references to searchLocationsAction have been updated throughout the codebase.

Run the following script to check for any remaining references to searchLocationsAction:

Verification successful

Replacement of searchLocationsAction with searchQueryAction is correct and complete.

The verification process confirms that:

  • There are no remaining references to searchLocationsAction in the codebase.
  • searchQueryAction is properly imported and used in SearchBar.tsx.
  • searchQueryAction is defined in searchLocationAtoms.ts, suggesting it's a properly implemented action.

These findings indicate that the replacement has been successfully carried out across the relevant parts of the codebase.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for any remaining references to `searchLocationsAction`.

rg --type typescript 'searchLocationsAction'

Length of output: 79


Script:

#!/bin/bash
# Search for 'searchLocationsAction' and 'searchQueryAction' in JS/TS files

echo "Searching for 'searchLocationsAction':"
rg -t js 'searchLocationsAction'

echo -e "\nSearching for 'searchQueryAction':"
rg -t js 'searchQueryAction'

echo -e "\nSearching for imports of both actions:"
rg -t js 'import.*\b(searchLocationsAction|searchQueryAction)\b'

echo -e "\nFinding TypeScript files and grepping for both actions:"
fd -e ts -e tsx | xargs grep -n -E 'searchLocationsAction|searchQueryAction'

Length of output: 904

src/features/search/searchLocationAtoms.ts Show resolved Hide resolved
src/features/search/componets/SearchBar/SearchBar.tsx Outdated Show resolved Hide resolved
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

Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between fbc470e and e2c3e67.

Files selected for processing (3)
  • src/features/search/componets/MCDASearch/MCDASearchResult.tsx (1 hunks)
  • src/features/search/componets/SearchBar/SearchBar.tsx (3 hunks)
  • src/features/search/searchLocationAtoms.ts (2 hunks)
Additional comments not posted (11)
src/features/search/componets/MCDASearch/MCDASearchResult.tsx (4)

1-4: LGTM!

The imports are correctly specified and follow the expected pattern.


5-55: LGTM!

The MCDASearchResult component is correctly defined and follows the expected pattern. It correctly renders different messages based on the state of MCDAAtom and uses the SelectItem component to render the messages. The component also correctly returns null when no message needs to be rendered.


9-21: LGTM!

The loadingMessage constant is correctly defined and follows the expected pattern. It correctly renders a SelectItem component with a loading message and specifies the required props.


23-35: LGTM!

The errorMessage constant is correctly defined and follows the expected pattern. It correctly renders a SelectItem component with an error message and specifies the required props.

src/features/search/searchLocationAtoms.ts (3)

9-13: Imports updated for MCDA functionality integration.

The import statements have been appropriately updated to support the new MCDA features:

  • Added fetchMCDAAsyncResource from ~features/search/searchMcdaAtoms.
  • Imported FeatureFlag to enable feature flag checking.
  • Changed imports of getLocations and LocationProperties to come from ~core/api/search.

These changes ensure that the necessary resources are available for the MCDA implementation.


42-47: Conditional fetching of MCDA data based on feature flag implemented correctly.

The searchQueryAction function now includes a conditional check for the LLM_MCDA feature flag before fetching MCDA data. This ensures that MCDA-related functionality is only activated when the feature is enabled, maintaining the existing behavior for users without the feature.


55-57: MCDA resources are reset to prevent stale data issues.

The resetAction function appropriately resets the fetchMCDAAsyncResource atoms alongside the location resources. This prevents potential issues with stale MCDA data or incorrect loading states during new searches.

src/features/search/componets/SearchBar/SearchBar.tsx (4)

7-10: Imports updated correctly to support MCDA feature

The necessary imports have been added to integrate the MCDA functionality into the search bar component.


19-20: Feature flags retrieved successfully

The feature flags are correctly fetched from the configuration repository to control the conditional rendering of components.


21-21: Search action updated appropriately

The search action has been updated to use searchQueryAction, aligning with the new search functionality requirements.


96-101: Conditional rendering of MCDA search result implemented correctly

The MCDASearchResult component is conditionally rendered based on the LLM_MCDA feature flag, ensuring it only appears when the feature is enabled.

@Natallia-Harshunova Natallia-Harshunova merged commit 14c5395 into main Sep 20, 2024
9 checks passed
@Natallia-Harshunova Natallia-Harshunova deleted the 19622-dn-fe-handle-mcda-suggestion branch September 20, 2024 14:09
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.

3 participants