Skip to content

Commit

Permalink
Fix conflict resolutions
Browse files Browse the repository at this point in the history
  • Loading branch information
cfisher-scottlogic committed Nov 14, 2023
1 parent 2c305f7 commit ea0e97a
Show file tree
Hide file tree
Showing 6 changed files with 174 additions and 175 deletions.
45 changes: 23 additions & 22 deletions vuu-ui/packages/vuu-data-react/src/hooks/useVuuMenuActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
MenuActionHandler,
MenuBuilder,
} from "@finos/vuu-data-types";
import { getFilterPredicate } from "@finos/vuu-filter-parser";
import {getFilterPredicate} from "@finos/vuu-filter-parser";
import {
ClientToServerMenuCellRPC,
ClientToServerMenuRowRPC,
Expand All @@ -28,8 +28,8 @@ import {
isGroupMenuItemDescriptor,
metadataKeys,
} from "@finos/vuu-utils";
import type { MenuActionClosePopup } from "@finos/vuu-popups";
import { useCallback } from "react";
import type {MenuActionClosePopup} from "@finos/vuu-popups";
import {useCallback} from "react";

export const addRowsFromInstruments = "addRowsFromInstruments";

Expand All @@ -38,12 +38,13 @@ export interface VuuCellMenuItem extends VuuMenuItem {
field: string;
value: VuuRowDataItemType;
}

export interface VuuRowMenuItem extends VuuMenuItem {
rowKey: string;
row: { [key: string]: VuuRowDataItemType };
}

const { KEY } = metadataKeys;
const {KEY} = metadataKeys;

const NO_CONFIG: MenuActionConfig = {};

Expand Down Expand Up @@ -105,7 +106,7 @@ const gridRowMeetsFilterCriteria = (
const getMenuRpcRequest = (
options: VuuMenuItem
): Omit<ClientToServerMenuRPC, "vpId"> => {
const { rpcName } = options;
const {rpcName} = options;
if (isCellMenu(options)) {
return {
field: options.field,
Expand Down Expand Up @@ -179,11 +180,11 @@ export type VuuServerMenuOptions = {
columnMap: ColumnMap;
columnName: string;
row: DataSourceRow;
selectedRowsCount: number;
selectedRows: DataSourceRow[];
viewport: string;
};

const hasFilter = ({ filter }: VuuMenuItem) =>
const hasFilter = ({filter}: VuuMenuItem) =>
typeof filter === "string" && filter.length > 0;

const getMenuItemOptions = (
Expand Down Expand Up @@ -260,12 +261,12 @@ const buildMenuDescriptor = (
};
} else {
const children = menu.menus
.map((childMenu) =>
buildMenuDescriptor(childMenu, tableLocation, options)
)
.filter(
(childMenu) => childMenu !== undefined
) as ContextMenuItemDescriptor[];
.map((childMenu) =>
buildMenuDescriptor(childMenu, tableLocation, options)
)
.filter(
(childMenu) => childMenu !== undefined
) as ContextMenuItemDescriptor[];
if (children.length > 0) {
return {
label: menu.name,
Expand All @@ -277,20 +278,20 @@ const buildMenuDescriptor = (
};

export const useVuuMenuActions = ({
clientSideMenuActionHandler,
dataSource,
menuActionConfig = NO_CONFIG,
onRpcResponse,
}: VuuMenuActionHookProps): ViewServerHookResult => {
clientSideMenuActionHandler,
dataSource,
menuActionConfig = NO_CONFIG,
onRpcResponse,
}: VuuMenuActionHookProps): ViewServerHookResult => {
const buildViewserverMenuOptions: MenuBuilder = useCallback(
(location, options) => {
const { links, menu } = dataSource;
const { visualLink } = menuActionConfig;
const {links, menu} = dataSource;
const {visualLink} = menuActionConfig;
const descriptors: ContextMenuItemDescriptor[] = [];

if (location === "grid" && links && !visualLink) {
links.forEach((linkDescriptor: LinkDescriptorWithLabel) => {
const { link, label: linkLabel } = linkDescriptor;
const {link, label: linkLabel} = linkDescriptor;
const label = linkLabel ? linkLabel : link.toTable;
descriptors.push({
label: `Link to ${label}`,
Expand Down Expand Up @@ -319,7 +320,7 @@ export const useVuuMenuActions = ({
);

const handleMenuAction = useCallback(
({ menuId, options }: MenuActionClosePopup) => {
({menuId, options}: MenuActionClosePopup) => {
if (clientSideMenuActionHandler?.(menuId, options)) {
return true;
} else if (menuId === "MENU_RPC_CALL") {
Expand Down
79 changes: 37 additions & 42 deletions vuu-ui/packages/vuu-data/src/connection-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,14 @@ import {
VuuTable,
VuuTableList,
} from "@finos/vuu-protocol-types";
import {
EventEmitter,
getLoggingConfigForWorker,
uuid,
} from "@finos/vuu-utils";
import {EventEmitter, getLoggingConfigForWorker, uuid,} from "@finos/vuu-utils";
import {
DataSourceCallbackMessage,
shouldMessageBeRoutedToDataSource as messageShouldBeRoutedToDataSource,
} from "./data-source";
import * as Message from "./server-proxy/messages";
import {
ConnectionQualityMetrics,
ConnectionStatusMessage,
isConnectionQualityMetrics,
isConnectionStatusMessage,
Expand All @@ -31,10 +28,9 @@ import {
} from "./vuuUIMessageTypes";

// Note: inlined-worker is a generated file, it must be built
import { workerSourceCode } from "./inlined-worker";
import { ConnectionQualityMetrics } from "./vuuUIMessageTypes";
import { WebSocketProtocol } from "./websocket-connection";
import { TableSchema } from "./message-utils";
import {workerSourceCode} from "./inlined-worker";
import {WebSocketProtocol} from "./websocket-connection";
import {TableSchema} from "./message-utils";

const workerBlob = new Blob([getLoggingConfigForWorker() + workerSourceCode], {
type: "text/javascript",
Expand Down Expand Up @@ -89,17 +85,17 @@ type WorkerOptions = {
// connection status messages before that, so we forward them to caller
// while they wait for worker.
const getWorker = async ({
handleConnectionStatusChange,
protocol,
retryLimitDisconnect,
retryLimitStartup,
token = "",
username,
url,
}: WorkerOptions) => {
handleConnectionStatusChange,
protocol,
retryLimitDisconnect,
retryLimitStartup,
token = "",
username,
url,
}: WorkerOptions) => {
if (token === "" && pendingWorker === undefined) {
return new Promise<Worker>((resolve) => {
pendingWorkerNoToken.push({ resolve });
pendingWorkerNoToken.push({resolve});
});
}
//FIXME If we have a pending request already and a new request arrives with a DIFFERENT
Expand All @@ -119,7 +115,7 @@ const getWorker = async ({
// establishing a connection. When we resolve the worker, a runtime message
// handler will replace this (see below)
worker.onmessage = (msg: MessageEvent<VuuUIMessageIn>) => {
const { data: message } = msg;
const {data: message} = msg;
if (message.type === "ready") {
window.clearTimeout(timer);
worker.postMessage({
Expand All @@ -139,7 +135,7 @@ const getWorker = async ({
}
pendingWorkerNoToken.length = 0;
} else if (isConnectionStatusMessage(message)) {
handleConnectionStatusChange({ data: message });
handleConnectionStatusChange({data: message});
} else {
console.warn("ConnectionManager: Unexpected message from the worker");
}
Expand All @@ -150,8 +146,8 @@ const getWorker = async ({
};

function handleMessageFromWorker({
data: message,
}: MessageEvent<VuuUIMessageIn | DataSourceCallbackMessage>) {
data: message,
}: MessageEvent<VuuUIMessageIn | DataSourceCallbackMessage>) {
if (messageShouldBeRoutedToDataSource(message)) {
const viewport = viewports.get(message.clientViewportId);
if (viewport) {
Expand All @@ -164,12 +160,11 @@ function handleMessageFromWorker({
} else if (isConnectionStatusMessage(message)) {
ConnectionManager.emit("connection-status", message);
} else if (isConnectionQualityMetrics(message)) {
console.log({ message });
ConnectionManager.emit("connection-metrics", message);
} else {
const requestId = (message as VuuUIMessageInRPC).requestId;
if (pendingRequests.has(requestId)) {
const { resolve } = pendingRequests.get(requestId);
const {resolve} = pendingRequests.get(requestId);
pendingRequests.delete(requestId);
const {
type: _1,
Expand Down Expand Up @@ -214,7 +209,7 @@ const asyncRequest = <T = unknown>(
...msg,
});
return new Promise((resolve, reject) => {
pendingRequests.set(requestId, { resolve, reject });
pendingRequests.set(requestId, {resolve, reject});
});
};

Expand Down Expand Up @@ -246,11 +241,11 @@ const connectedServerAPI: ServerAPI = {
request: message,
postMessageToClientDataSource: callback,
});
worker.postMessage({ type: "subscribe", ...message });
worker.postMessage({type: "subscribe", ...message});
},

unsubscribe: (viewport) => {
worker.postMessage({ type: "unsubscribe", viewport });
worker.postMessage({type: "unsubscribe", viewport});
},

send: (message) => {
Expand All @@ -268,7 +263,7 @@ const connectedServerAPI: ServerAPI = {
) => asyncRequest<T>(message),

getTableList: async () =>
asyncRequest<VuuTableList>({ type: "GET_TABLE_LIST" }),
asyncRequest<VuuTableList>({type: "GET_TABLE_LIST"}),

getTableSchema: async (table) =>
asyncRequest<TableSchema>({
Expand Down Expand Up @@ -297,13 +292,13 @@ class _ConnectionManager extends EventEmitter<ConnectionEvents> {
// The first request must have the token. We can change this to block others until
// the request with token is received.
async connect({
url,
authToken,
username,
protocol,
retryLimitDisconnect,
retryLimitStartup,
}: ConnectOptions): Promise<ServerAPI> {
url,
authToken,
username,
protocol,
retryLimitDisconnect,
retryLimitStartup,
}: ConnectOptions): Promise<ServerAPI> {
// By passing handleMessageFromWorker here, we can get connection status
//messages while we wait for worker to resolve.
worker = await getWorker({
Expand Down Expand Up @@ -338,13 +333,13 @@ export const ConnectionManager = new _ConnectionManager();
* @param token
*/
export const connectToServer = async ({
url,
protocol = undefined,
authToken,
username,
retryLimitDisconnect,
retryLimitStartup,
}: ConnectOptions) => {
url,
protocol = undefined,
authToken,
username,
retryLimitDisconnect,
retryLimitStartup,
}: ConnectOptions) => {
try {
const serverAPI = await ConnectionManager.connect({
protocol,
Expand Down
Loading

0 comments on commit ea0e97a

Please sign in to comment.