Skip to content

Commit d764432

Browse files
committed
generalized label removed inline function
1 parent 3cac0ab commit d764432

File tree

1 file changed

+47
-28
lines changed

1 file changed

+47
-28
lines changed

src/components/gitOps/GitOpsConfiguration.tsx

Lines changed: 47 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -487,12 +487,51 @@ class GitOpsConfiguration extends Component<GitOpsProps, GitOpsState> {
487487
)
488488
}
489489

490-
const renderInputLabel = (label: string, link: string, linkText: string) => {
490+
const getInputFieldlabelAndlink = (inputName): { label: string; link: string; linkText: string } => {
491+
let fieldLable = {
492+
label: '',
493+
link: '',
494+
linkText: '',
495+
}
496+
switch (inputName) {
497+
case 'workspaceID':
498+
return {
499+
...fieldLable,
500+
label: 'Bitbucket Workspace ID',
501+
link: GitLink.BITBUCKET_WORKSPACE,
502+
linkText: '(How to create workspace in bitbucket?)',
503+
}
504+
case 'groupID':
505+
return {
506+
...fieldLable,
507+
label: LinkAndLabelSpec[this.state.providerTab]['label'],
508+
link: LinkAndLabelSpec[this.state.providerTab]['link'],
509+
linkText: LinkAndLabelSpec[this.state.providerTab]['linkText'],
510+
}
511+
case 'token': {
512+
return {
513+
...fieldLable,
514+
label:
515+
this.state.providerTab === GitProvider.AZURE_DEVOPS
516+
? 'Azure DevOps Access Token '
517+
: 'Personal Access Token ',
518+
link: DOCUMENTATION.GLOBAL_CONFIG_GIT_ACCESS_LINK,
519+
linkText: '(Check permissions required for PAT)',
520+
}
521+
}
522+
}
523+
}
524+
525+
const renderInputLabel = (inputName: string) => {
491526
return (
492527
<div className="flex">
493-
<span className="dc__required-field">{label}</span>&nbsp;
494-
<a target="_blank" href={link} className="cursor fs-13 onlink ml-4">
495-
{linkText}
528+
<span className="dc__required-field">{getInputFieldlabelAndlink(inputName).label}</span>&nbsp;
529+
<a
530+
target="_blank"
531+
href={getInputFieldlabelAndlink(inputName).link}
532+
className="cursor fs-13 onlink ml-4"
533+
>
534+
{getInputFieldlabelAndlink(inputName).linkText}
496535
</a>
497536
</div>
498537
)
@@ -638,13 +677,7 @@ class GitOpsConfiguration extends Component<GitOpsProps, GitOpsState> {
638677
{this.state.providerTab === GitProvider.BITBUCKET_CLOUD && (
639678
<CustomInput
640679
name="workspaceID"
641-
label={() =>
642-
renderInputLabel(
643-
'Bitbucket Workspace ID',
644-
GitLink.BITBUCKET_WORKSPACE,
645-
'(How to create workspace in bitbucket?)',
646-
)
647-
}
680+
label={renderInputLabel.bind(this, 'workspaceID')}
648681
value={this.state.form.bitBucketWorkspaceId}
649682
onChange={(event) => this.handleChange(event, 'bitBucketWorkspaceId')}
650683
error={this.state.isError.bitBucketWorkspaceId}
@@ -658,13 +691,7 @@ class GitOpsConfiguration extends Component<GitOpsProps, GitOpsState> {
658691
<div className="mt-16">
659692
<CustomInput
660693
name="groupID"
661-
label={() =>
662-
renderInputLabel(
663-
LinkAndLabelSpec[this.state.providerTab]['label'],
664-
LinkAndLabelSpec[this.state.providerTab]['link'],
665-
LinkAndLabelSpec[this.state.providerTab]['linkText'],
666-
)
667-
}
694+
label={renderInputLabel.bind(this, 'groupID')}
668695
value={this.state.form[key]}
669696
tabIndex={2}
670697
error={this.state.isError[key]}
@@ -730,16 +757,8 @@ class GitOpsConfiguration extends Component<GitOpsProps, GitOpsState> {
730757
</div>
731758
<div>
732759
<CustomInput
733-
name="Enter token"
734-
label={() =>
735-
renderInputLabel(
736-
this.state.providerTab === GitProvider.AZURE_DEVOPS
737-
? 'Azure DevOps Access Token '
738-
: 'Personal Access Token ',
739-
DOCUMENTATION.GLOBAL_CONFIG_GIT_ACCESS_LINK,
740-
'(Check permissions required for PAT)',
741-
)
742-
}
760+
name="token"
761+
label={renderInputLabel.bind(this, 'token')}
743762
value={this.state.form.token}
744763
onChange={(event) => this.handleChange(event, 'token')}
745764
tabIndex={4}

0 commit comments

Comments
 (0)