Skip to content

Commit

Permalink
revise add-visual-links
Browse files Browse the repository at this point in the history
  • Loading branch information
chuchee committed Jul 24, 2024
1 parent 00f3aed commit 71b2523
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 77 deletions.
197 changes: 123 additions & 74 deletions vuu-ui/packages/vuu-data-test/src/VuuModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T extends string = string> {
createDataSource: (tableName: T) => DataSource;
Expand All @@ -33,7 +32,7 @@ export interface VuuModuleConstructorProps<T extends string = string> {
schemas: Record<T, Readonly<TableSchema>>;
services?: Record<T, RpcService[] | undefined>;
tables: Record<T, Table>;
visualLinks?: Record<T, VuuLink[] | undefined>;
vuuLinks?: Record<T, VuuLink[] | undefined>;
}

export type SessionTableMap = Record<string, Table>;
Expand Down Expand Up @@ -65,62 +64,62 @@ export type RpcService = {
service: (rpcRequest: RpcServiceRequest) => Promise<unknown>;
};

class CompLink {
#compLinks: Record<BasketsTableName, LinkDescriptorWithLabel[] | undefined> =
{
algoType: undefined,
basket: undefined,
basketConstituent: undefined,
basketTrading: undefined,
basketTradingConstituent: undefined,
basketTradingConstituentJoin: undefined,
priceStrategyType: undefined,
};

getLink = (
childTable: BasketsTableName,
subscriptionMap: Map<string, string[]>,
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<T extends string = string> {
// #compLinks: Record<T, LinkDescriptorWithLabel[] | undefined> = {
// algoType: undefined,
// basket: undefined,
// basketConstituent: undefined,
// basketTrading: undefined,
// basketTradingConstituent: undefined,
// basketTradingConstituentJoin: undefined,
// priceStrategyType: undefined,
// };

// getLink = (
// childTable: T,
// subscriptionMap: Map<string, Subscription[]>,
// 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<T extends string = string> implements IVuuModule<T> {
#menus: Record<T, VuuMenu | undefined> | undefined;
#name: string;
Expand All @@ -129,15 +128,15 @@ export class VuuModule<T extends string = string> implements IVuuModule<T> {
#tables: Record<T, Table>;
#tableServices: Record<T, RpcService[] | undefined> | undefined;
#visualLinks: Record<T, VuuLink[] | undefined> | undefined;
#subscriptionMap: Map<string, string[]> = new Map();
#subscriptionMap: Map<string, Subscription[]> = new Map();

constructor({
menus,
name,
schemas,
services,
tables,
visualLinks,
vuuLinks: visualLinks,
}: VuuModuleConstructorProps<T>) {
this.#menus = menus;
this.#name = name;
Expand All @@ -154,11 +153,11 @@ export class VuuModule<T extends string = string> implements IVuuModule<T> {
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) => {
Expand All @@ -173,7 +172,46 @@ export class VuuModule<T extends string = string> implements IVuuModule<T> {
//TODO: update visual links
};

getLink = (
// childTable: T,
subscriptionMap: Map<string, Subscription[]>,
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,
Expand All @@ -185,19 +223,30 @@ export class VuuModule<T extends string = string> implements IVuuModule<T> {
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;
};

Expand Down
4 changes: 2 additions & 2 deletions vuu-ui/packages/vuu-data-test/src/basket/basket-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ export const tables: Record<BasketsTableName, Table> = {
),
};

const visualLinks: Record<
const vuuLinks: Record<
BasketsTableName,
// LinkDescriptorWithLabel[]
VuuLink[] | undefined
Expand Down Expand Up @@ -284,5 +284,5 @@ export const basketModule = new VuuModule<BasketsTableName>({
schemas,
services,
tables,
visualLinks,
vuuLinks,
});
2 changes: 1 addition & 1 deletion vuu-ui/packages/vuu-data-test/src/simul/simul-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,5 +128,5 @@ export const simulModule = new VuuModule<SimulTableName>({
schemas,
services,
tables,
visualLinks,
vuuLinks: visualLinks,
});

0 comments on commit 71b2523

Please sign in to comment.