From 16d3d5b507364405b2c94f744147bc0625c2013a Mon Sep 17 00:00:00 2001 From: Alex Khomenko Date: Tue, 31 Mar 2020 14:48:15 +0300 Subject: [PATCH] Fix search item links (#23210) * Wrap search into into a * Justify Icon * Align items inside section header * Remove log * Fix clicking tags inside search item --- .../grafana-ui/src/components/Icon/Icon.tsx | 1 + .../features/search/components/SearchItem.tsx | 37 ++++++++++++------- .../search/components/SearchResults.tsx | 1 + 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/packages/grafana-ui/src/components/Icon/Icon.tsx b/packages/grafana-ui/src/components/Icon/Icon.tsx index f1098407ead..11002e6191b 100644 --- a/packages/grafana-ui/src/components/Icon/Icon.tsx +++ b/packages/grafana-ui/src/components/Icon/Icon.tsx @@ -16,6 +16,7 @@ const getIconStyles = stylesFactory(() => { display: inline-flex; width: 16px; align-items: center; + justify-content: center; height: 16px; text-align: center; font-size: 14px; diff --git a/public/app/features/search/components/SearchItem.tsx b/public/app/features/search/components/SearchItem.tsx index 3fb040ba089..095b512f74b 100644 --- a/public/app/features/search/components/SearchItem.tsx +++ b/public/app/features/search/components/SearchItem.tsx @@ -1,4 +1,4 @@ -import React, { FC, useCallback } from 'react'; +import React, { FC, useCallback, useRef, useEffect } from 'react'; import { css, cx } from 'emotion'; import { GrafanaTheme } from '@grafana/data'; import { e2e } from '@grafana/e2e'; @@ -20,6 +20,14 @@ const { selectors } = e2e.pages.Dashboards; export const SearchItem: FC = ({ item, editable, onToggleSelection, onTagSelected }) => { const theme = useTheme(); const styles = getResultsItemStyles(theme); + const inputEl = useRef(null); + + useEffect(() => { + inputEl.current.addEventListener('click', (event: MouseEvent) => { + // manually prevent default on TagList click, as doing it via normal onClick doesn't work inside angular + event.preventDefault(); + }); + }, []); const onItemClick = () => { //Check if one string can be found in the other @@ -28,12 +36,7 @@ export const SearchItem: FC = ({ item, editable, onToggleSelection, onTag } }; - const navigate = () => { - window.location.pathname = item.url; - }; - const tagSelected = (tag: string, event: React.MouseEvent) => { - event.stopPropagation(); onTagSelected(tag); }; @@ -48,15 +51,18 @@ export const SearchItem: FC = ({ item, editable, onToggleSelection, onTag
  • - -
    - {item.title} - {item.folderTitle} -
    - + + +
    + {item.title} + {item.folderTitle} +
    + + + +
  • ); }; @@ -104,4 +110,9 @@ const getResultsItemStyles = stylesFactory((theme: GrafanaTheme) => ({ display: none; } `, + link: css` + display: flex; + align-items: center; + width: 100%; + `, })); diff --git a/public/app/features/search/components/SearchResults.tsx b/public/app/features/search/components/SearchResults.tsx index 7e77c8d93e4..9ffb85103f6 100644 --- a/public/app/features/search/components/SearchResults.tsx +++ b/public/app/features/search/components/SearchResults.tsx @@ -120,6 +120,7 @@ const getSectionHeaderStyles = stylesFactory((theme: GrafanaTheme, selected = fa wrapper: cx( css` display: flex; + align-items: center; font-size: ${theme.typography.size.base}; padding: ${sm} ${xs} ${xs}; color: ${theme.colors.textWeak};