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

Deals with defaults specific to a preset #41

Merged
merged 2 commits into from
Feb 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@code-ready/crc-react-components",
"version": "0.9.9",
"version": "0.9.10",
"author": {
"name": "Gerard Braad",
"email": "[email protected]"
Expand Down
49 changes: 43 additions & 6 deletions src/components/Configuration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -38,6 +38,7 @@ export default class Configuration extends React.Component<ConfigurationProps> {
onSaveClicked: PropTypes.func,
onResetClicked: PropTypes.func,
onPullsecretChangeClicked: PropTypes.func,
onPresetChange: PropTypes.func,
height: PropTypes.string,
textInputWidth: PropTypes.string
};
Expand All @@ -47,6 +48,18 @@ export default class Configuration extends React.Component<ConfigurationProps> {
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);
Expand All @@ -68,7 +81,9 @@ export default class Configuration extends React.Component<ConfigurationProps> {
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
Expand All @@ -85,7 +100,18 @@ export default class Configuration extends React.Component<ConfigurationProps> {
});
}

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;
}
Expand All @@ -99,6 +125,17 @@ export default class Configuration extends React.Component<ConfigurationProps> {
}
}

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);
}
Expand Down Expand Up @@ -136,7 +173,7 @@ export default class Configuration extends React.Component<ConfigurationProps> {
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'] }
/>
</FormGroup>
Expand All @@ -151,7 +188,7 @@ export default class Configuration extends React.Component<ConfigurationProps> {
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'] }
/>
</FormGroup>
Expand All @@ -166,15 +203,15 @@ export default class Configuration extends React.Component<ConfigurationProps> {
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'] }
/>
</FormGroup>
<FormGroup fieldId='settings-preset' label="Preset">
<PresetSelection id="settings-preset" isCompact
className="preset"
value={this.state["preset"]}
onPresetChange={value => this.updateValue('preset', value)} />
onPresetChange={value => this.presetChanged(value)} />
</FormGroup>
</Form>
</TabContentBody>
Expand Down