Skip to content

Commit

Permalink
connect takeOffMarket
Browse files Browse the repository at this point in the history
  • Loading branch information
heswell committed Dec 5, 2023
1 parent 32a3159 commit a9a94e4
Show file tree
Hide file tree
Showing 7 changed files with 2,653 additions and 21 deletions.
2,601 changes: 2,598 additions & 3 deletions vuu-ui/packages/vuu-data/src/inlined-worker.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions vuu-ui/packages/vuu-protocol-types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@ export interface ServerToClientRPC {
// TODO flesh out as we know more
export interface ServerToClientViewportRpcResponse {
action: {
msg: string;
type: "VP_RPC_FAILURE";
msg?: string;
type: "VP_RCP_FAILURE" | "VP_RCP_SUCCESS";
};
type: "VIEW_PORT_RPC_REPONSE";
method: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
padding-top: 24px;
padding-left: var(--vuu-side-panel-padding, 0);
padding-right: var(--vuu-side-panel-padding, 0);
position: absolute;
position: absolute !important;
right: 0;
top:0;
transition-property: padding-left, padding-right, width;
Expand All @@ -41,7 +41,7 @@
align-items: center;
display: flex;
flex-wrap: nowrap;
flex: 0 0 27px;
flex: 0 0 27px !important;
justify-content: space-between;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export const useInstrumentSearch = ({
searchColumns = ["description"],
table,
}: InstrumentSearchHookProps) => {
console.log(`useInstrumentSearch`);
const [dataSource, setDataSource] = useState(dataSourceProp);
const { loadSession, saveSession } = useViewContext();

Expand All @@ -42,8 +41,9 @@ export const useInstrumentSearch = ({
} else {
getVuuTableSchema(table).then((tableSchema) => {
const newDataSource = new RemoteDataSource({
table: tableSchema.table,
columns: tableSchema.columns.map((col) => col.name),
// sort: { sortDefs: [{ column: "description", sortType: "A" }] },
table: tableSchema.table,
});
setDataSource(newDataSource);
saveSession?.(newDataSource, sessionKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export interface BasketToolbarProps extends HTMLAttributes<HTMLDivElement> {
BasketSelectorProps: BasketSelectorProps;
onCommit?: BasketChangeHandler;
onSendToMarket: (basketInstanceId: string) => void;
onTakeOffMarket: () => void;
onTakeOffMarket: (basketInstanceId: string) => void;
}

export const BasketToolbar = ({
Expand Down Expand Up @@ -94,6 +94,12 @@ export const BasketToolbar = ({
}
}, [basket?.instanceId, onSendToMarket]);

const handleTakeOffMarket = useCallback(() => {
if (basket?.instanceId) {
onTakeOffMarket(basket?.instanceId);
}
}, [basket?.instanceId, onTakeOffMarket]);

const basketSelector = (
<BasketSelector {...BasketSelectorProps} basket={basket} key="selector" />
);
Expand Down Expand Up @@ -191,7 +197,7 @@ export const BasketToolbar = ({
<Button
className={`${classBase}-takeOffMarket`}
key="off-market"
onClick={onTakeOffMarket}
onClick={handleTakeOffMarket}
variant="primary"
>
off market
Expand Down
29 changes: 22 additions & 7 deletions vuu-ui/sample-apps/feature-basket-trading/src/useBasketTrading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@ import { useVuuMenuActions } from "@finos/vuu-data-react";
import { DataSourceRow } from "@finos/vuu-data-types";
import { useViewContext } from "@finos/vuu-layout";
import { buildColumnMap, ColumnMap } from "@finos/vuu-utils";
import { ContextMenuConfiguration } from "@finos/vuu-popups";
import {
ContextMenuConfiguration,
NotificationLevel,
useNotifications,
} from "@finos/vuu-popups";
import { useCallback, useEffect, useMemo, useState } from "react";
import { BasketSelectorProps } from "./basket-selector";
import { BasketChangeHandler } from "./basket-toolbar";
import { NewBasketPanel } from "./new-basket-panel";
import { useBasketTradingDataSources } from "./useBasketTradingDatasources";
import { BasketTradingFeatureProps } from "./VuuBasketTradingFeature";
import { VuuDataRow, VuuDataRowDto } from "packages/vuu-protocol-types";
import { SubscribeCallback } from "packages/vuu-data/src";
import { SubscribeCallback, ViewportRpcResponse } from "packages/vuu-data/src";

export class Basket {
basketId: string;
Expand Down Expand Up @@ -69,6 +73,7 @@ export const useBasketTrading = ({
basketTradingConstituentJoinSchema,
}: BasketTradingHookProps) => {
const { load, save } = useViewContext();
const { notify } = useNotifications();

const basketConstituentMap = useMemo(
() => buildColumnMap(basketConstituentSchema.columns),
Expand Down Expand Up @@ -239,20 +244,30 @@ export const useBasketTrading = ({
);
const ric = constituentRow[basketConstituentMap.ric];
dataSourceBasketTradingConstituentJoin
.rpcCall?.({
.rpcCall?.<ViewportRpcResponse>({
type: "VIEW_PORT_RPC_CALL",
rpcName: "addConstituent",
namedParams: {},
params: [ric],
})
.then((response) => {
console.log(`rpc call response`, {
response,
});
if (response?.action.type === "VP_RCP_SUCCESS") {
notify?.({
type: NotificationLevel.Success,
header: "Add Constituent to Basket",
body: `${ric} added to basket`,
});
} else if (response?.action.type === "VP_RCP_FAILURE") {
notify?.({
type: NotificationLevel.Error,
header: "Add Constituent to Basket",
body: response?.action.msg ?? `Failed to add ${ric} to basket`,
});
}
});
}
},
[basketConstituentMap, dataSourceBasketTradingConstituentJoin]
[basketConstituentMap.ric, dataSourceBasketTradingConstituentJoin, notify]
);

useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export const useBasketTradingDataSources = ({
type: "VIEW_PORT_RPC_CALL",
})
.then((response) => {
if (response?.action.type === "VP_RPC_FAILURE") {
if (response?.action.type === "VP_RCP_FAILURE") {
notify({
type: NotificationLevel.Error,
header: "Failed to Send to market",
Expand All @@ -116,8 +116,24 @@ export const useBasketTradingDataSources = ({
[dataSourceBasketTradingControl, notify]
);

const handleTakeOffMarket = useCallback(() => {
console.log("take off market");
const handleTakeOffMarket = useCallback((basketInstanceId: string) => {
dataSourceBasketTradingControl
.rpcCall?.<ViewportRpcResponse>({
namedParams: {},
params: [basketInstanceId],
rpcName: "takeOffMarket",
type: "VIEW_PORT_RPC_CALL",
})
.then((response) => {
if (response?.action.type === "VP_RCP_FAILURE") {
notify({
type: NotificationLevel.Error,
header: "Failed to take off market",
body: "Please contact your support team",
});
console.error(response.action.msg);
}
});
}, []);

return {
Expand Down

0 comments on commit a9a94e4

Please sign in to comment.