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

#1409 preserve message type on response to UI #1411

Merged
merged 1 commit into from
Jul 1, 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
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
Loading