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

docs: enforce string format to ensure Algolia search indexing functions correctly #902

Merged
merged 2 commits into from
Jul 31, 2024

Conversation

cheton
Copy link
Member

@cheton cheton commented Jul 30, 2024

PR Type

documentation, enhancement


Description

  • Simplified sidebar route titles by removing Flex component and using plain strings to ensure better search indexing.
  • Enhanced Algolia search indexing script by adding a utility function to check for non-empty strings and removing the icon property from the flattened data.

Changes walkthrough 📝

Relevant files
Documentation
sidebar-routes.js
Simplify sidebar route titles for better search indexing 

packages/react-docs/config/sidebar-routes.js

  • Removed usage of Flex component for titles.
  • Changed titles to plain strings for better indexing.
  • +2/-3     
    Enhancement
    algolia-search-indexing.js
    Enhance Algolia search indexing script with string validation

    packages/react-docs/scripts/algolia-search-indexing.js

  • Added isNonEmptyString utility function.
  • Removed icon property from flattened data.
  • Enforced non-empty string check for title and path.
  • +5/-4     

    💡 PR-Agent usage:
    Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    Copy link

    codesandbox bot commented Jul 30, 2024

    Review or Edit in CodeSandbox

    Open the branch in Web EditorVS CodeInsiders

    Open Preview

    Copy link

    changeset-bot bot commented Jul 30, 2024

    ⚠️ No Changeset found

    Latest commit: f5646ba

    Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

    This PR includes no changesets

    When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

    Click here to learn what changesets are, and how to add one.

    Click here if you're a maintainer who wants to add a changeset to this PR

    Copy link
    Contributor

    PR Reviewer Guide 🔍

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Key issues to review

    Code Redundancy
    The function isNonEmptyString checks for non-empty strings but the condition !!x is redundant since typeof x === 'string' ensures x is a string and empty strings are falsy in JavaScript.

    Copy link
    Contributor

    codiumai-pr-agent-free bot commented Jul 30, 2024

    PR Code Suggestions ✨

    CategorySuggestion                                                                                                                                    Score
    Possible bug
    Add a safeguard against undefined state in node destructuring to prevent errors

    Add a check to ensure that the state object exists before destructuring to prevent
    potential runtime errors.

    packages/react-docs/scripts/algolia-search-indexing.js [21]

    -const { title = '', path = '', [stateKey]: state = {} } = node;
    +const { title = '', path = '', [stateKey]: state = node.state || {} } = node;
     
    • Apply this suggestion
    Suggestion importance[1-10]: 9

    Why: This suggestion adds a safeguard against potential runtime errors by ensuring the state object exists before destructuring. It is a valuable improvement for robustness.

    9
    Enhancement
    ✅ Improve the string validation function to exclude whitespace-only strings

    Use a more robust string check to handle cases where a string might contain only
    whitespace.

    packages/react-docs/scripts/algolia-search-indexing.js [12]

    -const isNonEmptyString = (x) => typeof x === 'string' && !!x;
    +const isNonEmptyString = (x) => typeof x === 'string' && x.trim().length > 0;
     

    [Suggestion has been applied]

    Suggestion importance[1-10]: 8

    Why: The suggestion improves the string validation function to exclude whitespace-only strings, enhancing the reliability of the code.

    8
    Best practice
    Simplify parameter handling in the flatten function using default parameter values

    Use destructuring with default values in the function parameter to simplify the
    function signature and improve readability.

    packages/react-docs/scripts/algolia-search-indexing.js [14-16]

    -const flatten = (data, options) => {
    -  const childrenKey = options?.childrenKey ?? 'children';
    +const flatten = (data, {childrenKey = 'children'} = {}) => {
     
    • Apply this suggestion
    Suggestion importance[1-10]: 7

    Why: This suggestion simplifies the function signature and improves readability by using destructuring with default values. It is a good practice but not crucial.

    7

    Copy link

    codesandbox-ci bot commented Jul 30, 2024

    This pull request is automatically built and testable in CodeSandbox.

    To see build info of the built libraries, click here or the icon next to each commit SHA.

    @trendmicro-frontend-bot
    Copy link
    Contributor

    trendmicro-frontend-bot commented Jul 30, 2024

    …e-only strings
    
    Co-authored-by: codiumai-pr-agent[bot] <138128286+codiumai-pr-agent[bot]@users.noreply.github.com>
    Copy link

    codecov bot commented Jul 30, 2024

    Codecov Report

    All modified and coverable lines are covered by tests ✅

    Project coverage is 74.91%. Comparing base (60fe4d5) to head (f5646ba).

    Additional details and impacted files
    @@           Coverage Diff           @@
    ##               v2     #902   +/-   ##
    =======================================
      Coverage   74.91%   74.91%           
    =======================================
      Files         378      378           
      Lines        6166     6166           
    =======================================
      Hits         4619     4619           
      Misses       1547     1547           
    Flag Coverage Δ
    -base 74.91% <ø> (ø)
    -github 74.91% <ø> (ø)
    -hooks 74.91% <ø> (ø)
    -icons 74.91% <ø> (ø)
    -system 74.91% <ø> (ø)
    codemod 74.91% <ø> (ø)
    react 74.91% <ø> (ø)
    theme 74.91% <ø> (ø)
    utils 74.91% <ø> (ø)

    Flags with carried forward coverage won't be shown. Click here to find out more.

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

    @cheton cheton merged commit 993100d into v2 Jul 31, 2024
    8 checks passed
    @cheton cheton deleted the docs/algoliasearch-indexing branch July 31, 2024 07:59
    cheton added a commit that referenced this pull request Sep 18, 2024
    …ns correctly (#902)
    
    * docs: enforce string format to ensure Algolia search indexing functions correctly
    
    * refactor: improve the string validation function to exclude whitespace-only strings
    
    Co-authored-by: codiumai-pr-agent[bot] <138128286+codiumai-pr-agent[bot]@users.noreply.github.com>
    
    ---------
    
    Co-authored-by: codiumai-pr-agent[bot] <138128286+codiumai-pr-agent[bot]@users.noreply.github.com>
    cheton added a commit that referenced this pull request Sep 18, 2024
    …ns correctly (#902)
    
    * docs: enforce string format to ensure Algolia search indexing functions correctly
    
    * refactor: improve the string validation function to exclude whitespace-only strings
    
    Co-authored-by: codiumai-pr-agent[bot] <138128286+codiumai-pr-agent[bot]@users.noreply.github.com>
    
    ---------
    
    Co-authored-by: codiumai-pr-agent[bot] <138128286+codiumai-pr-agent[bot]@users.noreply.github.com>
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    3 participants