From e81b49973527d5bdb725d018211d6ab894ff735d Mon Sep 17 00:00:00 2001 From: keikeicheung Date: Mon, 12 Aug 2024 12:23:18 +0800 Subject: [PATCH 1/4] #1403 by default if no parent selected on visual linked tables, child should show all --- .../finos/vuu/core/sort/FilterAndSort.scala | 8 +- .../viewport/VisualLinkedViewPortTest.scala | 129 +++++++++++++++--- 2 files changed, 115 insertions(+), 22 deletions(-) diff --git a/vuu/src/main/scala/org/finos/vuu/core/sort/FilterAndSort.scala b/vuu/src/main/scala/org/finos/vuu/core/sort/FilterAndSort.scala index 504607315..3ceb553e6 100644 --- a/vuu/src/main/scala/org/finos/vuu/core/sort/FilterAndSort.scala +++ b/vuu/src/main/scala/org/finos/vuu/core/sort/FilterAndSort.scala @@ -64,9 +64,13 @@ case class VisualLinkedFilter(viewPortVisualLink: ViewPortVisualLink) extends Fi val parentColumn = viewPortVisualLink.parentColumn val childColumn = viewPortVisualLink.childColumn - val filtered = doFilterByIndexIfPossible(parentSelectionKeys, parentColumn, childColumn, source, primaryKeys) + if (parentSelectionKeys.isEmpty) { + primaryKeys + } else { + val filtered = doFilterByIndexIfPossible(parentSelectionKeys, parentColumn, childColumn, source, primaryKeys) + filtered + } - filtered } } diff --git a/vuu/src/test/scala/org/finos/vuu/viewport/VisualLinkedViewPortTest.scala b/vuu/src/test/scala/org/finos/vuu/viewport/VisualLinkedViewPortTest.scala index 2e0ca0b9b..83213485f 100644 --- a/vuu/src/test/scala/org/finos/vuu/viewport/VisualLinkedViewPortTest.scala +++ b/vuu/src/test/scala/org/finos/vuu/viewport/VisualLinkedViewPortTest.scala @@ -3,7 +3,7 @@ package org.finos.vuu.viewport import org.finos.toolbox.jmx.{MetricsProvider, MetricsProviderImpl} import org.finos.toolbox.lifecycle.LifecycleContainer import org.finos.toolbox.time.{Clock, TestFriendlyClock} -import org.finos.vuu.api.{Index, Indices, Link, TableDef, VisualLinks} +import org.finos.vuu.api._ import org.finos.vuu.client.messages.RequestId import org.finos.vuu.core.table.TableTestHelper.combineQs import org.finos.vuu.core.table.{Columns, TableContainer, ViewPortColumnCreator} @@ -86,8 +86,8 @@ class VisualLinkedViewPortTest extends AbstractViewPortTestCase with Matchers wi And("we run the container once through") viewPortContainer.runOnce() - Then("we should have nothing available in the viewport") - viewPortOrders.getKeys.length shouldEqual 0 + Then("we should show all by default in the viewport") + viewPortOrders.getKeys.length shouldEqual 12 When("we select some rows in the grid") viewPortContainer.changeSelection(session, outQueue, viewPortPrices.id, ViewPortSelectedIndices(Array(1))) @@ -103,6 +103,8 @@ class VisualLinkedViewPortTest extends AbstractViewPortTestCase with Matchers wi And("we run the container once through to pick up ") viewPortContainer.runOnce() + Then("check we now have 4 keys in the viewport") + viewPortOrders.getKeys.length shouldEqual 4 assertVpEqWithMeta(combineQs(viewPortOrders)) { Table( ("sel" ,"orderId" ,"trader" ,"ric" ,"tradeTime","quantity"), @@ -118,6 +120,8 @@ class VisualLinkedViewPortTest extends AbstractViewPortTestCase with Matchers wi viewPortContainer.runOnce() + Then("check we now have 9 keys in the viewport") + viewPortOrders.getKeys.length shouldEqual 9 Then("Check we still maintain the selection") assertVpEqWithMeta(combineQs(viewPortOrders).filter(vpu => vpu.vp.id == viewPortOrders.id)) { Table( @@ -130,15 +134,28 @@ class VisualLinkedViewPortTest extends AbstractViewPortTestCase with Matchers wi ) } - Then("check we now have 9 keys in the viewport") - viewPortOrders.getKeys.length shouldEqual 9 - And("if we set selection to none") viewPortContainer.changeSelection(session, outQueue, viewPortPrices.id, ViewPortSelectedIndices(Array())) viewPortContainer.runOnce() - Then("we should have nothing available in the viewport") - viewPortOrders.getKeys.length shouldEqual 0 + Then("we should show all by default in the viewport") + viewPortOrders.getKeys.length shouldEqual 12 + + assertVpEqWithMeta(combineQs(viewPortOrders).filter(vpu => vpu.vp.id == viewPortOrders.id)) { + Table( + ("sel", "orderId", "trader", "ric", "tradeTime", "quantity"), + (0, "NYC-0000", "chris", "VOD.L", 1311544800000L, 100), + (0, "NYC-0001", "chris", "VOD.L", 1311544800010L, 101), + (0, "NYC-0002", "chris", "VOD.L", 1311544800020L, 102), + (0, "NYC-0003", "chris", "BT.L", 1311544800030L, 100), + (0, "NYC-0004", "chris", "BT.L", 1311544800040L, 101), + (0, "NYC-0005", "chris", "BT.L", 1311544800050L, 102), + (0, "NYC-0006", "chris", "BT.L", 1311544800060L, 103), + (0, "NYC-0007", "chris", "BP.L", 1311544800070L, 100), + (0, "NYC-0008", "chris", "BP.L", 1311544800080L, 101), + (0, "NYC-0009", "chris", "BP.L", 1311544800090L, 102) + ) + } Then("Change the viewport to sort by quantity") viewPortContainer.change(RequestId.oneNew(), session, viewPortOrders.id, ViewPortRange(0, 10), vpcolumnsOrders, SortSpec(List(SortDef("quantity", 'D')))) @@ -146,16 +163,19 @@ class VisualLinkedViewPortTest extends AbstractViewPortTestCase with Matchers wi viewPortContainer.runOnce() - Then("Check we still maintain the selection even with a new sort or filter") - assertVpEqWithMeta(combineQs(viewPortOrders).filter(vpu => vpu.vp.id == viewPortOrders.id)) { - Table( - ("sel" ,"orderId" ,"trader" ,"ric" ,"tradeTime","quantity"), - (0 ,"NYC-0003","chris" ,"BT.L" ,1311544800030L,100 ), - (0 ,"NYC-0004","chris" ,"BT.L" ,1311544800040L,101 ), - (0 ,"NYC-0005","chris" ,"BT.L" ,1311544800050L,102 ), - (0 ,"NYC-0006","chris" ,"BT.L" ,1311544800060L,103 ) - ) - } + Then("check we now have 4 keys in the viewport") + viewPortOrders.getKeys.length shouldEqual 4 + +// Then("Check we still maintain the selection even with a new sort or filter") +// assertVpEqWithMeta(combineQs(viewPortOrders).filter(vpu => vpu.vp.id == viewPortOrders.id)) { +// Table( +// ("sel" ,"orderId" ,"trader" ,"ric" ,"tradeTime","quantity"), +// (0 ,"NYC-0003","chris" ,"BT.L" ,1311544800030L,100 ), +// (0 ,"NYC-0004","chris" ,"BT.L" ,1311544800040L,101 ), +// (0 ,"NYC-0005","chris" ,"BT.L" ,1311544800050L,102 ), +// (0 ,"NYC-0006","chris" ,"BT.L" ,1311544800060L,103 ) +// ) +// } Then("Check we can remove the visual linking") @@ -292,8 +312,8 @@ class VisualLinkedViewPortTest extends AbstractViewPortTestCase with Matchers wi And("we run the container once through") viewPortContainer.runOnce() - Then("we should have nothing available in the viewport") - viewPortOrders1.getKeys.length shouldEqual 0 + Then("we should show all by default in the viewport") + viewPortOrders1.getKeys.length shouldEqual 12 When("we select second row in the grid") viewPortContainer.changeSelection(session, outQueue, viewPortOrders2.id, ViewPortSelectedIndices(Array(1))) @@ -316,5 +336,74 @@ class VisualLinkedViewPortTest extends AbstractViewPortTestCase with Matchers wi ) } } + + Scenario("should should all when no parent is selected") { + + implicit val clock: Clock = new TestFriendlyClock(TestTimeStamp.EPOCH_DEFAULT) + implicit val metrics: MetricsProvider = new MetricsProviderImpl + + Given("we've created a viewport with orders in") + val (viewPortContainer, orders, ordersProvider, prices, pricesProvider, session, outQueue) = createDefaultOrderPricesViewPortInfra() + + val vpcolumnsOrders = ViewPortColumnCreator.create(orders, List("orderId", "trader", "tradeTime", "quantity", "ric")) + val vpcolumnsPrices = ViewPortColumnCreator.create(prices, List("ric", "bid", "ask", "last", "open")) + + createPricesRow(pricesProvider, "VOD.L", 100, 101, 100.5, 99.5) + createPricesRow(pricesProvider, "BT.L", 200, 201, 200.5, 199.5) + createPricesRow(pricesProvider, "BP.L", 300, 301, 300.5, 299.5) + + createNOrderRows(ordersProvider, 3)(clock) + createNOrderRows(ordersProvider, 4, ric = "BT.L", idOffset = 3)(clock) + createNOrderRows(ordersProvider, 5, ric = "BP.L", idOffset = 7)(clock) + + val viewPortOrders = viewPortContainer.create(RequestId.oneNew(), session, outQueue, orders, ViewPortRange(0, 10), vpcolumnsOrders) + val viewPortPrices = viewPortContainer.create(RequestId.oneNew(), session, outQueue, prices, ViewPortRange(0, 10), vpcolumnsPrices) + + viewPortContainer.runOnce() + + val combinedUpdates = combineQs(viewPortOrders) + + val priceUpdates = combinedUpdates.filter(_.vp.id == viewPortPrices.id) + val orderUpdates = combinedUpdates.filter(_.vp.id == viewPortOrders.id) + + assertVpEqWithMeta(orderUpdates) { + Table( + ("sel", "orderId", "trader", "ric", "tradeTime", "quantity"), + (0, "NYC-0000", "chris", "VOD.L", 1311544800000L, 100), + (0, "NYC-0001", "chris", "VOD.L", 1311544800010L, 101), + (0, "NYC-0002", "chris", "VOD.L", 1311544800020L, 102), + (0, "NYC-0003", "chris", "BT.L", 1311544800030L, 100), + (0, "NYC-0004", "chris", "BT.L", 1311544800040L, 101), + (0, "NYC-0005", "chris", "BT.L", 1311544800050L, 102), + (0, "NYC-0006", "chris", "BT.L", 1311544800060L, 103), + (0, "NYC-0007", "chris", "BP.L", 1311544800070L, 100), + (0, "NYC-0008", "chris", "BP.L", 1311544800080L, 101), + (0, "NYC-0009", "chris", "BP.L", 1311544800090L, 102) + ) + } + + assertVpEqWithMeta(priceUpdates) { + Table( + ("sel", "ric", "bid", "ask", "last", "open"), + (0, "BP.L", 300.0, 301.0, 300.5, null), + (0, "BT.L", 200.0, 201.0, 200.5, null), + (0, "VOD.L", 100.0, 101.0, 100.5, null) + ) + } + + val results = viewPortContainer.getViewPortVisualLinks(session, viewPortOrders.id) + results.size shouldEqual 1 + results.head._2.table.name shouldEqual "prices" + + Then("we link the viewports, with nothing selected in the parent grid yet") + viewPortContainer.linkViewPorts(session, outQueue, childVpId = viewPortOrders.id, parentVpId = viewPortPrices.id, "ric", "ric") + + And("we run the container once through") + viewPortContainer.runOnce() + + Then("we should show all by default in the viewport") + viewPortOrders.getKeys.length shouldEqual 12 + } + } } From 4701602da642d689cff4852112802d18e4b88e5c Mon Sep 17 00:00:00 2001 From: keikeicheung Date: Mon, 12 Aug 2024 12:25:35 +0800 Subject: [PATCH 2/4] #1403 by default if no parent selected on visual linked tables, child should show all --- .../finos/vuu/core/sort/FilterAndSort.scala | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/vuu/src/main/scala/org/finos/vuu/core/sort/FilterAndSort.scala b/vuu/src/main/scala/org/finos/vuu/core/sort/FilterAndSort.scala index 3ceb553e6..9b1ba6d82 100644 --- a/vuu/src/main/scala/org/finos/vuu/core/sort/FilterAndSort.scala +++ b/vuu/src/main/scala/org/finos/vuu/core/sort/FilterAndSort.scala @@ -16,7 +16,7 @@ case class VisualLinkedFilter(viewPortVisualLink: ViewPortVisualLink) extends Fi childColumn: Column, source: RowSource, primaryKeys: TablePrimaryKeys): TablePrimaryKeys = { if (parentSelectionKeys.isEmpty) { - InMemTablePrimaryKeys(ImmutableArray.empty[String]) + primaryKeys } else { source.asTable.indexForColumn(childColumn) match { case Some(index: StringIndexedField) if childColumn.dataType == DataType.StringDataType => @@ -64,12 +64,10 @@ case class VisualLinkedFilter(viewPortVisualLink: ViewPortVisualLink) extends Fi val parentColumn = viewPortVisualLink.parentColumn val childColumn = viewPortVisualLink.childColumn - if (parentSelectionKeys.isEmpty) { - primaryKeys - } else { - val filtered = doFilterByIndexIfPossible(parentSelectionKeys, parentColumn, childColumn, source, primaryKeys) - filtered - } + + val filtered = doFilterByIndexIfPossible(parentSelectionKeys, parentColumn, childColumn, source, primaryKeys) + filtered + } } @@ -112,18 +110,20 @@ case class AntlrBasedFilter(clause: FilterClause) extends Filter with StrictLogg trait FilterAndSort { - def filterAndSort(source: RowSource, primaryKeys: TablePrimaryKeys, vpColumns:ViewPortColumns, permission: Option[RowPermissionChecker]): TablePrimaryKeys + def filterAndSort(source: RowSource, primaryKeys: TablePrimaryKeys, vpColumns: ViewPortColumns, permission: Option[RowPermissionChecker]): TablePrimaryKeys + def filter: Filter + def sort: Sort } case class UserDefinedFilterAndSort(filter: Filter, sort: Sort) extends FilterAndSort with StrictLogging { - override def filterAndSort(source: RowSource, primaryKeys: TablePrimaryKeys, vpColumns:ViewPortColumns, checkerOption: Option[RowPermissionChecker]): TablePrimaryKeys = { - try { + override def filterAndSort(source: RowSource, primaryKeys: TablePrimaryKeys, vpColumns: ViewPortColumns, checkerOption: Option[RowPermissionChecker]): TablePrimaryKeys = { + try { val realizedFilter = checkerOption match { case Some(checker) => TwoStepCompoundFilter(RowPermissionFilter(checker), filter) - case None=> filter + case None => filter } val filteredKeys = realizedFilter.dofilter(source, primaryKeys, vpColumns) @@ -146,7 +146,9 @@ class NoFilterNoSort() extends FilterAndSort { override def filterAndSort(source: RowSource, primaryKeys: TablePrimaryKeys, viewPortColumns: ViewPortColumns, checkerOption: Option[RowPermissionChecker]): TablePrimaryKeys = { primaryKeys } + override def filter: Filter = NoFilter + override def sort: Sort = NoSort } From ce964297a07fb021f6c34bcb7cc5514dbdf5f758 Mon Sep 17 00:00:00 2001 From: keikeicheung Date: Mon, 12 Aug 2024 12:29:25 +0800 Subject: [PATCH 3/4] #1403 by default if no parent selected on visual linked tables, child should show all --- .../scala/org/finos/vuu/core/sort/FilterAndSort.scala | 1 + .../finos/vuu/viewport/VisualLinkedTreeViewPortTest.scala | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/vuu/src/main/scala/org/finos/vuu/core/sort/FilterAndSort.scala b/vuu/src/main/scala/org/finos/vuu/core/sort/FilterAndSort.scala index 9b1ba6d82..8ce65d5a7 100644 --- a/vuu/src/main/scala/org/finos/vuu/core/sort/FilterAndSort.scala +++ b/vuu/src/main/scala/org/finos/vuu/core/sort/FilterAndSort.scala @@ -16,6 +16,7 @@ case class VisualLinkedFilter(viewPortVisualLink: ViewPortVisualLink) extends Fi childColumn: Column, source: RowSource, primaryKeys: TablePrimaryKeys): TablePrimaryKeys = { if (parentSelectionKeys.isEmpty) { +// InMemTablePrimaryKeys(ImmutableArray.empty[String]) primaryKeys } else { source.asTable.indexForColumn(childColumn) match { diff --git a/vuu/src/test/scala/org/finos/vuu/viewport/VisualLinkedTreeViewPortTest.scala b/vuu/src/test/scala/org/finos/vuu/viewport/VisualLinkedTreeViewPortTest.scala index 3aa087c96..8e4875ac8 100644 --- a/vuu/src/test/scala/org/finos/vuu/viewport/VisualLinkedTreeViewPortTest.scala +++ b/vuu/src/test/scala/org/finos/vuu/viewport/VisualLinkedTreeViewPortTest.scala @@ -83,8 +83,8 @@ class VisualLinkedTreeViewPortTest extends AbstractViewPortTestCase with Matcher And("we run the container once through") viewPortContainer.runOnce() - Then("we should have nothing available in the viewport") - viewPortOrders.getKeys.length shouldEqual 0 + Then("we should show all by default in the viewport") + viewPortOrders.getKeys.length shouldEqual 12 When("we select some rows in the grid") viewPortContainer.changeSelection(session, outQueue, viewPortPricesGroupBy.id, ViewPortSelectedIndices(Array(5))) @@ -146,8 +146,8 @@ class VisualLinkedTreeViewPortTest extends AbstractViewPortTestCase with Matcher viewPortContainer.changeSelection(session, outQueue, viewPortPricesGroupBy.id, ViewPortSelectedIndices(Array())) viewPortContainer.runOnce() - Then("we should have nothing available in the viewport") - viewPortOrders.getKeys.length shouldEqual 0 + Then("we should show all by default in the viewport") + viewPortOrders.getKeys.length shouldEqual 12 } } } From 07902cbb92c8832c5be985bf43663cca9b9bd415 Mon Sep 17 00:00:00 2001 From: keikeicheung Date: Wed, 14 Aug 2024 14:49:11 +0800 Subject: [PATCH 4/4] #1403 amended based on the feedbacks --- .../org/finos/vuu/core/sort/FilterAndSort.scala | 1 - .../vuu/viewport/VisualLinkedViewPortTest.scala | 13 +------------ 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/vuu/src/main/scala/org/finos/vuu/core/sort/FilterAndSort.scala b/vuu/src/main/scala/org/finos/vuu/core/sort/FilterAndSort.scala index 8ce65d5a7..9b1ba6d82 100644 --- a/vuu/src/main/scala/org/finos/vuu/core/sort/FilterAndSort.scala +++ b/vuu/src/main/scala/org/finos/vuu/core/sort/FilterAndSort.scala @@ -16,7 +16,6 @@ case class VisualLinkedFilter(viewPortVisualLink: ViewPortVisualLink) extends Fi childColumn: Column, source: RowSource, primaryKeys: TablePrimaryKeys): TablePrimaryKeys = { if (parentSelectionKeys.isEmpty) { -// InMemTablePrimaryKeys(ImmutableArray.empty[String]) primaryKeys } else { source.asTable.indexForColumn(childColumn) match { diff --git a/vuu/src/test/scala/org/finos/vuu/viewport/VisualLinkedViewPortTest.scala b/vuu/src/test/scala/org/finos/vuu/viewport/VisualLinkedViewPortTest.scala index 83213485f..c77816e7f 100644 --- a/vuu/src/test/scala/org/finos/vuu/viewport/VisualLinkedViewPortTest.scala +++ b/vuu/src/test/scala/org/finos/vuu/viewport/VisualLinkedViewPortTest.scala @@ -166,17 +166,6 @@ class VisualLinkedViewPortTest extends AbstractViewPortTestCase with Matchers wi Then("check we now have 4 keys in the viewport") viewPortOrders.getKeys.length shouldEqual 4 -// Then("Check we still maintain the selection even with a new sort or filter") -// assertVpEqWithMeta(combineQs(viewPortOrders).filter(vpu => vpu.vp.id == viewPortOrders.id)) { -// Table( -// ("sel" ,"orderId" ,"trader" ,"ric" ,"tradeTime","quantity"), -// (0 ,"NYC-0003","chris" ,"BT.L" ,1311544800030L,100 ), -// (0 ,"NYC-0004","chris" ,"BT.L" ,1311544800040L,101 ), -// (0 ,"NYC-0005","chris" ,"BT.L" ,1311544800050L,102 ), -// (0 ,"NYC-0006","chris" ,"BT.L" ,1311544800060L,103 ) -// ) -// } - Then("Check we can remove the visual linking") viewPortContainer.unlinkViewPorts(session, outQueue, viewPortOrders.id) @@ -337,7 +326,7 @@ class VisualLinkedViewPortTest extends AbstractViewPortTestCase with Matchers wi } } - Scenario("should should all when no parent is selected") { + Scenario("should show all when no parent is selected") { implicit val clock: Clock = new TestFriendlyClock(TestTimeStamp.EPOCH_DEFAULT) implicit val metrics: MetricsProvider = new MetricsProviderImpl