mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-18 03:01:05 +01:00
Show repository avatar in quick search (#1759)
This commit is contained in:
2
gradle/changelog/repository_avatar.yaml
Normal file
2
gradle/changelog/repository_avatar.yaml
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
- type: Added
|
||||||
|
description: Show repository avatar in quick search ([#1759](https://github.com/scm-manager/scm-manager/issues/1759))
|
||||||
@@ -22,13 +22,20 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
import React, { FC, KeyboardEvent as ReactKeyboardEvent, MouseEvent, useCallback, useState, useEffect } from "react";
|
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 styled from "styled-components";
|
||||||
import { BackendError, useSearch } from "@scm-manager/ui-api";
|
import { BackendError, useSearch } from "@scm-manager/ui-api";
|
||||||
import classNames from "classnames";
|
import classNames from "classnames";
|
||||||
import { Link, useHistory } from "react-router-dom";
|
import { Link, useHistory } from "react-router-dom";
|
||||||
import { useTranslation } from "react-i18next";
|
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`
|
const Field = styled.div`
|
||||||
margin-bottom: 0 !important;
|
margin-bottom: 0 !important;
|
||||||
@@ -118,6 +125,30 @@ const ResultFooter = styled.div`
|
|||||||
padding: 0.375rem 0.5rem;
|
padding: 0.375rem 0.5rem;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
const AvatarSection: FC<HitProps> = ({ 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 (
|
||||||
|
<span className="mr-2">
|
||||||
|
<RepositoryAvatar repository={repository} size={24} />
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
const MoreResults: FC<GotoProps> = ({ gotoDetailSearch }) => {
|
const MoreResults: FC<GotoProps> = ({ gotoDetailSearch }) => {
|
||||||
const [t] = useTranslation("commons");
|
const [t] = useTranslation("commons");
|
||||||
return (
|
return (
|
||||||
@@ -143,7 +174,7 @@ const Hits: FC<HitsProps> = ({ hits, index, clear, gotoDetailSearch }) => {
|
|||||||
{hits.map((hit, idx) => (
|
{hits.map((hit, idx) => (
|
||||||
<div key={id(hit)} onMouseDown={(e) => e.preventDefault()} onClick={clear}>
|
<div key={id(hit)} onMouseDown={(e) => e.preventDefault()} onClick={clear}>
|
||||||
<Link
|
<Link
|
||||||
className={classNames("dropdown-item", "has-text-weight-medium", "is-ellipsis-overflow", {
|
className={classNames("is-flex", "dropdown-item", "has-text-weight-medium", "is-ellipsis-overflow", {
|
||||||
"is-active": idx === index,
|
"is-active": idx === index,
|
||||||
})}
|
})}
|
||||||
title={id(hit)}
|
title={id(hit)}
|
||||||
@@ -151,7 +182,7 @@ const Hits: FC<HitsProps> = ({ hits, index, clear, gotoDetailSearch }) => {
|
|||||||
role="option"
|
role="option"
|
||||||
data-omnisearch="true"
|
data-omnisearch="true"
|
||||||
>
|
>
|
||||||
{id(hit)}
|
<AvatarSection hit={hit} /> {id(hit)}
|
||||||
</Link>
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
|
|||||||
Reference in New Issue
Block a user