@scm-manager/ui-components 2.27.3 → 2.27.5-20211121-150210
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 +7 -8
- package/src/Autocomplete.tsx +7 -6
- package/src/BranchSelector.tsx +2 -2
- package/src/Breadcrumb.tsx +1 -0
- package/src/CardColumnGroup.tsx +6 -6
- package/src/DangerZone.tsx +1 -0
- package/src/DateFromNow.tsx +2 -1
- package/src/DateShort.tsx +2 -1
- package/src/ErrorBoundary.tsx +2 -2
- package/src/Icon.tsx +4 -4
- package/src/Logo.stories.tsx +1 -0
- package/src/OverviewPageActions.tsx +2 -2
- package/src/SmallLoadingSpinner.stories.tsx +32 -0
- package/src/SmallLoadingSpinner.tsx +34 -0
- package/src/SplitAndReplace.tsx +3 -2
- package/src/SyntaxHighlighter.stories.tsx +1 -1
- package/src/Tooltip.tsx +1 -1
- package/src/__resources__/SearchHit.ts +97 -0
- package/src/__snapshots__/storyshots.test.ts.snap +1340 -2086
- package/src/buttons/Button.tsx +33 -34
- package/src/forms/FileInput.tsx +1 -1
- package/src/forms/FileUpload.tsx +1 -1
- package/src/forms/FilterInput.tsx +1 -0
- package/src/forms/InputField.tsx +2 -2
- package/src/forms/Select.tsx +4 -4
- package/src/forms/TriStateCheckbox.tsx +2 -2
- package/src/index.ts +4 -3
- package/src/languages.test.ts +1 -5
- package/src/languages.ts +1 -10
- package/src/layout/Footer.tsx +1 -1
- package/src/layout/Header.tsx +2 -2
- package/src/layout/SubSubtitle.tsx +41 -0
- package/src/layout/index.ts +2 -1
- package/src/modals/FullscreenModal.tsx +1 -1
- package/src/modals/Modal.tsx +6 -6
- package/src/navigation/RoutingProps.ts +3 -1
- package/src/navigation/SecondaryNavigation.stories.tsx +3 -3
- package/src/navigation/SecondaryNavigation.tsx +1 -1
- package/src/popover/Popover.tsx +7 -7
- package/src/repos/DiffFile.tsx +21 -15
- package/src/repos/HealthCheckFailureDetail.tsx +2 -2
- package/src/repos/RepositoryEntry.tsx +9 -6
- package/src/repos/RepositoryFlags.tsx +2 -2
- package/src/repos/TokenizedDiffView.tsx +20 -2
- package/src/repos/annotate/Annotate.stories.tsx +1 -1
- package/src/repos/annotate/Annotate.tsx +2 -2
- package/src/repos/annotate/AnnotateLine.tsx +1 -0
- package/src/repos/annotate/{Popover.tsx → AnnotatePopover.tsx} +2 -2
- package/src/repos/index.ts +2 -0
- package/src/repos/refractorAdapter.ts +11 -6
- package/src/search/HighlightedFragment.tsx +7 -4
- package/src/search/SyntaxHighlightedFragment.tsx +130 -0
- package/src/search/TextHitField.stories.tsx +69 -0
- package/src/search/TextHitField.tsx +58 -19
- package/src/styleConstants.ts +2 -1
- package/src/syntax-highlighting.module.css +1 -1
|
@@ -86,13 +86,13 @@ const RepositoryFlags: FC<Props> = ({ repository, className, tooltipLocation = "
|
|
|
86
86
|
);
|
|
87
87
|
|
|
88
88
|
return (
|
|
89
|
-
<
|
|
89
|
+
<div className={classNames("is-flex", "is-align-items-center", className)}>
|
|
90
90
|
{modal}
|
|
91
91
|
<RepositoryFlagContainer>
|
|
92
92
|
{repositoryFlags}
|
|
93
93
|
<ExtensionPoint name="repository.flags" props={{ repository, tooltipLocation }} renderAll={true} />
|
|
94
94
|
</RepositoryFlagContainer>
|
|
95
|
-
</
|
|
95
|
+
</div>
|
|
96
96
|
);
|
|
97
97
|
};
|
|
98
98
|
|
|
@@ -26,35 +26,46 @@ import styled from "styled-components";
|
|
|
26
26
|
// @ts-ignore we have no typings for react-diff-view
|
|
27
27
|
import { Diff, useTokenizeWorker } from "react-diff-view";
|
|
28
28
|
import { FileDiff } from "@scm-manager/ui-types";
|
|
29
|
-
import { determineLanguage } from "../languages";
|
|
30
29
|
|
|
31
30
|
// @ts-ignore no types for css modules
|
|
32
31
|
import theme from "../syntax-highlighting.module.css";
|
|
32
|
+
import { determineLanguage } from "../languages";
|
|
33
33
|
|
|
34
34
|
const DiffView = styled(Diff)`
|
|
35
35
|
/* align line numbers */
|
|
36
|
+
|
|
36
37
|
& .diff-gutter {
|
|
37
38
|
text-align: right;
|
|
38
39
|
}
|
|
40
|
+
|
|
39
41
|
/* column sizing */
|
|
42
|
+
|
|
40
43
|
> colgroup .diff-gutter-col {
|
|
41
44
|
width: 3.25rem;
|
|
42
45
|
}
|
|
46
|
+
|
|
43
47
|
/* prevent following content from moving down */
|
|
48
|
+
|
|
44
49
|
> .diff-gutter:empty:hover::after {
|
|
45
50
|
font-size: 0.7rem;
|
|
46
51
|
}
|
|
52
|
+
|
|
47
53
|
/* smaller font size for code and
|
|
48
54
|
ensure same monospace font throughout whole scmm */
|
|
55
|
+
|
|
49
56
|
& .diff-line {
|
|
50
57
|
font-size: 0.75rem;
|
|
51
58
|
font-family: "Courier New", Monaco, Menlo, "Ubuntu Mono", "source-code-pro", monospace;
|
|
52
59
|
}
|
|
60
|
+
|
|
53
61
|
/* comment padding for sidebyside view */
|
|
62
|
+
|
|
54
63
|
&.split .diff-widget-content .is-indented-line {
|
|
55
64
|
padding-left: 3.25rem;
|
|
56
65
|
}
|
|
66
|
+
|
|
57
67
|
/* comment padding for combined view */
|
|
68
|
+
|
|
58
69
|
&.unified .diff-widget-content .is-indented-line {
|
|
59
70
|
padding-left: 6.5rem;
|
|
60
71
|
}
|
|
@@ -71,10 +82,17 @@ type Props = {
|
|
|
71
82
|
className?: string;
|
|
72
83
|
};
|
|
73
84
|
|
|
85
|
+
const findSyntaxHighlightingLanguage = (file: FileDiff) => {
|
|
86
|
+
if (file.syntaxModes) {
|
|
87
|
+
return file.syntaxModes["prism"] || file.syntaxModes["codemirror"] || file.syntaxModes["ace"] || file.language;
|
|
88
|
+
}
|
|
89
|
+
return file.language;
|
|
90
|
+
};
|
|
91
|
+
|
|
74
92
|
const TokenizedDiffView: FC<Props> = ({ file, viewType, className, children }) => {
|
|
75
93
|
const { tokens } = useTokenizeWorker(tokenize, {
|
|
76
94
|
hunks: file.hunks,
|
|
77
|
-
language: determineLanguage(file
|
|
95
|
+
language: determineLanguage(findSyntaxHighlightingLanguage(file))
|
|
78
96
|
});
|
|
79
97
|
|
|
80
98
|
return (
|
|
@@ -32,7 +32,7 @@ import { PrismAsyncLight as ReactSyntaxHighlighter, createElement } from "react-
|
|
|
32
32
|
// eslint-disable-next-line no-restricted-imports
|
|
33
33
|
import highlightingTheme from "../../syntax-highlighting";
|
|
34
34
|
import { DateInput } from "../../useDateFormatter";
|
|
35
|
-
import
|
|
35
|
+
import AnnotatePopover from "./AnnotatePopover";
|
|
36
36
|
import AnnotateLine from "./AnnotateLine";
|
|
37
37
|
import { Action } from "./actions";
|
|
38
38
|
import { determineLanguage } from "../../languages";
|
|
@@ -128,7 +128,7 @@ const Annotate: FC<Props> = ({ source, repository, baseDate }) => {
|
|
|
128
128
|
let popover = null;
|
|
129
129
|
if ((state.onPopover || state.onLine) && state.annotation) {
|
|
130
130
|
popover = (
|
|
131
|
-
<
|
|
131
|
+
<AnnotatePopover
|
|
132
132
|
annotation={state.annotation}
|
|
133
133
|
dispatch={dispatch}
|
|
134
134
|
offsetTop={state.offset}
|
|
@@ -85,7 +85,7 @@ type PopoverProps = {
|
|
|
85
85
|
dispatch: Dispatch<Action>;
|
|
86
86
|
};
|
|
87
87
|
|
|
88
|
-
const
|
|
88
|
+
const AnnotatePopover: FC<PopoverProps> = ({ annotation, offsetTop, repository, baseDate, dispatch }) => {
|
|
89
89
|
const [t] = useTranslation("repos");
|
|
90
90
|
const [height, setHeight] = useState(125);
|
|
91
91
|
const ref = useRef<HTMLDivElement>(null);
|
|
@@ -135,4 +135,4 @@ const Popover: FC<PopoverProps> = ({ annotation, offsetTop, repository, baseDate
|
|
|
135
135
|
);
|
|
136
136
|
};
|
|
137
137
|
|
|
138
|
-
export default
|
|
138
|
+
export default AnnotatePopover;
|
package/src/repos/index.ts
CHANGED
|
@@ -30,6 +30,7 @@ import {
|
|
|
30
30
|
AnnotationFactoryContext,
|
|
31
31
|
DiffEventHandler,
|
|
32
32
|
DiffEventContext,
|
|
33
|
+
DiffObjectProps
|
|
33
34
|
} from "./DiffTypes";
|
|
34
35
|
|
|
35
36
|
import { FileDiff as File, FileChangeType, Hunk, Change, ChangeType } from "@scm-manager/ui-types";
|
|
@@ -64,4 +65,5 @@ export {
|
|
|
64
65
|
AnnotationFactoryContext,
|
|
65
66
|
DiffEventHandler,
|
|
66
67
|
DiffEventContext,
|
|
68
|
+
DiffObjectProps
|
|
67
69
|
};
|
|
@@ -46,10 +46,15 @@ const createAdapter = (theme: { [key: string]: string }): RefractorAdapter => {
|
|
|
46
46
|
import(
|
|
47
47
|
/* webpackChunkName: "tokenizer-refractor-[request]" */
|
|
48
48
|
`refractor/lang/${lang}`
|
|
49
|
-
)
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
49
|
+
)
|
|
50
|
+
.then(loadedLanguage => {
|
|
51
|
+
refractor.register(loadedLanguage.default);
|
|
52
|
+
callback();
|
|
53
|
+
})
|
|
54
|
+
.catch(e => {
|
|
55
|
+
// eslint-disable-next-line no-console
|
|
56
|
+
console.log(`failed to load refractor language ${lang}: ${e}`);
|
|
57
|
+
});
|
|
53
58
|
}
|
|
54
59
|
};
|
|
55
60
|
|
|
@@ -58,7 +63,7 @@ const createAdapter = (theme: { [key: string]: string }): RefractorAdapter => {
|
|
|
58
63
|
const runHook = (name: string, env: RunHookEnv) => {
|
|
59
64
|
originalRunHook.apply(name, env);
|
|
60
65
|
if (env.classes) {
|
|
61
|
-
env.classes = env.classes.map(
|
|
66
|
+
env.classes = env.classes.map(className => theme[className] || className);
|
|
62
67
|
}
|
|
63
68
|
};
|
|
64
69
|
// @ts-ignore hooks are not in the type definition
|
|
@@ -67,7 +72,7 @@ const createAdapter = (theme: { [key: string]: string }): RefractorAdapter => {
|
|
|
67
72
|
return {
|
|
68
73
|
isLanguageRegistered,
|
|
69
74
|
loadLanguage,
|
|
70
|
-
...refractor
|
|
75
|
+
...refractor
|
|
71
76
|
};
|
|
72
77
|
};
|
|
73
78
|
|
|
@@ -24,6 +24,9 @@
|
|
|
24
24
|
|
|
25
25
|
import React, { FC } from "react";
|
|
26
26
|
|
|
27
|
+
const PRE_TAG = "<|[[--";
|
|
28
|
+
const POST_TAG = "--]]|>";
|
|
29
|
+
|
|
27
30
|
type Props = {
|
|
28
31
|
value: string;
|
|
29
32
|
};
|
|
@@ -33,14 +36,14 @@ const HighlightedFragment: FC<Props> = ({ value }) => {
|
|
|
33
36
|
|
|
34
37
|
const result = [];
|
|
35
38
|
while (content.length > 0) {
|
|
36
|
-
const start = content.indexOf(
|
|
37
|
-
const end = content.indexOf(
|
|
39
|
+
const start = content.indexOf(PRE_TAG);
|
|
40
|
+
const end = content.indexOf(POST_TAG);
|
|
38
41
|
if (start >= 0 && end > 0) {
|
|
39
42
|
if (start > 0) {
|
|
40
43
|
result.push(content.substring(0, start));
|
|
41
44
|
}
|
|
42
|
-
result.push(<
|
|
43
|
-
content = content.substring(end +
|
|
45
|
+
result.push(<mark>{content.substring(start + PRE_TAG.length, end)}</mark>);
|
|
46
|
+
content = content.substring(end + POST_TAG.length);
|
|
44
47
|
} else {
|
|
45
48
|
result.push(content);
|
|
46
49
|
break;
|
|
@@ -0,0 +1,130 @@
|
|
|
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 React, { FC, ReactNode, useEffect, useMemo, useState } from "react";
|
|
26
|
+
import createAdapter from "../repos/refractorAdapter";
|
|
27
|
+
// @ts-ignore no types for css modules
|
|
28
|
+
import theme from "../syntax-highlighting.module.css";
|
|
29
|
+
import SplitAndReplace, { Replacement } from "../SplitAndReplace";
|
|
30
|
+
import { AST, RefractorNode } from "refractor";
|
|
31
|
+
import { determineLanguage } from "../languages";
|
|
32
|
+
|
|
33
|
+
const PRE_TAG = "<|[[--";
|
|
34
|
+
const POST_TAG = "--]]|>";
|
|
35
|
+
const PRE_TAG_REGEX = /<\|\[\[--/g;
|
|
36
|
+
const POST_TAG_REGEX = /--]]\|>/g;
|
|
37
|
+
|
|
38
|
+
const adapter = createAdapter(theme);
|
|
39
|
+
|
|
40
|
+
function createReplacement(textToReplace: string): Replacement {
|
|
41
|
+
return {
|
|
42
|
+
textToReplace,
|
|
43
|
+
replacement: <mark>{textToReplace}</mark>,
|
|
44
|
+
replaceAll: true
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function mapWithDepth(depth: number, replacements: Replacement[]) {
|
|
49
|
+
return function mapChildrenWithDepth(child: RefractorNode, i: number) {
|
|
50
|
+
return mapChild(child, i, depth, replacements);
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function isAstElement(node: RefractorNode): node is AST.Element {
|
|
55
|
+
return (node as AST.Element).tagName !== undefined;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function mapChild(child: RefractorNode, i: number, depth: number, replacements: Replacement[]): ReactNode {
|
|
59
|
+
if (isAstElement(child)) {
|
|
60
|
+
const className =
|
|
61
|
+
child.properties && Array.isArray(child.properties.className)
|
|
62
|
+
? child.properties.className.join(" ")
|
|
63
|
+
: child.properties.className;
|
|
64
|
+
|
|
65
|
+
return React.createElement(
|
|
66
|
+
child.tagName,
|
|
67
|
+
Object.assign({ key: `fract-${depth}-${i}` }, child.properties, { className }),
|
|
68
|
+
child.children && child.children.map(mapWithDepth(depth + 1, replacements))
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return (
|
|
73
|
+
<SplitAndReplace key={`fract-${depth}-${i}`} text={child.value} replacements={replacements} textWrapper={s => s} />
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
type Props = {
|
|
78
|
+
value: string;
|
|
79
|
+
language: string;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const stripAndReplace = (value: string) => {
|
|
83
|
+
const strippedValue = value.replace(PRE_TAG_REGEX, "").replace(POST_TAG_REGEX, "");
|
|
84
|
+
let content = value;
|
|
85
|
+
|
|
86
|
+
const result: string[] = [];
|
|
87
|
+
while (content.length > 0) {
|
|
88
|
+
const start = content.indexOf(PRE_TAG);
|
|
89
|
+
const end = content.indexOf(POST_TAG);
|
|
90
|
+
if (start >= 0 && end > 0) {
|
|
91
|
+
const item = content.substring(start + PRE_TAG.length, end);
|
|
92
|
+
if (!result.includes(item)) {
|
|
93
|
+
result.push(item);
|
|
94
|
+
}
|
|
95
|
+
content = content.substring(end + POST_TAG.length);
|
|
96
|
+
} else {
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
result.sort((a, b) => b.length - a.length);
|
|
102
|
+
|
|
103
|
+
return {
|
|
104
|
+
strippedValue,
|
|
105
|
+
replacements: result.map(createReplacement)
|
|
106
|
+
};
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
const SyntaxHighlightedFragment: FC<Props> = ({ value, language }) => {
|
|
110
|
+
const [isLoading, setIsLoading] = useState(true);
|
|
111
|
+
const determinedLanguage = determineLanguage(language);
|
|
112
|
+
const { strippedValue, replacements } = useMemo(() => stripAndReplace(value), [value]);
|
|
113
|
+
|
|
114
|
+
useEffect(() => {
|
|
115
|
+
adapter.loadLanguage(determinedLanguage, () => {
|
|
116
|
+
setIsLoading(false);
|
|
117
|
+
});
|
|
118
|
+
}, [determinedLanguage]);
|
|
119
|
+
|
|
120
|
+
if (isLoading) {
|
|
121
|
+
return <SplitAndReplace text={strippedValue} replacements={replacements} textWrapper={s => s} />;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const refractorNodes = adapter.highlight(strippedValue, determinedLanguage);
|
|
125
|
+
const highlightedFragment = refractorNodes.map(mapWithDepth(0, replacements));
|
|
126
|
+
|
|
127
|
+
return <>{highlightedFragment}</>;
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
export default SyntaxHighlightedFragment;
|
|
@@ -0,0 +1,69 @@
|
|
|
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
|
+
import React from "react";
|
|
25
|
+
import { storiesOf } from "@storybook/react";
|
|
26
|
+
import { bashHit, filenameXmlHit, javaHit, markdownHit, pullRequestHit } from "../__resources__/SearchHit";
|
|
27
|
+
import TextHitField from "./TextHitField";
|
|
28
|
+
|
|
29
|
+
storiesOf("TextHitField", module)
|
|
30
|
+
.add("Default", () => (
|
|
31
|
+
<pre>
|
|
32
|
+
<TextHitField hit={javaHit} field={"content"} />
|
|
33
|
+
</pre>
|
|
34
|
+
))
|
|
35
|
+
.add("Java SyntaxHighlighting", () => (
|
|
36
|
+
<pre>
|
|
37
|
+
<TextHitField hit={javaHit} field={"content"} syntaxHighlightingLanguage="java" />
|
|
38
|
+
</pre>
|
|
39
|
+
))
|
|
40
|
+
.add("Bash SyntaxHighlighting", () => (
|
|
41
|
+
<pre>
|
|
42
|
+
<TextHitField hit={bashHit} field={"content"} syntaxHighlightingLanguage="bash" />
|
|
43
|
+
</pre>
|
|
44
|
+
))
|
|
45
|
+
.add("Markdown SyntaxHighlighting", () => (
|
|
46
|
+
<pre>
|
|
47
|
+
<TextHitField hit={markdownHit} field={"content"} syntaxHighlightingLanguage="markdown" />
|
|
48
|
+
</pre>
|
|
49
|
+
))
|
|
50
|
+
.add("Unknown SyntaxHighlighting", () => (
|
|
51
|
+
<pre>
|
|
52
|
+
<TextHitField hit={bashHit} field={"content"} syntaxHighlightingLanguage="__unknown__" />
|
|
53
|
+
</pre>
|
|
54
|
+
))
|
|
55
|
+
.add("Non Content Search", () => (
|
|
56
|
+
<pre>
|
|
57
|
+
<TextHitField hit={filenameXmlHit} field={"content"} syntaxHighlightingLanguage="xml" />
|
|
58
|
+
</pre>
|
|
59
|
+
))
|
|
60
|
+
.add("Truncate", () => (
|
|
61
|
+
<pre>
|
|
62
|
+
<TextHitField hit={pullRequestHit} field={"description"} truncateValueAt={128} />
|
|
63
|
+
</pre>
|
|
64
|
+
))
|
|
65
|
+
.add("Truncate Keep Whole Line", () => (
|
|
66
|
+
<pre>
|
|
67
|
+
<TextHitField hit={filenameXmlHit} field={"content"} syntaxHighlightingLanguage="xml" truncateValueAt={1024} />
|
|
68
|
+
</pre>
|
|
69
|
+
));
|
|
@@ -26,41 +26,80 @@ import React, { FC } from "react";
|
|
|
26
26
|
import { HighlightedHitField, Hit } from "@scm-manager/ui-types";
|
|
27
27
|
import HighlightedFragment from "./HighlightedFragment";
|
|
28
28
|
import { isHighlightedHitField } from "./fields";
|
|
29
|
+
import SyntaxHighlightedFragment from "./SyntaxHighlightedFragment";
|
|
30
|
+
|
|
31
|
+
type HighlightedTextFieldProps = {
|
|
32
|
+
field: HighlightedHitField;
|
|
33
|
+
syntaxHighlightingLanguage?: string;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const HighlightedTextField: FC<HighlightedTextFieldProps> = ({ field, syntaxHighlightingLanguage }) => {
|
|
37
|
+
const separator = syntaxHighlightingLanguage ? "...\n" : " ... ";
|
|
38
|
+
return (
|
|
39
|
+
<>
|
|
40
|
+
{field.fragments.map((fragment, i) => (
|
|
41
|
+
<React.Fragment key={fragment}>
|
|
42
|
+
{field.matchesContentStart ? null : separator}
|
|
43
|
+
<FieldFragment fragment={fragment} syntaxHighlightingLanguage={syntaxHighlightingLanguage} />
|
|
44
|
+
{i + 1 >= field.fragments.length && !field.matchesContentEnd ? separator : null}
|
|
45
|
+
</React.Fragment>
|
|
46
|
+
))}
|
|
47
|
+
</>
|
|
48
|
+
);
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
type FieldFragmentProps = {
|
|
52
|
+
fragment: string;
|
|
53
|
+
syntaxHighlightingLanguage?: string;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const FieldFragment: FC<FieldFragmentProps> = ({ fragment, syntaxHighlightingLanguage }) => {
|
|
57
|
+
if (syntaxHighlightingLanguage) {
|
|
58
|
+
return <SyntaxHighlightedFragment value={fragment} language={syntaxHighlightingLanguage} />;
|
|
59
|
+
}
|
|
60
|
+
return <HighlightedFragment value={fragment} />;
|
|
61
|
+
};
|
|
29
62
|
|
|
30
63
|
type Props = {
|
|
31
64
|
hit: Hit;
|
|
32
65
|
field: string;
|
|
33
66
|
truncateValueAt?: number;
|
|
67
|
+
syntaxHighlightingLanguage?: string;
|
|
34
68
|
};
|
|
35
69
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
</>
|
|
50
|
-
);
|
|
70
|
+
function truncate(value: string, truncateValueAt: number = 0, syntaxHighlightingLanguage?: string): string {
|
|
71
|
+
if (truncateValueAt > 0 && value.length > truncateValueAt) {
|
|
72
|
+
if (syntaxHighlightingLanguage) {
|
|
73
|
+
let nextLineBreak = value.indexOf("\n", truncateValueAt);
|
|
74
|
+
if (nextLineBreak >= 0 && nextLineBreak < value.length - 1) {
|
|
75
|
+
value = value.substring(0, nextLineBreak) + "\n...";
|
|
76
|
+
}
|
|
77
|
+
} else {
|
|
78
|
+
value = value.substring(0, truncateValueAt) + "...";
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return value;
|
|
82
|
+
}
|
|
51
83
|
|
|
52
|
-
const TextHitField: FC<Props> = ({
|
|
84
|
+
const TextHitField: FC<Props> = ({
|
|
85
|
+
hit,
|
|
86
|
+
field: fieldName,
|
|
87
|
+
children,
|
|
88
|
+
syntaxHighlightingLanguage,
|
|
89
|
+
truncateValueAt = 0
|
|
90
|
+
}) => {
|
|
53
91
|
const field = hit.fields[fieldName];
|
|
54
92
|
if (!field) {
|
|
55
93
|
return <>{children}</>;
|
|
56
94
|
} else if (isHighlightedHitField(field)) {
|
|
57
|
-
return <HighlightedTextField field={field} />;
|
|
95
|
+
return <HighlightedTextField field={field} syntaxHighlightingLanguage={syntaxHighlightingLanguage} />;
|
|
58
96
|
} else {
|
|
59
97
|
let value = field.value;
|
|
60
98
|
if (value === "") {
|
|
61
99
|
return <>{children}</>;
|
|
62
|
-
} else if (typeof value === "string"
|
|
63
|
-
|
|
100
|
+
} else if (typeof value === "string") {
|
|
101
|
+
const v = truncate(value, truncateValueAt, syntaxHighlightingLanguage);
|
|
102
|
+
return <FieldFragment fragment={v} syntaxHighlightingLanguage={syntaxHighlightingLanguage} />;
|
|
64
103
|
}
|
|
65
104
|
return <>{value}</>;
|
|
66
105
|
}
|
package/src/styleConstants.ts
CHANGED
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
|
+
// TODO erweitern
|
|
25
26
|
export const colors = [
|
|
26
27
|
"black",
|
|
27
28
|
"dark",
|
|
@@ -32,7 +33,7 @@ export const colors = [
|
|
|
32
33
|
"info",
|
|
33
34
|
"success",
|
|
34
35
|
"warning",
|
|
35
|
-
"danger"
|
|
36
|
+
"danger"
|
|
36
37
|
] as const;
|
|
37
38
|
export type Color = typeof colors[number];
|
|
38
39
|
|