This repository was archived by the owner on Jul 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 200
/
Copy pathConnectionDetailsForm.tsx
185 lines (169 loc) · 4.46 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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
import {
Alert,
Button,
Card,
CardBody,
CardFooter,
CardHeader,
Form,
Title,
} from '@patternfly/react-core';
import * as React from 'react';
import { Container, Loader, PageSection } from '../Layout';
import { ERROR, WARNING } from '../Shared/models';
import './ConnectionDetailsForm.css';
export interface IConnectionDetailsValidationResult {
message: string;
type: 'error' | 'success' | 'info';
}
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;
/**
* `true` if the connector has configuration fields, false if there are none
*/
hasProperties: 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 const ConnectionDetailsForm: React.FunctionComponent<IConnectionDetailsFormProps> = ({
children,
i18nCancelLabel,
i18nEditLabel,
i18nSaveLabel,
i18nTitle,
i18nValidateLabel,
isValid,
isWorking,
hasProperties,
validationResults,
handleSubmit,
onValidate,
isEditing,
onCancelEditing,
onStartEditing,
}) => (
<PageSection>
<Container>
<div className="row row-cards-pf">
<Card>
<CardHeader>
<Title size="2xl">{i18nTitle}</Title>
</CardHeader>
<CardBody>
<Form
isHorizontal={true}
data-testid={'connection-details-form'}
onSubmit={handleSubmit}
>
{validationResults.map((e, idx) => (
<Alert
title={e.message}
key={idx}
type={e.type === ERROR ? WARNING : e.type}
/>
))}
{children}
<div>
{isEditing ? (
<Button
data-testid={'connection-details-form-validate-button'}
variant="secondary"
disabled={isWorking || !isValid}
onClick={onValidate}
>
{isWorking ? <Loader size={'sm'} inline={true} /> : null}
{i18nValidateLabel}
</Button>
) : (
<>
{hasProperties && (
<Button
data-testid={'connection-details-form-edit-button'}
variant="primary"
onClick={onStartEditing}
>
{i18nEditLabel}
</Button>
)}
</>
)}
</div>
</Form>
</CardBody>
{isEditing && (
<CardFooter>
<Button
data-testid={'connection-details-form-cancel-button'}
variant="secondary"
className="connection-details-form__editButton"
disabled={isWorking}
onClick={onCancelEditing}
>
{i18nCancelLabel}
</Button>
<Button
data-testid={'connection-details-form-save-button'}
variant="primary"
className="connection-details-form__editButton"
disabled={isWorking || !isValid}
onClick={handleSubmit}
>
{i18nSaveLabel}
</Button>
</CardFooter>
)}
</Card>
</div>
</Container>
</PageSection>
);