1- import React , { Component } from 'react' ;
1+ import React , { useState } from 'react' ;
22import { css } from 'emotion' ;
33
44import CopyToClipBoard from '../CopyToClipBoard' ;
@@ -11,86 +11,77 @@ import Tab from '../../muiComponents/Tab';
1111import { CommandContainer } from './styles' ;
1212import { Props , State } from './types' ;
1313
14- /* eslint react/prop-types:0 */
15- function TabContainer ( { children } ) : JSX . Element {
16- return (
17- < CommandContainer >
18- < Typography
19- className = { css `
20- padding : 0 ;
21- min-height : 170 ;
22- ` }
23- component = "div" >
24- { children }
25- </ Typography >
26- </ CommandContainer >
27- ) ;
28- }
14+ const RegistryInfoContent : React . FC < Props > = props => {
15+ const [ tabPosition , setTabPosition ] = useState < State [ 'tabPosition' ] > ( 0 ) ;
16+ const handleChange = ( event : React . ChangeEvent < { } > , tabPosition : number ) : void => {
17+ event . preventDefault ( ) ;
18+ setTabPosition ( tabPosition ) ;
19+ } ;
2920
30- class RegistryInfoContent extends Component < Props , State > {
31- public state = {
32- tabPosition : 0 ,
21+ const renderNpmTab = ( scope : string , registryUrl : string ) : JSX . Element => {
22+ return (
23+ < >
24+ < CopyToClipBoard text = { getCLISetConfigRegistry ( `${ NODE_MANAGER . npm } set` , scope , registryUrl ) } />
25+ < CopyToClipBoard text = { getCLISetRegistry ( `${ NODE_MANAGER . npm } adduser` , registryUrl ) } />
26+ < CopyToClipBoard text = { getCLIChangePassword ( NODE_MANAGER . npm , registryUrl ) } />
27+ </ >
28+ ) ;
3329 } ;
3430
35- public render ( ) : JSX . Element {
36- return < div > { this . renderTabs ( ) } </ div > ;
37- }
31+ const renderPnpmTab = ( scope : string , registryUrl : string ) : JSX . Element => {
32+ return (
33+ < >
34+ < CopyToClipBoard text = { getCLISetConfigRegistry ( `${ NODE_MANAGER . pnpm } set` , scope , registryUrl ) } />
35+ < CopyToClipBoard text = { getCLISetRegistry ( `${ NODE_MANAGER . pnpm } adduser` , registryUrl ) } />
36+ < CopyToClipBoard text = { getCLIChangePassword ( NODE_MANAGER . pnpm , registryUrl ) } />
37+ </ >
38+ ) ;
39+ } ;
3840
39- private handleChange = ( event : React . ChangeEvent < { } > , tabPosition : number ) => {
40- event . preventDefault ( ) ;
41- this . setState ( { tabPosition } ) ;
41+ const renderYarnTab = ( scope : string , registryUrl : string ) : JSX . Element => {
42+ return < CopyToClipBoard text = { getCLISetConfigRegistry ( `${ NODE_MANAGER . yarn } config set` , scope , registryUrl ) } /> ;
4243 } ;
4344
44- private renderTabs ( ) : JSX . Element {
45- const { scope, registryUrl } = this . props ;
46- const { tabPosition } = this . state ;
45+ const renderTabs = ( ) : JSX . Element => {
46+ const { scope, registryUrl } = props ;
4747
4848 return (
49- < React . Fragment >
49+ < >
5050 < Tabs
51+ data-testid = { 'tabs-el' }
5152 indicatorColor = "primary"
52- onChange = { this . handleChange }
53+ onChange = { handleChange }
5354 textColor = "primary"
5455 value = { tabPosition }
5556 variant = "fullWidth" >
56- < Tab label = { NODE_MANAGER . npm } />
57- < Tab label = { NODE_MANAGER . pnpm } />
58- < Tab label = { NODE_MANAGER . yarn } />
57+ < Tab data-testid = { 'npm-tab' } label = { NODE_MANAGER . npm } />
58+ < Tab data-testid = { 'pnpm-tab' } label = { NODE_MANAGER . pnpm } />
59+ < Tab data-testid = { 'yarn-tab' } label = { NODE_MANAGER . yarn } />
5960 </ Tabs >
60- { tabPosition === 0 && < TabContainer > { this . renderNpmTab ( scope , registryUrl ) } </ TabContainer > }
61- { tabPosition === 1 && < TabContainer > { this . renderPNpmTab ( scope , registryUrl ) } </ TabContainer > }
62- { tabPosition === 2 && < TabContainer > { this . renderYarnTab ( scope , registryUrl ) } </ TabContainer > }
63- </ React . Fragment >
61+ { tabPosition === 0 && < TabContainer > { renderNpmTab ( scope , registryUrl ) } </ TabContainer > }
62+ { tabPosition === 1 && < TabContainer > { renderPnpmTab ( scope , registryUrl ) } </ TabContainer > }
63+ { tabPosition === 2 && < TabContainer > { renderYarnTab ( scope , registryUrl ) } </ TabContainer > }
64+ </ >
6465 ) ;
65- }
66+ } ;
6667
67- private renderNpmTab ( scope : string , registryUrl : string ) : JSX . Element {
68+ /* eslint react/prop-types:0 */
69+ const TabContainer = ( { children } ) : JSX . Element => {
6870 return (
69- < React . Fragment >
70- < CopyToClipBoard text = { getCLISetConfigRegistry ( `${ NODE_MANAGER . npm } set` , scope , registryUrl ) } />
71- < CopyToClipBoard text = { getCLISetRegistry ( `${ NODE_MANAGER . npm } adduser` , registryUrl ) } />
72- < CopyToClipBoard text = { getCLIChangePassword ( NODE_MANAGER . npm , registryUrl ) } />
73- </ React . Fragment >
71+ < CommandContainer >
72+ < Typography
73+ className = { css `
74+ padding : 0 ;
75+ min-height : 170 ;
76+ ` }
77+ component = "div" >
78+ { children }
79+ </ Typography >
80+ </ CommandContainer >
7481 ) ;
75- }
76-
77- private renderPNpmTab ( scope : string , registryUrl : string ) : JSX . Element {
78- return (
79- < React . Fragment >
80- < CopyToClipBoard text = { getCLISetConfigRegistry ( `${ NODE_MANAGER . pnpm } set` , scope , registryUrl ) } />
81- < CopyToClipBoard text = { getCLISetRegistry ( `${ NODE_MANAGER . pnpm } adduser` , registryUrl ) } />
82- < CopyToClipBoard text = { getCLIChangePassword ( NODE_MANAGER . pnpm , registryUrl ) } />
83- </ React . Fragment >
84- ) ;
85- }
82+ } ;
8683
87- private renderYarnTab ( scope : string , registryUrl : string ) : JSX . Element {
88- return (
89- < React . Fragment >
90- < CopyToClipBoard text = { getCLISetConfigRegistry ( `${ NODE_MANAGER . yarn } config set` , scope , registryUrl ) } />
91- </ React . Fragment >
92- ) ;
93- }
94- }
84+ return < div > { renderTabs ( ) } </ div > ;
85+ } ;
9586
9687export default RegistryInfoContent ;
0 commit comments