2019-02-03 17:23:33 +07:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
|
2019-06-20 19:37:28 +07:00
|
|
|
import { Props, State } from './types';
|
2019-02-03 17:23:33 +07:00
|
|
|
import { CommandContainer } from './styles';
|
|
|
|
import CopyToClipBoard from '../CopyToClipBoard';
|
2019-06-20 19:37:28 +07:00
|
|
|
import Tabs from '@material-ui/core/Tabs';
|
|
|
|
import Tab from '@material-ui/core/Tab';
|
|
|
|
import Typography from '@material-ui/core/Typography';
|
2019-02-03 17:23:33 +07:00
|
|
|
|
|
|
|
import { getCLISetRegistry, getCLIChangePassword, getCLISetConfigRegistry } from '../../utils/cli-utils';
|
|
|
|
import { NODE_MANAGER } from '../../utils/constants';
|
|
|
|
|
|
|
|
/* eslint react/prop-types:0 */
|
2019-06-25 05:01:13 +07:00
|
|
|
function TabContainer({ children }): JSX.Element {
|
2019-02-03 17:23:33 +07:00
|
|
|
return (
|
|
|
|
<CommandContainer>
|
2019-06-20 19:37:28 +07:00
|
|
|
<Typography component="div" style={{ padding: 0, minHeight: 170 }}>
|
2019-02-03 17:23:33 +07:00
|
|
|
{children}
|
|
|
|
</Typography>
|
|
|
|
</CommandContainer>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-06-20 19:37:28 +07:00
|
|
|
class RegistryInfoContent extends Component<Props, State> {
|
2019-06-25 04:03:21 +07:00
|
|
|
public state = {
|
2019-02-03 17:23:33 +07:00
|
|
|
tabPosition: 0,
|
|
|
|
};
|
|
|
|
|
2019-06-25 05:01:13 +07:00
|
|
|
public render(): JSX.Element {
|
2019-02-03 17:23:33 +07:00
|
|
|
return <div>{this.renderTabs()}</div>;
|
|
|
|
}
|
|
|
|
|
2019-06-25 05:54:32 +07:00
|
|
|
private handleChange = (event: React.ChangeEvent<{}>, tabPosition: number) => {
|
2019-06-25 05:01:13 +07:00
|
|
|
event.preventDefault();
|
|
|
|
this.setState({ tabPosition });
|
|
|
|
};
|
|
|
|
|
|
|
|
private renderTabs(): JSX.Element {
|
2019-02-03 17:23:33 +07:00
|
|
|
const { scope, registryUrl } = this.props;
|
|
|
|
const { tabPosition } = this.state;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<React.Fragment>
|
2019-06-20 19:37:28 +07:00
|
|
|
<Tabs indicatorColor="primary" onChange={this.handleChange} textColor="primary" value={tabPosition} variant="fullWidth">
|
2019-02-03 17:23:33 +07:00
|
|
|
<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>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-06-25 05:01:13 +07:00
|
|
|
private renderNpmTab(scope: string, registryUrl: string): JSX.Element {
|
2019-02-03 17:23:33 +07:00
|
|
|
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>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-06-25 05:01:13 +07:00
|
|
|
private renderPNpmTab(scope: string, registryUrl: string): JSX.Element {
|
2019-02-03 17:23:33 +07:00
|
|
|
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>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-06-25 05:01:13 +07:00
|
|
|
private renderYarnTab(scope: string, registryUrl: string): JSX.Element {
|
2019-02-03 17:23:33 +07:00
|
|
|
return (
|
|
|
|
<React.Fragment>
|
|
|
|
<CopyToClipBoard text={getCLISetConfigRegistry(`${NODE_MANAGER.yarn} config set`, scope, registryUrl)} />
|
|
|
|
</React.Fragment>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default RegistryInfoContent;
|