fix(ui): select a predictable first table on startup

previously map.values.iterator.next was selecting a random table
This commit is contained in:
Valters Vingolds
2025-03-19 10:57:00 +01:00
parent 35baafa46f
commit 5aa98158a2
2 changed files with 15 additions and 1 deletions
@@ -37,11 +37,13 @@ import java.util.IdentityHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeMap;
import java.util.TreeSet;
import org.apache.commons.collections4.MapUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -304,6 +306,18 @@ public class DataModel {
return tables.values();
}
/**
* When starting UI we need to pick a table to get selected at first, in a stable way.
* Alphabetically first table sounds good and deterministic.
*/
public Optional<Table> firstTable() {
if (MapUtils.isEmpty(tables)) {
return Optional.empty();
}
return tables.keySet().stream().sorted().findFirst().map(tables::get);
}
/**
* Reads in <code>table.csv</code> and <code>association.csv</code>
* and builds the relational data model.
@@ -198,7 +198,7 @@ public class ExtractionModel {
public ExtractionModel(DataModel dataModel, ExecutionContext executionContext) {
this.dataModel = dataModel;
this.version = null;
subject = dataModel.getTables().iterator().hasNext()? dataModel.getTables().iterator().next() : null;
subject = dataModel.firstTable().orElse(null);
condition = "";
dataModel.setRestrictionModel(new RestrictionModel(dataModel, executionContext));
dataModel.deriveFilters();