diff --git a/gradle/changelog/hide_blame_button_for_binaries.yaml b/gradle/changelog/hide_blame_button_for_binaries.yaml new file mode 100644 index 0000000000..e730832b69 --- /dev/null +++ b/gradle/changelog/hide_blame_button_for_binaries.yaml @@ -0,0 +1,2 @@ +- type: fixed + description: Non-functional annotate view for binary files diff --git a/scm-ui/ui-webapp/src/repos/sources/components/content/FileButtonAddons.tsx b/scm-ui/ui-webapp/src/repos/sources/components/content/FileButtonAddons.tsx index d4f7683d9b..5361812d6d 100644 --- a/scm-ui/ui-webapp/src/repos/sources/components/content/FileButtonAddons.tsx +++ b/scm-ui/ui-webapp/src/repos/sources/components/content/FileButtonAddons.tsx @@ -21,71 +21,61 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -import React from "react"; -import { WithTranslation, withTranslation } from "react-i18next"; +import React, { FC, useMemo } from "react"; +import { useTranslation } from "react-i18next"; import { Button, ButtonAddons } from "@scm-manager/ui-components"; import { SourceViewSelection } from "../../containers/Content"; +import { File, Link } from "@scm-manager/ui-types"; +import { useContentType } from "@scm-manager/ui-api"; -type Props = WithTranslation & { +type Props = { className?: string; selected: SourceViewSelection; showSources: () => void; showHistory: () => void; showAnnotations: () => void; + file: File; }; -class FileButtonAddons extends React.Component { - showHistory = () => { - this.props.showHistory(); - }; +const color = (selected: boolean) => { + return selected ? "link is-selected" : ""; +}; - showSources = () => { - this.props.showSources(); - }; +const FileButtonAddons: FC = ({ className, selected, showSources, showHistory, showAnnotations, file }) => { + const [t] = useTranslation("repos"); + const { data: contentTypeData } = useContentType((file._links.self as Link).href); + const showAnnotationButton = useMemo( + () => + contentTypeData?.language || + ["text/", "markdown/"].some((nonBinaryContentType) => contentTypeData?.type.startsWith(nonBinaryContentType)), + [contentTypeData] + ); - showAnnotations = () => { - this.props.showAnnotations(); - }; - - color = (selected: boolean) => { - return selected ? "link is-selected" : ""; - }; - - render() { - const { className, t, selected, showSources, showHistory, showAnnotations } = this.props; - - return ( - - + return ( + + + {showAnnotationButton ? ( - - - ); - } -} + ) : null} + + + ); +}; -export default withTranslation("repos")(FileButtonAddons); +export default FileButtonAddons; diff --git a/scm-ui/ui-webapp/src/repos/sources/containers/Content.tsx b/scm-ui/ui-webapp/src/repos/sources/containers/Content.tsx index 516b6c2c79..18454c673f 100644 --- a/scm-ui/ui-webapp/src/repos/sources/containers/Content.tsx +++ b/scm-ui/ui-webapp/src/repos/sources/containers/Content.tsx @@ -114,6 +114,7 @@ const Content: FC = ({ file, repository, revision, breadcrumb, error }) = const selector = file._links.history ? ( setSelected("source")}