-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Lookoutv2: add sidebar displaying useful commands (#3354)
- Loading branch information
1 parent
95572c8
commit 4b587f9
Showing
11 changed files
with
119 additions
and
1 deletion.
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
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
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
11 changes: 11 additions & 0 deletions
11
internal/lookout/ui/src/components/lookoutV2/sidebar/SidebarTabJobCommands.module.css
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,11 @@ | ||
.commandsText { | ||
width: 100%; | ||
white-space: pre-wrap; | ||
font-family: monospace; | ||
word-wrap: break-word; | ||
background: #1b1b1b none; | ||
color: #fff; | ||
padding: 5px; | ||
border-radius: 5px; | ||
position: relative; | ||
} |
61 changes: 61 additions & 0 deletions
61
internal/lookout/ui/src/components/lookoutV2/sidebar/SidebarTabJobCommands.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,61 @@ | ||
import React, { useCallback } from "react" | ||
|
||
import { ContentCopy } from "@mui/icons-material" | ||
import { IconButton, Link } from "@mui/material" | ||
import { template, templateSettings } from "lodash" | ||
import { Job } from "models/lookoutV2Models" | ||
import validator from "validator" | ||
|
||
import styles from "./SidebarTabJobCommands.module.css" | ||
import { useCustomSnackbar } from "../../../hooks/useCustomSnackbar" | ||
import { CommandSpec } from "../../../utils" | ||
|
||
export interface SidebarTabJobCommandsProps { | ||
job: Job | ||
commandSpecs: CommandSpec[] | ||
} | ||
|
||
function getCommandText(job: Job, commandSpec: CommandSpec): string { | ||
templateSettings.interpolate = /{{([\s\S]+?)}}/g | ||
const compiledTemplate = template(commandSpec.template) | ||
return compiledTemplate(job) | ||
} | ||
|
||
export const SidebarTabJobCommands = ({ job, commandSpecs }: SidebarTabJobCommandsProps) => { | ||
const openSnackbar = useCustomSnackbar() | ||
|
||
const copyCommand = useCallback(async (commandText: string) => { | ||
await navigator.clipboard.writeText(commandText) | ||
openSnackbar("Copied command to clipboard!", "info", { | ||
autoHideDuration: 3000, | ||
preventDuplicate: true, | ||
}) | ||
}, []) | ||
|
||
return ( | ||
<div style={{ width: "100%", height: "100%" }}> | ||
{job.runs?.length ? ( | ||
<div> | ||
{commandSpecs.map((c, i) => ( | ||
<> | ||
<div> | ||
{i > 0 ? <br /> : undefined} | ||
{c.name} | ||
<IconButton size="small" title="Copy to clipboard" onClick={() => copyCommand(getCommandText(job, c))}> | ||
<ContentCopy /> | ||
</IconButton> | ||
</div> | ||
{validator.isURL(getCommandText(job, c)) ? ( | ||
<Link href={getCommandText(job, c)} target="_blank"> | ||
<div>{getCommandText(job, c)}</div> | ||
</Link> | ||
) : ( | ||
<div className={styles.commandsText}>{getCommandText(job, c)}</div> | ||
)} | ||
</> | ||
))} | ||
</div> | ||
) : undefined} | ||
</div> | ||
) | ||
} |
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
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
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