Skip to content

Commit

Permalink
#1409 preserve message type on response to UI
Browse files Browse the repository at this point in the history
  • Loading branch information
heswell committed Jul 1, 2024
1 parent b8a7471 commit c36b2f7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
19 changes: 5 additions & 14 deletions vuu-ui/packages/vuu-data-remote/src/connection-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ import {
ServerProxySubscribeMessage,
TableSchema,
VuuUIMessageIn,
VuuUIMessageInRPC,
VuuUIMessageInTableList,
VuuUIMessageInTableMeta,
VuuUIMessageOut,
WebSocketProtocol,
} from "@finos/vuu-data-types";
Expand All @@ -24,6 +21,7 @@ import {
getLoggingConfigForWorker,
isConnectionQualityMetrics,
isConnectionStatusMessage,
isRequestResponse,
isTableSchemaMessage,
messageHasResult,
uuid,
Expand Down Expand Up @@ -176,19 +174,12 @@ function handleMessageFromWorker({
ConnectionManager.emit("connection-status", message);
} else if (isConnectionQualityMetrics(message)) {
ConnectionManager.emit("connection-metrics", message);
} else {
const requestId = (message as VuuUIMessageInRPC).requestId;
} else if (isRequestResponse(message)) {
const { requestId } = message;
if (pendingRequests.has(requestId)) {
const { resolve } = pendingRequests.get(requestId);
pendingRequests.delete(requestId);
const {
type: _1,
requestId: _2,
...rest
} = message as
| VuuUIMessageInRPC
| VuuUIMessageInTableList
| VuuUIMessageInTableMeta;
const { requestId: _, ...messageWithoutRequestId } = message;

if (messageHasResult(message)) {
resolve(message.result);
Expand All @@ -200,7 +191,7 @@ function handleMessageFromWorker({
} else if (isTableSchemaMessage(message)) {
resolve(message.tableSchema);
} else {
resolve(rest);
resolve(messageWithoutRequestId);
}
} else {
console.warn(
Expand Down
22 changes: 13 additions & 9 deletions vuu-ui/packages/vuu-data-types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -625,18 +625,22 @@ export interface VuuUIMessageInMenuRej {
type: "VIEW_PORT_MENU_REJ";
}

export type VuuUIMessageIn =
| VuuUIMessageInConnected
| VuuUIMessageInConnectionFailed
| VuuUIMessageInWorkerReady
| VuuUIMessageInRPC
| ViewportRpcResponse
export type VuuUiMessageInRequestResponse =
| VuuUIMessageInMenuRej
| MenuRpcResponse
| MenuRpcReject
| VuuUIMessageInTableList
| VuuUIMessageInTableMeta
| VuuUIMessageInRPC
| VuuUIMessageInRPCEditReject
| VuuUIMessageInRPCEditResponse;
| VuuUIMessageInRPCEditResponse
| ViewportRpcResponse
| VuuUIMessageInTableList
| VuuUIMessageInTableMeta;

export type VuuUIMessageIn =
| VuuUiMessageInRequestResponse
| VuuUIMessageInConnected
| VuuUIMessageInConnectionFailed
| VuuUIMessageInWorkerReady;

export type WebSocketProtocol = string | string[] | undefined;

Expand Down
7 changes: 6 additions & 1 deletion vuu-ui/packages/vuu-utils/src/protocol-message-utils.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import {
import type {
MenuRpcAction,
MenuRpcResponse,
OpenDialogActionWithSchema,
RpcResponse,
VuuUIMessageOut,
VuuUiMessageInRequestResponse,
} from "@finos/vuu-data-types";
import {
ClientToServerMenuRPC,
Expand All @@ -28,6 +29,10 @@ export const isVuuMenuRpcRequest = (
message: VuuUIMessageOut | VuuRpcRequest | ClientToServerMenuRPC
): message is ClientToServerMenuRPC => MENU_RPC_TYPES.includes(message["type"]);

export const isRequestResponse = (
message: object
): message is VuuUiMessageInRequestResponse => "requestId" in message;

export const isOpenSessionTableDialogMessage = (
rpcResponse: RpcResponse
): rpcResponse is MenuRpcResponse<OpenDialogActionWithSchema> =>
Expand Down

0 comments on commit c36b2f7

Please sign in to comment.