This repository has been archived by the owner on Apr 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce basic form fields handling Add @patternfly/react-icons to allow for using icons
- Loading branch information
Jiri Tomasek
committed
Feb 14, 2019
1 parent
667148c
commit d049a44
Showing
7 changed files
with
278 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
import React, { Component } from 'react'; | ||
import { | ||
Form, | ||
FormGroup, | ||
Grid, | ||
GridItem, | ||
TextInput, | ||
PageSectionVariants, | ||
TextContent, | ||
Text | ||
} from '@patternfly/react-core'; | ||
|
||
import RedHatAccountFields from './RedHatAccountFields'; | ||
import PageSection from '../ui/PageSection'; | ||
import PullSecretFields from './PullSecretFields'; | ||
|
||
interface FormState { | ||
clusterName: string; | ||
DNSDomain: string; | ||
username: string; | ||
password: string; | ||
pullSecret: string; | ||
} | ||
|
||
export interface CreateClusterFormState { | ||
providePullSecret: boolean; | ||
form: FormState; | ||
} | ||
|
||
class CreateClusterForm extends Component<{}, CreateClusterFormState> { | ||
state: CreateClusterFormState = { | ||
providePullSecret: false, | ||
form: { | ||
clusterName: '', | ||
DNSDomain: '', | ||
username: '', | ||
password: '', | ||
pullSecret: '' | ||
} | ||
}; | ||
|
||
updateFormState = (field: string, value: string) => | ||
this.setState(prevState => ({ | ||
...prevState, | ||
form: { ...prevState.form, [field]: value } | ||
})); | ||
|
||
handleClusterNameChange = (value: string) => { | ||
this.updateFormState('clusterName', value); | ||
}; | ||
handleDNSDomainChange = (value: string) => { | ||
this.updateFormState('DNSDomain', value); | ||
}; | ||
handleUsernameChange = (value: string) => { | ||
this.updateFormState('username', value); | ||
}; | ||
handlePasswordChange = (value: string) => { | ||
this.updateFormState('password', value); | ||
}; | ||
handlePullSecretChange = (value: string) => { | ||
this.updateFormState('pullSecret', value); | ||
}; | ||
|
||
render(): JSX.Element { | ||
const { | ||
providePullSecret, | ||
form: { clusterName, DNSDomain, username, password, pullSecret } | ||
} = this.state; | ||
return ( | ||
<PageSection variant={PageSectionVariants.light} isMain> | ||
<Grid gutter="md"> | ||
<GridItem span={12} md={10} lg={6}> | ||
<TextContent> | ||
<Text component="h1">Define Cluster</Text> | ||
</TextContent> | ||
<Form> | ||
<FormGroup | ||
label="Cluster name" | ||
fieldId="create-cluster-cluster-name" | ||
helperText="Please provide cluster name" | ||
isRequired | ||
> | ||
<TextInput | ||
type="text" | ||
id="create-cluster-cluster-name" | ||
name="clusterName" | ||
aria-describedby="create-cluster-cluster-name-helper" | ||
value={clusterName} | ||
onChange={this.handleClusterNameChange} | ||
isRequired | ||
/> | ||
</FormGroup> | ||
<FormGroup | ||
label="Base DNS domain" | ||
fieldId="create-cluster-base-dns-domain" | ||
isRequired | ||
> | ||
<TextInput | ||
type="text" | ||
id="create-cluster-base-dns-domain" | ||
name="DNSDomain" | ||
aria-describedby="create-cluster-base-dns-domain-helper" | ||
value={DNSDomain} | ||
onChange={this.handleDNSDomainChange} | ||
isRequired | ||
/> | ||
</FormGroup> | ||
<TextContent> | ||
<Text component="h2">Connect to Red Hat Account </Text> | ||
</TextContent> | ||
{providePullSecret ? ( | ||
<PullSecretFields | ||
onProvideCredentials={() => | ||
this.setState({ providePullSecret: false }) | ||
} | ||
handlePullSecretChange={this.handlePullSecretChange} | ||
pullSecret={pullSecret} | ||
/> | ||
) : ( | ||
<RedHatAccountFields | ||
onProvidePullSecret={() => | ||
this.setState({ providePullSecret: true }) | ||
} | ||
handleUsernameChange={this.handleUsernameChange} | ||
handlePasswordChange={this.handlePasswordChange} | ||
username={username} | ||
password={password} | ||
/> | ||
)} | ||
</Form> | ||
</GridItem> | ||
</Grid> | ||
</PageSection> | ||
); | ||
} | ||
} | ||
export default CreateClusterForm; |
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,47 @@ | ||
import React, { FC, Fragment } from 'react'; | ||
import { FormGroup, TextArea, TextContent, Text } from '@patternfly/react-core'; | ||
|
||
import ExternalLink from '../ui/ExternalLink'; | ||
|
||
interface PullSecretFieldsProps { | ||
onProvideCredentials: () => void; | ||
handlePullSecretChange: (value: string) => void; | ||
pullSecret: string; | ||
} | ||
|
||
const PullSecretFields: FC<PullSecretFieldsProps> = ({ | ||
onProvideCredentials, | ||
handlePullSecretChange, | ||
pullSecret | ||
}: PullSecretFieldsProps): JSX.Element => ( | ||
<Fragment> | ||
<TextContent> | ||
<Text component="p"> | ||
Provide your Red Hat Account Pull Secret from{' '} | ||
<ExternalLink href="https://try.openshift.com/"> | ||
try.openshift.com | ||
</ExternalLink>{' '} | ||
to download necessary resources. You can also{' '} | ||
<Text component="a" onClick={onProvideCredentials}> | ||
provide your credentials | ||
</Text>{' '} | ||
instead. | ||
</Text> | ||
</TextContent> | ||
<FormGroup | ||
label="Pull secret" | ||
fieldId="create-cluster-pull-secret" | ||
isRequired | ||
> | ||
<TextArea | ||
id="create-cluster-pull-secret" | ||
name="pullSecret" | ||
value={pullSecret} | ||
onChange={handlePullSecretChange} | ||
aria-label="Pull secret" | ||
isRequired | ||
/> | ||
</FormGroup> | ||
</Fragment> | ||
); | ||
export default PullSecretFields; |
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,65 @@ | ||
import React, { FC, Fragment } from 'react'; | ||
import { | ||
FormGroup, | ||
TextInput, | ||
TextContent, | ||
Text | ||
} from '@patternfly/react-core'; | ||
|
||
import ExternalLink from '../ui/ExternalLink'; | ||
|
||
interface RedHatAccountFieldsProps { | ||
onProvidePullSecret: () => void; | ||
handleUsernameChange: (value: string) => void; | ||
handlePasswordChange: (value: string) => void; | ||
username: string; | ||
password: string; | ||
} | ||
|
||
const RedHatAccountFields: FC<RedHatAccountFieldsProps> = ({ | ||
onProvidePullSecret, | ||
handleUsernameChange, | ||
handlePasswordChange, | ||
username, | ||
password | ||
}: RedHatAccountFieldsProps): JSX.Element => ( | ||
<Fragment> | ||
<TextContent> | ||
<Text component="p"> | ||
Provide your Red Hat Account credentials to download necessary resources | ||
from{' '} | ||
<ExternalLink href="https://try.openshift.com/"> | ||
try.openshift.com | ||
</ExternalLink>{' '} | ||
. You can also{' '} | ||
<Text component="a" onClick={onProvidePullSecret}> | ||
provide a Pull Secret | ||
</Text>{' '} | ||
instead. | ||
</Text> | ||
</TextContent> | ||
<FormGroup label="Username" fieldId="create-cluster-username" isRequired> | ||
<TextInput | ||
type="text" | ||
id="create-cluster-username" | ||
name="username" | ||
aria-describedby="create-cluster-username-helper" | ||
value={username} | ||
onChange={handleUsernameChange} | ||
isRequired | ||
/> | ||
</FormGroup> | ||
<FormGroup label="Password" fieldId="create-cluster-password" isRequired> | ||
<TextInput | ||
type="text" | ||
id="create-cluster-password-domain" | ||
name="password" | ||
aria-describedby="create-cluster-password-helper" | ||
value={password} | ||
onChange={handlePasswordChange} | ||
isRequired | ||
/> | ||
</FormGroup> | ||
</Fragment> | ||
); | ||
export default RedHatAccountFields; |
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,19 @@ | ||
import React, { FC, ReactNode } from 'react'; | ||
import { Text } from '@patternfly/react-core'; | ||
import { ExternalLinkAltIcon } from '@patternfly/react-icons'; | ||
|
||
interface ExternalLinkProps { | ||
href: string; | ||
children?: ReactNode; | ||
} | ||
const ExternalLink: FC<ExternalLinkProps> = ({ | ||
href, | ||
children, | ||
...rest | ||
}: ExternalLinkProps): JSX.Element => ( | ||
<Text component="a" href={href} target="_blank" {...rest}> | ||
{children ? children : href}{' '} | ||
<ExternalLinkAltIcon color="rgb(0, 123, 186)" /> | ||
</Text> | ||
); | ||
export default ExternalLink; |
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