Skip to content
This repository was archived by the owner on Apr 28, 2020. It is now read-only.

Commit 5e0862c

Browse files
rawagnersuomiy
authored andcommitted
Ability to specify if form field labels should be shown (#290)
1 parent 8551cbd commit 5e0862c

File tree

9 files changed

+33
-6
lines changed

9 files changed

+33
-6
lines changed

src/components/CreateDeviceRow/CreateDeviceRow.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export class CreateDeviceRow extends React.Component {
3333
actions={actions}
3434
onFormChange={this.onFormChange}
3535
columnSizes={columnSizes}
36+
showLabels={false}
3637
/>
3738
);
3839
}

src/components/CreateDeviceRow/tests/__snapshots__/CreateDeviceRow.test.js.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,6 @@ exports[`<CreateDeviceRow /> renders correctly 1`] = `
4343
}
4444
}
4545
onFormChange={[Function]}
46+
showLabels={false}
4647
/>
4748
`;

src/components/Dialog/CloneDialog/tests/__snapshots__/CloneDialog.test.js.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ exports[`<CloneDialog /> renders correctly 1`] = `
122122
horizontal={true}
123123
labelSize={2}
124124
onFormChange={[Function]}
125+
showLabels={true}
125126
textPosition="text-right"
126127
/>
127128
</div>

src/components/Form/FormFactory.js

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,16 @@ const getLabel = field =>
188188
</React.Fragment>
189189
);
190190

191-
const getFormGroups = ({ fields, fieldsValues, onFormChange, textPosition, labelSize, controlSize, horizontal }) =>
191+
const getFormGroups = ({
192+
fields,
193+
fieldsValues,
194+
onFormChange,
195+
textPosition,
196+
showLabels,
197+
labelSize,
198+
controlSize,
199+
horizontal,
200+
}) =>
192201
Object.keys(fields)
193202
.filter(key => fields[key] && (!fields[key].isVisible || fields[key].isVisible(fieldsValues)))
194203
.map(key => {
@@ -216,7 +225,7 @@ const getFormGroups = ({ fields, fieldsValues, onFormChange, textPosition, label
216225

217226
let label;
218227

219-
if (field.title) {
228+
if (showLabels && field.title) {
220229
if (horizontal) {
221230
label = (
222231
<Col sm={labelSize} className={textPosition}>
@@ -253,11 +262,11 @@ const getFormGroups = ({ fields, fieldsValues, onFormChange, textPosition, label
253262
);
254263
});
255264

256-
export const InlineFormFactory = ({ fields, fieldsValues, onFormChange }) =>
257-
getFormGroups({ fields, fieldsValues, onFormChange, horizontal: true });
265+
export const InlineFormFactory = ({ fields, fieldsValues, onFormChange, showLabels }) =>
266+
getFormGroups({ fields, fieldsValues, onFormChange, horizontal: true, showLabels });
258267

259-
export const ListFormFactory = ({ fields, fieldsValues, onFormChange, actions, columnSizes }) => {
260-
const formGroups = getFormGroups({ fields, fieldsValues, onFormChange });
268+
export const ListFormFactory = ({ fields, fieldsValues, onFormChange, actions, columnSizes, showLabels }) => {
269+
const formGroups = getFormGroups({ fields, fieldsValues, onFormChange, showLabels });
261270
const form = formGroups.map((formGroup, index) => (
262271
<Col
263272
key={`col-${index}`}
@@ -278,12 +287,17 @@ export const ListFormFactory = ({ fields, fieldsValues, onFormChange, actions, c
278287
);
279288
};
280289

290+
ListFormFactory.defaultProps = {
291+
showLabels: true,
292+
};
293+
281294
ListFormFactory.propTypes = {
282295
fields: PropTypes.object.isRequired,
283296
fieldsValues: PropTypes.object.isRequired,
284297
onFormChange: PropTypes.func.isRequired,
285298
actions: PropTypes.object.isRequired,
286299
columnSizes: PropTypes.object.isRequired,
300+
showLabels: PropTypes.bool,
287301
};
288302

289303
export const FormFactory = ({
@@ -295,6 +309,7 @@ export const FormFactory = ({
295309
controlSize,
296310
formClassName,
297311
horizontal,
312+
showLabels,
298313
}) => {
299314
const formGroups = getFormGroups({
300315
fields,
@@ -304,6 +319,7 @@ export const FormFactory = ({
304319
labelSize,
305320
controlSize,
306321
horizontal,
322+
showLabels,
307323
});
308324
return (
309325
<Form horizontal={horizontal} className={formClassName}>
@@ -318,6 +334,7 @@ FormFactory.defaultProps = {
318334
controlSize: 5,
319335
formClassName: undefined,
320336
horizontal: true,
337+
showLabels: true,
321338
};
322339

323340
FormFactory.propTypes = {
@@ -329,4 +346,5 @@ FormFactory.propTypes = {
329346
controlSize: PropTypes.number,
330347
formClassName: PropTypes.string,
331348
horizontal: PropTypes.bool,
349+
showLabels: PropTypes.bool,
332350
};

src/components/Form/tests/__snapshots__/FormFactory.test.js.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ exports[`<FormFactory /> renders correctly 1`] = `
122122
horizontal={true}
123123
labelSize={3}
124124
onFormChange={[MockFunction]}
125+
showLabels={true}
125126
textPosition="text-right"
126127
>
127128
<Form

src/components/VmConsoles/tests/__snapshots__/DesktopViewerSelector.test.js.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ exports[`<DesktopViewerSelector /> renders correctly 1`] = `
3838
horizontal={true}
3939
labelSize={3}
4040
onFormChange={[Function]}
41+
showLabels={true}
4142
textPosition="text-right"
4243
/>
4344
<RdpServiceNotConfigured

src/components/Wizard/CreateVmWizard/tests/__snapshots__/BasicSettingsTab.test.js.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ exports[`<BasicSettingsTab /> for Create VM Template renders correctly 1`] = `
360360
horizontal={true}
361361
labelSize={3}
362362
onFormChange={[Function]}
363+
showLabels={true}
363364
textPosition="text-right"
364365
/>
365366
`;
@@ -724,6 +725,7 @@ exports[`<BasicSettingsTab /> renders correctly 1`] = `
724725
horizontal={true}
725726
labelSize={3}
726727
onFormChange={[Function]}
728+
showLabels={true}
727729
textPosition="text-right"
728730
/>
729731
`;

src/components/Wizard/CreateVmWizard/tests/__snapshots__/NetworksTab.test.js.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ exports[`<NetworksTab /> renders correctly 1`] = `
100100
horizontal={true}
101101
labelSize={2}
102102
onFormChange={[Function]}
103+
showLabels={true}
103104
textPosition="text-left"
104105
/>
105106
</Fragment>

src/components/Wizard/CreateVmWizard/tests/__snapshots__/StorageTab.test.js.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ exports[`<StorageTab /> renders correctly 1`] = `
107107
horizontal={true}
108108
labelSize={2}
109109
onFormChange={[Function]}
110+
showLabels={true}
110111
textPosition="text-left"
111112
/>
112113
</Fragment>

0 commit comments

Comments
 (0)