-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathconflict-banner.tsx
More file actions
134 lines (128 loc) · 4.45 KB
/
Copy pathconflict-banner.tsx
File metadata and controls
134 lines (128 loc) · 4.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import * as C from '@/constants'
import * as Kb from '@/common-adapters'
import * as T from '@/constants/types'
import * as Kbfs from '@/fs/common'
import {openURL as openUrl} from '@/util/misc'
import * as FS from '@/constants/fs'
type OwnProps = {
path: T.FS.Path
}
const ConnectedBanner = (ownProps: OwnProps) => {
const {path} = ownProps
const errorToActionOrThrow = Kbfs.useFsErrorActionOrThrow()
const openPathInSystemFileManagerDesktop = Kbfs.useOpenPathInSystemFileManagerDesktop()
const tlf = Kbfs.useFsTlf(path)
const onFinishResolving = () => {
const f = async () => {
try {
await T.RPCGen.SimpleFSSimpleFSFinishResolvingConflictRpcPromise({
path: FS.pathToRPCPath(path),
})
} catch (error) {
errorToActionOrThrow(error, path)
}
}
C.ignorePromise(f())
}
const onGoToSamePathInDifferentTlf = (tlfPath: T.FS.Path) => {
C.Router2.navigateAppend({name: 'fsBrowse', params: {path: FS.rebasePathToDifferentTlf(path, tlfPath)}})
}
const onHelp = () => {
void openUrl('https://book.keybase.io/docs/files/details#conflict-resolution')
}
const onStartResolving = () => {
const f = async () => {
try {
await T.RPCGen.SimpleFSSimpleFSClearConflictStateRpcPromise({
path: FS.pathToRPCPath(path),
})
} catch (error) {
errorToActionOrThrow(error, path)
}
}
C.ignorePromise(f())
}
const openInSystemFileManager = (path: T.FS.Path) => {
openPathInSystemFileManagerDesktop(path, errorToActionOrThrow)
}
const conflictState = tlf.conflictState
const finishRes = {onClick: onFinishResolving, text: ' Delete this conflict view '}
const helpAction = {onClick: onHelp, text: ' What does this mean? '}
const startRes = {onClick: onStartResolving, text: ' Resolve conflict '}
switch (conflictState.type) {
case T.FS.ConflictStateType.NormalView: {
if (conflictState.stuckInConflict) {
const color = conflictState.localViewTlfPaths.length ? 'red' : 'yellow'
return (
<Kb.Banner color={color}>
<Kb.BannerParagraph
bannerColor={color}
content={
'Your changes to this folder' +
' conflict with changes made on another device. ' +
'Automatic conflict resolution has failed,' +
' so you need to manually resolve the conflict. '
}
/>
<Kb.BannerParagraph bannerColor={color} content={[startRes, helpAction]} />
</Kb.Banner>
)
}
if (conflictState.localViewTlfPaths.length) {
const localViewCount = conflictState.localViewTlfPaths.length
return (
<Kb.Banner color="green">
<Kb.BannerParagraph
bannerColor="green"
content={
localViewCount > 1
? 'Local conflicted copies were created.'
: 'A local conflicted copy was created.'
}
/>
<Kb.BannerParagraph
bannerColor="green"
content={conflictState.localViewTlfPaths.map((tlfPath, idx) => ({
onClick: () => onGoToSamePathInDifferentTlf(tlfPath),
text: ' Open conflicted copy' + (localViewCount > 1 ? ` #${(idx + 1).toString()} ` : ' '),
}))}
/>
<Kb.BannerParagraph bannerColor="green" content={[helpAction]} />
</Kb.Banner>
)
}
return null
}
case T.FS.ConflictStateType.ManualResolvingLocalView: {
return (
<Kb.Banner color="yellow">
<Kb.BannerParagraph
bannerColor="yellow"
content={[
'This is a conflicted copy of ',
{
onClick: () => onGoToSamePathInDifferentTlf(conflictState.normalViewTlfPath),
text: T.FS.pathToString(conflictState.normalViewTlfPath),
},
'.',
]}
/>
<Kb.BannerParagraph
bannerColor="yellow"
content={[
{
onClick: () => openInSystemFileManager(conflictState.normalViewTlfPath),
text: ` Open in ${C.fileUIName} `,
},
finishRes,
helpAction,
]}
/>
</Kb.Banner>
)
}
default:
return <Kb.Text type="Body">{'Unknown conflictState: ' + String(conflictState)}</Kb.Text>
}
}
export default ConnectedBanner