Allow enrichment of embedded repositories on search hits (#1760)

* Introduce RepositoryCoordinates

RepositoryCoordinates will be used for the enrichment of the embedded repositories of search result hits. This is required, because if we used the normal repository for the enrichment, we would get a lot of unrelated enrichers would be applied.

* Add builder method to HalEnricherContext

With the new builder method it is possible to add an object to the context with an interface as key.

* Add enricher support for embedded repository by applying enricher for RepositoryCoordinates

* Use embedded repository for avatars
This commit is contained in:
Sebastian Sdorra
2021-08-05 15:12:48 +02:00
committed by GitHub
parent 21a6943980
commit 8ce69d9848
9 changed files with 185 additions and 43 deletions

View File

@@ -22,7 +22,7 @@
* SOFTWARE.
*/
import React, { FC, KeyboardEvent as ReactKeyboardEvent, MouseEvent, useCallback, useState, useEffect } from "react";
import { Hit, Links, Repository, ValueHitField } from "@scm-manager/ui-types";
import { Hit, Links, ValueHitField } from "@scm-manager/ui-types";
import styled from "styled-components";
import { BackendError, useSearch } from "@scm-manager/ui-api";
import classNames from "classnames";
@@ -130,18 +130,11 @@ const AvatarSection: FC<HitProps> = ({ hit }) => {
const name = useStringHitFieldValue(hit, "name");
const type = useStringHitFieldValue(hit, "type");
if (!namespace || !name || !type) {
const repository = hit._embedded.repository;
if (!namespace || !name || !type || !repository) {
return null;
}
const repository: Repository = {
namespace,
name,
type,
_links: {},
_embedded: hit._embedded,
};
return (
<span className="mr-2">
<RepositoryAvatar repository={repository} size={24} />
@@ -278,7 +271,8 @@ const useShowResultsOnFocus = () => {
};
const onKeyUp = (e: KeyboardEvent) => {
if (e.which === 9) { // tab
if (e.which === 9) {
// tab
const element = document.activeElement;
if (!element || !isOnmiSearchElement(element)) {
close();