@scm-manager/ui-components 3.4.2-20240820-125924 → 3.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +8 -8
- package/src/index.ts +2 -7
- package/src/repos/Diff.tsx +11 -64
- package/src/repos/DiffStatistics.tsx +0 -17
- package/src/repos/JumpToFileButton.tsx +2 -6
- package/src/repos/LoadingDiff.tsx +17 -46
- package/src/repos/diff/styledElements.tsx +0 -29
- package/src/repos/diffs.ts +0 -10
- package/src/useScrollToElement.ts +4 -26
- package/src/repos/diff/DiffFileTree.tsx +0 -131
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scm-manager/ui-components",
|
|
3
|
-
"version": "3.4.2
|
|
3
|
+
"version": "3.4.2",
|
|
4
4
|
"description": "UI Components for SCM-Manager and its plugins",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"files": [
|
|
@@ -24,10 +24,10 @@
|
|
|
24
24
|
"@scm-manager/jest-preset": "^2.13.0",
|
|
25
25
|
"@scm-manager/prettier-config": "^2.10.1",
|
|
26
26
|
"@scm-manager/tsconfig": "^2.13.0",
|
|
27
|
-
"@scm-manager/ui-shortcuts": "3.4.2
|
|
28
|
-
"@scm-manager/ui-syntaxhighlighting": "3.4.2
|
|
29
|
-
"@scm-manager/ui-tests": "3.4.2
|
|
30
|
-
"@scm-manager/ui-text": "3.4.2
|
|
27
|
+
"@scm-manager/ui-shortcuts": "3.4.2",
|
|
28
|
+
"@scm-manager/ui-syntaxhighlighting": "3.4.2",
|
|
29
|
+
"@scm-manager/ui-tests": "3.4.2",
|
|
30
|
+
"@scm-manager/ui-text": "3.4.2",
|
|
31
31
|
"@storybook/addon-actions": "^6.4.20",
|
|
32
32
|
"@storybook/addon-essentials": "^6.4.20",
|
|
33
33
|
"@storybook/addon-interactions": "^6.4.20",
|
|
@@ -65,9 +65,9 @@
|
|
|
65
65
|
},
|
|
66
66
|
"dependencies": {
|
|
67
67
|
"@headlessui/react": "^1.4.3",
|
|
68
|
-
"@scm-manager/ui-api": "3.4.2
|
|
69
|
-
"@scm-manager/ui-extensions": "3.4.2
|
|
70
|
-
"@scm-manager/ui-types": "3.4.2
|
|
68
|
+
"@scm-manager/ui-api": "3.4.2",
|
|
69
|
+
"@scm-manager/ui-extensions": "3.4.2",
|
|
70
|
+
"@scm-manager/ui-types": "3.4.2",
|
|
71
71
|
"classnames": "^2.2.6",
|
|
72
72
|
"date-fns": "^2.4.1",
|
|
73
73
|
"deepmerge": "^4.2.2",
|
package/src/index.ts
CHANGED
|
@@ -90,8 +90,8 @@ export * from "./devices";
|
|
|
90
90
|
export { default as copyToClipboard } from "./CopyToClipboard";
|
|
91
91
|
export { createA11yId } from "./createA11yId";
|
|
92
92
|
export { useSecondaryNavigation } from "./useSecondaryNavigation";
|
|
93
|
-
export { default as useScrollToElement
|
|
94
|
-
export { default as DiffDropDown }
|
|
93
|
+
export { default as useScrollToElement } from "./useScrollToElement";
|
|
94
|
+
export { default as DiffDropDown } from "./repos/DiffDropDown";
|
|
95
95
|
|
|
96
96
|
export { default as comparators } from "./comparators";
|
|
97
97
|
|
|
@@ -143,8 +143,3 @@ export { urls };
|
|
|
143
143
|
export const getPageFromMatch = urls.getPageFromMatch;
|
|
144
144
|
|
|
145
145
|
export { default as useGeneratedId } from "./useGeneratedId";
|
|
146
|
-
|
|
147
|
-
export { default as DiffFileTree } from "./repos/diff/DiffFileTree";
|
|
148
|
-
export { FileTreeContent } from "./repos/diff/styledElements";
|
|
149
|
-
export { getFileNameFromHash } from "./repos/diffs";
|
|
150
|
-
export { getAnchorId as getDiffAnchorId } from "./repos/diff/helpers";
|
package/src/repos/Diff.tsx
CHANGED
|
@@ -21,26 +21,20 @@
|
|
|
21
21
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
|
-
import React, { FC,
|
|
24
|
+
import React, { FC, useState } from "react";
|
|
25
25
|
import DiffFile from "./DiffFile";
|
|
26
26
|
import { DiffObjectProps, FileControlFactory } from "./DiffTypes";
|
|
27
27
|
import { FileDiff } from "@scm-manager/ui-types";
|
|
28
|
-
import {
|
|
28
|
+
import { escapeWhitespace } from "./diffs";
|
|
29
29
|
import Notification from "../Notification";
|
|
30
30
|
import { useTranslation } from "react-i18next";
|
|
31
31
|
import { useLocation } from "react-router-dom";
|
|
32
|
-
import
|
|
33
|
-
import { getAnchorId } from "./diff/helpers";
|
|
32
|
+
import useScrollToElement from "../useScrollToElement";
|
|
34
33
|
|
|
35
34
|
type Props = DiffObjectProps & {
|
|
36
35
|
diff: FileDiff[];
|
|
37
36
|
fileControlFactory?: FileControlFactory;
|
|
38
37
|
ignoreWhitespace?: string;
|
|
39
|
-
fetchNextPage?: () => void;
|
|
40
|
-
isFetchingNextPage?: boolean;
|
|
41
|
-
isDataPartial?: boolean;
|
|
42
|
-
prevHash?: string;
|
|
43
|
-
setPrevHash?: (newHash: string) => void;
|
|
44
38
|
};
|
|
45
39
|
|
|
46
40
|
const createKey = (file: FileDiff, ignoreWhitespace?: string) => {
|
|
@@ -49,70 +43,23 @@ const createKey = (file: FileDiff, ignoreWhitespace?: string) => {
|
|
|
49
43
|
return `${file.oldPath}@${file.oldRevision}/${file.newPath}@${file.newRevision}?${ignoreWhitespace}`;
|
|
50
44
|
};
|
|
51
45
|
|
|
52
|
-
const
|
|
53
|
-
return
|
|
46
|
+
const getAnchorSelector = (uriHashContent: string) => {
|
|
47
|
+
return "#" + escapeWhitespace(decodeURIComponent(uriHashContent));
|
|
54
48
|
};
|
|
55
49
|
|
|
56
|
-
const
|
|
57
|
-
const fileName = getFileNameFromHash(hash);
|
|
58
|
-
return fileName ? getAnchorSelector(fileName) : undefined;
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
const jumpToBottom = () => {
|
|
62
|
-
window.scrollTo(0, document.body.scrollHeight);
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
const Diff: FC<Props> = ({
|
|
66
|
-
diff,
|
|
67
|
-
ignoreWhitespace,
|
|
68
|
-
fetchNextPage,
|
|
69
|
-
isFetchingNextPage,
|
|
70
|
-
isDataPartial,
|
|
71
|
-
prevHash,
|
|
72
|
-
setPrevHash,
|
|
73
|
-
...fileProps
|
|
74
|
-
}) => {
|
|
50
|
+
const Diff: FC<Props> = ({ diff, ignoreWhitespace, ...fileProps }) => {
|
|
75
51
|
const [t] = useTranslation("repos");
|
|
76
52
|
const [contentRef, setContentRef] = useState<HTMLElement | null>();
|
|
77
53
|
const { hash } = useLocation();
|
|
78
|
-
|
|
79
|
-
useEffect(() => {
|
|
80
|
-
if (isFetchingNextPage) {
|
|
81
|
-
jumpToBottom();
|
|
82
|
-
}
|
|
83
|
-
}, [isFetchingNextPage]);
|
|
84
|
-
|
|
85
|
-
useScrollToElementWithCallback(
|
|
54
|
+
useScrollToElement(
|
|
86
55
|
contentRef,
|
|
87
56
|
() => {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
if (prevHash === hash) {
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
const encodedFileName = getFileNameFromHash(hash);
|
|
97
|
-
if (!encodedFileName) {
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
const selectedFile = getFile(diff, decodeURIComponent(encodedFileName));
|
|
102
|
-
if (selectedFile) {
|
|
103
|
-
return getAnchorSelector(getAnchorId(selectedFile));
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
if (isDataPartial && !isFetchingNextPage) {
|
|
107
|
-
fetchNextPage();
|
|
57
|
+
const match = hash.match(/^#diff-(.*)$/);
|
|
58
|
+
if (match) {
|
|
59
|
+
return getAnchorSelector(match[1]);
|
|
108
60
|
}
|
|
109
61
|
},
|
|
110
|
-
|
|
111
|
-
() => {
|
|
112
|
-
if (setPrevHash) {
|
|
113
|
-
setPrevHash(hash);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
62
|
+
hash
|
|
116
63
|
);
|
|
117
64
|
|
|
118
65
|
return (
|
|
@@ -49,23 +49,6 @@ const DiffStatistics: FC<DiffStatisticsProps> = ({ data }) => {
|
|
|
49
49
|
values={{ newFiles: data.added, modified: data.modified, deleted: data.deleted }}
|
|
50
50
|
components={{ tag: <Tag size={"normal"} rounded={true} className={"mx-1"} /> }}
|
|
51
51
|
></Trans>
|
|
52
|
-
{data.renamed > 0 && (
|
|
53
|
-
<Trans
|
|
54
|
-
t={t}
|
|
55
|
-
i18nKey="changesets.showRenamedFiles"
|
|
56
|
-
values={{ renamed: data.renamed }}
|
|
57
|
-
components={{ tag: <Tag size={"normal"} rounded={true} className={"mx-1"} /> }}
|
|
58
|
-
></Trans>
|
|
59
|
-
)}
|
|
60
|
-
{data.copied > 0 && (
|
|
61
|
-
<Trans
|
|
62
|
-
t={t}
|
|
63
|
-
i18nKey="changesets.showCopiedFiles"
|
|
64
|
-
values={{ copied: data.copied }}
|
|
65
|
-
components={{ tag: <Tag size={"normal"} rounded={true} className={"mx-1"} /> }}
|
|
66
|
-
></Trans>
|
|
67
|
-
)}
|
|
68
|
-
<span className="ml-1">{t("changesets.showFiles")}</span>
|
|
69
52
|
</DiffStatisticsContainer>
|
|
70
53
|
);
|
|
71
54
|
};
|
|
@@ -37,17 +37,13 @@ const Button = styled(Link)`
|
|
|
37
37
|
type Props = {
|
|
38
38
|
link: string;
|
|
39
39
|
tooltip: string;
|
|
40
|
-
icon?: string;
|
|
41
|
-
color?: string;
|
|
42
40
|
};
|
|
43
41
|
|
|
44
|
-
const JumpToFileButton: FC<Props> = ({ link, tooltip
|
|
45
|
-
const iconToUse = icon ?? "file-code";
|
|
46
|
-
const colorToUse = color ?? "inherit";
|
|
42
|
+
const JumpToFileButton: FC<Props> = ({ link, tooltip }) => {
|
|
47
43
|
return (
|
|
48
44
|
<Tooltip message={tooltip} side="top">
|
|
49
45
|
<Button aria-label={tooltip} className="button is-clickable" to={link}>
|
|
50
|
-
<Icon name=
|
|
46
|
+
<Icon name="file-code" color="inherit" alt="" />
|
|
51
47
|
</Button>
|
|
52
48
|
</Tooltip>
|
|
53
49
|
);
|
|
@@ -32,10 +32,6 @@ import Diff from "./Diff";
|
|
|
32
32
|
import { DiffObjectProps } from "./DiffTypes";
|
|
33
33
|
import DiffStatistics from "./DiffStatistics";
|
|
34
34
|
import { DiffDropDown } from "../index";
|
|
35
|
-
import DiffFileTree from "./diff/DiffFileTree";
|
|
36
|
-
import { DiffContent, FileTreeContent } from "./diff/styledElements";
|
|
37
|
-
import { useHistory, useLocation } from "react-router-dom";
|
|
38
|
-
import { getFileNameFromHash } from "./diffs";
|
|
39
35
|
|
|
40
36
|
type Props = DiffObjectProps & {
|
|
41
37
|
url: string;
|
|
@@ -64,13 +60,9 @@ const PartialNotification: FC<NotificationProps> = ({ fetchNextPage, isFetchingN
|
|
|
64
60
|
const LoadingDiff: FC<Props> = ({ url, limit, refetchOnWindowFocus, ...props }) => {
|
|
65
61
|
const [ignoreWhitespace, setIgnoreWhitespace] = useState(false);
|
|
66
62
|
const [collapsed, setCollapsed] = useState(false);
|
|
67
|
-
const [prevHash, setPrevHash] = useState("");
|
|
68
|
-
const location = useLocation();
|
|
69
|
-
const history = useHistory();
|
|
70
|
-
|
|
71
63
|
const evaluateWhiteSpace = () => {
|
|
72
|
-
return ignoreWhitespace ? "ALL" : "NONE"
|
|
73
|
-
}
|
|
64
|
+
return ignoreWhitespace ? "ALL" : "NONE"
|
|
65
|
+
}
|
|
74
66
|
const { error, isLoading, data, fetchNextPage, isFetchingNextPage } = useDiff(url, {
|
|
75
67
|
limit,
|
|
76
68
|
refetchOnWindowFocus,
|
|
@@ -86,11 +78,6 @@ const LoadingDiff: FC<Props> = ({ url, limit, refetchOnWindowFocus, ...props })
|
|
|
86
78
|
setCollapsed(!collapsed);
|
|
87
79
|
};
|
|
88
80
|
|
|
89
|
-
const setFilePath = (path: string) => {
|
|
90
|
-
setPrevHash("");
|
|
91
|
-
history.push(`#diff-${encodeURIComponent(path)}`);
|
|
92
|
-
};
|
|
93
|
-
|
|
94
81
|
if (error) {
|
|
95
82
|
if (error instanceof NotFoundError) {
|
|
96
83
|
return <Notification type="info">{t("changesets.noChangesets")}</Notification>;
|
|
@@ -102,37 +89,21 @@ const LoadingDiff: FC<Props> = ({ url, limit, refetchOnWindowFocus, ...props })
|
|
|
102
89
|
return null;
|
|
103
90
|
} else {
|
|
104
91
|
return (
|
|
105
|
-
|
|
106
|
-
<
|
|
107
|
-
{data
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
)}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
<Diff
|
|
121
|
-
defaultCollapse={collapsed}
|
|
122
|
-
diff={data.files}
|
|
123
|
-
ignoreWhitespace={evaluateWhiteSpace()}
|
|
124
|
-
fetchNextPage={fetchNextPage}
|
|
125
|
-
isFetchingNextPage={isFetchingNextPage}
|
|
126
|
-
isDataPartial={data.partial}
|
|
127
|
-
prevHash={prevHash}
|
|
128
|
-
setPrevHash={setPrevHash}
|
|
129
|
-
{...props}
|
|
130
|
-
/>
|
|
131
|
-
{data.partial ? (
|
|
132
|
-
<PartialNotification fetchNextPage={fetchNextPage} isFetchingNextPage={isFetchingNextPage} />
|
|
133
|
-
) : null}
|
|
134
|
-
</DiffContent>
|
|
135
|
-
</div>
|
|
92
|
+
<>
|
|
93
|
+
<div className="is-flex has-gap-4 mb-4 mt-4 is-justify-content-space-between">
|
|
94
|
+
<DiffStatistics data={data.statistics} />
|
|
95
|
+
<DiffDropDown collapseDiffs={collapseDiffs} ignoreWhitespaces={ignoreWhitespaces} renderOnMount={true} />
|
|
96
|
+
</div>
|
|
97
|
+
<Diff
|
|
98
|
+
defaultCollapse={collapsed}
|
|
99
|
+
diff={data.files}
|
|
100
|
+
ignoreWhitespace={evaluateWhiteSpace()}
|
|
101
|
+
{...props}
|
|
102
|
+
/>
|
|
103
|
+
{data.partial ? (
|
|
104
|
+
<PartialNotification fetchNextPage={fetchNextPage} isFetchingNextPage={isFetchingNextPage} />
|
|
105
|
+
) : null}
|
|
106
|
+
</>
|
|
136
107
|
);
|
|
137
108
|
}
|
|
138
109
|
};
|
|
@@ -90,32 +90,3 @@ export const PanelHeading = styled.div<{ sticky?: boolean | number }>`
|
|
|
90
90
|
}
|
|
91
91
|
}}
|
|
92
92
|
`;
|
|
93
|
-
|
|
94
|
-
export const FileTreeContent = styled.div`
|
|
95
|
-
min-width: 25%;
|
|
96
|
-
max-width: 25%;
|
|
97
|
-
`;
|
|
98
|
-
|
|
99
|
-
export const DiffContent = styled.div`
|
|
100
|
-
width: 100%;
|
|
101
|
-
`;
|
|
102
|
-
|
|
103
|
-
export const FileDiffContainer = styled.div`
|
|
104
|
-
border: 1px solid var(--scm-border-color);
|
|
105
|
-
border-radius: 1rem;
|
|
106
|
-
position: sticky;
|
|
107
|
-
top: 5rem;
|
|
108
|
-
`;
|
|
109
|
-
|
|
110
|
-
export const FileDiffContentTitle = styled.div`
|
|
111
|
-
border-bottom: 1px solid var(--scm-border-color);
|
|
112
|
-
box-shadow: 0 24px 3px -24px var(--scm-border-color);
|
|
113
|
-
`;
|
|
114
|
-
|
|
115
|
-
export const FileDiffContent = styled.ul`
|
|
116
|
-
overflow: auto;
|
|
117
|
-
@supports (-moz-appearance: none) {
|
|
118
|
-
max-height: calc(100vh - 11rem);
|
|
119
|
-
}
|
|
120
|
-
max-height: calc(100svh - 11rem);
|
|
121
|
-
`;
|
package/src/repos/diffs.ts
CHANGED
|
@@ -44,13 +44,3 @@ export function createHunkIdentifierFromContext(ctx: BaseContext) {
|
|
|
44
44
|
export function escapeWhitespace(path: string) {
|
|
45
45
|
return path?.toLowerCase().replace(/\W/g, "-");
|
|
46
46
|
}
|
|
47
|
-
|
|
48
|
-
export function getAnchorSelector(uriHashContent: string) {
|
|
49
|
-
return "#" + escapeWhitespace(decodeURIComponent(uriHashContent));
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export function getFileNameFromHash(hash: string) {
|
|
53
|
-
const matcher = new RegExp(/^#diff-(.*)$/, "g");
|
|
54
|
-
const match = matcher.exec(hash);
|
|
55
|
-
return match ? match[1] : undefined;
|
|
56
|
-
}
|
|
@@ -24,12 +24,10 @@
|
|
|
24
24
|
|
|
25
25
|
import { useEffect } from "react";
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
export const useScrollToElementWithCallback = (
|
|
27
|
+
const useScrollToElement = (
|
|
29
28
|
contentRef: HTMLElement | null | undefined,
|
|
30
29
|
elementSelectorResolver: () => string | undefined,
|
|
31
|
-
dependencies:
|
|
32
|
-
callback?: () => void
|
|
30
|
+
...dependencies: any
|
|
33
31
|
) => {
|
|
34
32
|
useEffect(() => {
|
|
35
33
|
const elementSelector = elementSelectorResolver();
|
|
@@ -41,17 +39,13 @@ export const useScrollToElementWithCallback = (
|
|
|
41
39
|
clearInterval(intervalId);
|
|
42
40
|
} else {
|
|
43
41
|
tries++;
|
|
44
|
-
const element = contentRef.querySelector(
|
|
42
|
+
const element = contentRef.querySelector(elementSelector);
|
|
45
43
|
if (element) {
|
|
46
44
|
const headerElement = document.querySelector(".navbar-brand");
|
|
47
45
|
const margin = headerElement ? headerElement.getBoundingClientRect().height : 45;
|
|
48
46
|
clearInterval(intervalId);
|
|
49
47
|
const y = element.getBoundingClientRect().top + window.pageYOffset - margin;
|
|
50
|
-
window.scrollTo({
|
|
51
|
-
|
|
52
|
-
if (callback) {
|
|
53
|
-
callback();
|
|
54
|
-
}
|
|
48
|
+
window.scrollTo({top: y});
|
|
55
49
|
}
|
|
56
50
|
}
|
|
57
51
|
}, 200);
|
|
@@ -63,20 +57,4 @@ export const useScrollToElementWithCallback = (
|
|
|
63
57
|
}, [contentRef, ...dependencies]);
|
|
64
58
|
};
|
|
65
59
|
|
|
66
|
-
const useScrollToElement = (
|
|
67
|
-
contentRef: HTMLElement | null | undefined,
|
|
68
|
-
elementSelectorResolver: () => string | undefined,
|
|
69
|
-
...dependencies: any
|
|
70
|
-
) => {
|
|
71
|
-
useScrollToElementWithCallback(contentRef, elementSelectorResolver, [...dependencies]);
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
function escapeIdStartingWithNumber(selector: string) {
|
|
75
|
-
if (selector.startsWith("#")) {
|
|
76
|
-
return `#${CSS.escape(selector.substring(1))}`;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
return selector;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
60
|
export default useScrollToElement;
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* MIT License
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
|
|
5
|
-
*
|
|
6
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
-
* in the Software without restriction, including without limitation the rights
|
|
9
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
-
* furnished to do so, subject to the following conditions:
|
|
12
|
-
*
|
|
13
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
-
* copies or substantial portions of the Software.
|
|
15
|
-
*
|
|
16
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
-
* SOFTWARE.
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
import { FileTree } from "@scm-manager/ui-types";
|
|
26
|
-
import React, { FC } from "react";
|
|
27
|
-
import { FileDiffContainer, FileDiffContent, FileDiffContentTitle } from "./styledElements";
|
|
28
|
-
import { Icon } from "@scm-manager/ui-core";
|
|
29
|
-
import { useTranslation } from "react-i18next";
|
|
30
|
-
import styled from "styled-components";
|
|
31
|
-
|
|
32
|
-
type Props = { tree: FileTree; currentFile: string; setCurrentFile: (path: string) => void };
|
|
33
|
-
|
|
34
|
-
const StyledIcon = styled(Icon)`
|
|
35
|
-
min-width: 1.5rem;
|
|
36
|
-
`;
|
|
37
|
-
|
|
38
|
-
const DiffFileTree: FC<Props> = ({ tree, currentFile, setCurrentFile }) => {
|
|
39
|
-
const [t] = useTranslation("repos");
|
|
40
|
-
|
|
41
|
-
return (
|
|
42
|
-
<FileDiffContainer className={"mt-4 py-3 pr-2"}>
|
|
43
|
-
<FileDiffContentTitle className={"ml-4 pb-4 title is-6"}>{t("changesets.diffTreeTitle")}</FileDiffContentTitle>
|
|
44
|
-
<FileDiffContent>
|
|
45
|
-
{Object.keys(tree.children).map((key) => (
|
|
46
|
-
<TreeNode
|
|
47
|
-
key={key}
|
|
48
|
-
node={tree.children[key]}
|
|
49
|
-
parentPath={""}
|
|
50
|
-
currentFile={currentFile}
|
|
51
|
-
setCurrentFile={setCurrentFile}
|
|
52
|
-
/>
|
|
53
|
-
))}
|
|
54
|
-
</FileDiffContent>
|
|
55
|
-
</FileDiffContainer>
|
|
56
|
-
);
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
export default DiffFileTree;
|
|
60
|
-
|
|
61
|
-
type NodeProps = { node: FileTree; parentPath: string; currentFile: string; setCurrentFile: (path: string) => void };
|
|
62
|
-
|
|
63
|
-
const addPath = (parentPath: string, path: string) => {
|
|
64
|
-
if ("" === parentPath) {
|
|
65
|
-
return path;
|
|
66
|
-
}
|
|
67
|
-
return parentPath + "/" + path;
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
const TreeNode: FC<NodeProps> = ({ node, parentPath, currentFile, setCurrentFile }) => {
|
|
71
|
-
const [t] = useTranslation("repos");
|
|
72
|
-
|
|
73
|
-
return (
|
|
74
|
-
<li>
|
|
75
|
-
{Object.keys(node.children).length > 0 ? (
|
|
76
|
-
<ul className={"py-1 pr-1 pl-3"}>
|
|
77
|
-
<li className={"is-flex has-text-grey"}>
|
|
78
|
-
<StyledIcon alt={t("diff.showContent")}>folder</StyledIcon>
|
|
79
|
-
<div className={"ml-1"}>{node.nodeName}</div>
|
|
80
|
-
</li>
|
|
81
|
-
{Object.keys(node.children).map((key) => (
|
|
82
|
-
<TreeNode
|
|
83
|
-
key={key}
|
|
84
|
-
node={node.children[key]}
|
|
85
|
-
parentPath={addPath(parentPath, node.nodeName)}
|
|
86
|
-
currentFile={currentFile}
|
|
87
|
-
setCurrentFile={setCurrentFile}
|
|
88
|
-
/>
|
|
89
|
-
))}
|
|
90
|
-
</ul>
|
|
91
|
-
) : (
|
|
92
|
-
<TreeFile
|
|
93
|
-
path={node.nodeName}
|
|
94
|
-
parentPath={parentPath}
|
|
95
|
-
currentFile={currentFile}
|
|
96
|
-
setCurrentFile={setCurrentFile}
|
|
97
|
-
/>
|
|
98
|
-
)}
|
|
99
|
-
</li>
|
|
100
|
-
);
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
type FileProps = { path: string; parentPath: string; currentFile: string; setCurrentFile: (path: string) => void };
|
|
104
|
-
|
|
105
|
-
export const TreeFileContent = styled.div`
|
|
106
|
-
cursor: pointer;
|
|
107
|
-
`;
|
|
108
|
-
|
|
109
|
-
const TreeFile: FC<FileProps> = ({ path, parentPath, currentFile, setCurrentFile }) => {
|
|
110
|
-
const [t] = useTranslation("repos");
|
|
111
|
-
const completePath = addPath(parentPath, path);
|
|
112
|
-
|
|
113
|
-
const isCurrentFile = () => {
|
|
114
|
-
return currentFile === completePath;
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
return (
|
|
118
|
-
<TreeFileContent className={"is-flex py-1 pl-3"} onClick={() => setCurrentFile(completePath)}>
|
|
119
|
-
{isCurrentFile() ? (
|
|
120
|
-
<StyledIcon style={{ minWidth: "1.5rem" }} key={completePath + "file"} alt={t("diff.showContent")}>
|
|
121
|
-
file
|
|
122
|
-
</StyledIcon>
|
|
123
|
-
) : (
|
|
124
|
-
<StyledIcon style={{ minWidth: "1.5rem" }} key={completePath + "file"} type="far" alt={t("diff.showContent")}>
|
|
125
|
-
file
|
|
126
|
-
</StyledIcon>
|
|
127
|
-
)}
|
|
128
|
-
<div className={"ml-1"}>{path}</div>
|
|
129
|
-
</TreeFileContent>
|
|
130
|
-
);
|
|
131
|
-
};
|