Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a button to copy markdown formatted report
Browse files Browse the repository at this point in the history
fee1-dead committed Apr 8, 2023

Verified

This commit was signed with the committer’s verified signature.
neesjanvaneck Nees Jan van Eck
1 parent b64a8d4 commit 1f0d0c1
Showing 2 changed files with 31 additions and 1 deletion.
30 changes: 30 additions & 0 deletions ui/frontend/Output/Gist.tsx
Original file line number Diff line number Diff line change
@@ -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>
@@ -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>
);
};
2 changes: 1 addition & 1 deletion ui/frontend/selectors/index.ts
Original file line number Diff line number Diff line change
@@ -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 = '';

0 comments on commit 1f0d0c1

Please sign in to comment.