use binder from context to make extensions it testable

This commit is contained in:
Sebastian Sdorra
2020-02-19 09:48:46 +01:00
parent 041a999a01
commit f23b464524
3 changed files with 68 additions and 75 deletions

View File

@@ -1,8 +1,8 @@
import React, { FC } from "react";
import { binder } from "@scm-manager/ui-extensions";
import { Image } from "..";
import { Person } from "./Avatar";
import { EXTENSION_POINT } from "./Avatar";
import { useBinder } from "@scm-manager/ui-extensions";
type Props = {
person: Person;
@@ -10,6 +10,7 @@ type Props = {
};
const AvatarImage: FC<Props> = ({ person, representation = "rounded-border" }) => {
const binder = useBinder();
const avatarFactory = binder.getExtension(EXTENSION_POINT);
if (avatarFactory) {
const avatar = avatarFactory(person);

View File

@@ -1,18 +1,13 @@
import React, { Component, ReactNode } from "react";
import { binder } from "@scm-manager/ui-extensions";
import React, { FC } from "react";
import { useBinder } from "@scm-manager/ui-extensions";
import { EXTENSION_POINT } from "./Avatar";
type Props = {
children: ReactNode;
};
class AvatarWrapper extends Component<Props> {
render() {
const AvatarWrapper: FC = ({ children }) => {
const binder = useBinder();
if (binder.hasExtension(EXTENSION_POINT)) {
return <>{this.props.children}</>;
return <>{children}</>;
}
return null;
}
}
};
export default AvatarWrapper;

View File

@@ -1,7 +1,7 @@
import React from "react";
import React, { FC } from "react";
import { Me, Links } from "@scm-manager/ui-types";
import { Link } from "react-router-dom";
import { binder } from "@scm-manager/ui-extensions";
import { useBinder } from "@scm-manager/ui-extensions";
import { AvatarWrapper, AvatarImage } from "../avatar";
type Props = {
@@ -10,13 +10,11 @@ type Props = {
links: Links;
};
class Footer extends React.Component<Props> {
render() {
const { me, version, links } = this.props;
const Footer: FC<Props> = ({ me, version, links }) => {
const binder = useBinder();
if (!me) {
return "";
return null;
}
const extensionProps = { me, links };
const extensions = binder.getExtensions("footer.links", extensionProps);
@@ -59,7 +57,6 @@ class Footer extends React.Component<Props> {
</div>
</footer>
);
}
}
};
export default Footer;