Skip to content

Commit ee5b710

Browse files
author
Lucas Bento
authored
fix: remove app prefix when appName is set (#139)
fix: remove AppPathPrefix when AppName is set
2 parents 08b9612 + 9ed265b commit ee5b710

File tree

6 files changed

+28
-11
lines changed

6 files changed

+28
-11
lines changed

src/components/common/Diff/Diff.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ const Diff = ({
8989
onToggleChangeSelection,
9090
areAllCollapsed,
9191
setAllCollapsed,
92-
diffViewStyle
92+
diffViewStyle,
93+
appName
9394
}) => {
9495
const [isDiffCollapsed, setIsDiffCollapsed] = useState(
9596
isDiffCollapsedByDefault({ type, hunks })
@@ -121,14 +122,15 @@ const Diff = ({
121122
}}
122123
isDiffCompleted={isDiffCompleted}
123124
onCompleteDiff={onCompleteDiff}
125+
appName={appName}
124126
/>
125127

126128
{!isDiffCollapsed && (
127129
<DiffView
128130
viewType={diffViewStyle}
129131
diffType={type}
130132
hunks={hunks}
131-
widgets={getComments({ newPath, fromVersion, toVersion })}
133+
widgets={getComments({ newPath, fromVersion, toVersion, appName })}
132134
optimizeSelection={true}
133135
selectedChanges={selectedChanges}
134136
>

src/components/common/Diff/DiffComment.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ const LINE_CHANGE_TYPES = {
3535
const getLineNumberWithType = ({ lineChangeType, lineNumber }) =>
3636
`${LINE_CHANGE_TYPES[lineChangeType.toUpperCase()]}${lineNumber}`
3737

38-
const getComments = ({ newPath, fromVersion, toVersion }) => {
39-
const newPathSanitized = removeAppPathPrefix(newPath)
38+
const getComments = ({ newPath, fromVersion, toVersion, appName }) => {
39+
const newPathSanitized = removeAppPathPrefix(newPath, appName)
4040

4141
const versionsInDiff = getVersionsInDiff({ fromVersion, toVersion }).filter(
4242
({ comments }) =>

src/components/common/Diff/DiffHeader.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ const FileRenameArrow = styled(props => <Icon {...props} type="right" />)`
99
color: #f78206;
1010
`
1111

12-
const FileName = ({ oldPath, newPath, type }) => {
13-
const oldPathSanitized = removeAppPathPrefix(oldPath)
14-
const newPathSanitized = removeAppPathPrefix(newPath)
12+
const FileName = ({ oldPath, newPath, type, appName }) => {
13+
const oldPathSanitized = removeAppPathPrefix(oldPath, appName)
14+
const newPathSanitized = removeAppPathPrefix(newPath, appName)
1515

1616
if (type === 'delete') {
1717
return <span>{oldPathSanitized}</span>
@@ -163,6 +163,7 @@ const DiffHeader = styled(
163163
setIsDiffCollapsed,
164164
isDiffCompleted,
165165
onCompleteDiff,
166+
appName,
166167
...props
167168
}) => (
168169
<div {...props}>
@@ -171,7 +172,12 @@ const DiffHeader = styled(
171172
isDiffCollapsed={isDiffCollapsed}
172173
onClick={({ altKey }) => setIsDiffCollapsed(!isDiffCollapsed, altKey)}
173174
/>
174-
<FileName oldPath={oldPath} newPath={newPath} type={type} />{' '}
175+
<FileName
176+
oldPath={oldPath}
177+
newPath={newPath}
178+
type={type}
179+
appName={appName}
180+
/>{' '}
175181
<FileStatus type={type} />
176182
<BinaryBadge visible={!hasDiff} />
177183
<HeaderButtonsContainer>

src/components/common/Diff/DiffSection.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ const DiffSection = ({
1717
handleCompleteDiff,
1818
selectedChanges,
1919
onToggleChangeSelection,
20-
diffViewStyle
20+
diffViewStyle,
21+
appName
2122
}) => {
2223
const [areAllCollapsed, setAllCollapsed] = useState(undefined)
2324

@@ -50,6 +51,7 @@ const DiffSection = ({
5051
onToggleChangeSelection={onToggleChangeSelection}
5152
areAllCollapsed={areAllCollapsed}
5253
setAllCollapsed={setAllCollapsed}
54+
appName={appName}
5355
/>
5456
)
5557
})}

src/components/common/DiffViewer.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,17 @@ const DiffViewer = ({
145145
{...diffSectionProps}
146146
isDoneSection={false}
147147
diffViewStyle={diffViewStyle}
148+
appName={appName}
148149
/>
149150

150151
{renderUpgradeDoneMessage({ diff, completedDiffs })}
151152

152-
<DiffSection {...diffSectionProps} isDoneSection={true} title="Done" />
153+
<DiffSection
154+
{...diffSectionProps}
155+
isDoneSection={true}
156+
title="Done"
157+
appName={appName}
158+
/>
153159

154160
<CompletedFilesCounter
155161
completed={completedDiffs.length}

src/utils.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ export const getDiffPatchURL = ({ fromVersion, toVersion }) =>
1212
export const getBinaryFileURL = ({ version, path }) =>
1313
`https://github.com/${RN_DIFF_REPO}/raw/release/${version}/${path}`
1414

15-
export const removeAppPathPrefix = path => path.replace(/RnDiffApp\//, '')
15+
export const removeAppPathPrefix = (path, appName) =>
16+
path.replace(new RegExp(`${appName || 'RnDiffApp'}/`), '')
1617

1718
export const getVersionsInDiff = ({ fromVersion, toVersion }) => {
1819
const cleanedToVersion = semver.valid(semver.coerce(toVersion))

0 commit comments

Comments
 (0)