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: add StudioSearch component #14348

Merged
merged 17 commits into from
Jan 13, 2025
Merged

Conversation

standeren
Copy link
Contributor

@standeren standeren commented Jan 3, 2025

Description

  • add StudioSearch component.
  • use new component in code list page in library.
  • use new component in text editor.
  • use new compone

Dashboard:
Skjermbilde 2025-01-06 kl  13 48 12
nt on dashboard.

Text-editor:
Skjermbilde 2025-01-06 kl  13 49 00

CodeLists in content library:
Skjermbilde 2025-01-06 kl  13 49 19

Related Issue(s)

Verification

  • Your code builds clean without any errors or warnings
  • Manual testing done (required)

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced a new StudioSearch component to enhance search functionality across multiple pages.
    • Added clear search functionality to improve user experience.
  • Improvements

    • Updated search input selection to use more accessible role-based methods.
    • Refined layout and styling of search components.
    • Improved internationalization of search labels.
  • Refactoring

    • Replaced existing search components with a more consistent StudioSearch component.
    • Updated CSS classes and spacing using design system variables.

@github-actions github-actions bot added area/text-editor Area: Related to creating, translating and editing texts. solution/studio/designer Issues related to the Altinn Studio Designer solution. frontend labels Jan 3, 2025
@standeren standeren added skip-releasenotes Issues that do not make sense to list in our release notes area/content-library Area: Related to library for shared resources team/studio-domain1 skip-documentation Issues where updating documentation is not relevant labels Jan 3, 2025
@TomasEng TomasEng self-assigned this Jan 3, 2025
@TomasEng TomasEng assigned standeren and unassigned TomasEng Jan 3, 2025
@ErlingHauan
Copy link
Contributor

Vi har et søkefelt på dashbordet også. Hvis det ikke er for mye jobb, kan du legge den til der i tillegg?

@github-actions github-actions bot added the area/dashboard Area: Related to the dashboard application label Jan 3, 2025
@github-actions github-actions bot added the quality/testing Tests that are missing, needs to be created or could be improved. label Jan 6, 2025
Copy link

codecov bot commented Jan 6, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.66%. Comparing base (683992b) to head (9fe3f1a).
Report is 9 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #14348   +/-   ##
=======================================
  Coverage   95.66%   95.66%           
=======================================
  Files        1871     1873    +2     
  Lines       24287    24297   +10     
  Branches     2788     2789    +1     
=======================================
+ Hits        23233    23244   +11     
  Misses        797      797           
+ Partials      257      256    -1     

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

@standeren standeren assigned TomasEng and unassigned standeren Jan 6, 2025
@TomasEng TomasEng self-requested a review January 6, 2025 08:34
@TomasEng TomasEng assigned standeren and unassigned TomasEng Jan 6, 2025
Copy link

coderabbitai bot commented Jan 13, 2025

Warning

Rate limit exceeded

@standeren has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 19 minutes and 25 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 7bc2dea and 9fe3f1a.

📒 Files selected for processing (1)
  • frontend/testing/playwright/pages/DashboardPage.ts (1 hunks)
📝 Walkthrough

Walkthrough

This pull request introduces a comprehensive update to the search functionality across multiple frontend components. The changes primarily focus on replacing existing search implementations with a new StudioSearch component, enhancing accessibility, and standardizing search-related interactions. The modifications span several files, including test suites, CSS modules, and component implementations, with a consistent approach to improving search input handling and user experience.

Changes

File Path Change Summary
frontend/libs/studio-components/src/components/StudioSearch/ New component added with comprehensive implementation and test suite
frontend/dashboard/pages/Dashboard/ Replaced Textfield and StudioButton with StudioSearch component
frontend/packages/text-editor/src/ Updated search implementation, added clear search functionality
frontend/libs/studio-content-library/src/ContentLibrary/ Replaced Search component with StudioSearch
frontend/dashboard/pages/Dashboard/Dashboard.module.css, frontend/packages/text-editor/src/TextEditor.module.css Updated CSS classes and layout properties
frontend/language/src/nb.json Updated search-related translation key

Possibly related PRs

Suggested labels

added-to-sprint

Suggested reviewers

  • ErlingHauan
  • Konrad-Simso

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

@ErlingHauan ErlingHauan left a comment

Choose a reason for hiding this comment

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

Test

Dashboard

Label er over søkefeltet i PR-beskrivelsen, men ser det nå står til venstre:
bilde

Språk

Label kommer helt inntil tekstfeltet når det er fokusert. Kan du gjøre avstanden litt større?
bilde

Bibliotek

Her har label havnet til venstre for tekstfelt, og ser i PR-beskrivelsen at den skal være over feltet.
bilde

Edit: fjernet en bolk som angikk feil konfig av .env hos meg 😅

@ErlingHauan ErlingHauan assigned standeren and unassigned ErlingHauan Jan 13, 2025
@standeren standeren force-pushed the add-studio-component-for-search branch from 8efefb3 to 3cfe28c Compare January 13, 2025 13:59
@standeren standeren assigned ErlingHauan and unassigned standeren Jan 13, 2025
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.

Caution

Inline review comments failed to post. This is likely due to GitHub's limits when posting large numbers of comments.

Actionable comments posted: 1

🧹 Nitpick comments (4)
frontend/libs/studio-components/src/components/StudioSearch/StudioSearch.tsx (1)

13-22: Consider adding aria-label when no visible label is present.

While the implementation looks good, consider adding an aria-label when showLabel is false to maintain accessibility.

 return (
   <div>
     {showLabel && (
       <Label htmlFor={searchId} spacing>
         {label}
       </Label>
     )}
-    <Search {...rest} id={searchId} size={size} ref={ref} />
+    <Search 
+      {...rest} 
+      id={searchId} 
+      size={size} 
+      ref={ref}
+      aria-label={!showLabel && label ? label : undefined}
+    />
   </div>
 );
frontend/libs/studio-components/src/components/StudioSearch/StudioSearch.test.tsx (1)

22-27: Add test for aria-label when no visible label is present.

To ensure accessibility is maintained, add a test case for the aria-label when showLabel is false.

+ it('should have aria-label when visible label is not shown', () => {
+   const label = 'Search for something';
+   renderTestSearch({ label, showLabel: false });
+   const search = screen.getByRole('searchbox', { name: label });
+   expect(search).toHaveAttribute('aria-label', label);
+ });
frontend/testing/playwright/pages/DashboardPage.ts (1)

96-96: Consider adding a name to the searchbox role selector.

While using getByRole('searchbox') follows accessibility best practices, adding the expected label text would make the test more specific and robust.

-    await this.page.getByRole('searchbox').fill(word);
+    await this.page.getByRole('searchbox', { name: this.textMock('dashboard.search') }).fill(word);
frontend/dashboard/pages/Dashboard/Dashboard.module.css (1)

6-7: Consider enhancing responsive layout

While the grid layout works, consider these improvements for better responsiveness:

  • Add media queries for narrow viewports
  • Define minimum column widths
  • Consider fallback for older browsers

Example improvement:

 .topBar {
   display: grid;
-  grid-template-columns: auto auto;
+  grid-template-columns: minmax(200px, 1fr) minmax(auto, max-content);
   justify-content: space-between;
   align-items: center;
   margin-bottom: var(--fds-spacing-10);
+  gap: var(--fds-spacing-4);
+  @media (max-width: 768px) {
+    grid-template-columns: 1fr;
+    gap: var(--fds-spacing-6);
+  }
 }

Also applies to: 55-55

🛑 Comments failed to post (1)
frontend/libs/studio-content-library/src/ContentLibrary/LibraryBody/pages/CodeListPage/CodeListsActionsBar/CodeListsActionsBar.tsx (1)

38-41: 💡 Codebase verification

Missing required controlled component props

The StudioSearch component requires controlled component implementation as evidenced by other usages in the codebase (e.g., in TextEditor.tsx and Dashboard.tsx). The current implementation should include:

  • value prop for controlled state
  • onChange handler for input changes
🔗 Analysis chain

Missing search functionality props.

The StudioSearch component appears to be missing essential props for search functionality:

  • onChange handler for search input
  • value prop for controlled input
  • placeholder for better UX when label is visible
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if search functionality is implemented elsewhere
rg -A 5 "StudioSearch.*onChange" .

Length of output: 36


Script:

#!/bin/bash
# Find StudioSearch component definition
fd StudioSearch

Length of output: 237


Script:

#!/bin/bash
# Look for any StudioSearch usage patterns
rg "StudioSearch" -A 3

Length of output: 6543


Script:

#!/bin/bash
# Find component imports
rg "import.*StudioSearch"

Length of output: 711

@standeren
Copy link
Contributor Author

Test

Dashboard

Label er over søkefeltet i PR-beskrivelsen, men ser det nå står til venstre: bilde

Språk

Label kommer helt inntil tekstfeltet når det er fokusert. Kan du gjøre avstanden litt større? bilde

Bibliotek

Her har label havnet til venstre for tekstfelt, og ser i PR-beskrivelsen at den skal være over feltet. bilde

Edit: fjernet en bolk som angikk feil konfig av .env hos meg 😅

Ups, bra vi tester si 😉 Har skjedd under kodegjennomgang - fikset nå!

Copy link
Contributor

@ErlingHauan ErlingHauan left a comment

Choose a reason for hiding this comment

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

Ser bra ut 🥳

@ErlingHauan ErlingHauan assigned standeren and unassigned ErlingHauan Jan 13, 2025
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)
frontend/libs/studio-components/src/components/StudioSearch/StudioSearch.tsx (1)

14-14: Consider enhancing className handling.

The className prop is directly passed to the wrapper div. Consider using a utility like clsx or classnames to combine multiple class names and ensure robust handling of undefined or null values.

-      <div className={className}>
+      <div className={clsx(className)}>

Don't forget to add the import:

import clsx from 'clsx';
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 8efefb3 and 7bc2dea.

📒 Files selected for processing (4)
  • frontend/dashboard/pages/Dashboard/Dashboard.module.css (0 hunks)
  • frontend/dashboard/pages/Dashboard/Dashboard.tsx (2 hunks)
  • frontend/libs/studio-components/src/components/StudioSearch/StudioSearch.tsx (1 hunks)
  • frontend/packages/text-editor/src/TextEditor.tsx (3 hunks)
💤 Files with no reviewable changes (1)
  • frontend/dashboard/pages/Dashboard/Dashboard.module.css
🚧 Files skipped from review as they are similar to previous changes (2)
  • frontend/dashboard/pages/Dashboard/Dashboard.tsx
  • frontend/packages/text-editor/src/TextEditor.tsx
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Build environment and run e2e test
  • GitHub Check: Testing
  • GitHub Check: Typechecking and linting
  • GitHub Check: CodeQL
🔇 Additional comments (4)
frontend/libs/studio-components/src/components/StudioSearch/StudioSearch.tsx (4)

1-5: LGTM! Clean imports and type definitions.

The imports are well-organized, and the WithoutAsChild utility is used appropriately to define the component's props type.


7-24: LGTM! Well-structured component implementation.

The component follows React best practices with proper ref forwarding, ID generation, and label accessibility.


26-28: LGTM! Proper component naming and export.

The displayName is set correctly for debugging purposes, and the export follows the standard pattern.


1-28: Verify integration points across the application.

Since this component replaces existing search implementations in multiple places (dashboard, text editor, code list page), let's verify the integration points:

✅ Verification successful

Integration verification successful

The StudioSearch component is properly integrated across all intended locations (dashboard, text editor, code list page) with consistent implementation patterns. No direct usage of the base Search component remains in the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify StudioSearch component usage across the application

# Check import statements
echo "Checking StudioSearch imports:"
rg -l "import.*StudioSearch" --type ts --type tsx

# Check component usage
echo "\nChecking StudioSearch component usage:"
rg "<StudioSearch" --type tsx -A 3

# Check for any remaining old search implementations
echo "\nChecking for potential remaining old implementations:"
rg -l "import.*Search.*from.*@digdir/designsystemet-react" --type ts --type tsx

Length of output: 537


Script:

#!/bin/bash
# Description: Verify StudioSearch component usage with corrected syntax

echo "Checking StudioSearch imports:"
rg "import.*StudioSearch" -g "*.{ts,tsx}"

echo -e "\nChecking StudioSearch component usage:"
rg "<StudioSearch" -g "*.tsx" -A 3

echo -e "\nChecking for potential remaining old Search implementations:"
rg "import.*Search.*from.*@digdir/designsystemet-react" -g "*.{ts,tsx}"

Length of output: 3428

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/content-library Area: Related to library for shared resources area/dashboard Area: Related to the dashboard application area/text-editor Area: Related to creating, translating and editing texts. frontend quality/testing Tests that are missing, needs to be created or could be improved. skip-documentation Issues where updating documentation is not relevant skip-releasenotes Issues that do not make sense to list in our release notes solution/studio/designer Issues related to the Altinn Studio Designer solution. team/studio-domain1
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

3 participants