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

#1434 an example to use new RPC request (draft) #1488

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
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";

Check failure on line 1 in vuu-ui/packages/vuu-data-react/src/hooks/useTypeaheadSuggestions.ts

View workflow job for this annotation

GitHub Actions / lint-and-typecheck

'makeRpcCall' is defined but never used. Allowed unused vars must match /^_$/u
import { SuggestionFetcher, TableSchemaTable } from "@finos/vuu-data-types";
import {
VuuRpcServiceRequest,

Check failure on line 4 in vuu-ui/packages/vuu-data-react/src/hooks/useTypeaheadSuggestions.ts

View workflow job for this annotation

GitHub Actions / lint-and-typecheck

'VuuRpcServiceRequest' is defined but never used. Allowed unused vars must match /^_$/u
TypeaheadParams,
TypeaheadParams, NewVuuRpcServiceRequest, VuuContext, NewTypeaheadParams
} from "@finos/vuu-protocol-types";
import { useCallback } from "react";

Expand All @@ -19,20 +19,30 @@
};

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 = {

Check failure on line 24 in vuu-ui/packages/vuu-data-react/src/hooks/useTypeaheadSuggestions.ts

View workflow job for this annotation

GitHub Actions / lint-and-typecheck

Unexpected var, use let or const instead
type: "VIEWPORT_CONTEXT",
viewPortId: ""
}

var params: NewTypeaheadParams = {

Check failure on line 29 in vuu-ui/packages/vuu-data-react/src/hooks/useTypeaheadSuggestions.ts

View workflow job for this annotation

GitHub Actions / lint-and-typecheck

Unexpected var, use let or const instead
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 @@
VuuTable,
VuuRpcRequest,
VuuCreateVisualLink,
VuuRemoveVisualLink,
VuuRemoveVisualLink, NewVuuRpcServiceRequest,
} from "@finos/vuu-protocol-types";
import {
isVuuMenuRpcRequest,
Expand Down Expand Up @@ -130,7 +130,7 @@
private authToken = "";
private user = "user";
private pendingLogin?: PendingLogin;
private pendingRequests = new Map<string, PendingRequest<any>>();

Check warning on line 133 in vuu-ui/packages/vuu-data-remote/src/server-proxy/server-proxy.ts

View workflow job for this annotation

GitHub Actions / lint-and-typecheck

Unexpected any. Specify a different type
private sessionId?: string;
private queuedRequests: Array<QueuedRequest> = [];
private cachedTableMetaRequests: Map<string, Promise<VuuTableMetaResponse>> =
Expand Down Expand Up @@ -596,6 +596,13 @@
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 @@
| 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 @@
}
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
Loading