-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds wbr elements to aid in path readibility when it is wrapped
Signed-off-by: Ian Bolton <ibolton@redhat.com>
- Loading branch information
1 parent
b3cd682
commit abaa445
Showing
2 changed files
with
28 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
client/src/app/pages/issues/issue-detail-drawer/path-display.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import React from "react"; | ||
|
||
interface PathDisplayProps { | ||
path: string; | ||
} | ||
|
||
const PathDisplay: React.FC<PathDisplayProps> = ({ path }) => { | ||
// Normalize path to use a single type of separator ("/" in this case) | ||
// The regex /[\\/]/ matches both "/" and "\" characters. | ||
const normalizedPath = path.replace(/\\/g, "/"); | ||
const formattedPath = normalizedPath | ||
.split("/") | ||
.reduce<React.ReactNode[]>((acc, segment, index, array) => { | ||
acc.push(segment); | ||
if (index < array.length - 1) { | ||
acc.push(<wbr key={`wbr-${index}`} />); | ||
acc.push(<span key={`slash-${index}`}>/</span>); | ||
} | ||
return acc; | ||
}, []); | ||
|
||
return <>{formattedPath}</>; | ||
}; | ||
|
||
export default PathDisplay; |