-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4e7b319
commit 6d96007
Showing
10 changed files
with
161 additions
and
30 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/** | ||
* @prettier | ||
* @flow | ||
*/ | ||
|
||
import React, { Component } from 'react'; | ||
|
||
import type { IProps, IState } from './types'; | ||
import { CommandContainer } from './styles'; | ||
import CopyToClipBoard from '../CopyToClipBoard'; | ||
import Tabs from '@material-ui/core/Tabs/index'; | ||
import Tab from '@material-ui/core/Tab/index'; | ||
import Typography from '@material-ui/core/Typography/index'; | ||
|
||
import { getCLISetRegistry, getCLIChangePassword, getCLISetConfigRegistry } from '../../utils/cli-utils'; | ||
import { NODE_MANAGER } from '../../utils/constants'; | ||
|
||
/* eslint react/prop-types:0 */ | ||
function TabContainer({ children }) { | ||
return ( | ||
<CommandContainer> | ||
<Typography component={'div'} style={{ padding: 0, minHeight: 170 }}> | ||
{children} | ||
</Typography> | ||
</CommandContainer> | ||
); | ||
} | ||
|
||
class RegistryInfoContent extends Component<IProps, IState> { | ||
state = { | ||
tabPosition: 0, | ||
}; | ||
|
||
render() { | ||
return <div>{this.renderTabs()}</div>; | ||
} | ||
|
||
renderTabs() { | ||
const { scope, registryUrl } = this.props; | ||
const { tabPosition } = this.state; | ||
|
||
return ( | ||
<React.Fragment> | ||
<Tabs indicatorColor={'primary'} onChange={this.handleChange} textColor={'primary'} value={tabPosition} variant={'fullWidth'}> | ||
<Tab label={NODE_MANAGER.npm} /> | ||
<Tab label={NODE_MANAGER.pnpm} /> | ||
<Tab label={NODE_MANAGER.yarn} /> | ||
</Tabs> | ||
{tabPosition === 0 && <TabContainer>{this.renderNpmTab(scope, registryUrl)}</TabContainer>} | ||
{tabPosition === 1 && <TabContainer>{this.renderPNpmTab(scope, registryUrl)}</TabContainer>} | ||
{tabPosition === 2 && <TabContainer>{this.renderYarnTab(scope, registryUrl)}</TabContainer>} | ||
</React.Fragment> | ||
); | ||
} | ||
|
||
renderNpmTab(scope: string, registryUrl: string) { | ||
return ( | ||
<React.Fragment> | ||
<CopyToClipBoard text={getCLISetConfigRegistry(`${NODE_MANAGER.npm} set`, scope, registryUrl)} /> | ||
<CopyToClipBoard text={getCLISetRegistry(`${NODE_MANAGER.npm} adduser`, registryUrl)} /> | ||
<CopyToClipBoard text={getCLIChangePassword(NODE_MANAGER.npm, registryUrl)} /> | ||
</React.Fragment> | ||
); | ||
} | ||
|
||
renderPNpmTab(scope: string, registryUrl: string) { | ||
return ( | ||
<React.Fragment> | ||
<CopyToClipBoard text={getCLISetConfigRegistry(`${NODE_MANAGER.pnpm} set`, scope, registryUrl)} /> | ||
<CopyToClipBoard text={getCLISetRegistry(`${NODE_MANAGER.pnpm} adduser`, registryUrl)} /> | ||
<CopyToClipBoard text={getCLIChangePassword(NODE_MANAGER.pnpm, registryUrl)} /> | ||
</React.Fragment> | ||
); | ||
} | ||
|
||
renderYarnTab(scope: string, registryUrl: string) { | ||
return ( | ||
<React.Fragment> | ||
<CopyToClipBoard text={getCLISetConfigRegistry(`${NODE_MANAGER.yarn} config set`, scope, registryUrl)} /> | ||
</React.Fragment> | ||
); | ||
} | ||
|
||
handleChange = (event: any, tabPosition: number) => { | ||
event.preventDefault(); | ||
this.setState({ tabPosition }); | ||
}; | ||
} | ||
|
||
export default RegistryInfoContent; |
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,7 @@ | ||
import styled from 'react-emotion'; | ||
|
||
export const CommandContainer = styled.div` | ||
&& { | ||
padding-top: 20px; | ||
} | ||
`; |
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,13 @@ | ||
/** | ||
* @prettier | ||
* @flow | ||
*/ | ||
|
||
export interface IProps { | ||
scope: string; | ||
registryUrl: string; | ||
} | ||
|
||
export interface IState { | ||
tabPosition: number; | ||
} |
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,33 @@ | ||
/** | ||
* @prettier | ||
* @flow | ||
*/ | ||
|
||
export const copyToClipBoardUtility = (str: string) => (event: SyntheticEvent<HTMLElement>) => { | ||
event.preventDefault(); | ||
const node = document.createElement('div'); | ||
node.innerText = str; | ||
if (document.body) { | ||
document.body.appendChild(node); | ||
const range = document.createRange(); | ||
const selection = window.getSelection(); | ||
range.selectNodeContents(node); | ||
selection.removeAllRanges(); | ||
selection.addRange(range); | ||
document.execCommand('copy'); | ||
// $FlowFixMe | ||
document.body.removeChild(node); | ||
} | ||
}; | ||
|
||
export function getCLISetConfigRegistry(command: string, scope: string, registryUrl: string): string { | ||
return `${command} ${scope} registry ${registryUrl}`; | ||
} | ||
|
||
export function getCLISetRegistry(command: string, registryUrl: string): string { | ||
return `${command} --registry ${registryUrl}`; | ||
} | ||
|
||
export function getCLIChangePassword(command: string, registryUrl: string): string { | ||
return `${command} profile set password --registry ${registryUrl}`; | ||
} |
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,9 @@ | ||
export const TEXT = { | ||
CLIPBOARD_COPY: 'Copy to Clipboard', | ||
}; | ||
|
||
export const NODE_MANAGER = { | ||
npm: 'npm', | ||
yarn: 'yarn', | ||
pnpm: 'pnpm', | ||
}; |
2 changes: 1 addition & 1 deletion
2
test/unit/webui/components/__snapshots__/copyToClipBoard.spec.js.snap
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`<CopyToClipBoard /> component render the component 1`] = `"<p class=\\"css-1a0lalv eduq2bv0\\"><span class=\\"css-1m8aenu eduq2bv1\\">copy text</span><button tabindex=\\"0\\" class=\\"MuiButtonBase-root-14 MuiIconButton-root-8 css-56v3u0 eduq2bv2\\" type=\\"button\\" title=\\"Copy to Clipboard\\"><span class=\\"MuiIconButton-label-13\\"><svg class=\\"MuiSvgIcon-root-17\\" focusable=\\"false\\" viewBox=\\"0 0 24 24\\" aria-hidden=\\"true\\" role=\\"presentation\\"><path fill=\\"none\\" d=\\"M0 0h24v24H0z\\"></path><path d=\\"M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm-1 4l6 6v10c0 1.1-.9 2-2 2H7.99C6.89 23 6 22.1 6 21l.01-14c0-1.1.89-2 1.99-2h7zm-1 7h5.5L14 6.5V12z\\"></path></svg></span><span class=\\"MuiTouchRipple-root-26\\"></span></button></p>"`; | ||
exports[`<CopyToClipBoard /> component render the component 1`] = `"<div class=\\"css-1mta3t8 eduq2bv0\\"><span class=\\"css-1m8aenu eduq2bv1\\">copy text</span><button tabindex=\\"0\\" class=\\"MuiButtonBase-root-14 MuiIconButton-root-8 css-56v3u0 eduq2bv2\\" type=\\"button\\" title=\\"Copy to Clipboard\\"><span class=\\"MuiIconButton-label-13\\"><svg class=\\"MuiSvgIcon-root-17\\" focusable=\\"false\\" viewBox=\\"0 0 24 24\\" aria-hidden=\\"true\\" role=\\"presentation\\"><path fill=\\"none\\" d=\\"M0 0h24v24H0z\\"></path><path d=\\"M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm-1 4l6 6v10c0 1.1-.9 2-2 2H7.99C6.89 23 6 22.1 6 21l.01-14c0-1.1.89-2 1.99-2h7zm-1 7h5.5L14 6.5V12z\\"></path></svg></span><span class=\\"MuiTouchRipple-root-26\\"></span></button></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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`<Help /> component should render the component in default state 1`] = `"<div class=\\"MuiPaper-root-2 MuiPaper-elevation1-5 MuiPaper-rounded-3 MuiCard-root-1 css-ryznli e1vnhvvu0\\" id=\\"help-card\\"><div class=\\"MuiCardContent-root-29\\"><h2 class=\\"MuiTypography-root-30 MuiTypography-headline-35 MuiTypography-gutterBottom-48\\" id=\\"help-card__title\\">No Package Published Yet.</h2><p class=\\"MuiTypography-root-30 MuiTypography-body1-39 MuiTypography-colorTextSecondary-54 MuiTypography-gutterBottom-48 css-zg2fwz e1vnhvvu1\\">To publish your first package just:</p><aside class=\\"MuiTypography-root-30 MuiTypography-body2-38\\">1. Login</aside><p class=\\"css-1a0lalv eduq2bv0\\"><span class=\\"css-1m8aenu eduq2bv1\\">$ npm adduser --registry http://localhost</span><button tabindex=\\"0\\" class=\\"MuiButtonBase-root-69 MuiIconButton-root-63 css-56v3u0 eduq2bv2\\" type=\\"button\\" title=\\"Copy to Clipboard\\"><span class=\\"MuiIconButton-label-68\\"><svg class=\\"MuiSvgIcon-root-72\\" focusable=\\"false\\" viewBox=\\"0 0 24 24\\" aria-hidden=\\"true\\" role=\\"presentation\\"><path fill=\\"none\\" d=\\"M0 0h24v24H0z\\"></path><path d=\\"M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm-1 4l6 6v10c0 1.1-.9 2-2 2H7.99C6.89 23 6 22.1 6 21l.01-14c0-1.1.89-2 1.99-2h7zm-1 7h5.5L14 6.5V12z\\"></path></svg></span><span class=\\"MuiTouchRipple-root-81\\"></span></button></p><aside class=\\"MuiTypography-root-30 MuiTypography-body2-38\\">2. Publish</aside><p class=\\"css-1a0lalv eduq2bv0\\"><span class=\\"css-1m8aenu eduq2bv1\\">$ npm publish --registry http://localhost</span><button tabindex=\\"0\\" class=\\"MuiButtonBase-root-69 MuiIconButton-root-63 css-56v3u0 eduq2bv2\\" type=\\"button\\" title=\\"Copy to Clipboard\\"><span class=\\"MuiIconButton-label-68\\"><svg class=\\"MuiSvgIcon-root-72\\" focusable=\\"false\\" viewBox=\\"0 0 24 24\\" aria-hidden=\\"true\\" role=\\"presentation\\"><path fill=\\"none\\" d=\\"M0 0h24v24H0z\\"></path><path d=\\"M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm-1 4l6 6v10c0 1.1-.9 2-2 2H7.99C6.89 23 6 22.1 6 21l.01-14c0-1.1.89-2 1.99-2h7zm-1 7h5.5L14 6.5V12z\\"></path></svg></span><span class=\\"MuiTouchRipple-root-81\\"></span></button></p><aside class=\\"MuiTypography-root-30 MuiTypography-body2-38\\">3. Refresh this page.</aside></div><div class=\\"MuiCardActions-root-88\\"><a tabindex=\\"0\\" class=\\"MuiButtonBase-root-69 MuiButton-root-90 MuiButton-text-92 MuiButton-textPrimary-93 MuiButton-flat-95 MuiButton-flatPrimary-96 MuiButton-sizeSmall-113 MuiCardActions-action-89\\" role=\\"button\\" href=\\"https://verdaccio.org/docs/en/installation\\" target=\\"_blank\\"><span class=\\"MuiButton-label-91\\">Learn More</span><span class=\\"MuiTouchRipple-root-81\\"></span></a></div></div>"`; | ||
exports[`<Help /> component should render the component in default state 1`] = `"<div class=\\"MuiPaper-root-2 MuiPaper-elevation1-5 MuiPaper-rounded-3 MuiCard-root-1 css-ryznli e1vnhvvu0\\" id=\\"help-card\\"><div class=\\"MuiCardContent-root-29\\"><h2 class=\\"MuiTypography-root-30 MuiTypography-headline-35 MuiTypography-gutterBottom-48\\" id=\\"help-card__title\\">No Package Published Yet.</h2><p class=\\"MuiTypography-root-30 MuiTypography-body1-39 MuiTypography-colorTextSecondary-54 MuiTypography-gutterBottom-48 css-zg2fwz e1vnhvvu1\\">To publish your first package just:</p><aside class=\\"MuiTypography-root-30 MuiTypography-body2-38\\">1. Login</aside><div class=\\"css-1mta3t8 eduq2bv0\\"><span class=\\"css-1m8aenu eduq2bv1\\">$ npm adduser --registry http://localhost</span><button tabindex=\\"0\\" class=\\"MuiButtonBase-root-69 MuiIconButton-root-63 css-56v3u0 eduq2bv2\\" type=\\"button\\" title=\\"Copy to Clipboard\\"><span class=\\"MuiIconButton-label-68\\"><svg class=\\"MuiSvgIcon-root-72\\" focusable=\\"false\\" viewBox=\\"0 0 24 24\\" aria-hidden=\\"true\\" role=\\"presentation\\"><path fill=\\"none\\" d=\\"M0 0h24v24H0z\\"></path><path d=\\"M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm-1 4l6 6v10c0 1.1-.9 2-2 2H7.99C6.89 23 6 22.1 6 21l.01-14c0-1.1.89-2 1.99-2h7zm-1 7h5.5L14 6.5V12z\\"></path></svg></span><span class=\\"MuiTouchRipple-root-81\\"></span></button></div><aside class=\\"MuiTypography-root-30 MuiTypography-body2-38\\">2. Publish</aside><div class=\\"css-1mta3t8 eduq2bv0\\"><span class=\\"css-1m8aenu eduq2bv1\\">$ npm publish --registry http://localhost</span><button tabindex=\\"0\\" class=\\"MuiButtonBase-root-69 MuiIconButton-root-63 css-56v3u0 eduq2bv2\\" type=\\"button\\" title=\\"Copy to Clipboard\\"><span class=\\"MuiIconButton-label-68\\"><svg class=\\"MuiSvgIcon-root-72\\" focusable=\\"false\\" viewBox=\\"0 0 24 24\\" aria-hidden=\\"true\\" role=\\"presentation\\"><path fill=\\"none\\" d=\\"M0 0h24v24H0z\\"></path><path d=\\"M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm-1 4l6 6v10c0 1.1-.9 2-2 2H7.99C6.89 23 6 22.1 6 21l.01-14c0-1.1.89-2 1.99-2h7zm-1 7h5.5L14 6.5V12z\\"></path></svg></span><span class=\\"MuiTouchRipple-root-81\\"></span></button></div><aside class=\\"MuiTypography-root-30 MuiTypography-body2-38\\">3. Refresh this page.</aside></div><div class=\\"MuiCardActions-root-88\\"><a tabindex=\\"0\\" class=\\"MuiButtonBase-root-69 MuiButton-root-90 MuiButton-text-92 MuiButton-textPrimary-93 MuiButton-flat-95 MuiButton-flatPrimary-96 MuiButton-sizeSmall-113 MuiCardActions-action-89\\" role=\\"button\\" href=\\"https://verdaccio.org/docs/en/installation\\" target=\\"_blank\\"><span class=\\"MuiButton-label-91\\">Learn More</span><span class=\\"MuiTouchRipple-root-81\\"></span></a></div></div>"`; |