Skip to content

Commit

Permalink
finos#1434 an example to use new RPC request (draft)
Browse files Browse the repository at this point in the history
  • Loading branch information
keikeicheung committed Sep 12, 2024
1 parent 2d7ffa3 commit 04b1dc1
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 20 deletions.
44 changes: 27 additions & 17 deletions vuu-ui/packages/vuu-data-react/src/hooks/useTypeaheadSuggestions.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { makeRpcCall } from "@finos/vuu-data-remote";
import {makeRpcCall, newMakeRpcCall} from "@finos/vuu-data-remote";
import { SuggestionFetcher, TableSchemaTable } from "@finos/vuu-data-types";
import {
VuuRpcServiceRequest,
TypeaheadParams,
TypeaheadParams, NewVuuRpcServiceRequest, VuuContext, NewTypeaheadParams
} from "@finos/vuu-protocol-types";
import { useCallback } from "react";

Expand All @@ -19,20 +19,30 @@ export const getTypeaheadParams = (
};

export const useTypeaheadSuggestions = () =>
useCallback<SuggestionFetcher>(async (params: TypeaheadParams) => {
const rpcMessage: VuuRpcServiceRequest =
params.length === 2
? {
type: "RPC_CALL",
service: "TypeAheadRpcHandler",
method: "getUniqueFieldValues",
params,
useCallback<SuggestionFetcher>(async (paramsArray: TypeaheadParams) => {

var context: VuuContext = {
type: "VIEWPORT_CONTEXT",
viewPortId: ""
}

var params: NewTypeaheadParams = {
table: paramsArray[0]["table"],
module: paramsArray[0]["module"],
column: paramsArray[1]
};
const rpcMessage: NewVuuRpcServiceRequest =
{
type: "RPC_REQUEST",
context,
rpcName: "getUniqueFieldValues",
params,
}
: {
type: "RPC_CALL",
service: "TypeAheadRpcHandler",
method: "getUniqueFieldValuesStartingWith",
params,
};
return makeRpcCall<string[]>(rpcMessage);
// : {
// type: "RPC_REQUEST",
// context,
// rpcName: "getUniqueFieldValuesStartingWith",
// params,
// };
return newMakeRpcCall<string[]>(rpcMessage);
}, []);
13 changes: 12 additions & 1 deletion vuu-ui/packages/vuu-data-remote/src/connection-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
VuuTable,
VuuTableList,
VuuCreateVisualLink,
VuuRemoveVisualLink,
VuuRemoveVisualLink, NewVuuRpcServiceRequest,
} from "@finos/vuu-protocol-types";
import {
EventEmitter,
Expand Down Expand Up @@ -232,6 +232,7 @@ export interface ServerAPI {
rpcCall: <T = unknown>(
msg:
| VuuRpcServiceRequest
| NewVuuRpcServiceRequest
| VuuRpcMenuRequest
| VuuRpcViewportRequest
| VuuCreateVisualLink
Expand Down Expand Up @@ -388,3 +389,13 @@ export const makeRpcCall = async <T = unknown>(
throw Error("Error accessing server api");
}
};

export const newMakeRpcCall = async <T = unknown>(
rpcRequest: NewVuuRpcServiceRequest,
) => {
try {
return (await serverAPI).rpcCall<T>(rpcRequest);
} catch (err) {
throw Error("Error accessing server api");
}
};
13 changes: 12 additions & 1 deletion vuu-ui/packages/vuu-data-remote/src/server-proxy/server-proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import type {
VuuTable,
VuuRpcRequest,
VuuCreateVisualLink,
VuuRemoveVisualLink,
VuuRemoveVisualLink, NewVuuRpcServiceRequest,
} from "@finos/vuu-protocol-types";
import {
isVuuMenuRpcRequest,
Expand Down Expand Up @@ -596,6 +596,13 @@ export class ServerProxy {
this.sendMessageToServer(rpcRequest, requestId, { module });
}

private newRpcCall(message: WithRequestId<NewVuuRpcServiceRequest>) {
const [requestId, rpcRequest] =
stripRequestId<NewVuuRpcServiceRequest>(message);
const module = getRpcServiceModule("TypeAheadRpcHandler");
this.sendMessageToServer(rpcRequest, requestId, { module });
}

public handleMessageFromClient(
message:
| Exclude<
Expand All @@ -605,11 +612,13 @@ export class ServerProxy {
| VuuUIMessageOutUnsubscribe
>
| WithRequestId<VuuRpcServiceRequest>
| WithRequestId<NewVuuRpcServiceRequest>
| WithRequestId<VuuRpcMenuRequest>
| WithRequestId<VuuCreateVisualLink>
| WithRequestId<VuuRemoveVisualLink>,
) {
if (isViewportMessage(message) || isVisualLinkMessage(message)) {

if (message.type === "disable") {
// Viewport may already have been unsubscribed
const viewport = this.getViewportForClient(message.viewport, false);
Expand Down Expand Up @@ -693,6 +702,8 @@ export class ServerProxy {
}
case "RPC_CALL":
return this.rpcCall(message);
case "RPC_REQUEST":
return this.newRpcCall(message);
default:
}
}
Expand Down
20 changes: 20 additions & 0 deletions vuu-ui/packages/vuu-protocol-types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,13 @@ export declare type TypeaheadParams =
| [VuuTable, string]
| [VuuTable, string, string];

export declare type NewTypeaheadParams = {
table: string;
module: string;
column: string;
}


export declare type TypeAheadMethod =
| "getUniqueFieldValues"
| "getUniqueFieldValuesStartingWith";
Expand Down Expand Up @@ -362,6 +369,13 @@ export declare type VuuRpcResponse =
| VuuRpcMenuResponse
| VuuRpcEditResponse;

export declare type NewVuuRpcServiceRequest = {
type: "RPC_REQUEST";
context: VuuContext;
rpcName: string;
params: NewTypeaheadParams;
}

export declare type VuuRpcServiceRequest = {
type: "RPC_CALL";
service: "TypeAheadRpcHandler";
Expand Down Expand Up @@ -552,6 +566,12 @@ export declare type VuuRange = {
to: number;
};

export declare type VuuContextType = "GLOBAL_CONTEXT" | "VIEWPORT_CONTEXT"|"VIEWPORT_ROW_CONTEXT";
export declare type VuuContext = {
type: VuuContextType;
viewPortId: string;
}

export declare type VuuSortType = "A" | "D";

export declare type VuuSortCol = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.finos.vuu.net.json
import com.fasterxml.jackson.core.JsonParser
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.scala.DefaultScalaModule
import com.typesafe.scalalogging.StrictLogging
import org.finos.vuu.net.{JsonViewServerMessage, MessageBody, ViewServerMessage}

trait Serializer[R, SERTYPE] {
Expand All @@ -11,7 +12,7 @@ trait Serializer[R, SERTYPE] {
def deserialize(message: R): ViewServerMessage
}

object JsonVsSerializer extends Serializer[String, MessageBody] {
object JsonVsSerializer extends Serializer[String, MessageBody] with StrictLogging {

def getMapper = {
val mapper = new ObjectMapper()
Expand All @@ -24,6 +25,7 @@ object JsonVsSerializer extends Serializer[String, MessageBody] {

def deserialize(s: String): JsonViewServerMessage = {
val mapper = getMapper
logger.info(s);
mapper.readValue(s, classOf[JsonViewServerMessage])
}

Expand Down

0 comments on commit 04b1dc1

Please sign in to comment.