sync the vcpu and memory sliders when moving around

This commit is contained in:
Tobias Brunner 2025-07-16 12:09:21 +02:00
parent a7713b46a2
commit 9a86e023dd
Signed by: tobru
SSH key fingerprint: SHA256:kOXg1R6c11XW3/Pt9dbLdQvOJGFAy+B2K6v6PtRWBGQ
4 changed files with 251 additions and 11 deletions

View file

@ -245,23 +245,51 @@ class UIManager {
if (!cpuRange || !memoryRange) return;
const { maxCpus, maxMemory } = pricingDataManager.getSliderMaximums();
const { cpuValues, memoryValues } = pricingDataManager.getAvailableSliderValues();
// Set slider maximums with some padding
if (maxCpus > 0) {
cpuRange.min = "0.25";
cpuRange.max = Math.ceil(maxCpus);
// Set CPU slider range based on available plan values
if (cpuValues.length > 0) {
cpuRange.min = Math.min(...cpuValues);
cpuRange.max = Math.max(...cpuValues);
// Calculate step size - use the smallest difference between consecutive values
const cpuStep = this.calculateOptimalStep(cpuValues);
cpuRange.step = cpuStep;
}
if (maxMemory > 0) {
memoryRange.min = "0.25";
memoryRange.max = Math.ceil(maxMemory);
// Set Memory slider range based on available plan values
if (memoryValues.length > 0) {
memoryRange.min = Math.min(...memoryValues);
memoryRange.max = Math.max(...memoryValues);
// Calculate step size - use the smallest difference between consecutive values
const memoryStep = this.calculateOptimalStep(memoryValues);
memoryRange.step = memoryStep;
}
// Update display values after changing min/max
domManager.updateSliderDisplayValues();
}
// Calculate optimal step size for slider based on available values
calculateOptimalStep(values) {
if (values.length <= 1) return 0.25; // Default step
// Find the smallest difference between consecutive values
let minDiff = Infinity;
for (let i = 1; i < values.length; i++) {
const diff = values[i] - values[i - 1];
if (diff > 0 && diff < minDiff) {
minDiff = diff;
}
}
// Use the minimum difference as step, but ensure it's reasonable
// Round to common step values (0.25, 0.5, 1, etc.)
if (minDiff <= 0.25) return 0.25;
if (minDiff <= 0.5) return 0.5;
if (minDiff <= 1) return 1;
return Math.ceil(minDiff);
}
// Update instances slider based on service level and replica info
updateInstancesSlider(domManager, pricingDataManager) {
const instancesRange = domManager.get('instancesRange');