-
Notifications
You must be signed in to change notification settings - Fork 900
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(titus): Render run job output file as YAML (#6992)
* feat(titus): Render run job output file as YAML * fixup - remove 6 or 7 lines of code * fixup - unbreak my build
- Loading branch information
1 parent
b888ff5
commit 4c06d10
Showing
4 changed files
with
34 additions
and
36 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
28 changes: 28 additions & 0 deletions
28
app/scripts/modules/core/src/presentation/RenderOutputFile.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,28 @@ | ||
import * as React from 'react'; | ||
import { dump as dumpYaml } from 'js-yaml'; | ||
|
||
interface IRenderOutputFileProps { | ||
outputFileObject: object; | ||
} | ||
|
||
/** | ||
* Renders an object as YAML. | ||
* Transforms strings that look like URLs into links | ||
* The intention is to render the output file from a Script or Run Job stage | ||
*/ | ||
export const RenderOutputFile = React.memo(({ outputFileObject }: IRenderOutputFileProps) => { | ||
const linkRegex = /(https?:\/\/[^$\s'"]+)/; | ||
const isLink = (str: string) => `'${str}'`.match(linkRegex); | ||
|
||
const yaml = dumpYaml(outputFileObject); | ||
|
||
let linkCount = 0; | ||
const segments = yaml.split(linkRegex); | ||
const renderLink = (url: string) => ( | ||
<a key={`${linkCount++}`} href={url} target="_blank"> | ||
{url} | ||
</a> | ||
); | ||
const renderSegment = (segment: string) => (isLink(segment) ? renderLink(segment) : segment); | ||
return <pre style={{ overflow: 'scroll', maxHeight: '400px' }}>{segments.map(renderSegment)}</pre>; | ||
}); |
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
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