Skip to content

Commit

Permalink
move set-link
Browse files Browse the repository at this point in the history
  • Loading branch information
chuchee authored and keikeicheung committed Jul 25, 2024
1 parent f8a06fb commit 8bcdf70
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 34 deletions.
11 changes: 0 additions & 11 deletions vuu-ui/packages/vuu-data-react/src/hooks/useVuuMenuActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import {
isTableLocation,
} from "@finos/vuu-utils";
import { Button } from "@salt-ds/core";
import { TickingArrayDataSource } from "@finos/vuu-data-test";
import { useCallback } from "react";

const NO_CONFIG: MenuActionConfig = {};
Expand Down Expand Up @@ -271,16 +270,6 @@ export const useVuuMenuActions = ({
});
return true;
} else if (menuId === "link-table") {
const { links } = dataSource;
console.log("tables linked");
(dataSource as TickingArrayDataSource).sendBroadcastMessage({
sourceId: (dataSource as TickingArrayDataSource).viewport,
sourceColumn: "basketId",
type: "subscribe-link-filter",
targetId: links?.[0].parentClientVpId as string,
targetColumn: "id",
});

return (
(dataSource.visualLink = options as LinkDescriptorWithLabel), true
);
Expand Down
20 changes: 20 additions & 0 deletions vuu-ui/packages/vuu-data-test/src/TickingArrayDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,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,
});
}
}
}
}
20 changes: 5 additions & 15 deletions vuu-ui/packages/vuu-data-test/src/VuuModule.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
DataSource,
DataSourceRow,
// DataSourceSubscribedMessage,
OpenDialogActionWithSchema,
SuggestionFetcher,
TableSchema,
Expand Down Expand Up @@ -94,30 +93,22 @@ 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 subscription of this.#subscriptionMap) {
if (subscription[1][0].viewportId.toString() === viewportId) {
this.#subscriptionMap.delete(subscription[0]);
for (const [tableName, subscriptions] of this.#subscriptionMap) {
if (subscriptions[0].viewportId.toString() === viewportId) {
this.#subscriptionMap.delete(tableName);
} else {
const links = subscription[1][0].dataSource.links;
const links = subscriptions[0].dataSource.links;
if (links) {
for (let i = 0; i < links?.length; i++) {
if (links[i].parentClientVpId === viewportId) {
links.splice(i);
}
}
}
subscription[1][0].dataSource.links = links;
subscriptions[0].dataSource.links = links;
}
}
};
Expand Down Expand Up @@ -164,7 +155,6 @@ export class VuuModule<T extends string = string> implements IVuuModule<T> {
visualLinks,
});

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

this.#subscriptionMap.set(tableName, [
Expand Down
7 changes: 1 addition & 6 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,4 @@
import {
// LinkDescriptorWithLabel,
VuuLink,
VuuMenu,
VuuRowDataItemType,
Expand Down Expand Up @@ -213,11 +212,7 @@ export const tables: Record<BasketsTableName, Table> = {
),
};

const vuuLinks: Record<
BasketsTableName,
// LinkDescriptorWithLabel[]
VuuLink[] | undefined
> = {
const vuuLinks: Record<BasketsTableName, VuuLink[] | undefined> = {
algoType: undefined,
basket: undefined,
basketConstituent: [
Expand Down
4 changes: 2 additions & 2 deletions vuu-ui/packages/vuu-data-test/src/simul/simul-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const tables: Record<SimulTableName, Table> = {
prices: pricesTable,
};

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

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

0 comments on commit 8bcdf70

Please sign in to comment.