From 4fa5ad1f0def478fc84404b62a0d084fc8092bb7 Mon Sep 17 00:00:00 2001 From: Florian Scholdei Date: Thu, 5 Aug 2021 07:47:38 +0200 Subject: [PATCH] Show repository avatar in quick search (#1759) --- gradle/changelog/repository_avatar.yaml | 2 + .../ui-webapp/src/containers/OmniSearch.tsx | 39 +++++++++++++++++-- 2 files changed, 37 insertions(+), 4 deletions(-) create mode 100644 gradle/changelog/repository_avatar.yaml diff --git a/gradle/changelog/repository_avatar.yaml b/gradle/changelog/repository_avatar.yaml new file mode 100644 index 0000000000..9503bb4d6a --- /dev/null +++ b/gradle/changelog/repository_avatar.yaml @@ -0,0 +1,2 @@ +- type: Added + description: Show repository avatar in quick search ([#1759](https://github.com/scm-manager/scm-manager/issues/1759)) diff --git a/scm-ui/ui-webapp/src/containers/OmniSearch.tsx b/scm-ui/ui-webapp/src/containers/OmniSearch.tsx index 4b5f23fe1e..a4627b2689 100644 --- a/scm-ui/ui-webapp/src/containers/OmniSearch.tsx +++ b/scm-ui/ui-webapp/src/containers/OmniSearch.tsx @@ -22,13 +22,20 @@ * SOFTWARE. */ import React, { FC, KeyboardEvent as ReactKeyboardEvent, MouseEvent, useCallback, useState, useEffect } from "react"; -import { Hit, Links, ValueHitField } from "@scm-manager/ui-types"; +import { Hit, Links, Repository, ValueHitField } from "@scm-manager/ui-types"; import styled from "styled-components"; import { BackendError, useSearch } from "@scm-manager/ui-api"; import classNames from "classnames"; import { Link, useHistory } from "react-router-dom"; import { useTranslation } from "react-i18next"; -import { Button, ErrorNotification, Notification } from "@scm-manager/ui-components"; +import { + Button, + ErrorNotification, + HitProps, + Notification, + RepositoryAvatar, + useStringHitFieldValue, +} from "@scm-manager/ui-components"; const Field = styled.div` margin-bottom: 0 !important; @@ -118,6 +125,30 @@ const ResultFooter = styled.div` padding: 0.375rem 0.5rem; `; +const AvatarSection: FC = ({ hit }) => { + const namespace = useStringHitFieldValue(hit, "namespace"); + const name = useStringHitFieldValue(hit, "name"); + const type = useStringHitFieldValue(hit, "type"); + + if (!namespace || !name || !type) { + return null; + } + + const repository: Repository = { + namespace, + name, + type, + _links: {}, + _embedded: hit._embedded, + }; + + return ( + + + + ); +}; + const MoreResults: FC = ({ gotoDetailSearch }) => { const [t] = useTranslation("commons"); return ( @@ -143,7 +174,7 @@ const Hits: FC = ({ hits, index, clear, gotoDetailSearch }) => { {hits.map((hit, idx) => (
e.preventDefault()} onClick={clear}> = ({ hits, index, clear, gotoDetailSearch }) => { role="option" data-omnisearch="true" > - {id(hit)} + {id(hit)}
))}