diff --git a/package.json b/package.json index 24fc25d..a52e678 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@code-ready/crc-react-components", - "version": "0.9.9", + "version": "0.9.10", "author": { "name": "Gerard Braad", "email": "me@gbraad.nl" diff --git a/src/components/Configuration.tsx b/src/components/Configuration.tsx index cec139a..fefbd97 100644 --- a/src/components/Configuration.tsx +++ b/src/components/Configuration.tsx @@ -18,10 +18,10 @@ export interface ConfigurationProps { onPullsecretChangeClicked: (event: React.SyntheticEvent) => void; onSaveClicked: (state: State) => void; onResetClicked: () => void; + onPresetChange: (preset: string) => void; } export interface State { - readonly activeTabKey: number; readonly preset: string; readonly cpus: number; readonly memory: number; @@ -38,6 +38,7 @@ export default class Configuration extends React.Component { onSaveClicked: PropTypes.func, onResetClicked: PropTypes.func, onPullsecretChangeClicked: PropTypes.func, + onPresetChange: PropTypes.func, height: PropTypes.string, textInputWidth: PropTypes.string }; @@ -47,6 +48,18 @@ export default class Configuration extends React.Component { textInputWidth: "320px" }; + static openshiftDefaults: any = { + cpus: 4, + memory: 9126, + 'disk-size': 31 + } + + static podmanDefaults: any = { + cpus: 1, + memory: 2048, + 'disk-size': 31 + } + state: State; constructor(props: ConfigurationProps) { super(props); @@ -68,7 +81,9 @@ export default class Configuration extends React.Component { this.handleTabClick = this.handleTabClick.bind(this); this.updateClampedValue = this.updateClampedValue.bind(this); + this.getMimimum = this.getMimimum.bind(this); this.updateValue = this.updateValue.bind(this); + this.presetChanged = this.presetChanged.bind(this) } // Toggle currently active tab @@ -85,7 +100,18 @@ export default class Configuration extends React.Component { }); } - updateClampedValue(key: string, min: number, value: number): void { + getMimimum(key: string) { + if(this.state.preset == "openshift") { + return Configuration.openshiftDefaults[key]; + } + if(this.state.preset == "podman") { + return Configuration.podmanDefaults[key]; + } + return 0; + } + + updateClampedValue(key: string, value: number): void { + const min = this.getMimimum(key); if(value < min) { value = min; } @@ -99,6 +125,17 @@ export default class Configuration extends React.Component { } } + presetChanged(value: string) { + this.updateValue("preset", value) + if(value == "openshift") { + this.updateValues(Configuration.openshiftDefaults); + } + if(value == "podman") { + this.updateValues(Configuration.podmanDefaults); + } + this.props.onPresetChange(value); + } + configurationSaveClicked() { this.props.onSaveClicked(this.state); } @@ -136,7 +173,7 @@ export default class Configuration extends React.Component { value={this.state.cpus} widthChars={5} onPlus={event => this.updateValue('cpus', this.state.cpus + 1)} - onMinus={event => this.updateClampedValue('cpus', 1, this.state.cpus - 1)} + onMinus={event => this.updateClampedValue('cpus', this.state.cpus - 1)} onChange={value => this.state['cpus'] } /> @@ -151,7 +188,7 @@ export default class Configuration extends React.Component { value={this.state.memory} widthChars={5} onPlus={event => this.updateValue('memory', this.state.memory + 512)} - onMinus={event => this.updateClampedValue('memory', 2048, this.state.memory - 512)} + onMinus={event => this.updateClampedValue('memory', this.state.memory - 512)} onChange={value => this.state['memory'] } /> @@ -166,7 +203,7 @@ export default class Configuration extends React.Component { value={this.state["disk-size"]} widthChars={5} onPlus={event => this.updateValue('disk-size', this.state["disk-size"] + 1)} - onMinus={event => this.updateClampedValue('disk-size', 10, this.state["disk-size"] - 1)} + onMinus={event => this.updateClampedValue('disk-size', this.state["disk-size"] - 1)} onChange={value => this.state['disk-size'] } /> @@ -174,7 +211,7 @@ export default class Configuration extends React.Component { this.updateValue('preset', value)} /> + onPresetChange={value => this.presetChanged(value)} />