@scm-manager/ui-components 2.31.0 → 2.31.2-20220121-143434
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 +5 -5
- package/src/Breadcrumb.tsx +34 -7
- package/src/DangerZone.tsx +7 -0
- package/src/__snapshots__/storyshots.test.ts.snap +2267 -3021
- package/src/buttons/ButtonGroup.tsx +1 -12
- package/src/forms/AddKeyValueEntryToTableField.tsx +15 -8
- package/src/layout/Page.tsx +8 -11
- package/src/markdown/LazyMarkdownView.tsx +230 -0
- package/src/markdown/MarkdownView.tsx +10 -203
- package/src/modals/Modal.tsx +4 -0
- package/src/repos/Diff.tsx +2 -2
- package/src/repos/DiffFile.tsx +10 -492
- package/src/repos/LazyDiffFile.tsx +520 -0
- package/src/repos/changesets/ChangesetRow.tsx +2 -2
- package/src/table/InfoTable.tsx +59 -0
- package/src/table/Table.stories.tsx +1 -0
- package/src/table/Table.tsx +5 -2
- package/src/table/index.ts +1 -0
- package/src/table/types.ts +1 -0
|
@@ -0,0 +1,520 @@
|
|
|
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 { withTranslation, WithTranslation } from "react-i18next";
|
|
26
|
+
import classNames from "classnames";
|
|
27
|
+
import styled from "styled-components";
|
|
28
|
+
// @ts-ignore
|
|
29
|
+
import { Decoration, getChangeKey, Hunk } from "react-diff-view";
|
|
30
|
+
import { ButtonGroup } from "../buttons";
|
|
31
|
+
import Tag from "../Tag";
|
|
32
|
+
import Icon from "../Icon";
|
|
33
|
+
import { Change, FileDiff, Hunk as HunkType } from "@scm-manager/ui-types";
|
|
34
|
+
import { ChangeEvent, DiffObjectProps } from "./DiffTypes";
|
|
35
|
+
import TokenizedDiffView from "./TokenizedDiffView";
|
|
36
|
+
import DiffButton from "./DiffButton";
|
|
37
|
+
import { MenuContext, OpenInFullscreenButton } from "@scm-manager/ui-components";
|
|
38
|
+
import DiffExpander, { ExpandableHunk } from "./DiffExpander";
|
|
39
|
+
import HunkExpandLink from "./HunkExpandLink";
|
|
40
|
+
import { Modal } from "../modals";
|
|
41
|
+
import ErrorNotification from "../ErrorNotification";
|
|
42
|
+
import HunkExpandDivider from "./HunkExpandDivider";
|
|
43
|
+
import { escapeWhitespace } from "./diffs";
|
|
44
|
+
|
|
45
|
+
const EMPTY_ANNOTATION_FACTORY = {};
|
|
46
|
+
|
|
47
|
+
type Props = DiffFileProps & WithTranslation;
|
|
48
|
+
|
|
49
|
+
export type DiffFileProps = DiffObjectProps & {
|
|
50
|
+
file: FileDiff;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
type Collapsible = {
|
|
54
|
+
collapsed?: boolean;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
type State = Collapsible & {
|
|
58
|
+
file: FileDiff;
|
|
59
|
+
sideBySide?: boolean;
|
|
60
|
+
diffExpander: DiffExpander;
|
|
61
|
+
expansionError?: any;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const DiffFilePanel = styled.div`
|
|
65
|
+
/* remove bottom border for collapsed panels */
|
|
66
|
+
${(props: Collapsible) => (props.collapsed ? "border-bottom: none;" : "")};
|
|
67
|
+
`;
|
|
68
|
+
|
|
69
|
+
const FullWidthTitleHeader = styled.div`
|
|
70
|
+
max-width: 100%;
|
|
71
|
+
`;
|
|
72
|
+
|
|
73
|
+
const MarginlessModalContent = styled.div`
|
|
74
|
+
margin: -1.25rem;
|
|
75
|
+
|
|
76
|
+
& .panel-block {
|
|
77
|
+
flex-direction: column;
|
|
78
|
+
align-items: stretch;
|
|
79
|
+
}
|
|
80
|
+
`;
|
|
81
|
+
|
|
82
|
+
class DiffFile extends React.Component<Props, State> {
|
|
83
|
+
static defaultProps: Partial<Props> = {
|
|
84
|
+
defaultCollapse: false,
|
|
85
|
+
markConflicts: true
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
constructor(props: Props) {
|
|
89
|
+
super(props);
|
|
90
|
+
this.state = {
|
|
91
|
+
collapsed: this.defaultCollapse(),
|
|
92
|
+
sideBySide: props.sideBySide,
|
|
93
|
+
diffExpander: new DiffExpander(props.file),
|
|
94
|
+
file: props.file
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
componentDidUpdate(prevProps: Readonly<Props>) {
|
|
99
|
+
if (!this.props.isCollapsed && this.props.defaultCollapse !== prevProps.defaultCollapse) {
|
|
100
|
+
this.setState({
|
|
101
|
+
collapsed: this.defaultCollapse()
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
defaultCollapse: () => boolean = () => {
|
|
107
|
+
const { defaultCollapse, file } = this.props;
|
|
108
|
+
if (typeof defaultCollapse === "boolean") {
|
|
109
|
+
return defaultCollapse;
|
|
110
|
+
} else if (typeof defaultCollapse === "function") {
|
|
111
|
+
return defaultCollapse(file.oldPath, file.newPath);
|
|
112
|
+
} else {
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
toggleCollapse = () => {
|
|
118
|
+
const { onCollapseStateChange } = this.props;
|
|
119
|
+
const { file } = this.state;
|
|
120
|
+
if (this.hasContent(file)) {
|
|
121
|
+
if (onCollapseStateChange) {
|
|
122
|
+
onCollapseStateChange(file);
|
|
123
|
+
} else {
|
|
124
|
+
this.setState(state => ({
|
|
125
|
+
collapsed: !state.collapsed
|
|
126
|
+
}));
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
toggleSideBySide = (callback: () => void) => {
|
|
132
|
+
this.setState(
|
|
133
|
+
state => ({
|
|
134
|
+
sideBySide: !state.sideBySide
|
|
135
|
+
}),
|
|
136
|
+
() => callback()
|
|
137
|
+
);
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
setCollapse = (collapsed: boolean) => {
|
|
141
|
+
const { onCollapseStateChange } = this.props;
|
|
142
|
+
if (onCollapseStateChange) {
|
|
143
|
+
onCollapseStateChange(this.state.file, collapsed);
|
|
144
|
+
} else {
|
|
145
|
+
this.setState({
|
|
146
|
+
collapsed
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
createHunkHeader = (expandableHunk: ExpandableHunk) => {
|
|
152
|
+
if (expandableHunk.maxExpandHeadRange > 0) {
|
|
153
|
+
if (expandableHunk.maxExpandHeadRange <= 10) {
|
|
154
|
+
return (
|
|
155
|
+
<HunkExpandDivider>
|
|
156
|
+
<HunkExpandLink
|
|
157
|
+
icon={"fa-angle-double-up"}
|
|
158
|
+
onClick={this.expandHead(expandableHunk, expandableHunk.maxExpandHeadRange)}
|
|
159
|
+
text={this.props.t("diff.expandComplete", { count: expandableHunk.maxExpandHeadRange })}
|
|
160
|
+
/>
|
|
161
|
+
</HunkExpandDivider>
|
|
162
|
+
);
|
|
163
|
+
} else {
|
|
164
|
+
return (
|
|
165
|
+
<HunkExpandDivider>
|
|
166
|
+
<HunkExpandLink
|
|
167
|
+
icon={"fa-angle-up"}
|
|
168
|
+
onClick={this.expandHead(expandableHunk, 10)}
|
|
169
|
+
text={this.props.t("diff.expandByLines", { count: 10 })}
|
|
170
|
+
/>{" "}
|
|
171
|
+
<HunkExpandLink
|
|
172
|
+
icon={"fa-angle-double-up"}
|
|
173
|
+
onClick={this.expandHead(expandableHunk, expandableHunk.maxExpandHeadRange)}
|
|
174
|
+
text={this.props.t("diff.expandComplete", { count: expandableHunk.maxExpandHeadRange })}
|
|
175
|
+
/>
|
|
176
|
+
</HunkExpandDivider>
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
// hunk header must be defined
|
|
181
|
+
return <span />;
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
createHunkFooter = (expandableHunk: ExpandableHunk) => {
|
|
185
|
+
if (expandableHunk.maxExpandBottomRange > 0) {
|
|
186
|
+
if (expandableHunk.maxExpandBottomRange <= 10) {
|
|
187
|
+
return (
|
|
188
|
+
<HunkExpandDivider>
|
|
189
|
+
<HunkExpandLink
|
|
190
|
+
icon={"fa-angle-double-down"}
|
|
191
|
+
onClick={this.expandBottom(expandableHunk, expandableHunk.maxExpandBottomRange)}
|
|
192
|
+
text={this.props.t("diff.expandComplete", { count: expandableHunk.maxExpandBottomRange })}
|
|
193
|
+
/>
|
|
194
|
+
</HunkExpandDivider>
|
|
195
|
+
);
|
|
196
|
+
} else {
|
|
197
|
+
return (
|
|
198
|
+
<HunkExpandDivider>
|
|
199
|
+
<HunkExpandLink
|
|
200
|
+
icon={"fa-angle-down"}
|
|
201
|
+
onClick={this.expandBottom(expandableHunk, 10)}
|
|
202
|
+
text={this.props.t("diff.expandByLines", { count: 10 })}
|
|
203
|
+
/>{" "}
|
|
204
|
+
<HunkExpandLink
|
|
205
|
+
icon={"fa-angle-double-down"}
|
|
206
|
+
onClick={this.expandBottom(expandableHunk, expandableHunk.maxExpandBottomRange)}
|
|
207
|
+
text={this.props.t("diff.expandComplete", { count: expandableHunk.maxExpandBottomRange })}
|
|
208
|
+
/>
|
|
209
|
+
</HunkExpandDivider>
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
// hunk footer must be defined
|
|
214
|
+
return <span />;
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
createLastHunkFooter = (expandableHunk: ExpandableHunk) => {
|
|
218
|
+
if (expandableHunk.maxExpandBottomRange !== 0) {
|
|
219
|
+
return (
|
|
220
|
+
<HunkExpandDivider>
|
|
221
|
+
<HunkExpandLink
|
|
222
|
+
icon={"fa-angle-down"}
|
|
223
|
+
onClick={this.expandBottom(expandableHunk, 10)}
|
|
224
|
+
text={this.props.t("diff.expandLastBottomByLines", { count: 10 })}
|
|
225
|
+
/>{" "}
|
|
226
|
+
<HunkExpandLink
|
|
227
|
+
icon={"fa-angle-double-down"}
|
|
228
|
+
onClick={this.expandBottom(expandableHunk, expandableHunk.maxExpandBottomRange)}
|
|
229
|
+
text={this.props.t("diff.expandLastBottomComplete")}
|
|
230
|
+
/>
|
|
231
|
+
</HunkExpandDivider>
|
|
232
|
+
);
|
|
233
|
+
}
|
|
234
|
+
// hunk header must be defined
|
|
235
|
+
return <span />;
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
expandHead = (expandableHunk: ExpandableHunk, count: number) => {
|
|
239
|
+
return () => {
|
|
240
|
+
return expandableHunk
|
|
241
|
+
.expandHead(count)
|
|
242
|
+
.then(this.diffExpanded)
|
|
243
|
+
.catch(this.diffExpansionFailed);
|
|
244
|
+
};
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
expandBottom = (expandableHunk: ExpandableHunk, count: number) => {
|
|
248
|
+
return () => {
|
|
249
|
+
return expandableHunk
|
|
250
|
+
.expandBottom(count)
|
|
251
|
+
.then(this.diffExpanded)
|
|
252
|
+
.catch(this.diffExpansionFailed);
|
|
253
|
+
};
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
diffExpanded = (newFile: FileDiff) => {
|
|
257
|
+
this.setState({ file: newFile, diffExpander: new DiffExpander(newFile) });
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
diffExpansionFailed = (err: any) => {
|
|
261
|
+
this.setState({ expansionError: err });
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
collectHunkAnnotations = (hunk: HunkType) => {
|
|
265
|
+
const { annotationFactory } = this.props;
|
|
266
|
+
const { file } = this.state;
|
|
267
|
+
if (annotationFactory) {
|
|
268
|
+
return annotationFactory({
|
|
269
|
+
hunk,
|
|
270
|
+
file
|
|
271
|
+
});
|
|
272
|
+
} else {
|
|
273
|
+
return EMPTY_ANNOTATION_FACTORY;
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
handleClickEvent = (change: Change, hunk: HunkType) => {
|
|
278
|
+
const { onClick } = this.props;
|
|
279
|
+
const { file } = this.state;
|
|
280
|
+
const context = {
|
|
281
|
+
changeId: getChangeKey(change),
|
|
282
|
+
change,
|
|
283
|
+
hunk,
|
|
284
|
+
file
|
|
285
|
+
};
|
|
286
|
+
if (onClick) {
|
|
287
|
+
onClick(context);
|
|
288
|
+
}
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
createGutterEvents = (hunk: HunkType) => {
|
|
292
|
+
const { onClick } = this.props;
|
|
293
|
+
if (onClick) {
|
|
294
|
+
return {
|
|
295
|
+
onClick: (event: ChangeEvent) => {
|
|
296
|
+
this.handleClickEvent(event.change, hunk);
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
renderHunk = (file: FileDiff, expandableHunk: ExpandableHunk, i: number) => {
|
|
303
|
+
const hunk = expandableHunk.hunk;
|
|
304
|
+
if (this.props.markConflicts && hunk.changes) {
|
|
305
|
+
this.markConflicts(hunk);
|
|
306
|
+
}
|
|
307
|
+
const items = [];
|
|
308
|
+
if (file._links?.lines) {
|
|
309
|
+
items.push(this.createHunkHeader(expandableHunk));
|
|
310
|
+
} else if (i > 0) {
|
|
311
|
+
items.push(
|
|
312
|
+
<Decoration>
|
|
313
|
+
<hr className="my-2" />
|
|
314
|
+
</Decoration>
|
|
315
|
+
);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
items.push(
|
|
319
|
+
<Hunk
|
|
320
|
+
key={"hunk-" + hunk.content}
|
|
321
|
+
hunk={expandableHunk.hunk}
|
|
322
|
+
widgets={this.collectHunkAnnotations(hunk)}
|
|
323
|
+
gutterEvents={this.createGutterEvents(hunk)}
|
|
324
|
+
className={this.props.hunkClass ? this.props.hunkClass(hunk) : null}
|
|
325
|
+
/>
|
|
326
|
+
);
|
|
327
|
+
if (file._links?.lines) {
|
|
328
|
+
if (i === file.hunks!.length - 1) {
|
|
329
|
+
items.push(this.createLastHunkFooter(expandableHunk));
|
|
330
|
+
} else {
|
|
331
|
+
items.push(this.createHunkFooter(expandableHunk));
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
return items;
|
|
335
|
+
};
|
|
336
|
+
|
|
337
|
+
markConflicts = (hunk: HunkType) => {
|
|
338
|
+
let inConflict = false;
|
|
339
|
+
for (let i = 0; i < hunk.changes.length; ++i) {
|
|
340
|
+
if (hunk.changes[i].content === "<<<<<<< HEAD") {
|
|
341
|
+
inConflict = true;
|
|
342
|
+
}
|
|
343
|
+
if (inConflict) {
|
|
344
|
+
hunk.changes[i].type = "conflict";
|
|
345
|
+
}
|
|
346
|
+
if (hunk.changes[i].content.startsWith(">>>>>>>")) {
|
|
347
|
+
inConflict = false;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
};
|
|
351
|
+
|
|
352
|
+
getAnchorId(file: FileDiff) {
|
|
353
|
+
let path: string;
|
|
354
|
+
if (file.type === "delete") {
|
|
355
|
+
path = file.oldPath;
|
|
356
|
+
} else {
|
|
357
|
+
path = file.newPath;
|
|
358
|
+
}
|
|
359
|
+
return escapeWhitespace(path);
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
renderFileTitle = (file: FileDiff) => {
|
|
363
|
+
const { t } = this.props;
|
|
364
|
+
if (file.oldPath !== file.newPath && (file.type === "copy" || file.type === "rename")) {
|
|
365
|
+
return (
|
|
366
|
+
<>
|
|
367
|
+
{file.oldPath} <Icon name="arrow-right" color="inherit" alt={t("diff.renamedTo")} /> {file.newPath}
|
|
368
|
+
</>
|
|
369
|
+
);
|
|
370
|
+
} else if (file.type === "delete") {
|
|
371
|
+
return file.oldPath;
|
|
372
|
+
}
|
|
373
|
+
return file.newPath;
|
|
374
|
+
};
|
|
375
|
+
|
|
376
|
+
hoverFileTitle = (file: FileDiff): string => {
|
|
377
|
+
if (file.oldPath !== file.newPath && (file.type === "copy" || file.type === "rename")) {
|
|
378
|
+
return `${file.oldPath} > ${file.newPath}`;
|
|
379
|
+
} else if (file.type === "delete") {
|
|
380
|
+
return file.oldPath;
|
|
381
|
+
}
|
|
382
|
+
return file.newPath;
|
|
383
|
+
};
|
|
384
|
+
|
|
385
|
+
renderChangeTag = (file: FileDiff) => {
|
|
386
|
+
const { t } = this.props;
|
|
387
|
+
if (!file.type) {
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
390
|
+
const key = "diff.changes." + file.type;
|
|
391
|
+
let value = t(key);
|
|
392
|
+
if (key === value) {
|
|
393
|
+
value = file.type;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
const color = value === "added" ? "success" : value === "deleted" ? "danger" : "info";
|
|
397
|
+
return (
|
|
398
|
+
<Tag
|
|
399
|
+
className={classNames("has-text-weight-normal", "ml-3")}
|
|
400
|
+
rounded={true}
|
|
401
|
+
outlined={true}
|
|
402
|
+
color={color}
|
|
403
|
+
label={value}
|
|
404
|
+
/>
|
|
405
|
+
);
|
|
406
|
+
};
|
|
407
|
+
|
|
408
|
+
isCollapsed = () => {
|
|
409
|
+
const { file, isCollapsed } = this.props;
|
|
410
|
+
if (isCollapsed) {
|
|
411
|
+
return isCollapsed(file);
|
|
412
|
+
}
|
|
413
|
+
return this.state.collapsed;
|
|
414
|
+
};
|
|
415
|
+
|
|
416
|
+
hasContent = (file: FileDiff) => file && !file.isBinary && file.hunks && file.hunks.length > 0;
|
|
417
|
+
|
|
418
|
+
render() {
|
|
419
|
+
const { fileControlFactory, fileAnnotationFactory, t } = this.props;
|
|
420
|
+
const { file, sideBySide, diffExpander, expansionError } = this.state;
|
|
421
|
+
const viewType = sideBySide ? "split" : "unified";
|
|
422
|
+
const collapsed = this.isCollapsed();
|
|
423
|
+
|
|
424
|
+
const fileAnnotations = fileAnnotationFactory ? fileAnnotationFactory(file) : null;
|
|
425
|
+
const innerContent = (
|
|
426
|
+
<div className="panel-block p-0">
|
|
427
|
+
{fileAnnotations}
|
|
428
|
+
<TokenizedDiffView className={viewType} viewType={viewType} file={file}>
|
|
429
|
+
{(hunks: HunkType[]) =>
|
|
430
|
+
hunks?.map((hunk, n) => {
|
|
431
|
+
return this.renderHunk(file, diffExpander.getHunk(n), n);
|
|
432
|
+
})
|
|
433
|
+
}
|
|
434
|
+
</TokenizedDiffView>
|
|
435
|
+
</div>
|
|
436
|
+
);
|
|
437
|
+
let icon = <Icon name="angle-right" color="inherit" alt={t("diff.showContent")} />;
|
|
438
|
+
let body = null;
|
|
439
|
+
if (!collapsed) {
|
|
440
|
+
icon = <Icon name="angle-down" color="inherit" alt={t("diff.hideContent")} />;
|
|
441
|
+
body = innerContent;
|
|
442
|
+
}
|
|
443
|
+
const collapseIcon = this.hasContent(file) ? icon : null;
|
|
444
|
+
const fileControls = fileControlFactory ? fileControlFactory(file, this.setCollapse) : null;
|
|
445
|
+
const modalTitle = file.type === "delete" ? file.oldPath : file.newPath;
|
|
446
|
+
const openInFullscreen = file?.hunks?.length ? (
|
|
447
|
+
<OpenInFullscreenButton
|
|
448
|
+
modalTitle={modalTitle}
|
|
449
|
+
modalBody={<MarginlessModalContent>{innerContent}</MarginlessModalContent>}
|
|
450
|
+
/>
|
|
451
|
+
) : null;
|
|
452
|
+
const sideBySideToggle = file?.hunks?.length && (
|
|
453
|
+
<MenuContext.Consumer>
|
|
454
|
+
{({ setCollapsed }) => (
|
|
455
|
+
<DiffButton
|
|
456
|
+
icon={sideBySide ? "align-left" : "columns"}
|
|
457
|
+
tooltip={t(sideBySide ? "diff.combined" : "diff.sideBySide")}
|
|
458
|
+
onClick={() =>
|
|
459
|
+
this.toggleSideBySide(() => {
|
|
460
|
+
if (this.state.sideBySide) {
|
|
461
|
+
setCollapsed(true);
|
|
462
|
+
}
|
|
463
|
+
})
|
|
464
|
+
}
|
|
465
|
+
/>
|
|
466
|
+
)}
|
|
467
|
+
</MenuContext.Consumer>
|
|
468
|
+
);
|
|
469
|
+
const headerButtons = (
|
|
470
|
+
<div className={classNames("level-right", "is-flex", "ml-auto")}>
|
|
471
|
+
<ButtonGroup>
|
|
472
|
+
{sideBySideToggle}
|
|
473
|
+
{openInFullscreen}
|
|
474
|
+
{fileControls}
|
|
475
|
+
</ButtonGroup>
|
|
476
|
+
</div>
|
|
477
|
+
);
|
|
478
|
+
|
|
479
|
+
let errorModal;
|
|
480
|
+
if (expansionError) {
|
|
481
|
+
errorModal = (
|
|
482
|
+
<Modal
|
|
483
|
+
title={t("diff.expansionFailed")}
|
|
484
|
+
closeFunction={() => this.setState({ expansionError: undefined })}
|
|
485
|
+
body={<ErrorNotification error={expansionError} />}
|
|
486
|
+
active={true}
|
|
487
|
+
/>
|
|
488
|
+
);
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
return (
|
|
492
|
+
<DiffFilePanel
|
|
493
|
+
className={classNames("panel", "is-size-6")}
|
|
494
|
+
collapsed={(file && file.isBinary) || collapsed}
|
|
495
|
+
id={this.getAnchorId(file)}
|
|
496
|
+
>
|
|
497
|
+
{errorModal}
|
|
498
|
+
<div className="panel-heading">
|
|
499
|
+
<div className={classNames("level", "is-flex-wrap-wrap")}>
|
|
500
|
+
<FullWidthTitleHeader
|
|
501
|
+
className={classNames("level-left", "is-flex", "is-clickable")}
|
|
502
|
+
onClick={this.toggleCollapse}
|
|
503
|
+
title={this.hoverFileTitle(file)}
|
|
504
|
+
>
|
|
505
|
+
{collapseIcon}
|
|
506
|
+
<h4 className={classNames("has-text-weight-bold", "is-ellipsis-overflow", "is-size-6", "ml-1")}>
|
|
507
|
+
{this.renderFileTitle(file)}
|
|
508
|
+
</h4>
|
|
509
|
+
{this.renderChangeTag(file)}
|
|
510
|
+
</FullWidthTitleHeader>
|
|
511
|
+
{headerButtons}
|
|
512
|
+
</div>
|
|
513
|
+
</div>
|
|
514
|
+
{body}
|
|
515
|
+
</DiffFilePanel>
|
|
516
|
+
);
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
export default withTranslation("repos")(DiffFile);
|
|
@@ -48,8 +48,8 @@ const Wrapper = styled.div`
|
|
|
48
48
|
const ChangesetRow: FC<Props> = ({ repository, changeset, file }) => {
|
|
49
49
|
return (
|
|
50
50
|
<Wrapper>
|
|
51
|
-
<div className={classNames("columns", "is-
|
|
52
|
-
<div className={classNames("column", "is-three-fifths")}>
|
|
51
|
+
<div className={classNames("columns", "is-variable", "is-1-mobile", "is-0-tablet")}>
|
|
52
|
+
<div className={classNames("column", "is-three-fifths", "is-full-mobile")}>
|
|
53
53
|
<SingleChangeset repository={repository} changeset={changeset} />
|
|
54
54
|
</div>
|
|
55
55
|
<div className={classNames("column", "is-flex", "is-justify-content-flex-end", "is-align-items-center")}>
|
|
@@ -0,0 +1,59 @@
|
|
|
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, HTMLProps, ReactNode } from "react";
|
|
26
|
+
import styled from "styled-components";
|
|
27
|
+
import classNames from "classnames";
|
|
28
|
+
import { devices } from "../devices";
|
|
29
|
+
|
|
30
|
+
type Props = Omit<HTMLProps<HTMLTableElement>, "children" | "as" | "ref"> & {
|
|
31
|
+
children: ReactNode;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const StyledTable = styled.table`
|
|
35
|
+
@media screen and (max-width: ${devices.mobile.width}px) {
|
|
36
|
+
td,
|
|
37
|
+
th {
|
|
38
|
+
display: block;
|
|
39
|
+
}
|
|
40
|
+
td {
|
|
41
|
+
border-width: 0 0 1px;
|
|
42
|
+
word-break: break-word;
|
|
43
|
+
}
|
|
44
|
+
th {
|
|
45
|
+
border: none;
|
|
46
|
+
padding-bottom: 0;
|
|
47
|
+
}
|
|
48
|
+
th:after {
|
|
49
|
+
content: ": ";
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
`;
|
|
53
|
+
|
|
54
|
+
const InfoTable: FC<Props> = ({ className, children, ...rest }) => (
|
|
55
|
+
<StyledTable className={classNames("table", className)} {...rest}>
|
|
56
|
+
{children}
|
|
57
|
+
</StyledTable>
|
|
58
|
+
);
|
|
59
|
+
export default InfoTable;
|
package/src/table/Table.tsx
CHANGED
|
@@ -61,7 +61,10 @@ const Table: FC<Props> = ({ data, sortable, children, emptyMessage, className })
|
|
|
61
61
|
return (
|
|
62
62
|
<tr key={rowIndex}>
|
|
63
63
|
{React.Children.map(children, (child, columnIndex) => {
|
|
64
|
-
|
|
64
|
+
const { className: columnClassName, ...childProperties } = child.props;
|
|
65
|
+
return (
|
|
66
|
+
<td className={columnClassName}>{React.cloneElement(child, { ...childProperties, columnIndex, row })}</td>
|
|
67
|
+
);
|
|
65
68
|
})}
|
|
66
69
|
</tr>
|
|
67
70
|
);
|
|
@@ -127,7 +130,7 @@ const Table: FC<Props> = ({ data, sortable, children, emptyMessage, className })
|
|
|
127
130
|
};
|
|
128
131
|
|
|
129
132
|
Table.defaultProps = {
|
|
130
|
-
sortable: true
|
|
133
|
+
sortable: true
|
|
131
134
|
};
|
|
132
135
|
|
|
133
136
|
const renderSortIcon = (child: ReactElement, ascending: boolean, showIcon: boolean) => {
|
package/src/table/index.ts
CHANGED