Benchmark editing

This commit is contained in:
2026-08-27 13:52:57 +02:00
parent 0d3f5ca8ad
commit 57586c6600
5 changed files with 37 additions and 10 deletions
+1 -1
View File
@@ -13,7 +13,7 @@ plugins {
alias(libs.plugins.buildconfig) alias(libs.plugins.buildconfig)
} }
version = rootProject.version as PhoebenchVersion version = PhoebenchVersion(1, 1, 1)
if((version as PhoebenchVersion) < (rootProject.version as PhoebenchVersion)) if((version as PhoebenchVersion) < (rootProject.version as PhoebenchVersion))
throw GradleException("UI Clients version must be at least as high as protocol/common version") throw GradleException("UI Clients version must be at least as high as protocol/common version")
@@ -232,7 +232,7 @@ class ProjectVM(
fun updateBenchmark(id: Uuid, name: String?) { fun updateBenchmark(id: Uuid, name: String?) {
withScope { withScope {
val old = _benchmarks.value.find { it.id == id } ?: return@withScope val old = _benchmarks.value.find { it.id == id } ?: return@withScope
_repo.updateVersion(id, name).snackOr { _repo.updateBenchmark(id, name).snackOr {
if(_job == null) { if(_job == null) {
_benchmarks.value = _benchmarks.value.replace({ it.id == id }) { it.copy(name = name ?: old.name) } _benchmarks.value = _benchmarks.value.replace({ it.id == id }) { it.copy(name = name ?: old.name) }
} }
@@ -115,6 +115,7 @@ fun ProjectPanel(vm: ProjectVM, editable: Boolean, versions: Map<Uuid, ProjectVM
var addOpen by remember { mutableStateOf(false) } var addOpen by remember { mutableStateOf(false) }
var addingLabel by remember { mutableStateOf(false) } var addingLabel by remember { mutableStateOf(false) }
var addingData by remember { mutableStateOf(false) } var addingData by remember { mutableStateOf(false) }
var editing by remember { mutableStateOf(false) }
Surface(Modifier.fillMaxSize().padding(8.dp), tonalElevation = 10.dp, shape = MaterialTheme.shapes.medium) { Surface(Modifier.fillMaxSize().padding(8.dp), tonalElevation = 10.dp, shape = MaterialTheme.shapes.medium) {
Column(Modifier.fillMaxSize()) { Column(Modifier.fillMaxSize()) {
@@ -126,10 +127,15 @@ fun ProjectPanel(vm: ProjectVM, editable: Boolean, versions: Map<Uuid, ProjectVM
Box(Modifier.weight(1f)) { Box(Modifier.weight(1f)) {
var isOpen by remember { mutableStateOf(false) } var isOpen by remember { mutableStateOf(false) }
Row(Modifier.clickable { isOpen = !isOpen }, verticalAlignment = Alignment.CenterVertically) { Surface(shape = MaterialTheme.shapes.medium) {
Text(currentBenchmark.name, style = MaterialTheme.typography.headlineMedium) Row(Modifier.clickable { isOpen = !isOpen }, verticalAlignment = Alignment.CenterVertically) {
Spacer(Modifier.width(10.dp)) Text(currentBenchmark.name, style = MaterialTheme.typography.headlineMedium)
Icon(Lucide.ChevronDown, "Select benchmark...") Spacer(Modifier.width(10.dp))
IconButton({ editing = true }) {
Icon(Lucide.Pencil, "Edit benchmark")
}
Icon(Lucide.ChevronDown, "Select benchmark...")
}
} }
DropdownMenu(isOpen, { isOpen = false }) { DropdownMenu(isOpen, { isOpen = false }) {
@@ -224,6 +230,8 @@ fun ProjectPanel(vm: ProjectVM, editable: Boolean, versions: Map<Uuid, ProjectVM
vm.mkEntry(label, warmups, measurements, unit, input, hardware) vm.mkEntry(label, warmups, measurements, unit, input, hardware)
addOpen = false addOpen = false
} }
if(editing) EditBenchmarkDialog(currentBenchmark, { editing = false }) { vm.updateBenchmark(currentBenchmark.id, it) }
} }
@Composable @Composable
@@ -287,6 +295,25 @@ fun AddBenchmarkDialog(onCancel: () -> Unit, onAdd: (name: String) -> Unit) {
} }
} }
@Composable
fun EditBenchmarkDialog(benchmark: ProjectVM.Benchmark, onCancel: () -> Unit, onUpdate: (name: String) -> Unit) {
Dialog(onDismissRequest = onCancel) {
var name by remember { mutableStateOf(benchmark.name) }
Surface(Modifier.padding(15.dp).widthIn(400.dp), shape = MaterialTheme.shapes.medium) {
Column(Modifier.padding(8.dp).width(IntrinsicSize.Min)) {
Text("Modify benchmark", Modifier.align(Alignment.CenterHorizontally), style = MaterialTheme.typography.headlineMedium)
OutlinedTextField(name, { name = it }, Modifier.fillMaxWidth(), label = { Text("Name") })
Spacer(Modifier.height(10.dp))
CancelConfirmXRow(onCancel, {
onUpdate(name.trim())
}, confirmText = "Update", canConfirm = name.trim().isNotBlank() && name.trim() != benchmark.name)
}
}
}
}
@Composable @Composable
fun AddVersionDialog(onCancel: () -> Unit, onAdd: (name: String, color: Color, meta: String) -> Unit) { fun AddVersionDialog(onCancel: () -> Unit, onAdd: (name: String, color: Color, meta: String) -> Unit) {
Dialog(onDismissRequest = onCancel) { Dialog(onDismissRequest = onCancel) {
@@ -789,7 +816,7 @@ fun ProjectPlotArea(vm: ProjectVM, benchmark: ProjectVM.Benchmark) {
item { Spacer(Modifier.height(10.dp)) } item { Spacer(Modifier.height(10.dp)) }
items((visibleInputs intersect inputFilter.toSet()).toList()) { items((visibleInputs intersect inputFilter.toSet()).sorted()) {
Row(Modifier.fillMaxWidth().clickable { Row(Modifier.fillMaxWidth().clickable {
if(inputFilter.size == allInputs.size) { if(inputFilter.size == allInputs.size) {
inputFilter.clear() inputFilter.clear()
@@ -809,7 +836,7 @@ fun ProjectPlotArea(vm: ProjectVM, benchmark: ProjectVM.Benchmark) {
} }
} }
items((visibleInputs - inputFilter.toSet()).toList()) { items((visibleInputs - inputFilter.toSet()).sorted()) {
Row(Modifier.fillMaxWidth().clickable { Row(Modifier.fillMaxWidth().clickable {
if(inputFilter.size == allInputs.size) { if(inputFilter.size == allInputs.size) {
inputFilter.clear() inputFilter.clear()
+1 -1
View File
@@ -7,7 +7,7 @@ plugins {
} }
group = "com.jaytux.phoebench" group = "com.jaytux.phoebench"
version = rootProject.version as PhoebenchVersion version = PhoebenchVersion(1, 1, 1)
if((version as PhoebenchVersion) < (rootProject.version as PhoebenchVersion)) if((version as PhoebenchVersion) < (rootProject.version as PhoebenchVersion))
throw GradleException("Server version must be at least as high as protocol/common version") throw GradleException("Server version must be at least as high as protocol/common version")
@@ -200,7 +200,7 @@ object ProjectHandler {
checkMigration(user) checkMigration(user)
val (proj, bench) = accessibleBenchmark(user, req.first, true) val (proj, bench) = accessibleBenchmark(user, req.first, true)
val changes = req.second val changes = req.second
changes.name?.let { proj.name = it } changes.name?.let { bench.name = it }
ServerScope.launch { ServerScope.launch {
Buses.projectBus(proj.id.value).sendAll(ProjectEvent.BenchmarkChanged( Buses.projectBus(proj.id.value).sendAll(ProjectEvent.BenchmarkChanged(