mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-01 11:05:56 +01:00
Add copy button to codeblocks
This commit is contained in:
2
gradle/changelog/codeblocks_with_copybutton.yaml
Normal file
2
gradle/changelog/codeblocks_with_copybutton.yaml
Normal file
@@ -0,0 +1,2 @@
|
||||
- type: added
|
||||
description: Copy button to codeblocks
|
||||
@@ -24,7 +24,7 @@
|
||||
import React, { FC } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Repository } from "@scm-manager/ui-types";
|
||||
import { SubSubtitle, ErrorNotification, Loading } from "@scm-manager/ui-components";
|
||||
import { SubSubtitle, ErrorNotification, Loading, PreformattedCodeBlock } from "@scm-manager/ui-components";
|
||||
import { useChangesets, useDefaultBranch } from "@scm-manager/ui-api";
|
||||
|
||||
type Props = {
|
||||
@@ -34,12 +34,18 @@ type Props = {
|
||||
|
||||
const CloneInformation: FC<Props> = ({ url, repository }) => {
|
||||
const [t] = useTranslation("plugins");
|
||||
const { data: changesets, error: changesetsError, isLoading: changesetsLoading } = useChangesets(repository, {
|
||||
limit: 1
|
||||
const {
|
||||
data: changesets,
|
||||
error: changesetsError,
|
||||
isLoading: changesetsLoading,
|
||||
} = useChangesets(repository, {
|
||||
limit: 1,
|
||||
});
|
||||
const { data: defaultBranchData, isLoading: defaultBranchLoading, error: defaultBranchError } = useDefaultBranch(
|
||||
repository
|
||||
);
|
||||
const {
|
||||
data: defaultBranchData,
|
||||
isLoading: defaultBranchLoading,
|
||||
error: defaultBranchError,
|
||||
} = useDefaultBranch(repository);
|
||||
|
||||
if (changesetsLoading || defaultBranchLoading) {
|
||||
return <Loading />;
|
||||
@@ -49,56 +55,34 @@ const CloneInformation: FC<Props> = ({ url, repository }) => {
|
||||
const branch = defaultBranchData?.defaultBranch;
|
||||
const emptyRepository = (changesets?._embedded?.changesets.length || 0) === 0;
|
||||
|
||||
let gitCloneCommand = `git clone ${url}\ncd ${repository.name}`;
|
||||
if (emptyRepository) {
|
||||
gitCloneCommand += `\ngit checkout -b ${branch}`;
|
||||
}
|
||||
const gitCreateCommand =
|
||||
`git init ${repository.name}\n` +
|
||||
`cd ${repository.name}\n` +
|
||||
`git checkout -b ${branch}\n` +
|
||||
`echo "# ${repository.name}" > README.md\n` +
|
||||
"git add README.md\n" +
|
||||
'git commit -m "Add readme"\n' +
|
||||
`git remote add origin ${url}\n` +
|
||||
`git push -u origin ${branch}`;
|
||||
const gitCommandCreate = `git remote add origin ${url}`;
|
||||
|
||||
return (
|
||||
<div className="content">
|
||||
<ErrorNotification error={error} />
|
||||
<SubSubtitle>{t("scm-git-plugin.information.clone")}</SubSubtitle>
|
||||
<pre>
|
||||
<code>
|
||||
git clone {url}
|
||||
<br />
|
||||
cd {repository.name}
|
||||
{emptyRepository && (
|
||||
<>
|
||||
<br />
|
||||
git checkout -b {branch}
|
||||
</>
|
||||
)}
|
||||
</code>
|
||||
</pre>
|
||||
<PreformattedCodeBlock>{gitCloneCommand}</PreformattedCodeBlock>
|
||||
{emptyRepository && (
|
||||
<>
|
||||
<SubSubtitle>{t("scm-git-plugin.information.create")}</SubSubtitle>
|
||||
<pre>
|
||||
<code>
|
||||
git init {repository.name}
|
||||
<br />
|
||||
cd {repository.name}
|
||||
<br />
|
||||
git checkout -b {branch}
|
||||
<br />
|
||||
echo "# {repository.name}
|
||||
" > README.md
|
||||
<br />
|
||||
git add README.md
|
||||
<br />
|
||||
git commit -m "Add readme"
|
||||
<br />
|
||||
git remote add origin {url}
|
||||
<br />
|
||||
git push -u origin {branch}
|
||||
<br />
|
||||
</code>
|
||||
</pre>
|
||||
<PreformattedCodeBlock>{gitCreateCommand}</PreformattedCodeBlock>
|
||||
</>
|
||||
)}
|
||||
<SubSubtitle>{t("scm-git-plugin.information.replace")}</SubSubtitle>
|
||||
<pre>
|
||||
<code>
|
||||
git remote add origin {url}
|
||||
<br />
|
||||
</code>
|
||||
</pre>
|
||||
<PreformattedCodeBlock>{gitCommandCreate}</PreformattedCodeBlock>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
import React from "react";
|
||||
import { WithTranslation, withTranslation } from "react-i18next";
|
||||
import { Branch } from "@scm-manager/ui-types";
|
||||
import { SubSubtitle } from "@scm-manager/ui-components";
|
||||
import { PreformattedCodeBlock, SubSubtitle } from "@scm-manager/ui-components";
|
||||
|
||||
type Props = WithTranslation & {
|
||||
branch: Branch;
|
||||
@@ -34,16 +34,15 @@ class GitBranchInformation extends React.Component<Props> {
|
||||
render() {
|
||||
const { branch, t } = this.props;
|
||||
|
||||
const gitFetchCommand = "git fetch";
|
||||
const gitCheckoutCommand = "git checkout " + branch.name;
|
||||
|
||||
return (
|
||||
<div>
|
||||
<SubSubtitle>{t("scm-git-plugin.information.fetch")}</SubSubtitle>
|
||||
<pre>
|
||||
<code>git fetch</code>
|
||||
</pre>
|
||||
<PreformattedCodeBlock>{gitFetchCommand}</PreformattedCodeBlock>
|
||||
<SubSubtitle>{t("scm-git-plugin.information.checkout")}</SubSubtitle>
|
||||
<pre>
|
||||
<code>git checkout {branch.name}</code>
|
||||
</pre>
|
||||
<PreformattedCodeBlock>{gitCheckoutCommand}</PreformattedCodeBlock>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
import React from "react";
|
||||
import { WithTranslation, withTranslation } from "react-i18next";
|
||||
import { Repository } from "@scm-manager/ui-types";
|
||||
import { SubSubtitle } from "@scm-manager/ui-components";
|
||||
import { PreformattedCodeBlock, SubSubtitle } from "@scm-manager/ui-components";
|
||||
|
||||
type Props = WithTranslation & {
|
||||
repository: Repository;
|
||||
@@ -37,35 +37,28 @@ class GitMergeInformation extends React.Component<Props> {
|
||||
render() {
|
||||
const { source, target, t } = this.props;
|
||||
|
||||
const gitCheckoutCommand = `git checkout ${target}`;
|
||||
const gitUpdateCommand = "git pull";
|
||||
const gitMergeCommand = `git merge ${source}`;
|
||||
const gitResolveCommand = "git add <conflict file>";
|
||||
const gitCommitCommand = `git commit -m "Merge ${source} into ${target}"`;
|
||||
const gitPushCommand = "git push";
|
||||
|
||||
return (
|
||||
<div>
|
||||
<SubSubtitle>{t("scm-git-plugin.information.merge.heading")}</SubSubtitle>
|
||||
{t("scm-git-plugin.information.merge.checkout")}
|
||||
<pre>
|
||||
<code>git checkout {target}</code>
|
||||
</pre>
|
||||
<PreformattedCodeBlock>{gitCheckoutCommand}</PreformattedCodeBlock>
|
||||
{t("scm-git-plugin.information.merge.update")}
|
||||
<pre>
|
||||
<code>git pull</code>
|
||||
</pre>
|
||||
<PreformattedCodeBlock>{gitUpdateCommand}</PreformattedCodeBlock>
|
||||
{t("scm-git-plugin.information.merge.merge")}
|
||||
<pre>
|
||||
<code>git merge {source}</code>
|
||||
</pre>
|
||||
<PreformattedCodeBlock>{gitMergeCommand}</PreformattedCodeBlock>
|
||||
{t("scm-git-plugin.information.merge.resolve")}
|
||||
<pre>
|
||||
<code>git add <conflict file></code>
|
||||
</pre>
|
||||
<PreformattedCodeBlock>{gitResolveCommand}</PreformattedCodeBlock>
|
||||
{t("scm-git-plugin.information.merge.commit")}
|
||||
<pre>
|
||||
<code>
|
||||
git commit -m "Merge {source} into {target}"
|
||||
</code>
|
||||
</pre>
|
||||
<PreformattedCodeBlock>{gitCommitCommand}</PreformattedCodeBlock>
|
||||
{t("scm-git-plugin.information.merge.push")}
|
||||
<pre>
|
||||
<code>git push</code>
|
||||
</pre>
|
||||
<PreformattedCodeBlock>{gitPushCommand}</PreformattedCodeBlock>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
import React, { FC } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Tag } from "@scm-manager/ui-types";
|
||||
import { SubSubtitle } from "@scm-manager/ui-components";
|
||||
import { PreformattedCodeBlock, SubSubtitle } from "@scm-manager/ui-components";
|
||||
|
||||
type Props = {
|
||||
tag: Tag;
|
||||
@@ -34,14 +34,12 @@ type Props = {
|
||||
const GitTagInformation: FC<Props> = ({ tag }) => {
|
||||
const [t] = useTranslation("plugins");
|
||||
|
||||
const gitCheckoutTagCommand = `git checkout tags/${tag.name} -b branch/${tag.name}`;
|
||||
|
||||
return (
|
||||
<>
|
||||
<SubSubtitle>{t("scm-git-plugin.information.checkoutTag")}</SubSubtitle>
|
||||
<pre>
|
||||
<code>
|
||||
git checkout tags/{tag.name} -b branch/{tag.name}
|
||||
</code>
|
||||
</pre>
|
||||
<PreformattedCodeBlock>{gitCheckoutTagCommand}</PreformattedCodeBlock>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
import React from "react";
|
||||
import { WithTranslation, withTranslation } from "react-i18next";
|
||||
import { Branch } from "@scm-manager/ui-types";
|
||||
import { SubSubtitle } from "@scm-manager/ui-components";
|
||||
import { PreformattedCodeBlock, SubSubtitle } from "@scm-manager/ui-components";
|
||||
|
||||
type Props = WithTranslation & {
|
||||
branch: Branch;
|
||||
@@ -34,16 +34,15 @@ class HgBranchInformation extends React.Component<Props> {
|
||||
render() {
|
||||
const { branch, t } = this.props;
|
||||
|
||||
const hgFetchCommand = "hg pull";
|
||||
const hgCheckoutCommand = `hg update ${branch.name}`;
|
||||
|
||||
return (
|
||||
<div>
|
||||
<SubSubtitle>{t("scm-hg-plugin.information.fetch")}</SubSubtitle>
|
||||
<pre>
|
||||
<code>hg pull</code>
|
||||
</pre>
|
||||
<PreformattedCodeBlock>{hgFetchCommand}</PreformattedCodeBlock>
|
||||
<SubSubtitle>{t("scm-hg-plugin.information.checkout")}</SubSubtitle>
|
||||
<pre>
|
||||
<code>hg update {branch.name}</code>
|
||||
</pre>
|
||||
<PreformattedCodeBlock>{hgCheckoutCommand}</PreformattedCodeBlock>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
import React, { FC } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Tag } from "@scm-manager/ui-types";
|
||||
import { SubSubtitle } from "@scm-manager/ui-components";
|
||||
import { PreformattedCodeBlock, SubSubtitle } from "@scm-manager/ui-components";
|
||||
|
||||
type Props = {
|
||||
tag: Tag;
|
||||
@@ -34,12 +34,12 @@ type Props = {
|
||||
const HgTagInformation: FC<Props> = ({ tag }) => {
|
||||
const [t] = useTranslation("plugins");
|
||||
|
||||
const hgCheckoutTagCommand = `hg update ${tag.name}`;
|
||||
|
||||
return (
|
||||
<>
|
||||
<SubSubtitle>{t("scm-hg-plugin.information.checkoutTag")}</SubSubtitle>
|
||||
<pre>
|
||||
<code>hg update {tag.name}</code>
|
||||
</pre>
|
||||
<PreformattedCodeBlock>{hgCheckoutTagCommand}</PreformattedCodeBlock>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -24,7 +24,13 @@
|
||||
import React, { FC } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Repository } from "@scm-manager/ui-types";
|
||||
import { ErrorNotification, Loading, SubSubtitle, repositories } from "@scm-manager/ui-components";
|
||||
import {
|
||||
ErrorNotification,
|
||||
Loading,
|
||||
SubSubtitle,
|
||||
repositories,
|
||||
PreformattedCodeBlock,
|
||||
} from "@scm-manager/ui-components";
|
||||
import { useChangesets } from "@scm-manager/ui-api";
|
||||
|
||||
type Props = {
|
||||
@@ -46,53 +52,37 @@ const ProtocolInformation: FC<Props> = ({ repository }) => {
|
||||
|
||||
const emptyRepository = (data?._embedded?.changesets.length || 0) === 0;
|
||||
|
||||
const hgCloneCommand = `hg clone ${href}`;
|
||||
const hgCreateCommand =
|
||||
`hg init ${repository.name}\n` +
|
||||
`cd ${repository.name}\n` +
|
||||
'echo "[paths]" > .hg/hgrc\n' +
|
||||
`echo "default = ${href}` +
|
||||
'" >> .hg/hgrc\n' +
|
||||
`echo "# ${repository.name}` +
|
||||
'" > README.md\n' +
|
||||
"hg add README.md\n" +
|
||||
'hg commit -m "added readme"\n\n' +
|
||||
"hg push";
|
||||
const hgReplaceCommand =
|
||||
"# add the repository url as default to your .hg/hgrc e.g:\n" +
|
||||
`default = ${href}\n` +
|
||||
"# push to remote repository\n" +
|
||||
"hg push";
|
||||
|
||||
return (
|
||||
<div className="content">
|
||||
<ErrorNotification error={error} />
|
||||
<SubSubtitle>{t("scm-hg-plugin.information.clone")}</SubSubtitle>
|
||||
<pre>
|
||||
<code>hg clone {href}</code>
|
||||
</pre>
|
||||
<PreformattedCodeBlock>{hgCloneCommand}</PreformattedCodeBlock>
|
||||
{emptyRepository && (
|
||||
<>
|
||||
<SubSubtitle>{t("scm-hg-plugin.information.create")}</SubSubtitle>
|
||||
<pre>
|
||||
<code>
|
||||
hg init {repository.name}
|
||||
<br />
|
||||
cd {repository.name}
|
||||
<br />
|
||||
echo "[paths]" > .hg/hgrc
|
||||
<br />
|
||||
echo "default = {href}
|
||||
" >> .hg/hgrc
|
||||
<br />
|
||||
echo "# {repository.name}
|
||||
" > README.md
|
||||
<br />
|
||||
hg add README.md
|
||||
<br />
|
||||
hg commit -m "added readme"
|
||||
<br />
|
||||
<br />
|
||||
hg push
|
||||
<br />
|
||||
</code>
|
||||
</pre>
|
||||
<PreformattedCodeBlock>{hgCreateCommand}</PreformattedCodeBlock>
|
||||
</>
|
||||
)}
|
||||
<SubSubtitle>{t("scm-hg-plugin.information.replace")}</SubSubtitle>
|
||||
<pre>
|
||||
<code>
|
||||
# add the repository url as default to your .hg/hgrc e.g:
|
||||
<br />
|
||||
default = {href}
|
||||
<br />
|
||||
# push to remote repository
|
||||
<br />
|
||||
hg push
|
||||
</code>
|
||||
</pre>
|
||||
<PreformattedCodeBlock>{hgReplaceCommand}</PreformattedCodeBlock>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
import React from "react";
|
||||
import { withTranslation, WithTranslation } from "react-i18next";
|
||||
import { Repository } from "@scm-manager/ui-types";
|
||||
import { repositories, SubSubtitle } from "@scm-manager/ui-components";
|
||||
import { PreformattedCodeBlock, repositories, SubSubtitle } from "@scm-manager/ui-components";
|
||||
|
||||
type Props = WithTranslation & {
|
||||
repository: Repository;
|
||||
@@ -37,12 +37,13 @@ class ProtocolInformation extends React.Component<Props> {
|
||||
if (!href) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const svnCheckoutCommand = `svn checkout ${href}`;
|
||||
|
||||
return (
|
||||
<div className="content">
|
||||
<SubSubtitle>{t("scm-svn-plugin.information.checkout")}</SubSubtitle>
|
||||
<pre>
|
||||
<code>svn checkout {href}</code>
|
||||
</pre>
|
||||
<PreformattedCodeBlock>{svnCheckoutCommand}</PreformattedCodeBlock>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
64
scm-ui/ui-components/src/PreformattedCodeBlock.stories.tsx
Normal file
64
scm-ui/ui-components/src/PreformattedCodeBlock.stories.tsx
Normal file
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
import * as React from "react";
|
||||
import { storiesOf } from "@storybook/react";
|
||||
import styled from "styled-components";
|
||||
import PreformattedCodeBlock from "./PreformattedCodeBlock";
|
||||
import { SubSubtitle } from "./layout";
|
||||
|
||||
const Wrapper = styled.div``;
|
||||
|
||||
const longContent =
|
||||
"#!/bin/bash\n" +
|
||||
"\n" +
|
||||
"### For this hook to work you need the SCM CLI client (https://scm-manager.org/cli/)\n" +
|
||||
"### installed and connected to your SCM Server.\n" +
|
||||
"\n" +
|
||||
"BRANCH_NAME=$(git symbolic-ref --short HEAD)\n" +
|
||||
"COMMIT_MSG_FILE=`cat $1`\n" +
|
||||
"\n" +
|
||||
'scm repo commit-message-check aaa/ultimate-repo $BRANCH_NAME "$COMMIT_MSG_FILE"';
|
||||
|
||||
storiesOf("PreformattedCodeBlock", module)
|
||||
.addDecorator((storyFn) => <Wrapper className="m-6">{storyFn()}</Wrapper>)
|
||||
.add("Default", () => <PreformattedCodeBlock>git checkout main</PreformattedCodeBlock>)
|
||||
.add("With scrollbar", () => (
|
||||
<PreformattedCodeBlock>
|
||||
git remote add origin
|
||||
https://scm-manager-instance4.example.org:8081/scm/repo/my-new-namespace/LoremipsumdolorsitametconsetetursadipscingelitrseddiamnonumyeirmodtemporinviduntutlaboreetdoloremagnaaliquyameratseddiamvoluptuaAtveroeosetaccusametjustoduodoloresetearebumStetclitakasdgubergrennoseatakimatasanctusestLoremipsumdolorsitametLoremipsumdolorsitametconsetetursadipscingelitrseddiamnonumyeirmodtemporinviduntutlaboreetdoloremagnaaliquyameratseddiamvoluptuaAtveroeosetaccusametjustoduodoloresetearebumStetclitakasdgubergrennoseatakimatasanctusestLoremipsumdolorsitamet
|
||||
</PreformattedCodeBlock>
|
||||
))
|
||||
.add("Long content", () => <PreformattedCodeBlock>{longContent}</PreformattedCodeBlock>)
|
||||
.add("Combination", () => (
|
||||
<div className="content">
|
||||
<SubSubtitle>Clone the Repository</SubSubtitle>
|
||||
<PreformattedCodeBlock>git clone https://fancy-scm.url/scm/repo/test/scmm\n cd scmm</PreformattedCodeBlock>
|
||||
<SubSubtitle>Git hook for commit message validation</SubSubtitle>
|
||||
<PreformattedCodeBlock>{longContent}</PreformattedCodeBlock>
|
||||
<SubSubtitle>Get Remote Changes</SubSubtitle>
|
||||
<PreformattedCodeBlock>git fetch</PreformattedCodeBlock>
|
||||
<SubSubtitle>Switch Branch</SubSubtitle>
|
||||
<PreformattedCodeBlock>git checkout feature/something</PreformattedCodeBlock>
|
||||
</div>
|
||||
));
|
||||
67
scm-ui/ui-components/src/PreformattedCodeBlock.tsx
Normal file
67
scm-ui/ui-components/src/PreformattedCodeBlock.tsx
Normal file
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
import * as React from "react";
|
||||
import { FC, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import styled from "styled-components";
|
||||
import Button from "./buttons/Button";
|
||||
import copyToClipboard from "./CopyToClipboard";
|
||||
|
||||
type Props = {
|
||||
children: string;
|
||||
};
|
||||
|
||||
const TopRightButton = styled(Button)`
|
||||
position: absolute;
|
||||
display: none;
|
||||
height: inherit;
|
||||
top: 1.25em;
|
||||
right: 1.5em;
|
||||
`;
|
||||
|
||||
const Container = styled.div`
|
||||
&:hover > ${TopRightButton} {
|
||||
display: inline-block;
|
||||
}
|
||||
`;
|
||||
|
||||
const PreformattedCodeBlock: FC<Props> = ({ children }) => {
|
||||
const [t] = useTranslation("repos");
|
||||
const [copied, setCopied] = useState(false);
|
||||
|
||||
const copy = () => copyToClipboard(children).then(() => setCopied(true));
|
||||
|
||||
return (
|
||||
<Container className="is-relative">
|
||||
<pre>
|
||||
<code>{children}</code>
|
||||
</pre>
|
||||
<TopRightButton className="is-small" title={t("syntaxHighlighting.copyButton")} action={copy}>
|
||||
<i className={copied ? "fa fa-clipboard-check" : "fa fa-clipboard"} />
|
||||
</TopRightButton>
|
||||
</Container>
|
||||
);
|
||||
};
|
||||
|
||||
export default PreformattedCodeBlock;
|
||||
@@ -19277,6 +19277,235 @@ exports[`Storyshots Popover Link 1`] = `
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`Storyshots PreformattedCodeBlock Combination 1`] = `
|
||||
<div
|
||||
className="PreformattedCodeBlockstories__Wrapper-sc-exgqpp-0 m-6"
|
||||
>
|
||||
<div
|
||||
className="content"
|
||||
>
|
||||
<h3
|
||||
className="is-size-5"
|
||||
>
|
||||
Clone the Repository
|
||||
</h3>
|
||||
<div
|
||||
className="PreformattedCodeBlock__Container-sc-11slzrr-1 iISymu is-relative"
|
||||
>
|
||||
<pre>
|
||||
<code>
|
||||
git clone https://fancy-scm.url/scm/repo/test/scmm\\n cd scmm
|
||||
</code>
|
||||
</pre>
|
||||
<button
|
||||
className="button is-default PreformattedCodeBlock__TopRightButton-sc-11slzrr-0 dfZgVU is-small"
|
||||
onClick={[Function]}
|
||||
title="syntaxHighlighting.copyButton"
|
||||
type="button"
|
||||
>
|
||||
<span>
|
||||
|
||||
|
||||
<i
|
||||
className="fa fa-clipboard"
|
||||
/>
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
<h3
|
||||
className="is-size-5"
|
||||
>
|
||||
Git hook for commit message validation
|
||||
</h3>
|
||||
<div
|
||||
className="PreformattedCodeBlock__Container-sc-11slzrr-1 iISymu is-relative"
|
||||
>
|
||||
<pre>
|
||||
<code>
|
||||
#!/bin/bash
|
||||
|
||||
### For this hook to work you need the SCM CLI client (https://scm-manager.org/cli/)
|
||||
### installed and connected to your SCM Server.
|
||||
|
||||
BRANCH_NAME=$(git symbolic-ref --short HEAD)
|
||||
COMMIT_MSG_FILE=\`cat $1\`
|
||||
|
||||
scm repo commit-message-check aaa/ultimate-repo $BRANCH_NAME "$COMMIT_MSG_FILE"
|
||||
</code>
|
||||
</pre>
|
||||
<button
|
||||
className="button is-default PreformattedCodeBlock__TopRightButton-sc-11slzrr-0 dfZgVU is-small"
|
||||
onClick={[Function]}
|
||||
title="syntaxHighlighting.copyButton"
|
||||
type="button"
|
||||
>
|
||||
<span>
|
||||
|
||||
|
||||
<i
|
||||
className="fa fa-clipboard"
|
||||
/>
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
<h3
|
||||
className="is-size-5"
|
||||
>
|
||||
Get Remote Changes
|
||||
</h3>
|
||||
<div
|
||||
className="PreformattedCodeBlock__Container-sc-11slzrr-1 iISymu is-relative"
|
||||
>
|
||||
<pre>
|
||||
<code>
|
||||
git fetch
|
||||
</code>
|
||||
</pre>
|
||||
<button
|
||||
className="button is-default PreformattedCodeBlock__TopRightButton-sc-11slzrr-0 dfZgVU is-small"
|
||||
onClick={[Function]}
|
||||
title="syntaxHighlighting.copyButton"
|
||||
type="button"
|
||||
>
|
||||
<span>
|
||||
|
||||
|
||||
<i
|
||||
className="fa fa-clipboard"
|
||||
/>
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
<h3
|
||||
className="is-size-5"
|
||||
>
|
||||
Switch Branch
|
||||
</h3>
|
||||
<div
|
||||
className="PreformattedCodeBlock__Container-sc-11slzrr-1 iISymu is-relative"
|
||||
>
|
||||
<pre>
|
||||
<code>
|
||||
git checkout feature/something
|
||||
</code>
|
||||
</pre>
|
||||
<button
|
||||
className="button is-default PreformattedCodeBlock__TopRightButton-sc-11slzrr-0 dfZgVU is-small"
|
||||
onClick={[Function]}
|
||||
title="syntaxHighlighting.copyButton"
|
||||
type="button"
|
||||
>
|
||||
<span>
|
||||
|
||||
|
||||
<i
|
||||
className="fa fa-clipboard"
|
||||
/>
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`Storyshots PreformattedCodeBlock Default 1`] = `
|
||||
<div
|
||||
className="PreformattedCodeBlockstories__Wrapper-sc-exgqpp-0 m-6"
|
||||
>
|
||||
<div
|
||||
className="PreformattedCodeBlock__Container-sc-11slzrr-1 iISymu is-relative"
|
||||
>
|
||||
<pre>
|
||||
<code>
|
||||
git checkout main
|
||||
</code>
|
||||
</pre>
|
||||
<button
|
||||
className="button is-default PreformattedCodeBlock__TopRightButton-sc-11slzrr-0 dfZgVU is-small"
|
||||
onClick={[Function]}
|
||||
title="syntaxHighlighting.copyButton"
|
||||
type="button"
|
||||
>
|
||||
<span>
|
||||
|
||||
|
||||
<i
|
||||
className="fa fa-clipboard"
|
||||
/>
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`Storyshots PreformattedCodeBlock Long content 1`] = `
|
||||
<div
|
||||
className="PreformattedCodeBlockstories__Wrapper-sc-exgqpp-0 m-6"
|
||||
>
|
||||
<div
|
||||
className="PreformattedCodeBlock__Container-sc-11slzrr-1 iISymu is-relative"
|
||||
>
|
||||
<pre>
|
||||
<code>
|
||||
#!/bin/bash
|
||||
|
||||
### For this hook to work you need the SCM CLI client (https://scm-manager.org/cli/)
|
||||
### installed and connected to your SCM Server.
|
||||
|
||||
BRANCH_NAME=$(git symbolic-ref --short HEAD)
|
||||
COMMIT_MSG_FILE=\`cat $1\`
|
||||
|
||||
scm repo commit-message-check aaa/ultimate-repo $BRANCH_NAME "$COMMIT_MSG_FILE"
|
||||
</code>
|
||||
</pre>
|
||||
<button
|
||||
className="button is-default PreformattedCodeBlock__TopRightButton-sc-11slzrr-0 dfZgVU is-small"
|
||||
onClick={[Function]}
|
||||
title="syntaxHighlighting.copyButton"
|
||||
type="button"
|
||||
>
|
||||
<span>
|
||||
|
||||
|
||||
<i
|
||||
className="fa fa-clipboard"
|
||||
/>
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`Storyshots PreformattedCodeBlock With scrollbar 1`] = `
|
||||
<div
|
||||
className="PreformattedCodeBlockstories__Wrapper-sc-exgqpp-0 m-6"
|
||||
>
|
||||
<div
|
||||
className="PreformattedCodeBlock__Container-sc-11slzrr-1 iISymu is-relative"
|
||||
>
|
||||
<pre>
|
||||
<code>
|
||||
git remote add origin https://scm-manager-instance4.example.org:8081/scm/repo/my-new-namespace/LoremipsumdolorsitametconsetetursadipscingelitrseddiamnonumyeirmodtemporinviduntutlaboreetdoloremagnaaliquyameratseddiamvoluptuaAtveroeosetaccusametjustoduodoloresetearebumStetclitakasdgubergrennoseatakimatasanctusestLoremipsumdolorsitametLoremipsumdolorsitametconsetetursadipscingelitrseddiamnonumyeirmodtemporinviduntutlaboreetdoloremagnaaliquyameratseddiamvoluptuaAtveroeosetaccusametjustoduodoloresetearebumStetclitakasdgubergrennoseatakimatasanctusestLoremipsumdolorsitamet
|
||||
</code>
|
||||
</pre>
|
||||
<button
|
||||
className="button is-default PreformattedCodeBlock__TopRightButton-sc-11slzrr-0 dfZgVU is-small"
|
||||
onClick={[Function]}
|
||||
title="syntaxHighlighting.copyButton"
|
||||
type="button"
|
||||
>
|
||||
<span>
|
||||
|
||||
|
||||
<i
|
||||
className="fa fa-clipboard"
|
||||
/>
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`Storyshots Repositories/Annotate Default 1`] = `
|
||||
<div
|
||||
className="Annotatestories__Wrapper-sc-1fdvl94-0 ldNvIm box"
|
||||
|
||||
@@ -81,6 +81,7 @@ export { default as CreateTagModal } from "./modals/CreateTagModal";
|
||||
export { default as CardColumn } from "./CardColumn";
|
||||
export { default as CardColumnSmall } from "./CardColumnSmall";
|
||||
export { default as CommaSeparatedList } from "./CommaSeparatedList";
|
||||
export { default as PreformattedCodeBlock } from "./PreformattedCodeBlock";
|
||||
export { SplitAndReplace, Replacement } from "@scm-manager/ui-text";
|
||||
export { useShortcut } from "@scm-manager/ui-shortcuts";
|
||||
export { regExpPattern as changesetShortLinkRegex } from "./markdown/remarkChangesetShortLinkParser";
|
||||
|
||||
Reference in New Issue
Block a user