Skip to content
This repository was archived by the owner on Feb 22, 2022. It is now read-only.

Commit ebf9dab

Browse files
committed
Fixes #63 Preset selection
Create preset selection with buttons Allow compact and large preset selection ToggleGroup is not used as this not allow easy alignment for the non-compact format to be used in the Wizard
1 parent eb3c6d7 commit ebf9dab

File tree

6 files changed

+156
-7
lines changed

6 files changed

+156
-7
lines changed

src/components/Configuration.jsx

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,17 @@ import {
88
} from '@patternfly/react-core';
99

1010
import "./Configuration.scss";
11+
import PresetSelection from './PresetSelection';
1112

1213
export default class Configuration extends React.Component {
1314
constructor(props) {
1415
super(props);
1516
this.state = {
17+
preset: "unknown",
1618
cpus: 0,
1719
memory: 0,
18-
"disk-size": 0,
19-
"consent-telemetry": false,
20+
'disk-size': 0,
21+
'consent-telemetry': false,
2022
'disk-size': 0,
2123
};
2224

@@ -52,7 +54,7 @@ export default class Configuration extends React.Component {
5254
render() {
5355
return (
5456
<div>
55-
<Form isHorizontal isWidthLimited>
57+
<Form isHorizontal>
5658
<FormGroup fieldId='settings-cpu' label="CPU">
5759
<NumberInput id='settings-cpu'
5860
className="cpus"
@@ -65,7 +67,8 @@ export default class Configuration extends React.Component {
6567
widthChars={5}
6668
onPlus={event => this.updateValue('cpus', this.state.cpus + 1)}
6769
onMinus={event => this.updateValue('cpus', this.state.cpus - 1)}
68-
onChange={value => this.props.onValueChanged(this, 'cpus', value)} />
70+
onChange={value => this.state['cpus'] }
71+
/>
6972
</FormGroup>
7073
<FormGroup fieldId='settings-memory' label="Memory">
7174
<NumberInput id='settings-memory'
@@ -79,7 +82,8 @@ export default class Configuration extends React.Component {
7982
widthChars={5}
8083
onPlus={event => this.updateValue('memory', this.state.memory + 512)}
8184
onMinus={event => this.updateValue('memory', this.state.memory - 512)}
82-
onChange={value => this.props.onValueChanged(this, 'memory', value)} />
85+
onChange={value => this.state['memory'] }
86+
/>
8387
</FormGroup>
8488
<FormGroup fieldId='settings-disksize' label="Disk size">
8589
<NumberInput id='settings-disksize'
@@ -93,7 +97,17 @@ export default class Configuration extends React.Component {
9397
widthChars={5}
9498
onPlus={event => this.updateValue('disk-size', this.state["disk-size"] + 1)}
9599
onMinus={event => this.updateValue('disk-size', this.state["disk-size"] - 1)}
96-
onChange={value => this.props.onValueChanged(this, 'disk-size', value)} />
100+
onChange={value => this.state['disk-size'] }
101+
/>
102+
</FormGroup>
103+
<FormGroup fieldId='settings-preset' label="Preset">
104+
<PresetSelection id="settings.preset" isCompact
105+
className="preset"
106+
inputName="preset"
107+
podmanDescription="This option will allow you to use podman to run containers inside a VM environment."
108+
openshiftDescription="This option will run a full cluster environment as a single node, providing a registry, monitoring and access to Operator Hub"
109+
value={this.state.preset}
110+
onChange={value => this.updateValue('preset', value)} />
97111
</FormGroup>
98112
<FormGroup fieldId='config-telemetry' label="Telemetry">
99113
<Checkbox id='config-consentTelemetry'

src/components/PresetSelection.jsx

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
import { Button } from '@patternfly/react-core';
4+
5+
import "./PresetSelection.scss";
6+
7+
export default class PresetSelection extends React.Component {
8+
constructor(props) {
9+
super(props);
10+
this.state = {
11+
presetSelected: this.props.value // from config
12+
};
13+
this.description = "";
14+
15+
this.handlePresetSelectClick = this.handlePresetSelectClick.bind(this);
16+
}
17+
18+
handlePresetSelectClick = (event, value) => {
19+
this.setState({ presetSelected: value });
20+
21+
if(value === "podman") {
22+
this.description = this.props.podmanDescription;
23+
}
24+
if(value === "openshift") {
25+
this.description = this.props.openshiftDescription;
26+
}
27+
28+
if(this.props.onChanged !== null) {
29+
this.props.onChange(value);
30+
}
31+
};
32+
33+
render() {
34+
var descriptionStyle= {
35+
fontSize: "var(--pf-global--FontSize--sm)",
36+
color: "var(--pf-global--Color--200)",
37+
display: "block",
38+
paddingTop: "5px"
39+
}
40+
41+
var compactTemplate = (
42+
<>
43+
<div role="group">
44+
<Button className="preset-selection-button-compact"
45+
variant={ (this.state.presetSelected === "openshift") ? "primary" : "secondary" }
46+
onClick={ event => this.handlePresetSelectClick(event, 'openshift') }>OpenShift</Button>
47+
48+
<Button className="preset-selection-button-compact"
49+
variant={ (this.state.presetSelected === "podman") ? "primary" : "secondary" }
50+
onClick={ event => this.handlePresetSelectClick(event, 'podman') }>Podman</Button>
51+
</div>
52+
<span className="preset-description">{this.description}</span>
53+
</>
54+
)
55+
56+
var regularTemplate = (
57+
<>
58+
<div role="group">
59+
<Button isLarge className="preset-selection-button"
60+
variant={ (this.state.presetSelected === "openshift") ? "primary" : "secondary" }
61+
onClick={ event => this.handlePresetSelectClick(event, 'openshift') }>OpenShift</Button>
62+
<span className="preset-description">{this.props.openshiftDescription}</span>
63+
<Button isLarge className="preset-selection-button"
64+
variant={ (this.state.presetSelected === "podman") ? "primary" : "secondary" }
65+
onClick={ event => this.handlePresetSelectClick(event, 'podman') }>Podman</Button>
66+
<span className="preset-description">{this.props.podmanDescription}</span>
67+
</div>
68+
</>
69+
)
70+
71+
return (this.props.isCompact ? compactTemplate : regularTemplate);
72+
}
73+
}
74+
75+
76+
PresetSelection.propTypes = {
77+
value: PropTypes.string,
78+
podmanDescription: PropTypes.string,
79+
openshiftDescription: PropTypes.string,
80+
onChange: PropTypes.func
81+
}
82+
83+
PresetSelection.defaultProps = {
84+
value: "unknown",
85+
podmanDescription: "",
86+
openshiftDescription: ""
87+
};

src/components/PresetSelection.scss

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
.pf-m-selected
2+
{
3+
background-color: #06c;
4+
color: white;
5+
}
6+
7+
.preset-selection-button-compact
8+
{
9+
border-radius: 0;
10+
width: 120px;
11+
}
12+
13+
.preset-selection-button-compact::after
14+
{
15+
border-radius: 0;
16+
}
17+
18+
.preset-selection-button
19+
{
20+
width: 150px;
21+
}
22+
23+
24+
.preset-description {
25+
font-size: var(--pf-global--FontSize--sm);
26+
color: var(--pf-global--Color--200);
27+
display: block;
28+
padding-top: 5px;
29+
padding-bottom: 5px;
30+
}

src/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import PodmanStatus from './components/PodmanStatus.jsx';
77
import OpenShiftStatus from './components/OpenShiftStatus.jsx';
88
import UnknownStatus from './components/UnknownStatus.jsx';
99
import PullSecretInputCard from './components/PullSecretInputCard.jsx';
10+
import PresetSelection from './components/PresetSelection.jsx';
1011

1112
export {
1213
Actions,
@@ -17,5 +18,6 @@ export {
1718
PodmanStatus,
1819
OpenShiftStatus,
1920
UnknownStatus,
20-
PullSecretInputCard
21+
PullSecretInputCard,
22+
PresetSelection
2123
};

src/stories/Configuration.stories.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ const Template = (args) => <Configuration {...args} />;
1212

1313
export const Default = Template.bind({});
1414
Default.args = {
15+
1516
};
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import React from 'react';
2+
import PresetSelection from '../components/PresetSelection';
3+
4+
export default {
5+
title: 'Example/PresetSelection',
6+
component: PresetSelection,
7+
argTypes: {
8+
},
9+
};
10+
11+
const Template = (args) => <PresetSelection {...args} />;
12+
13+
export const Default = Template.bind({});
14+
Default.args = {
15+
};

0 commit comments

Comments
 (0)