Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a button to copy markdown formatted report #761

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions ui/frontend/Output/Gist.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,41 @@ class Copied extends React.PureComponent<CopiedProps, CopiedState> {
}
}

interface ReportProps {
snippet: string;
}

class CopyReport extends React.PureComponent<ReportProps, CopiedState> {
public constructor(props: ReportProps) {
super(props);
this.state = { copied: false };
}

public render() {
return (
<p className={this.state.copied ? styles.active : styles.container}>
<CopyToClipboard text={this.props.snippet} onCopy={this.copied}>
<div className={styles.container}><a href="#">Copy a Markdown formatted report of results</a>
<button className={styles.button}><ClipboardIcon /></button></div>
</CopyToClipboard>
<span className={styles.text}>Copied!</span>
</p>
);
}

private copied = () => {
this.setState({ copied: true });
setTimeout(() => { this.setState({ copied: false }); }, 1000);
}
}

const Links: React.FC = () => {
const codeUrl = useSelector(selectors.codeUrlSelector);
const gistUrl = useSelector((state: State) => state.output.gist.url);
const permalink = useSelector(selectors.permalinkSelector);
const urloUrl = useSelector(selectors.urloUrlSelector);
const textChanged = useSelector(selectors.textChangedSinceShareSelector);
const markdownSnippet = useSelector(selectors.snippetSelector);

return (
<Fragment>
Expand All @@ -70,6 +99,7 @@ const Links: React.FC = () => {
{textChanged ? <Section kind="warning" label="Code changed">
Source code has been changed since gist was saved
</Section>: null }
<CopyReport snippet={markdownSnippet} />
</Fragment>
);
};
Expand Down
2 changes: 1 addition & 1 deletion ui/frontend/selectors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ const maybeOutput = (code: string | undefined, whenPresent: (_: string) => void)
if (code && code.length !== 0) { whenPresent(code); }
};

const snippetSelector = createSelector(
export const snippetSelector = createSelector(
gistSelector, permalinkSelector,
(gist, permalink) => {
let snippet = '';
Expand Down