2020-03-23 15:35:58 +01:00
|
|
|
/*
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
2021-02-24 08:17:40 +01:00
|
|
|
|
|
|
|
|
import React, { FC } from "react";
|
|
|
|
|
import { useTranslation } from "react-i18next";
|
2019-10-20 18:02:52 +02:00
|
|
|
import styled from "styled-components";
|
2021-11-01 16:54:58 +01:00
|
|
|
import { binder, ExtensionPoint, extensionPoints } from "@scm-manager/ui-extensions";
|
2021-09-30 16:41:04 +02:00
|
|
|
import { File, Repository } from "@scm-manager/ui-types";
|
2019-10-20 18:02:52 +02:00
|
|
|
import FileTreeLeaf from "./FileTreeLeaf";
|
2021-02-24 08:17:40 +01:00
|
|
|
import TruncatedNotification from "./TruncatedNotification";
|
2021-09-30 16:41:04 +02:00
|
|
|
import { isRootPath } from "../utils/files";
|
2020-02-19 18:37:09 +01:00
|
|
|
|
2021-02-24 08:17:40 +01:00
|
|
|
type Props = {
|
2021-09-30 16:41:04 +02:00
|
|
|
repository: Repository;
|
2021-02-24 08:17:40 +01:00
|
|
|
directory: File;
|
2019-10-19 16:38:07 +02:00
|
|
|
baseUrl: string;
|
2021-02-24 08:17:40 +01:00
|
|
|
revision: string;
|
|
|
|
|
fetchNextPage: () => void;
|
|
|
|
|
isFetchingNextPage: boolean;
|
2019-12-17 12:42:05 +01:00
|
|
|
};
|
2019-12-17 12:14:43 +01:00
|
|
|
|
2019-10-09 16:17:02 +02:00
|
|
|
const FixedWidthTh = styled.th`
|
|
|
|
|
width: 16px;
|
|
|
|
|
`;
|
|
|
|
|
|
2018-09-28 11:31:38 +02:00
|
|
|
export function findParent(path: string) {
|
2019-10-20 18:02:52 +02:00
|
|
|
if (path.endsWith("/")) {
|
2018-10-19 16:02:21 +02:00
|
|
|
path = path.substring(0, path.length - 1);
|
2018-09-28 11:31:38 +02:00
|
|
|
}
|
|
|
|
|
|
2019-10-20 18:02:52 +02:00
|
|
|
const index = path.lastIndexOf("/");
|
2018-09-28 11:31:38 +02:00
|
|
|
if (index > 0) {
|
|
|
|
|
return path.substring(0, index);
|
|
|
|
|
}
|
2019-10-20 18:02:52 +02:00
|
|
|
return "";
|
2018-09-28 11:31:38 +02:00
|
|
|
}
|
|
|
|
|
|
2021-09-30 16:41:04 +02:00
|
|
|
const FileTree: FC<Props> = ({ repository, directory, baseUrl, revision, fetchNextPage, isFetchingNextPage }) => {
|
2021-02-24 08:17:40 +01:00
|
|
|
const [t] = useTranslation("repos");
|
|
|
|
|
const { path } = directory;
|
|
|
|
|
const files: File[] = [];
|
|
|
|
|
|
2021-03-03 11:00:26 +01:00
|
|
|
if (!isRootPath(path)) {
|
2021-02-24 08:17:40 +01:00
|
|
|
files.push({
|
|
|
|
|
name: "..",
|
|
|
|
|
path: findParent(path),
|
|
|
|
|
directory: true,
|
|
|
|
|
revision,
|
|
|
|
|
_links: {},
|
|
|
|
|
_embedded: {
|
2021-12-09 09:12:02 +01:00
|
|
|
children: []
|
|
|
|
|
}
|
2021-02-24 08:17:40 +01:00
|
|
|
});
|
2018-09-27 16:32:37 +02:00
|
|
|
}
|
2018-10-17 16:01:40 +02:00
|
|
|
|
2021-03-03 11:00:26 +01:00
|
|
|
files.push(...(directory._embedded?.children || []));
|
2019-12-17 10:25:53 +01:00
|
|
|
|
2021-02-24 08:17:40 +01:00
|
|
|
const baseUrlWithRevision = baseUrl + "/" + encodeURIComponent(revision);
|
2018-10-19 16:02:21 +02:00
|
|
|
|
2021-09-30 16:41:04 +02:00
|
|
|
const extProps: extensionPoints.ReposSourcesTreeWrapperProps = {
|
|
|
|
|
repository,
|
|
|
|
|
directory,
|
|
|
|
|
baseUrl,
|
2021-12-09 09:12:02 +01:00
|
|
|
revision
|
2021-09-30 16:41:04 +02:00
|
|
|
};
|
|
|
|
|
|
2021-02-24 08:17:40 +01:00
|
|
|
return (
|
|
|
|
|
<div className="panel-block">
|
2022-03-29 15:04:14 +02:00
|
|
|
<ExtensionPoint<extensionPoints.ReposSourcesTreeWrapper>
|
|
|
|
|
name="repos.source.tree.wrapper"
|
|
|
|
|
props={extProps}
|
|
|
|
|
renderAll={true}
|
|
|
|
|
wrapper={true}
|
|
|
|
|
>
|
2021-09-30 16:41:04 +02:00
|
|
|
<table className="table table-hover table-sm is-fullwidth">
|
|
|
|
|
<thead>
|
|
|
|
|
<tr>
|
|
|
|
|
<FixedWidthTh />
|
|
|
|
|
<th>{t("sources.fileTree.name")}</th>
|
|
|
|
|
<th className="is-hidden-mobile">{t("sources.fileTree.length")}</th>
|
|
|
|
|
<th className="is-hidden-mobile">{t("sources.fileTree.commitDate")}</th>
|
|
|
|
|
<th className="is-hidden-touch">{t("sources.fileTree.description")}</th>
|
|
|
|
|
{binder.hasExtension("repos.sources.tree.row.right") && <th className="is-hidden-mobile" />}
|
|
|
|
|
</tr>
|
|
|
|
|
</thead>
|
|
|
|
|
<tbody>
|
|
|
|
|
{files.map((file: File) => (
|
2021-11-01 16:54:58 +01:00
|
|
|
<FileTreeLeaf key={file.name} file={file} baseUrl={baseUrlWithRevision} repository={repository} />
|
2021-09-30 16:41:04 +02:00
|
|
|
))}
|
|
|
|
|
</tbody>
|
|
|
|
|
</table>
|
|
|
|
|
<TruncatedNotification
|
|
|
|
|
directory={directory}
|
|
|
|
|
fetchNextPage={fetchNextPage}
|
|
|
|
|
isFetchingNextPage={isFetchingNextPage}
|
|
|
|
|
/>
|
|
|
|
|
</ExtensionPoint>
|
2021-02-24 08:17:40 +01:00
|
|
|
</div>
|
|
|
|
|
);
|
2018-10-19 16:02:21 +02:00
|
|
|
};
|
|
|
|
|
|
2021-02-24 08:17:40 +01:00
|
|
|
export default FileTree;
|