From 71b2523f47ab1e1271a217f88c9b7ac063004744 Mon Sep 17 00:00:00 2001 From: Zhen Date: Mon, 22 Jul 2024 18:27:13 -0400 Subject: [PATCH] revise add-visual-links --- .../packages/vuu-data-test/src/VuuModule.ts | 197 +++++++++++------- .../vuu-data-test/src/basket/basket-module.ts | 4 +- .../vuu-data-test/src/simul/simul-module.ts | 2 +- 3 files changed, 126 insertions(+), 77 deletions(-) diff --git a/vuu-ui/packages/vuu-data-test/src/VuuModule.ts b/vuu-ui/packages/vuu-data-test/src/VuuModule.ts index 395efbc83..73a0bd0be 100644 --- a/vuu-ui/packages/vuu-data-test/src/VuuModule.ts +++ b/vuu-ui/packages/vuu-data-test/src/VuuModule.ts @@ -20,7 +20,6 @@ import { uuid } from "@finos/vuu-utils"; import { Table, buildDataColumnMapFromSchema } from "./Table"; import { TickingArrayDataSource } from "./TickingArrayDataSource"; import { makeSuggestions } from "./makeSuggestions"; -import { BasketsTableName } from "./basket"; export interface IVuuModule { createDataSource: (tableName: T) => DataSource; @@ -33,7 +32,7 @@ export interface VuuModuleConstructorProps { schemas: Record>; services?: Record; tables: Record; - visualLinks?: Record; + vuuLinks?: Record; } export type SessionTableMap = Record; @@ -65,62 +64,62 @@ export type RpcService = { service: (rpcRequest: RpcServiceRequest) => Promise; }; -class CompLink { - #compLinks: Record = - { - algoType: undefined, - basket: undefined, - basketConstituent: undefined, - basketTrading: undefined, - basketTradingConstituent: undefined, - basketTradingConstituentJoin: undefined, - priceStrategyType: undefined, - }; - - getLink = ( - childTable: BasketsTableName, - subscriptionMap: Map, - tempLinks: VuuLink[] - ) => { - for (let i = 0; i < tempLinks.length; i++) { - if (subscriptionMap.get(tempLinks[i].toTable)) { - const newLink: LinkDescriptorWithLabel = { - parentClientVpId: subscriptionMap.get( - tempLinks[i].toTable - )?.[0] as string, - parentVpId: subscriptionMap.get(tempLinks[i].toTable)?.[0] as string, - link: tempLinks[i], - }; - this.updateLink(childTable, newLink); - } - } - console.log("visualLinks: ", this.#compLinks); - return this.#compLinks; - }; - - updateLink = ( - childTable: BasketsTableName, - newLink: LinkDescriptorWithLabel - ) => { - if (this.#compLinks[childTable]) { - const compLinks = this.#compLinks?.[ - childTable - ] as LinkDescriptorWithLabel[]; - for (let i = 0; i < compLinks.length; i++) { - if (compLinks[i].parentVpId === newLink.parentVpId) { - console.log("existed"); - } else { - compLinks?.push(newLink); - } - } - } else { - this.#compLinks[childTable] = [newLink]; - } - }; -} - -const vLink = new CompLink(); - +// class CompLink { +// #compLinks: Record = { +// algoType: undefined, +// basket: undefined, +// basketConstituent: undefined, +// basketTrading: undefined, +// basketTradingConstituent: undefined, +// basketTradingConstituentJoin: undefined, +// priceStrategyType: undefined, +// }; + +// getLink = ( +// childTable: T, +// subscriptionMap: Map, +// tempLinks: VuuLink[] +// ) => { +// for (let i = 0; i < tempLinks.length; i++) { +// if (subscriptionMap.get(tempLinks[i].toTable)) { +// const newLink: LinkDescriptorWithLabel = { +// parentClientVpId: subscriptionMap.get(tempLinks[i].toTable)?.[0] +// .viewportId as string, +// parentVpId: subscriptionMap.get(tempLinks[i].toTable)?.[0] +// .viewportId as string, +// link: tempLinks[i], +// }; +// this.updateLink(childTable, newLink); +// } +// } +// console.log("visualLinks: ", this.#compLinks); +// return this.#compLinks; +// }; + +// updateLink = (childTable: T, newLink: LinkDescriptorWithLabel) => { +// if (this.#compLinks[childTable]) { +// const compLinks = this.#compLinks?.[ +// childTable +// ] as LinkDescriptorWithLabel[]; +// for (let i = 0; i < compLinks.length; i++) { +// if (compLinks[i].parentVpId === newLink.parentVpId) { +// console.log("existed"); +// } else { +// compLinks?.push(newLink); +// } +// } +// } else { +// this.#compLinks[childTable] = [newLink]; +// } +// }; +// } + +// const vLink = new CompLink(); + +type Subscription = { + viewportId: string; + dataSource: DataSource; +}; export class VuuModule implements IVuuModule { #menus: Record | undefined; #name: string; @@ -129,7 +128,7 @@ export class VuuModule implements IVuuModule { #tables: Record; #tableServices: Record | undefined; #visualLinks: Record | undefined; - #subscriptionMap: Map = new Map(); + #subscriptionMap: Map = new Map(); constructor({ menus, @@ -137,7 +136,7 @@ export class VuuModule implements IVuuModule { schemas, services, tables, - visualLinks, + vuuLinks: visualLinks, }: VuuModuleConstructorProps) { this.#menus = menus; this.#name = name; @@ -154,11 +153,11 @@ export class VuuModule implements IVuuModule { subscriptionDetails, }); - const parentTable = subscriptionDetails.tableSchema.table.table; - this.#subscriptionMap.set(parentTable, [ - subscriptionDetails.clientViewportId, - ]); - console.log("subscriptionMap: ", this.#subscriptionMap); + // const parentTable = subscriptionDetails.tableSchema.table.table; + // this.#subscriptionMap.set(parentTable, [ + // { viewportId: subscriptionDetails.clientViewportId, visualLink: [] }, + // ]); + // console.log("subscriptionMap: ", this.#subscriptionMap); }; private unregisterViewport = (viewportId: string) => { @@ -173,7 +172,46 @@ export class VuuModule implements IVuuModule { //TODO: update visual links }; + getLink = ( + // childTable: T, + subscriptionMap: Map, + vuuLinks: VuuLink[] + ) => { + const visualLinks: LinkDescriptorWithLabel[] = []; + for (let i = 0; i < vuuLinks.length; i++) { + if (subscriptionMap.get(vuuLinks[i].toTable)) { + const newLink: LinkDescriptorWithLabel = { + parentClientVpId: subscriptionMap.get(vuuLinks[i].toTable)?.[0] + .viewportId as string, + parentVpId: subscriptionMap.get(vuuLinks[i].toTable)?.[0] + .viewportId as string, + link: vuuLinks[i], + }; + // this.updateLink(childTable, newLink); + visualLinks.push(newLink); + } + } + return visualLinks; + }; + createDataSource = (tableName: T) => { + // check if you can create visual links + // const visualLinks = + // this.#visualLinks?.[tableName] === undefined + // ? undefined + // : vLink.getLink( + // tableName as BasketsTableName, + // this.#subscriptionMap, + // this.#visualLinks[tableName] as VuuLink[] + // )[tableName]; + const visualLinks = + this.#visualLinks?.[tableName] === undefined + ? undefined + : this.getLink( + this.#subscriptionMap, + this.#visualLinks[tableName] as VuuLink[] + ); + const columnDescriptors = this.getColumnDescriptors(tableName); const dataSource = new TickingArrayDataSource({ columnDescriptors, @@ -185,19 +223,30 @@ export class VuuModule implements IVuuModule { menu: this.#menus?.[tableName], rpcServices: this.getServices(tableName), sessionTables: this.#sessionTableMap, - visualLinks: - this.#visualLinks?.[tableName] === undefined - ? undefined - : vLink.getLink( - tableName as BasketsTableName, - this.#subscriptionMap, - this.#visualLinks[tableName] as VuuLink[] - )[tableName], + visualLinks, }); - dataSource.on("subscribed", this.registerViewport); + // dataSource.on("subscribed", this.registerViewport); dataSource.on("unsubscribed", this.unregisterViewport); + this.#subscriptionMap.set(tableName, [ + { viewportId: dataSource.viewport, dataSource }, + ]); + console.log("subscriptionMap: ", this.#subscriptionMap); + + for (const key of this.#subscriptionMap.keys()) { + if (this.#visualLinks?.[key as T] && key !== tableName) { + const vLink = this.getLink( + this.#subscriptionMap, + this.#visualLinks?.[key as T] as VuuLink[] + ); + const ds = this.#subscriptionMap.get(key)?.[0].dataSource; + if (ds?.links) { + ds.links = vLink; + } + } + } + return dataSource; }; diff --git a/vuu-ui/packages/vuu-data-test/src/basket/basket-module.ts b/vuu-ui/packages/vuu-data-test/src/basket/basket-module.ts index 07a3da29e..fd0323f06 100644 --- a/vuu-ui/packages/vuu-data-test/src/basket/basket-module.ts +++ b/vuu-ui/packages/vuu-data-test/src/basket/basket-module.ts @@ -213,7 +213,7 @@ export const tables: Record = { ), }; -const visualLinks: Record< +const vuuLinks: Record< BasketsTableName, // LinkDescriptorWithLabel[] VuuLink[] | undefined @@ -284,5 +284,5 @@ export const basketModule = new VuuModule({ schemas, services, tables, - visualLinks, + vuuLinks, }); diff --git a/vuu-ui/packages/vuu-data-test/src/simul/simul-module.ts b/vuu-ui/packages/vuu-data-test/src/simul/simul-module.ts index 1c9a1f9b2..0f4af3cf0 100644 --- a/vuu-ui/packages/vuu-data-test/src/simul/simul-module.ts +++ b/vuu-ui/packages/vuu-data-test/src/simul/simul-module.ts @@ -128,5 +128,5 @@ export const simulModule = new VuuModule({ schemas, services, tables, - visualLinks, + vuuLinks: visualLinks, });