From d2d1034e10a78992a9d3aa3267dc770832646af1 Mon Sep 17 00:00:00 2001 From: Jeremy Davis Date: Tue, 26 Jul 2022 15:05:37 +0200 Subject: [PATCH] SONAR-16683 [891539] Semantic html for the search results --- .../main/js/app/components/search/Search.tsx | 2 +- .../js/app/components/search/SearchResult.tsx | 10 +- .../app/components/search/SearchResults.tsx | 47 +++---- .../__snapshots__/SearchResult-test.tsx.snap | 12 ++ .../__snapshots__/SearchResults-test.tsx.snap | 124 ++++++++++-------- .../main/js/app/styles/components/menu.css | 4 + 6 files changed, 110 insertions(+), 89 deletions(-) diff --git a/server/sonar-web/src/main/js/app/components/search/Search.tsx b/server/sonar-web/src/main/js/app/components/search/Search.tsx index eb716f341e7..98996b99490 100644 --- a/server/sonar-web/src/main/js/app/components/search/Search.tsx +++ b/server/sonar-web/src/main/js/app/components/search/Search.tsx @@ -378,7 +378,7 @@ export class Search extends React.PureComponent { selected={this.state.selected} />
-
+
{translate('recently_browsed')}
diff --git a/server/sonar-web/src/main/js/app/components/search/SearchResult.tsx b/server/sonar-web/src/main/js/app/components/search/SearchResult.tsx index 16f946915d7..c155d0bb86f 100644 --- a/server/sonar-web/src/main/js/app/components/search/SearchResult.tsx +++ b/server/sonar-web/src/main/js/app/components/search/SearchResult.tsx @@ -41,6 +41,7 @@ interface State { } const TOOLTIP_DELAY = 1000; +const MILLISECONDS_PER_SECOND = 1000; export default class SearchResult extends React.PureComponent { interval?: number; @@ -101,9 +102,11 @@ export default class SearchResult extends React.PureComponent {
  • this.props.innerRef(component.key, node)}> + ref={node => this.props.innerRef(component.key, node)} + role="option" + aria-selected={this.props.selected}> @@ -118,7 +121,8 @@ export default class SearchResult extends React.PureComponent { {component.match ? ( ) : ( diff --git a/server/sonar-web/src/main/js/app/components/search/SearchResults.tsx b/server/sonar-web/src/main/js/app/components/search/SearchResults.tsx index 4b12eff31df..c0ccf411c86 100644 --- a/server/sonar-web/src/main/js/app/components/search/SearchResults.tsx +++ b/server/sonar-web/src/main/js/app/components/search/SearchResults.tsx @@ -41,39 +41,30 @@ export default function SearchResults(props: Props): React.ReactElement { sortQualifiers(qualifiers).forEach(qualifier => { const components = props.results[qualifier]; - if (components.length > 0 && renderedComponents.length > 0) { - renderedComponents.push(
  • ); - } - if (components.length > 0) { - renderedComponents.push( -
  • - {translate('qualifiers', qualifier)} -
  • - ); - } - - components.forEach(component => renderedComponents.push(props.renderResult(component))); + const more = props.more[qualifier]; - const more = props.more[qualifier]; - if (more !== undefined && more > 0) { renderedComponents.push( - +
      +
    • + {translate('qualifiers', qualifier)} +
    • + {components.map(component => props.renderResult(component))} + {more !== undefined && more > 0 && ( + + )} +
    ); } }); - return renderedComponents.length > 0 ? ( -
      {renderedComponents}
    - ) : ( - props.renderNoResults() - ); + return renderedComponents.length > 0 ?
    {renderedComponents}
    : props.renderNoResults(); } diff --git a/server/sonar-web/src/main/js/app/components/search/__tests__/__snapshots__/SearchResult-test.tsx.snap b/server/sonar-web/src/main/js/app/components/search/__tests__/__snapshots__/SearchResult-test.tsx.snap index d4e19eaf97b..4cee1218fcd 100644 --- a/server/sonar-web/src/main/js/app/components/search/__tests__/__snapshots__/SearchResult-test.tsx.snap +++ b/server/sonar-web/src/main/js/app/components/search/__tests__/__snapshots__/SearchResult-test.tsx.snap @@ -2,7 +2,9 @@ exports[`renders favorite 1`] = `
  • -
  • +
      - qualifiers.TRK - - - foo - - - bar - - -
    +
  • + qualifiers.TRK +
  • + + foo + + + bar + + + +
    `; exports[`renders different components and dividers between them 1`] = ` -
      -
    • +
        - qualifiers.FIL - - - zux - -
      • -
      • + qualifiers.FIL +
      • + + zux + +
      +
        - qualifiers.TRK - - - foo - - - bar - -
      +
    • + qualifiers.TRK +
    • + + foo + + + bar + +
    +
    `; exports[`should render no results 1`] = ` diff --git a/server/sonar-web/src/main/js/app/styles/components/menu.css b/server/sonar-web/src/main/js/app/styles/components/menu.css index 6ed64f7f2e6..567e5f9a18c 100644 --- a/server/sonar-web/src/main/js/app/styles/components/menu.css +++ b/server/sonar-web/src/main/js/app/styles/components/menu.css @@ -27,6 +27,10 @@ background-clip: padding-box; } +.menu + .menu { + border-top: 1px solid var(--barBorderColor); +} + .menu:focus { outline: none; } -- 2.39.5