Fix issue of empty list facet choices disappearing. Closes #1827.

This commit is contained in:
Antonin Delpeuch 2018-11-16 12:51:49 +00:00
parent a2dd6d97e4
commit 0e0dcbafef
2 changed files with 28 additions and 0 deletions

View File

@ -305,6 +305,7 @@ public class ListFacet implements Facet {
*/ */
NominalFacetChoice choice = new NominalFacetChoice(decoratedValue); NominalFacetChoice choice = new NominalFacetChoice(decoratedValue);
choice.count = 0; choice.count = 0;
choice.selected = true;
_choices.add(choice); _choices.add(choice);
} }
} }

View File

@ -43,6 +43,18 @@ public class ListFacetTests extends RefineTest {
+ " {\"v\":{\"v\":\"barbar\",\"l\":\"barbar\"},\"c\":1,\"s\":false}" + " {\"v\":{\"v\":\"barbar\",\"l\":\"barbar\"},\"c\":1,\"s\":false}"
+ "]}"; + "]}";
private static String selectedEmptyChoiceFacet = "{"
+ "\"name\":\"facet A\","
+ "\"expression\":\"value+\\\"bar\\\"\","
+ "\"columnName\":\"Column A\","
+ "\"invert\":false,"
+ "\"choices\":["
+ " {\"v\":{\"v\":\"ebar\",\"l\":\"ebar\"},\"c\":1,\"s\":false},"
+ " {\"v\":{\"v\":\"cbar\",\"l\":\"cbar\"},\"c\":1,\"s\":false},"
+ " {\"v\":{\"v\":\"abar\",\"l\":\"abar\"},\"c\":1,\"s\":false},"
+ " {\"v\":{\"v\":\"foobar\",\"l\":\"true\"},\"c\":0,\"s\":true}"
+ "]}";
@Test @Test
public void serializeListFacetConfig() { public void serializeListFacetConfig() {
ListFacetConfig facetConfig = new ListFacetConfig(); ListFacetConfig facetConfig = new ListFacetConfig();
@ -77,4 +89,19 @@ public class ListFacetTests extends RefineTest {
Facet facet = facetConfig.apply(project); Facet facet = facetConfig.apply(project);
TestUtils.isSerializedTo(facet, jsonFacetError); TestUtils.isSerializedTo(facet, jsonFacetError);
} }
@Test
public void testSelectedEmptyChoice() {
Project project = createCSVProject("Column A\n" +
"a\n" +
"c\n" +
"e");
Engine engine = new Engine(project);
ListFacetConfig facetConfig = new ListFacetConfig();
facetConfig.initializeFromJSON(new JSONObject(jsonConfig));
Facet facet = facetConfig.apply(project);
facet.computeChoices(project, engine.getAllFilteredRows());
TestUtils.isSerializedTo(facet, selectedEmptyChoiceFacet);
}
} }