Skip to content

Commit

Permalink
set column order in views.yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
frankyhollywood committed Dec 13, 2023
1 parent 2133f82 commit 5c61a04
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 6 deletions.
1 change: 1 addition & 0 deletions projects/mercury/src/metadata/views/MetadataViewAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export type MetadataViewFacet = {
};

export type MetadataViewColumn = {
displayIndex: number;
name: string;
title: string;
type: ValueType;
Expand Down
10 changes: 9 additions & 1 deletion projects/mercury/src/metadata/views/MetadataViewTabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,15 @@ export const MetadataViewTabs = (props: MetadataViewTabsProperties) => {
accessColumn
];
}
return view.columns;
return view.columns.sort((a, b) => {
if (a.displayIndex > b.displayIndex) {
return 1;
}
if (a.displayIndex < b.displayIndex) {
return -1;
}
return 0;
});
};

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ public static class Column {
@NotBlank public String title;
@NotNull public ColumnType type;
@NotBlank public String source;
// displayIndex determines the order of columns on the view page.
@NotNull public Integer displayIndex = 999;
public String rdfType;
public int priority;
}
Expand All @@ -97,6 +99,8 @@ public static class JoinView {
public boolean reverse = false;
@JsonSetter(nulls = Nulls.AS_EMPTY)
public List<String> include;
// displayIndex determines the order of columns on the view page, for joinView it is the column displaying the related entity
public Integer displayIndex = 999;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ public class ColumnDTO {
String name;
String title;
ViewsConfig.ColumnType type;
Integer displayIndex;
}
Original file line number Diff line number Diff line change
Expand Up @@ -175,23 +175,23 @@ public List<ViewDTO> getViews() {
return viewsConfig.views.stream()
.map(v -> {
var columns = new ArrayList<ColumnDTO>();
columns.add(new ColumnDTO(v.name, v.itemName == null ? v.name : v.itemName, ColumnType.Identifier));
columns.add(new ColumnDTO(v.name, v.itemName == null ? v.name : v.itemName, ColumnType.Identifier, 0));
for (var c : v.columns) {
columns.add(new ColumnDTO(v.name + "_" + c.name, c.title, c.type));
columns.add(new ColumnDTO(v.name + "_" + c.name, c.title, c.type, c.displayIndex));
}
for (var j : v.join) {
var joinView = viewsConfig.views.stream().filter(view -> view.name.equalsIgnoreCase(j.view)).findFirst().orElse(null);
if (joinView == null) {
continue;
}
if (j.include.contains("id")) {
columns.add(new ColumnDTO(joinView.name, joinView.title, ColumnType.Identifier));
columns.add(new ColumnDTO(joinView.name, joinView.title, ColumnType.Identifier, j.displayIndex));
}
for (var c : joinView.columns) {
if (!j.include.contains(c.name)) {
continue;
}
columns.add(new ColumnDTO(joinView.name + "_" + c.name, c.title, c.type));
columns.add(new ColumnDTO(joinView.name + "_" + c.name, c.title, c.type, c.displayIndex));
}
}
return new ViewDTO(v.name, v.title, columns);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import java.util.stream.*;

import static io.fairspace.saturn.TestUtils.*;
import static io.fairspace.saturn.TestUtils.mockAuthentication;
import static io.fairspace.saturn.auth.RequestContext.getCurrentRequest;
import static org.apache.jena.query.DatasetFactory.*;
import static org.mockito.ArgumentMatchers.any;
Expand Down Expand Up @@ -117,4 +116,20 @@ public void testFetchViewConfig() {
.toList();
Assert.assertEquals(1, boolFacets.size());
}

@Test
public void testDisplayIndex_IsSet() {
var views = viewService.getViews();
var columns = views.get(1).getColumns().stream().toList();
var selectedColumn = columns.stream().filter(c -> c.getTitle().equals("Morphology")).collect(Collectors.toList()).get(0);
Assert.assertEquals(Integer.valueOf(1), selectedColumn.getDisplayIndex());
}

@Test
public void testDisplayIndex_IsNotSet() {
var views = viewService.getViews();
var columns = views.get(1).getColumns().stream().toList();
var selectedColumn = columns.stream().filter(c -> c.getTitle().equals("Laterality")).collect(Collectors.toList()).get(0);
Assert.assertEquals(Integer.valueOf(999), selectedColumn.getDisplayIndex());
}
}
2 changes: 2 additions & 0 deletions projects/saturn/src/test/resources/test-views.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ views:
source: https://institut-curie.org/ontology#tumorMorphology
rdfType: https://institut-curie.org/ontology#Morphology
type: termSet
displayIndex: 1
- name: laterality
title: Laterality
source: https://institut-curie.org/ontology#tumorLaterality
Expand Down Expand Up @@ -177,6 +178,7 @@ views:
- id
- gender
- ageAtDeath
displayIndex: 0
- view: Sample
on: https://institut-curie.org/ontology#diagnosis
reverse: true
Expand Down

0 comments on commit 5c61a04

Please sign in to comment.