Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Approvedpush 20240723 01 #1442

Merged
merged 4 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 deletions vuu-ui/packages/vuu-data-test/src/TickingArrayDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ type DataSourceBroadcastSubscribeMessage = {
targetId: string;
targetColumn: string;
sourceId: string;
sourceColumn?: string;
};

type DataSourceBroadcastSelectionMessage = {
sourceColumnName?: string;
columnName: string;
linkType: "subscribe-link-filter" | "subscribe-link-select";
targetId: string;
Expand All @@ -65,6 +67,7 @@ const isMessageForSelf = (message: DataSourceBroadcastMessage, id: string) =>
message.targetId === id;

type LinkSubscription = {
sourceColumnName?: string;
columnName: string;
linkType: "subscribe-link-filter" | "subscribe-link-select";
};
Expand Down Expand Up @@ -148,8 +151,9 @@ export class TickingArrayDataSource extends ArrayDataSource {
this.#selectionLinkSubscribers?.size ?? 0;
if (numberOfSelectionSubscribers > 0) {
this.#selectionLinkSubscribers?.forEach(
({ columnName, linkType }, targetId) => {
({ sourceColumnName, columnName, linkType }, targetId) => {
this.sendBroadcastMessage({
sourceColumnName,
columnName,
linkType,
sourceId: this.viewport,
Expand Down Expand Up @@ -320,6 +324,7 @@ export class TickingArrayDataSource extends ArrayDataSource {
LinkSubscription
>());
subscribers.set(message.sourceId, {
sourceColumnName: message.sourceColumn,
columnName: message.targetColumn,
linkType: message.type,
});
Expand All @@ -328,7 +333,8 @@ export class TickingArrayDataSource extends ArrayDataSource {

case "selection-changed":
{
const { columnName, linkType, selectedValues } = message;
const { sourceColumnName, columnName, linkType, selectedValues } =
message;
const selectedIndices = [];
const colIndex = this.columnMap[columnName];
if (linkType === "subscribe-link-select") {
Expand All @@ -341,7 +347,9 @@ export class TickingArrayDataSource extends ArrayDataSource {
this.select(selectedIndices);
} else {
this.filter = {
filter: `${columnName} in ["${selectedValues.join('","')}"]`,
filter: `${sourceColumnName} in ["${selectedValues.join(
'","'
)}"]`,
};
}
}
Expand All @@ -351,4 +359,24 @@ export class TickingArrayDataSource extends ArrayDataSource {
console.log(`unrecognised message ${message.type}`);
}
};

set visualLink(visualLink: LinkDescriptorWithLabel | undefined) {
if (visualLink) {
const {
parentClientVpId,
link: { fromColumn, toColumn },
} = visualLink;

if (this.viewport) {
console.log("tables linked");
this.sendBroadcastMessage({
sourceId: this.viewport,
sourceColumn: fromColumn,
type: "subscribe-link-filter",
targetId: parentClientVpId,
targetColumn: toColumn,
});
}
}
}
}
86 changes: 71 additions & 15 deletions vuu-ui/packages/vuu-data-test/src/VuuModule.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import {
DataSource,
DataSourceRow,
DataSourceSubscribedMessage,
OpenDialogActionWithSchema,
SuggestionFetcher,
TableSchema,
} from "@finos/vuu-data-types";
import {
ClientToServerMenuRPC,
ClientToServerViewportRpcCall,
LinkDescriptorWithLabel,
TypeaheadParams,
VuuMenu,
VuuRowDataItemType,
VuuTable,
VuuLink,
LinkDescriptorWithLabel,
} from "@finos/vuu-protocol-types";
import { uuid } from "@finos/vuu-utils";
import { Table, buildDataColumnMapFromSchema } from "./Table";
Expand All @@ -31,7 +31,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, LinkDescriptorWithLabel[] | undefined>;
vuuLinks?: Record<T, VuuLink[] | undefined>;
}

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

type Subscription = {
viewportId: string;
dataSource: DataSource;
};
export class VuuModule<T extends string = string> implements IVuuModule<T> {
#menus: Record<T, VuuMenu | undefined> | undefined;
#name: string;
#schemas: Record<T, Readonly<TableSchema>>;
#sessionTableMap: SessionTableMap = {};
#tables: Record<T, Table>;
#tableServices: Record<T, RpcService[] | undefined> | undefined;
#visualLinks: Record<T, LinkDescriptorWithLabel[] | undefined> | undefined;
#visualLinks: Record<T, VuuLink[] | undefined> | undefined;
#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 @@ -88,19 +93,54 @@ export class VuuModule<T extends string = string> implements IVuuModule<T> {
this.#visualLinks = visualLinks;
}

private registerViewport = (
subscriptionDetails: DataSourceSubscribedMessage
) => {
console.log("<subscription-open> register new viewport", {
subscriptionDetails,
});
};

private unregisterViewport = (viewportId: string) => {
console.log(`<subscription-closed> unregister viewport ${viewportId}`);

for (const [tableName, subscriptions] of this.#subscriptionMap) {
if (subscriptions[0].viewportId.toString() === viewportId) {
this.#subscriptionMap.delete(tableName);
} else {
const links = subscriptions[0].dataSource.links;
if (links) {
for (let i = 0; i < links?.length; i++) {
if (links[i].parentClientVpId === viewportId) {
links.splice(i);
}
}
}
subscriptions[0].dataSource.links = links;
}
}
};

getLink = (
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],
};
visualLinks.push(newLink);
}
}
return visualLinks;
};

createDataSource = (tableName: T) => {
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 @@ -112,12 +152,28 @@ 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],
visualLinks,
});

dataSource.on("subscribed", this.registerViewport);
dataSource.on("unsubscribed", this.unregisterViewport);

this.#subscriptionMap.set(tableName, [
{ viewportId: dataSource.viewport, dataSource },
]);

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
13 changes: 6 additions & 7 deletions vuu-ui/packages/vuu-data-test/src/basket/basket-module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
LinkDescriptorWithLabel,
VuuLink,
VuuMenu,
VuuRowDataItemType,
} from "@finos/vuu-protocol-types";
Expand Down Expand Up @@ -212,13 +212,12 @@ export const tables: Record<BasketsTableName, Table> = {
),
};

const visualLinks: Record<
BasketsTableName,
LinkDescriptorWithLabel[] | undefined
> = {
const vuuLinks: Record<BasketsTableName, VuuLink[] | undefined> = {
algoType: undefined,
basket: undefined,
basketConstituent: undefined,
basketConstituent: [
{ fromColumn: "basketId", toColumn: "id", toTable: "basket" },
],
basketTrading: undefined,
basketTradingConstituent: undefined,
basketTradingConstituentJoin: undefined,
Expand Down Expand Up @@ -280,5 +279,5 @@ export const basketModule = new VuuModule<BasketsTableName>({
schemas,
services,
tables,
visualLinks,
vuuLinks,
});
9 changes: 3 additions & 6 deletions vuu-ui/packages/vuu-data-test/src/simul/simul-module.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
ClientToServerMenuRowRPC,
LinkDescriptorWithLabel,
ShowNotificationAction,
VuuLink,
VuuMenu,
} from "@finos/vuu-protocol-types";
import { Table, buildDataColumnMap, joinTables } from "../Table";
Expand Down Expand Up @@ -46,10 +46,7 @@ const tables: Record<SimulTableName, Table> = {
prices: pricesTable,
};

const visualLinks: Record<
SimulTableName,
LinkDescriptorWithLabel[] | undefined
> = {
const vuuLinks: Record<SimulTableName, VuuLink[] | undefined> = {
...undefinedTables,
};

Expand Down Expand Up @@ -131,5 +128,5 @@ export const simulModule = new VuuModule<SimulTableName>({
schemas,
services,
tables,
visualLinks,
vuuLinks,
});
Loading