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

Bug fix: search bar in spaces page not working, and page refreshes on search term enter #7462

Conversation

reactoholic
Copy link
Contributor

@reactoholic reactoholic commented Jan 19, 2025

Bug fixes and improvements in the "Search spaces" page:

  1. Fixed unexpected page refresh and search term lose
  2. Fixed the filtered spaces not being displayed
  3. Optimized the performance of the page, multiple re-renders are avoided now
  4. Added a "Searching" flag so the user knows the request is still on the fly

Summary by CodeRabbit

  • New Features

    • Introduced "Searching..." message during search operations.
    • Added a loading state for search functionality.
  • Improvements

    • Refined management of search terms within Space Explorer components.
    • Enhanced rendering logic for displaying search results.
    • Optimized performance of space rendering with improved structure.
  • Localization

    • Added new translation for search loading state in the English language file.

@reactoholic reactoholic added bug Something isn't working client enhancement UX Enhanced user experience labels Jan 19, 2025
@reactoholic reactoholic self-assigned this Jan 19, 2025
Copy link

coderabbitai bot commented Jan 19, 2025

Walkthrough

This pull request introduces changes to the search functionality across multiple components in the application. Modifications include adding a new translation for the search loading state, updating the SpaceExplorerContainer to manage search terms internally, and enhancing the SpaceExplorerView to handle loading states during searches. The changes streamline state management and improve user feedback during search operations.

Changes

File Change Summary
src/core/i18n/en/translation.en.json Added new translation key "searching": "Searching…" in the search section
src/main/topLevelPages/topLevelSpaces/SpaceExplorerContainer.tsx - Updated ChallengeExplorerContainerEntities interface with setSearchTerms and loadingSearchResults
- Removed searchTerms from SpaceExplorerContainerProps
- Implemented internal state management for search terms
src/main/topLevelPages/topLevelSpaces/SpaceExplorerPage.tsx Removed searchTerms state and associated logic
src/main/topLevelPages/topLevelSpaces/SpaceExplorerView.tsx - Added loadingSearchResults optional property to SpaceExplorerViewProps
- Implemented new renderVisibleSpaces function
- Updated rendering logic to handle search loading state

Possibly related PRs

Suggested reviewers

  • bobbykolev

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.

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: 2

🔭 Outside diff range comments (1)
src/domain/journey/space/SpaceSubspaceCard/StackedAvatar.tsx (1)

Line range hint 7-23: Add alt text for accessibility and consider fallback UI.

The avatars lack proper alt text for screen readers. Also, consider showing a fallback UI when avatarUris is undefined.

    {avatarUris?.map((avatarUri, index) => {
      return (
        <JourneyAvatar
          key={index}
          sx={{
            width: gutters(1.5),
            height: gutters(1.5),
            zIndex: index,
            position: 'absolute',
            top: theme => `${theme.spacing(index * 0.5)}`,
            left: theme => `${theme.spacing(index * 0.5)}`,
            border: theme => `${theme.spacing(0.2)} solid #FFFFFF`,
            borderRadius: theme => theme.spacing(0.6),
          }}
          src={avatarUri}
+         alt={`Avatar ${index + 1}`}
        />
      );
-    })}
+    }) ?? <EmptyAvatarPlaceholder />}
🧹 Nitpick comments (2)
src/core/i18n/en/translation.en.json (1)

2300-2301: LGTM! Consider adding an ellipsis for consistency.

The search-related translations look good and align with the PR objectives. The messages are clear and follow common UX patterns.

Consider adding an ellipsis to the "Searching" message to match the ellipsis style used in other loading states throughout the translations file (e.g., "loading": "Loading..." on line 1074):

-        "searching": "Searching…"
+        "searching": "Searching..."
src/domain/journey/space/SpaceSubspaceCard/StackedAvatar.tsx (1)

4-5: Define proper TypeScript interface for props.

Consider adding a proper interface with documentation for better type safety and maintainability:

+interface StackedAvatarProps {
+  /** Array of avatar URIs to display in a stacked layout */
+  avatarUris: string[] | undefined;
+}

-const StackedAvatar = ({ avatarUris }: { avatarUris: string[] }) => (
+const StackedAvatar = ({ avatarUris }: StackedAvatarProps) => (
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 40d077b and 6b4b08a.

📒 Files selected for processing (5)
  • src/core/i18n/en/translation.en.json (1 hunks)
  • src/domain/journey/space/SpaceSubspaceCard/StackedAvatar.tsx (1 hunks)
  • src/main/topLevelPages/topLevelSpaces/SpaceExplorerContainer.tsx (2 hunks)
  • src/main/topLevelPages/topLevelSpaces/SpaceExplorerPage.tsx (1 hunks)
  • src/main/topLevelPages/topLevelSpaces/SpaceExplorerView.tsx (7 hunks)
🧰 Additional context used
📓 Path-based instructions (5)
src/domain/journey/space/SpaceSubspaceCard/StackedAvatar.tsx (1)

Pattern src/**/*.{ts,tsx,js}: Review the React.js/TypeScript/JavaScript code for best practices and potential bugs.
Ensure that the code adheres to TypeScript's typing system and modern standards.
Use the following code guide documentation in the codebase: 'docs/code-guidelines.md'.
Ensure sufficient error handling and logging is present, but note:

  • We have a global error handler in place. So local try/catch blocks are not required unless they provide value beyond what the global error handler already covers.
  • Avoid flagging the absence of local error handling in cases where the global error handler suffices.
  • Avoid flagging the absence of logging in cases where the global logger is already in place (graphql usage).

Inform about the recommendation of not using non-null assertion,
except on GraphQL queries where the variable is asserted non-null and followed by a
skip: with the same variable.
Examples:

  • Not Required: there's a skip
    {
    variables: { templateId: templateId! },
    skip: !templateId,
    }

Check for common security vulnerabilities such as:

  • SQL Injection
  • XSS (Cross-Site Scripting)
  • CSRF (Cross-Site Request Forgery)
  • Insecure dependencies
  • Sensitive data exposure
src/main/topLevelPages/topLevelSpaces/SpaceExplorerPage.tsx (1)

Pattern src/**/*.{ts,tsx,js}: Review the React.js/TypeScript/JavaScript code for best practices and potential bugs.
Ensure that the code adheres to TypeScript's typing system and modern standards.
Use the following code guide documentation in the codebase: 'docs/code-guidelines.md'.
Ensure sufficient error handling and logging is present, but note:

  • We have a global error handler in place. So local try/catch blocks are not required unless they provide value beyond what the global error handler already covers.
  • Avoid flagging the absence of local error handling in cases where the global error handler suffices.
  • Avoid flagging the absence of logging in cases where the global logger is already in place (graphql usage).

Inform about the recommendation of not using non-null assertion,
except on GraphQL queries where the variable is asserted non-null and followed by a
skip: with the same variable.
Examples:

  • Not Required: there's a skip
    {
    variables: { templateId: templateId! },
    skip: !templateId,
    }

Check for common security vulnerabilities such as:

  • SQL Injection
  • XSS (Cross-Site Scripting)
  • CSRF (Cross-Site Request Forgery)
  • Insecure dependencies
  • Sensitive data exposure
src/main/topLevelPages/topLevelSpaces/SpaceExplorerView.tsx (1)

Pattern src/**/*.{ts,tsx,js}: Review the React.js/TypeScript/JavaScript code for best practices and potential bugs.
Ensure that the code adheres to TypeScript's typing system and modern standards.
Use the following code guide documentation in the codebase: 'docs/code-guidelines.md'.
Ensure sufficient error handling and logging is present, but note:

  • We have a global error handler in place. So local try/catch blocks are not required unless they provide value beyond what the global error handler already covers.
  • Avoid flagging the absence of local error handling in cases where the global error handler suffices.
  • Avoid flagging the absence of logging in cases where the global logger is already in place (graphql usage).

Inform about the recommendation of not using non-null assertion,
except on GraphQL queries where the variable is asserted non-null and followed by a
skip: with the same variable.
Examples:

  • Not Required: there's a skip
    {
    variables: { templateId: templateId! },
    skip: !templateId,
    }

Check for common security vulnerabilities such as:

  • SQL Injection
  • XSS (Cross-Site Scripting)
  • CSRF (Cross-Site Request Forgery)
  • Insecure dependencies
  • Sensitive data exposure
src/core/i18n/en/translation.en.json (1)

Pattern src/**/*.json: Review the JSON files for correct syntax and structure.
Ensure that the configuration and data are accurate and follow the project's standards.
Check for sensitive data exposure and ensure that the data is properly validated.

src/main/topLevelPages/topLevelSpaces/SpaceExplorerContainer.tsx (1)

Pattern src/**/*.{ts,tsx,js}: Review the React.js/TypeScript/JavaScript code for best practices and potential bugs.
Ensure that the code adheres to TypeScript's typing system and modern standards.
Use the following code guide documentation in the codebase: 'docs/code-guidelines.md'.
Ensure sufficient error handling and logging is present, but note:

  • We have a global error handler in place. So local try/catch blocks are not required unless they provide value beyond what the global error handler already covers.
  • Avoid flagging the absence of local error handling in cases where the global error handler suffices.
  • Avoid flagging the absence of logging in cases where the global logger is already in place (graphql usage).

Inform about the recommendation of not using non-null assertion,
except on GraphQL queries where the variable is asserted non-null and followed by a
skip: with the same variable.
Examples:

  • Not Required: there's a skip
    {
    variables: { templateId: templateId! },
    skip: !templateId,
    }

Check for common security vulnerabilities such as:

  • SQL Injection
  • XSS (Cross-Site Scripting)
  • CSRF (Cross-Site Request Forgery)
  • Insecure dependencies
  • Sensitive data exposure
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Travis CI - Pull Request
🔇 Additional comments (5)
src/main/topLevelPages/topLevelSpaces/SpaceExplorerPage.tsx (1)

27-31: LGTM! Clean state management.

The changes improve the component by moving the search state management to the container component, making the page component more focused on layout and composition.

src/main/topLevelPages/topLevelSpaces/SpaceExplorerContainer.tsx (2)

41-42: LGTM! Clean state management implementation.

The container now properly manages the search state and loading indicators, improving the separation of concerns.

Also applies to: 50-53


221-222: LGTM! Proper prop passing.

The container correctly provides the search state and loading indicators to child components.

src/main/topLevelPages/topLevelSpaces/SpaceExplorerView.tsx (2)

154-193: LGTM! Performance optimization with useCallback.

The renderVisibleSpaces function is properly memoized to prevent unnecessary re-renders.


247-256: LGTM! Clear user feedback during search.

The component properly handles loading states and provides clear feedback to users during search operations.

@reactoholic reactoholic force-pushed the client-web/7230_bugfix_search-bar-in-spaces-page-not-working branch from 6b4b08a to bb5d9b2 Compare January 19, 2025 10:29
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 (3)
src/main/topLevelPages/topLevelSpaces/SpaceExplorerContainer.tsx (1)

50-54: Consider memoizing the shouldSearch value.

Since shouldSearch is derived from searchTerms and used in multiple places, consider memoizing it with useMemo to prevent unnecessary recalculations.

-  const shouldSearch = searchTerms.length > 0;
+  const shouldSearch = useMemo(() => searchTerms.length > 0, [searchTerms]);
src/main/topLevelPages/topLevelSpaces/SpaceExplorerView.tsx (2)

247-256: Enhance accessibility for loading and no results states.

Consider adding ARIA attributes to improve screen reader experience.

-      {loadingSearchResults && (
+      {loadingSearchResults && (
+        <Gutters role="status" aria-live="polite">
-          <Caption>{t('pages.exploreSpaces.search.searching')}</Caption>
+          <Caption aria-label={t('pages.exploreSpaces.search.searching')}>
+            {t('pages.exploreSpaces.search.searching')}
+          </Caption>
         </Gutters>
       )}

257-261: Consider virtualizing the space cards list for better performance.

For large lists, consider using a virtualization library like react-window or react-virtualized to render only the visible cards.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6b4b08a and bb5d9b2.

📒 Files selected for processing (5)
  • src/core/i18n/en/translation.en.json (1 hunks)
  • src/domain/journey/space/SpaceSubspaceCard/StackedAvatar.tsx (1 hunks)
  • src/main/topLevelPages/topLevelSpaces/SpaceExplorerContainer.tsx (2 hunks)
  • src/main/topLevelPages/topLevelSpaces/SpaceExplorerPage.tsx (1 hunks)
  • src/main/topLevelPages/topLevelSpaces/SpaceExplorerView.tsx (7 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/domain/journey/space/SpaceSubspaceCard/StackedAvatar.tsx
  • src/main/topLevelPages/topLevelSpaces/SpaceExplorerPage.tsx
  • src/core/i18n/en/translation.en.json
🧰 Additional context used
📓 Path-based instructions (2)
src/main/topLevelPages/topLevelSpaces/SpaceExplorerView.tsx (1)

Pattern src/**/*.{ts,tsx,js}: Review the React.js/TypeScript/JavaScript code for best practices and potential bugs.
Ensure that the code adheres to TypeScript's typing system and modern standards.
Use the following code guide documentation in the codebase: 'docs/code-guidelines.md'.
Ensure sufficient error handling and logging is present, but note:

  • We have a global error handler in place. So local try/catch blocks are not required unless they provide value beyond what the global error handler already covers.
  • Avoid flagging the absence of local error handling in cases where the global error handler suffices.
  • Avoid flagging the absence of logging in cases where the global logger is already in place (graphql usage).

Inform about the recommendation of not using non-null assertion,
except on GraphQL queries where the variable is asserted non-null and followed by a
skip: with the same variable.
Examples:

  • Not Required: there's a skip
    {
    variables: { templateId: templateId! },
    skip: !templateId,
    }

Check for common security vulnerabilities such as:

  • SQL Injection
  • XSS (Cross-Site Scripting)
  • CSRF (Cross-Site Request Forgery)
  • Insecure dependencies
  • Sensitive data exposure
src/main/topLevelPages/topLevelSpaces/SpaceExplorerContainer.tsx (1)

Pattern src/**/*.{ts,tsx,js}: Review the React.js/TypeScript/JavaScript code for best practices and potential bugs.
Ensure that the code adheres to TypeScript's typing system and modern standards.
Use the following code guide documentation in the codebase: 'docs/code-guidelines.md'.
Ensure sufficient error handling and logging is present, but note:

  • We have a global error handler in place. So local try/catch blocks are not required unless they provide value beyond what the global error handler already covers.
  • Avoid flagging the absence of local error handling in cases where the global error handler suffices.
  • Avoid flagging the absence of logging in cases where the global logger is already in place (graphql usage).

Inform about the recommendation of not using non-null assertion,
except on GraphQL queries where the variable is asserted non-null and followed by a
skip: with the same variable.
Examples:

  • Not Required: there's a skip
    {
    variables: { templateId: templateId! },
    skip: !templateId,
    }

Check for common security vulnerabilities such as:

  • SQL Injection
  • XSS (Cross-Site Scripting)
  • CSRF (Cross-Site Request Forgery)
  • Insecure dependencies
  • Sensitive data exposure
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Travis CI - Pull Request
🔇 Additional comments (4)
src/main/topLevelPages/topLevelSpaces/SpaceExplorerContainer.tsx (2)

41-42: LGTM! Type definitions are well-structured.

The new properties align with React's state management patterns and properly handle loading states.


221-222: LGTM! Context values are properly provided.

The new state and loading indicator are correctly passed down through context.

src/main/topLevelPages/topLevelSpaces/SpaceExplorerView.tsx (2)

99-106: Fix potential undefined return in collectParentAvatars.

The function returns undefined when profile is not present, which could lead to runtime errors.


154-193: Remove unnecessary non-null assertions.

The non-null assertions on type and privacy mode are not needed and could be handled more safely.

Consider optimizing the memoization dependencies.

The useCallback dependency array could be more specific to prevent unnecessary re-renders.

-  }, [visibleSpaces, shouldDisplayPrivacyInfo]);
+  }, [
+    visibleSpaces?.map(space => space?.id).join(','), // Only re-render if IDs change
+    shouldDisplayPrivacyInfo
+  ]);

@bobbykolev bobbykolev self-requested a review January 20, 2025 09:20
@bobbykolev
Copy link
Contributor

@reactoholic , can you double-check the logic in ?
The code is not reused but the logic is similar. Let's make sure if there's a fix for the results, it applies there as well.

@reactoholic reactoholic force-pushed the client-web/7230_bugfix_search-bar-in-spaces-page-not-working branch from 4b4b340 to e770d88 Compare January 21, 2025 12:59
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 (2)
src/main/topLevelPages/topLevelSpaces/SpaceExplorerContainer.tsx (2)

41-42: Consider renaming interface and refining types.

The interface name ChallengeExplorerContainerEntities seems inconsistent with the file name and component purpose (SpaceExplorer). Also, loadingSearchResults type could be simplified to just boolean since the null state appears unnecessary.

-export interface ChallengeExplorerContainerEntities {
+export interface SpaceExplorerContainerEntities {
   // ...
-  loadingSearchResults: boolean | null;
+  loadingSearchResults: boolean;

50-50: Consider memoizing the shouldSearch calculation.

While the state management looks good, consider memoizing shouldSearch to prevent unnecessary recalculations on re-renders:

-const shouldSearch = searchTerms.length > 0;
+const shouldSearch = useMemo(() => searchTerms.length > 0, [searchTerms]);

Also applies to: 53-54

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bb5d9b2 and e770d88.

📒 Files selected for processing (5)
  • src/core/i18n/en/translation.en.json (1 hunks)
  • src/domain/journey/space/SpaceSubspaceCard/StackedAvatar.tsx (1 hunks)
  • src/main/topLevelPages/topLevelSpaces/SpaceExplorerContainer.tsx (2 hunks)
  • src/main/topLevelPages/topLevelSpaces/SpaceExplorerPage.tsx (1 hunks)
  • src/main/topLevelPages/topLevelSpaces/SpaceExplorerView.tsx (7 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • src/domain/journey/space/SpaceSubspaceCard/StackedAvatar.tsx
  • src/main/topLevelPages/topLevelSpaces/SpaceExplorerPage.tsx
  • src/core/i18n/en/translation.en.json
  • src/main/topLevelPages/topLevelSpaces/SpaceExplorerView.tsx
🧰 Additional context used
📓 Path-based instructions (1)
src/main/topLevelPages/topLevelSpaces/SpaceExplorerContainer.tsx (1)

Pattern src/**/*.{ts,tsx,js}: Review the React.js/TypeScript/JavaScript code for best practices and potential bugs.
Ensure that the code adheres to TypeScript's typing system and modern standards.
Use the following code guide documentation in the codebase: 'docs/code-guidelines.md'.
Ensure sufficient error handling and logging is present, but note:

  • We have a global error handler in place. So local try/catch blocks are not required unless they provide value beyond what the global error handler already covers.
  • Avoid flagging the absence of local error handling in cases where the global error handler suffices.
  • Avoid flagging the absence of logging in cases where the global logger is already in place (graphql usage).

Inform about the recommendation of not using non-null assertion,
except on GraphQL queries where the variable is asserted non-null and followed by a
skip: with the same variable.
Examples:

  • Not Required: there's a skip
    {
    variables: { templateId: templateId! },
    skip: !templateId,
    }

Check for common security vulnerabilities such as:

  • SQL Injection
  • XSS (Cross-Site Scripting)
  • CSRF (Cross-Site Request Forgery)
  • Insecure dependencies
  • Sensitive data exposure
🔇 Additional comments (2)
src/main/topLevelPages/topLevelSpaces/SpaceExplorerContainer.tsx (2)

45-45: LGTM! Props interface simplified correctly.

Moving searchTerms from props to internal state is a good approach to prevent the page refresh issue mentioned in the PR objectives.

Also applies to: 47-47


221-222: LGTM! Search state management properly exposed.

The addition of setSearchTerms and loadingSearchResults to the provided context properly enables search term management and loading state feedback, fulfilling the PR objectives.

bobbykolev
bobbykolev previously approved these changes Jan 22, 2025
Copy link
Contributor

@bobbykolev bobbykolev left a comment

Choose a reason for hiding this comment

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

Search looks far better now 👏

@reactoholic reactoholic force-pushed the client-web/7230_bugfix_search-bar-in-spaces-page-not-working branch from 35ec18c to 0a2b3e8 Compare January 22, 2025 10:15
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

♻️ Duplicate comments (1)
src/main/topLevelPages/topLevelSpaces/SpaceExplorerView.tsx (1)

174-174: ⚠️ Potential issue

Remove unsafe non-null assertions.

The non-null assertions on the type property could lead to runtime errors if the type is undefined.

Apply this diff to handle the properties safely:

-          type={space.profile?.type!}
+          type={space.profile?.type ?? ProfileType.Space}
-                type={space.profile?.type!}
+                type={space.profile?.type ?? ProfileType.Space}

Also applies to: 183-183

🧹 Nitpick comments (2)
src/main/topLevelPages/topLevelSpaces/SpaceExplorerContainer.tsx (2)

41-42: Consider refining the loadingSearchResults type.

The loadingSearchResults type could be simplified to just boolean since the null state doesn't provide additional value here. The loading state is typically binary - either loading or not loading.

-  loadingSearchResults: boolean | null;
+  loadingSearchResults: boolean;

50-54: LGTM! Consider memoizing shouldSearch.

The state management looks good. For optimization, consider memoizing shouldSearch with useMemo since it's used in multiple query skip conditions.

-  const shouldSearch = searchTerms.length > 0;
+  const shouldSearch = useMemo(() => searchTerms.length > 0, [searchTerms]);
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 35ec18c and 0a2b3e8.

📒 Files selected for processing (4)
  • src/core/i18n/en/translation.en.json (1 hunks)
  • src/main/topLevelPages/topLevelSpaces/SpaceExplorerContainer.tsx (3 hunks)
  • src/main/topLevelPages/topLevelSpaces/SpaceExplorerPage.tsx (1 hunks)
  • src/main/topLevelPages/topLevelSpaces/SpaceExplorerView.tsx (8 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/main/topLevelPages/topLevelSpaces/SpaceExplorerPage.tsx
  • src/core/i18n/en/translation.en.json
🧰 Additional context used
📓 Path-based instructions (2)
src/main/topLevelPages/topLevelSpaces/SpaceExplorerContainer.tsx (1)

Pattern src/**/*.{ts,tsx,js}: Review the React.js/TypeScript/JavaScript code for best practices and potential bugs.
Ensure that the code adheres to TypeScript's typing system and modern standards.
Use the following code guide documentation in the codebase: 'docs/code-guidelines.md'.
Ensure sufficient error handling and logging is present, but note:

  • We have a global error handler in place. So local try/catch blocks are not required unless they provide value beyond what the global error handler already covers.
  • Avoid flagging the absence of local error handling in cases where the global error handler suffices.
  • Avoid flagging the absence of logging in cases where the global logger is already in place (graphql usage).

Inform about the recommendation of not using non-null assertion,
except on GraphQL queries where the variable is asserted non-null and followed by a
skip: with the same variable.
Examples:

  • Not Required: there's a skip
    {
    variables: { templateId: templateId! },
    skip: !templateId,
    }

Check for common security vulnerabilities such as:

  • SQL Injection
  • XSS (Cross-Site Scripting)
  • CSRF (Cross-Site Request Forgery)
  • Insecure dependencies
  • Sensitive data exposure
src/main/topLevelPages/topLevelSpaces/SpaceExplorerView.tsx (1)

Pattern src/**/*.{ts,tsx,js}: Review the React.js/TypeScript/JavaScript code for best practices and potential bugs.
Ensure that the code adheres to TypeScript's typing system and modern standards.
Use the following code guide documentation in the codebase: 'docs/code-guidelines.md'.
Ensure sufficient error handling and logging is present, but note:

  • We have a global error handler in place. So local try/catch blocks are not required unless they provide value beyond what the global error handler already covers.
  • Avoid flagging the absence of local error handling in cases where the global error handler suffices.
  • Avoid flagging the absence of logging in cases where the global logger is already in place (graphql usage).

Inform about the recommendation of not using non-null assertion,
except on GraphQL queries where the variable is asserted non-null and followed by a
skip: with the same variable.
Examples:

  • Not Required: there's a skip
    {
    variables: { templateId: templateId! },
    skip: !templateId,
    }

Check for common security vulnerabilities such as:

  • SQL Injection
  • XSS (Cross-Site Scripting)
  • CSRF (Cross-Site Request Forgery)
  • Insecure dependencies
  • Sensitive data exposure
🔇 Additional comments (7)
src/main/topLevelPages/topLevelSpaces/SpaceExplorerView.tsx (4)

24-24: LGTM! Loading state implementation aligns with requirements.

The addition of the Loading component and loadingSearchResults prop properly supports the new search loading state functionality.

Also applies to: 41-41


100-102: Fix for undefined return implemented correctly.

The function now properly returns the initial array when profile is not present, preventing potential runtime errors.


155-194: Good performance optimization with useCallback!

The memoization of the rendering logic helps prevent unnecessary re-renders.


248-254: Search state handling implemented correctly.

Good implementation of:

  • Loading state indicator using the common Loading component
  • Clear "no results" message when search yields no matches
  • Proper conditional rendering based on search state
src/main/topLevelPages/topLevelSpaces/SpaceExplorerContainer.tsx (3)

45-47: LGTM! Good refactor moving searchTerms to internal state.

This change helps prevent the page refresh issue by managing search terms internally within the component.


162-162: LGTM! Important type check added.

The added type check for Space and Subspace results is crucial for type safety and fixes the production issue.


221-222: LGTM! Search state properly exposed to children.

The addition of search state setter and loading indicator to the provided context enables proper state management in child components.

@reactoholic reactoholic merged commit d350ece into develop Jan 22, 2025
3 checks passed
@reactoholic reactoholic deleted the client-web/7230_bugfix_search-bar-in-spaces-page-not-working branch January 22, 2025 10:31
@coderabbitai coderabbitai bot mentioned this pull request Jan 28, 2025
reactoholic added a commit that referenced this pull request Jan 29, 2025
* fix forum discussion styles

* update contributors image for unauth users and fix styles (#7354)

* update contributors image for unauth users and fix styles

* resolve pr comments

* Remove location from VC card

* remove usage of anonymousReadAccess (#7332)

* Fix dashboard access (#7360)

* Fix dashboard access

* fixed scope

* change polling interval

* fix pr comment

* renamed to useSpaceTemplate*s*ManagerQuery

---------

Co-authored-by: Carlos Cano <carlos@alkem.io>

* Handling of scroll and page change in documentation. (#7359)

* logs for the frame origin

* add allow-scripts to the docs iframe

* Improve the layout banner of Documentation page;

* Subtitle for the Docs page

* added new tabs to user + org admin pages; refactored contributor admin pages (#7367)

* added new tabs to user + org admin pages; refactored how admin pages for users + orgs + vcs are managed; moved some global admin functionality out of domain down to platform admin; ...

* updated generation to match api tidy ups related to set of preference types + ID passing for org mutations

* fix compile errors related to dropping of separate UserPreferenceType enum

* Synchronize icons, remove comments, make sure there are no redundant settings calls.

* Links & Docs to BoK on VC creation (#7365)

* VC documents and links BoK - refactor the AddContent

* VC documents and links implementation without validation;

* resolve rabbit comments

---------

Co-authored-by: Petar Kolev <33326233+reactoholic@users.noreply.github.com>
Co-authored-by: reactoholic <petar.georgiev.kolev@gmail.com>

* Links and Docs - forgotten commit with Validation  (#7377)

* CalloutsSet entity (#7376)

* codegen passing with updated api

* fixed api + codegen passes

* code compiling

* pick up create callout privilege from the CalloutsSet

* callouts showing up after creation

* retrieving of callouts using only calloutsSet ID

* moved code around to have notion of calloutsSet in tree

* fix array dep breaking tool creation; small code optimizations;

---------

Co-authored-by: bobbykolev <bobbykolev@abv.bg>

* split useCallouts into also useCalloutsOnCollaboration (#7378)

* Style UserAvatar tooltip (#7384)

* Fix: Deleting subspace l2 from its settings throws errors on space dashboard

* InnovationFlow States names validation - no commas (#7391)

* Add arcadeSoftware to the whitelist of iframes (#7397)

* bump client version (#7403)

* implement image pasting in md editor (#7387)

* codegen compilation

* Fix: ENTITY_NOT_FOUND Error is triggered after first login server#4790 (#7396)

* Remove `makeStyles` from `AlkemioAvatar` and `CommunityUpdatesView` (#7390)

* Clean up alkemio avatar component

The goal is to remove `@mui/styles`, but as the component is deprecated,
it is replaced with the new avatar component in the user popup and the
deprecated component is cleaned up from all unused features. The user
popup is inlined in it to simplify more the interface of the
component.

* update contributors image for unauth user (#7410)

* bug fix: verified label overlaps with text (#7415)

* removed usage of AuthorizationCredential, replaced with RoleName; removed usage of UserGroups

* added label to issue templates (#7425)

* Limit the answers length on ApplicationForm (#7419)

* Limit the answers length on ApplicationForm

* Fix error message

---------

Co-authored-by: Petar Kolev <33326233+reactoholic@users.noreply.github.com>

* Display account entitlements (#7414)

* wip

* removed state from some dialogs

---------

Co-authored-by: Carlos Cano <carlos@alkem.io>

* Fix: ENTITY_NOT_FOUND Error is triggered after first login server#4790 (#7396)

* Remove `makeStyles` from `AlkemioAvatar` and `CommunityUpdatesView` (#7390)

* Clean up alkemio avatar component

The goal is to remove `@mui/styles`, but as the component is deprecated,
it is replaced with the new avatar component in the user popup and the
deprecated component is cleaned up from all unused features. The user
popup is inlined in it to simplify more the interface of the
component.

* update contributors image for unauth user (#7410)

* bug fix: verified label overlaps with text (#7415)

* added label to issue templates (#7425)

* Limit the answers length on ApplicationForm (#7419)

* Limit the answers length on ApplicationForm

* Fix error message

---------

Co-authored-by: Petar Kolev <33326233+reactoholic@users.noreply.github.com>

* Display account entitlements (#7414)

* wip

* removed state from some dialogs

---------

Co-authored-by: Carlos Cano <carlos@alkem.io>

* update contributors image for unauth user (#7410)

* first pass fixing

* second pass

* Third pass

* 6 errors left

* Removing scary words in translation.en.json (#7432)

* moved to using UUIDs

* Add Updates from leads block to the subspaces page (l1 & l2). (#7417)

* Add Updates from leads block to the subspaces page (l1 & l2).

* share url

---------

Co-authored-by: Carlos Cano <carlos@alkem.io>

* Fix Sidebar list of spaces not refreshing after subspace delete (#7418)

Co-authored-by: Petar Kolev <33326233+reactoholic@users.noreply.github.com>

* fix

* [VC] Knowledge base instead of Subspace BoK in Written Knowledge step (#7381)

* added new tabs to user + org admin pages; refactored how admin pages for users + orgs + vcs are managed; moved some global admin functionality out of domain down to platform admin; ...

* updated generation to match api tidy ups related to set of preference types + ID passing for org mutations

* fix compile errors related to dropping of separate UserPreferenceType enum

* Synchronize icons, remove comments, make sure there are no redundant settings calls.

* Links & Docs to BoK on VC creation (#7365)

* VC documents and links BoK - refactor the AddContent

* VC documents and links implementation without validation;

* resolve rabbit comments

---------

Co-authored-by: Petar Kolev <33326233+reactoholic@users.noreply.github.com>
Co-authored-by: reactoholic <petar.georgiev.kolev@gmail.com>

* Links and Docs - forgotten commit with Validation  (#7377)

* CalloutsSet entity (#7376)

* codegen passing with updated api

* fixed api + codegen passes

* code compiling

* pick up create callout privilege from the CalloutsSet

* callouts showing up after creation

* retrieving of callouts using only calloutsSet ID

* moved code around to have notion of calloutsSet in tree

* fix array dep breaking tool creation; small code optimizations;

---------

Co-authored-by: bobbykolev <bobbykolev@abv.bg>

* VC knowledge base instead of subspace init

* Space creation after VC creation, loading, code opt & reorganization

* Fix docs uploading, code organization and documentation;

* fix uploading of docs in case there's no space under the acc; remove misleading createdSpaceId usage;

* useLoadingState instead of a new React State

* Fix - set properly the persona type depending on the 3 steps;

* Ability to select SpaceLevel2 on create VC (#7386)

* VC Knowledge Base callouts dialog (#7388)

* VC Knowledge Base callouts dialog - init.
* Filter available callout types.
* disable rich media on VC callout creation.
* Description component with update functionality.
* Update the Create Written Knowledge UI and initial state; Fix dialog titles in VC flow.
* Reingest logic in the Knowledge dialog.
* Remove the icon logic for CalloutVisibilityChangeDialog.
* Use the account hostname for space created in the VC flow.

* fix VC dialog not opening; remove outdated copy;

* storage config for KnowledgeBase description

---------

Co-authored-by: Neil Smyth <neil@thesmyths.eu>
Co-authored-by: Petar Kolev <33326233+reactoholic@users.noreply.github.com>
Co-authored-by: reactoholic <petar.georgiev.kolev@gmail.com>
Co-authored-by: Neil Smyth <30729240+techsmyth@users.noreply.github.com>
Co-authored-by: Carlos Cano <carlos@alkem.io>

* add cspell config (#7404)

* resolveIds returns string and not the entity

* proper check for available account for the vc flow (#7433)

* VirtualContributor fixes

* name ids

* updated for renamed mutation

* Client web/7416 disable image pasting when hide image options flag is true (#7428)

* fix organization verified sign font size by simone's ask

* disable image pasting if hideImageOptions flag is true

* optimize paste handler

* resolve pr comment

* Extract the isImageOrHtmlWithImage and call it once per item.

---------

Co-authored-by: Bobby Kolev <bobbykolev@abv.bg>

* Fix can't add callout to VC KnowledgeBase. (#7437)

Co-authored-by: Valentin Yanakiev <valentin.yanakiev@gmail.com>

* url resolver

* url builders

* Create space link entitlements (#7442)

* check for entitlements in the CreateSpaceLink

(cherry picked from commit aed1830)

* 0.79.7

(cherry picked from commit 7ec232c)

* updated to work with fields for entryRole + elevatedRole availability

* MD fixes - comments not visible with long Post description; `pre` long line not visible; (#7435)

* move fragment

* missing padding for the items on the left block on space and subspaces (#7448)

* Optimize the Contributor Account Tab and VC flow  (#7444)

* Optimize subspace query under acc. Fix first VC/Space flow resulting in errors.

* Fix add to community and navigation related to spaceId

* polishing

* fix navigation of subspaces

* Optimize the main vcWizard account call.

* pr fix

---------

Co-authored-by: Carlos Cano <carlos@alkem.io>

* Admin Roles management

* Available users search. Organizations auth using rolesetAdmin

* Organization roles management

* fix style

* clean up. first 0 errors

* removed usage of platform role set id on mutations for roles on platform as not needed (only one)

* check for the correct privilege for Callout creation

* Add checkbox for adding tutorials when creating new space and fix UI issue in Mozilla regarding the URL input (#7447)

* updated for adjusted privilege names

* [VC Flow] Choose community step (#7457)

* choose community step in vc flow
* fix data reload on home dash;
* refetch the BoK after VC callouts creation

* Append visuals to create profile input (#7301)

* profileData renamed to profile on CreateWhiteboardInput

* Removed visualUrl from post, which doens't make sense on creation

* graphical tweak and little rename

* Fix #7316 Create template permission (#7319)

* Filter file extensions robustly (#7326)

* Fix creating a subspace on a Space by nameId (#7328)

* Fix creating a subspace on a Space by nameId

* remove unused var

* Fix Tutorials Iframes (#7323)

* Fix tutorials iframes

* parse the iframe with the DOMParser instead of with regex

---------

Co-authored-by: Valentin Yanakiev <valentin.yanakiev@gmail.com>

* Add Callouts preview accordion on SubspacesList default subspace template selector (#7325)

* Add Callouts preview accordion on SubspacesList default subspace template selector

* usememo

* memoize the Description component

---------

Co-authored-by: Valentin Yanakiev <valentin.yanakiev@gmail.com>

* codegen

---------

Co-authored-by: Valentin Yanakiev <valentin.yanakiev@gmail.com>

* restrict activities block to 10 results and add activities dialog (#7463)

* Handle missing privileges for add VC to community. (#7470)

* Fix the save as template option missing due to missing array deps (#7476)

* Remove nameIds from VC dialogs

* Entitlements view based on permissions and limits (#7467)

* Fix #7451

* Common component to handle the

---------

Co-authored-by: Svetoslav Petkov <svetoslav@alkem.io>

* display usage-limit of spaces in the account page (#7468)

* display usage-limit of spaces in the account page

* making safer check

---------

Co-authored-by: Svetoslav Petkov <svetoslav@alkem.io>

* removed another url builder

* Remove SpaceRoleSetContributorTypes query and a few unused queries more

* Fix innovationHubs

* Fix add checkbox for tutorials UI bug (#7466)

* fix add checkbox for tutorials ui

* restore graphql files

---------

Co-authored-by: Bobby Kolev <bobbykolev@abv.bg>

* Fix first-child + useEffect dynamic deps array length console errors; (#7477)

Co-authored-by: Petar Kolev <33326233+reactoholic@users.noreply.github.com>

* Bug fix: search bar in spaces page not working, and page refreshes on search term enter (#7462)

* search spaces page not working

* visualize subspaces as well

* resolve pr comment

* resolve pr comment

* fix missing callouts in create template preview (#7482)

Co-authored-by: Petar Kolev <33326233+reactoholic@users.noreply.github.com>

* Fix organization provider

* clean

* Rename files

* Removed variables from notification query (#7481)

* First pass removing useCommunityAdmin

* rename forlder

* wip

* VC Flow - proper filtering of Existing Spaces  (#7490)

* apply multiple filters on space activities (#7489)

Co-authored-by: Bobby Kolev <bobbykolev@abv.bg>

* Available users/orgs/vcs hook

* support knowledge-base route on VC profile (#7480)

* fix nameId issue on VC profile

* fix userNameId issues on UserProfile

* a bit of cleanup. 0 errors again

* fix paste issue (#7493)

* removing fragment CommunityRoleSetDetails

* clean up

* Moved files

* Remove groups

* VC Flow - proper filtering of Existing Spaces  (#7490)

* apply multiple filters on space activities (#7489)

Co-authored-by: Bobby Kolev <bobbykolev@abv.bg>

* support knowledge-base route on VC profile (#7480)

* fix paste issue (#7493)

* VC Flow - proper filtering of Existing Spaces  (#7490)

* UserPage clean nameId

* Removed some unused code

* ApplicationDialog

* invitations in RolesetAdmin

* Delete more group things

* updatePreference mutation

* remove useInviteUsers

* fix md editor typing issue (#7501)

* small refactor

* no space creation when org has no spaces and vc is created

* refetch

* Account storage config for the account resources (#7486)

* use account storage config for entities under the account (instead userStorage)

* refactor a bit

---------

Co-authored-by: Carlos Cano <carlos@alkem.io>

* disable new posts on knowledgebase callouts (#7507)

* knowledgebase-disable-new-posts (#7509)

* No default callouts on space creation w tutorials (#7518)

* update graphql schema

* Add VC Callouts route (#7515)

* Url for posts that are inside VC knowledge-base
* fix url resolver

* 0.80.0 (#7526)

* reingest after creation of a VC with Space BoK (#7536)

* 0.80.1

* BugFix anonymous user access to public space (#7541)

* crowdin config (#7549)

* Fix search in space (#7552)

* Fix search in space

* Also use the lookup for space details

* Translations (#7553)

* 0.80.2

* disabled Crowdin action

---------

Co-authored-by: reactoholic <petar.georgiev.kolev@gmail.com>
Co-authored-by: Petar Kolev <33326233+reactoholic@users.noreply.github.com>
Co-authored-by: Carlos Cano <carlos@alkem.io>
Co-authored-by: Neil Smyth <30729240+techsmyth@users.noreply.github.com>
Co-authored-by: Valentin Yanakiev <valentin.yanakiev@gmail.com>
Co-authored-by: Neil Smyth <neil@thesmyths.eu>
Co-authored-by: Todorka Halacheva <56818790+thalacheva@users.noreply.github.com>
Co-authored-by: Svetoslav Petkov <svetoslav@alkem.io>
Co-authored-by: Simone <38861315+SimoneZaza@users.noreply.github.com>
Co-authored-by: Evgeni Dimitrov <comoque@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working client enhancement UX Enhanced user experience
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants