/* * MIT License * * Copyright (c) 2020-present Cloudogu GmbH and Contributors * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import React, { useState } from "react"; import { Link as RouteLink, Redirect, Route, Switch, useRouteMatch } from "react-router-dom"; import { useTranslation } from "react-i18next"; import { binder, ExtensionPoint } from "@scm-manager/ui-extensions"; import { Changeset, Link } from "@scm-manager/ui-types"; import { CustomQueryFlexWrappedColumns, ErrorPage, FileControlFactory, HealthCheckFailureDetail, JumpToFileButton, Loading, NavLink, Page, PrimaryContentColumn, RepositoryFlag, SecondaryNavigation, SecondaryNavigationColumn, StateMenuContextProvider, SubNavigation, Tooltip, urls, } from "@scm-manager/ui-components"; import RepositoryDetails from "../components/RepositoryDetails"; import EditRepo from "./EditRepo"; import BranchesOverview from "../branches/containers/BranchesOverview"; import CreateBranch from "../branches/containers/CreateBranch"; import Permissions from "../permissions/containers/Permissions"; import EditRepoNavLink from "../components/EditRepoNavLink"; import BranchRoot from "../branches/containers/BranchRoot"; import PermissionsNavLink from "../components/PermissionsNavLink"; import RepositoryNavLink from "../components/RepositoryNavLink"; import CodeOverview from "../codeSection/containers/CodeOverview"; import ChangesetView from "./ChangesetView"; import SourceExtensions from "../sources/containers/SourceExtensions"; import TagsOverview from "../tags/container/TagsOverview"; import TagRoot from "../tags/container/TagRoot"; import { useIndexLinks, useRepository } from "@scm-manager/ui-api"; import styled from "styled-components"; const TagGroup = styled.div` font-weight: bold; & > * { margin-right: 0.25rem; } `; type UrlParams = { namespace: string; name: string; }; const useRepositoryFromUrl = (match: match) => { const { namespace, name } = match.params; const { data: repository, ...rest } = useRepository(namespace, name); return { repository, ...rest, }; }; const RepositoryRoot = () => { const match = useRouteMatch(); const { isLoading, error, repository } = useRepositoryFromUrl(match); const indexLinks = useIndexLinks(); const [showHealthCheck, setShowHealthCheck] = useState(false); const [t] = useTranslation("repos"); if (error) { return ( ); } if (!repository || isLoading) { return ; } const url = urls.matchedUrlFromMatch(match); // props used for extensions // most of the props required for compatibility const props = { namespace: repository.namespace, name: repository.name, repository: repository, loading: isLoading, error, repoLink: (indexLinks.repositories as Link)?.href, indexLinks, match, }; const redirectUrlFactory = binder.getExtension("repository.redirect", props); let redirectedUrl; if (redirectUrlFactory) { redirectedUrl = url + redirectUrlFactory(props); } else { redirectedUrl = url + "/info"; } const fileControlFactoryFactory: (changeset: Changeset) => FileControlFactory = (changeset) => (file) => { const baseUrl = `${url}/code/sources`; const sourceLink = file.newPath && { url: `${baseUrl}/${changeset.id}/${file.newPath}/`, label: t("diff.jumpToSource"), }; const targetLink = file.oldPath && changeset._embedded?.parents?.length === 1 && { url: `${baseUrl}/${changeset._embedded.parents[0].id}/${file.oldPath}`, label: t("diff.jumpToTarget"), }; const links = []; switch (file.type) { case "add": if (sourceLink) { links.push(sourceLink); } break; case "delete": if (targetLink) { links.push(targetLink); } break; default: if (targetLink && sourceLink) { links.push(targetLink, sourceLink); // Target link first because its the previous file } else if (sourceLink) { links.push(sourceLink); } } return links ? links.map(({ url, label }) => ) : null; }; const repositoryFlags = []; if (repository.archived) { repositoryFlags.push( {t("repository.archived")} ); } if (repository.exporting) { repositoryFlags.push( {t("repository.exporting")} ); } if (repository.healthCheckFailures && repository.healthCheckFailures.length > 0) { repositoryFlags.push( setShowHealthCheck(true)} color="danger"> {t("repository.healthCheckFailure")} ); } const titleComponent = ( <> {repository.namespace} /{repository.name} ); const extensionProps = { repository, url, indexLinks, }; const matchesBranches = (route: any) => { const regex = new RegExp(`${url}/branch/.+/info`); return route.location.pathname.match(regex); }; const matchesTags = (route: any) => { const regex = new RegExp(`${url}/tag/.+/info`); return route.location.pathname.match(regex); }; const matchesCode = (route: any) => { const regex = new RegExp(`${url}(/code)/.*`); return route.location.pathname.match(regex); }; const getCodeLinkname = () => { if (repository?._links?.sources) { return "sources"; } if (repository?._links?.changesets) { return "changesets"; } return ""; }; const evaluateDestinationForCodeLink = () => { if (repository?._links?.sources) { return `${url}/code/sources/`; } return `${url}/code/changesets`; }; const modal = ( setShowHealthCheck(false)} active={showHealthCheck} failures={repository.healthCheckFailures} /> ); return ( {repositoryFlags} } > {modal} {/* redirect pre 2.0.0-rc2 links */} ( )} /> } /> } /> } /> } /> } /> } /> } /> ); }; export default RepositoryRoot;