forked from syndesisio/syndesis-react
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConnectionDetailsForm.tsx
171 lines (155 loc) · 4.67 KB
/
ConnectionDetailsForm.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
import { Alert, Button, Card } from 'patternfly-react';
import * as React from 'react';
import { Container, Loader, PageSection } from '../Layout';
import { toTestId } from '../utils';
import './ConnectionDetailsForm.css';
export interface IConnectionDetailsValidationResult {
message: string;
type: 'error' | 'success';
}
export interface IConnectionDetailsFormProps {
/**
* The localized text for the cancel button.
*/
i18nCancelLabel: string;
/**
* The localized text for the edit button.
*/
i18nEditLabel: string;
/**
* The localized text for the save button.
*/
i18nSaveLabel: string;
/**
* The localized text of the form title.
*/
i18nTitle: string;
/**
* The localized text for the validate button.
*/
i18nValidateLabel: string;
/**
* `true` if all form fields have valid values.
*/
isValid: boolean;
/**
* `true` if the parent is doing some work and this form should disable user input.
*/
isWorking: boolean;
/**
* Form level validationResults
*/
validationResults: IConnectionDetailsValidationResult[];
/**
* The callback fired when submitting the form.
* @param e
*/
handleSubmit: (e?: any) => void;
/**
* The callback for when the validate button is clicked.
*/
onValidate: () => void;
/**
* `true` when the connection details are being edited.
*/
isEditing: boolean;
/**
* The callback for editing has been canceled.
*/
onCancelEditing: () => void;
/**
* The callback for start editing.
*/
onStartEditing: () => void;
}
export class ConnectionDetailsForm extends React.Component<
IConnectionDetailsFormProps
> {
public static defaultProps = {
validationResults: [],
};
public render() {
return (
<PageSection>
<Container>
<div className="row row-cards-pf">
<Card>
<Card.Heading>
<Card.Title>{this.props.i18nTitle}</Card.Title>
</Card.Heading>
<Card.Body>
<form
className="required-pf"
role="form"
onSubmit={this.props.handleSubmit}
>
{this.props.validationResults.map((e, idx) => (
<Alert key={idx} type={e.type}>
{e.message}
</Alert>
))}
{this.props.children}
<div>
{this.props.isEditing ? (
<Button
data-testid={`${toTestId(
'ConnectionDetailsForm',
'validate-button'
)}`}
bsStyle="default"
disabled={this.props.isWorking || !this.props.isValid}
onClick={this.props.onValidate}
>
{this.props.isWorking ? (
<Loader size={'sm'} inline={true} />
) : null}
{this.props.i18nValidateLabel}
</Button>
) : (
<Button
data-testid={`${toTestId(
'ConnectionDetailsForm',
'edit-button'
)}`}
bsStyle="primary"
onClick={this.props.onStartEditing}
>
{this.props.i18nEditLabel}
</Button>
)}
</div>
</form>
</Card.Body>
<Card.Footer>
<Button
data-testid={`${toTestId(
'ConnectionDetailsForm',
'cancel-button'
)}`}
bsStyle="default"
className="connection-details-form__editButton"
disabled={this.props.isWorking}
onClick={this.props.onCancelEditing}
>
{this.props.i18nCancelLabel}
</Button>
<Button
data-testid={`${toTestId(
'ConnectionDetailsForm',
'save-button'
)}`}
bsStyle="primary"
className="connection-details-form__editButton"
disabled={this.props.isWorking || !this.props.isValid}
onClick={this.props.handleSubmit}
>
{this.props.i18nSaveLabel}
</Button>
</Card.Footer>
</Card>
</div>
</Container>
</PageSection>
);
}
}