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

Use ECP sendData API in CleverDeal operations page #29

Open
wants to merge 1 commit into
base: master
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
10 changes: 8 additions & 2 deletions AppExamples/CleverDeal.React/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,14 @@ HTTPS=true yarn start

## Query params

- `ecpOrigin`: URL of the target pod to be loaded in ECP (supported values are `corporate.symphony.com` [default] and `st3.symphony.com`)
- `ecpOrigin`: URL of the target pod to be loaded in ECP (supported values are `corporate.symphony.com` [default], `st3.symphony.com` or `preview.symphony.com`)
- `partnerId`: loads ECP with a given partnerId, useful if your environment has partnership configurations (use partnerId=3 to allow Symphony to be loaded on localhost)
- `sdkPath`: used to target a specific version of ECP (supported values are `/embed/sdk.js` [default] and `/apps/embed/{tag}/sdk.js`)


### Run against ECP (SFE-Lite) running locally

```sh
HTTPS=true yarn start
```

- go to https://localhost:3000/?ecpOrigin=local-dev.symphony.com:9090&sdkPath=/client-bff/sdk.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable react-hooks/exhaustive-deps */
import { useEffect, useRef, useState } from "react";
import { useCallback, useEffect, useRef, useState } from "react";
import {
INITIAL_TRADE_EXCEPTIONS,
TRADE_EXCEPTION_REQUEST_INTENT,
Expand All @@ -17,11 +17,12 @@ interface TradeExceptionDashboardProps {
export const TradeExceptionDashboard = (
props: TradeExceptionDashboardProps
) => {
const { ecpOrigin } = props;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops, leftover debug code..

const [tradeExceptions, setTradeExceptions] = useState<TradeException[]>([
...INITIAL_TRADE_EXCEPTIONS,
]);
const tradeExceptionsLatest = useRef<TradeException[]>(tradeExceptions);

const dataListenersRef = useRef<string[]>([]);
const [selectedException, setSelectedException] = useState<TradeException>();

const updateTradeException = (newTradeException: TradeException) => {
Expand All @@ -35,17 +36,49 @@ export const TradeExceptionDashboard = (
newTradeExceptions[tradeExceptionIndex] = newTradeException;

setTradeExceptions(newTradeExceptions);
setSelectedException(newTradeException);
setSelectedException((currentSelection) => {
if (!currentSelection || currentSelection.streamId?.[ecpOrigin] === newTradeException.streamId?.[ecpOrigin]) {
return newTradeException
}
return currentSelection;
});
};

useEffect(() => {
tradeExceptionsLatest.current = tradeExceptions;
tradeExceptions.forEach((tradeException: TradeException) => {
const streamId = tradeException.streamId?.[ecpOrigin];
if (streamId && !dataListenersRef.current.includes(streamId)) {
dataListenersRef.current = [...dataListenersRef.current, streamId];
(window as any).symphony.listen({
type: 'DataNotifications',
params: {
type: TRADE_EXCEPTION_REQUEST_INTENT,
streamId
},
callback: onReceivedData
});
}
})
}, [tradeExceptions]);

const sendData = (tradeException: TradeException) => {
const streamId = tradeException.streamId?.[ecpOrigin];
(window as any).symphony.sendData({
type: TRADE_EXCEPTION_REQUEST_INTENT,
content: tradeException,
}, {streamId});
};

const onReceivedData = useCallback(({content}: any) => {
updateTradeException(content);
}, [selectedException]);

useEffect(() => {
(window as any).symphony.registerInterop((intent: any, context: any) => {
if (intent === TRADE_EXCEPTION_REQUEST_INTENT) {
updateTradeException(context.tradeException);
sendData(context.tradeException);
}
});
}, []);
Expand All @@ -56,13 +89,13 @@ export const TradeExceptionDashboard = (
<div className="content-header">
<FakeTopMenu />
</div>

<div className="table-container">
<TradeExceptionTable
selectedException={selectedException}
onRowSelect={setSelectedException}
tradeExceptions={tradeExceptions}
ecpOrigin={props.ecpOrigin}
ecpOrigin={ecpOrigin}
/>
</div>
</div>
Expand All @@ -71,8 +104,9 @@ export const TradeExceptionDashboard = (
<div className="details-container">
<TradeExceptionDetails
tradeException={selectedException}
ecpOrigin={props.ecpOrigin}
ecpOrigin={ecpOrigin}
updateTradeExceptionHandler={updateTradeException}
sendData={sendData}
/>
</div>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ interface TraceExceptionDetailsProps {
tradeException: TradeException;
ecpOrigin: string;
updateTradeExceptionHandler: (newTradeException: TradeException) => void;
sendData: (tradeException: TradeException) => void;
}

const TradeExceptionDetails = ({
updateTradeExceptionHandler,
tradeException,
ecpOrigin,
sendData
}: TraceExceptionDetailsProps) => {
const [loadedStreamId, setLoadedStreamId] = useState<string>();
const [isStreamReady, setIsStreamReady] = useState<boolean>(false);
Expand Down Expand Up @@ -145,6 +147,7 @@ const TradeExceptionDetails = ({
.then((response: EcpApiResponse) => {
if (response.messages) {
updateTradeExceptionHandler(newTradeException);
sendData(newTradeException);
}
});
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ const TradeExceptionTable = ({
</tr>
</thead>
<tbody>
{tradeExceptions.map((tradeException) => (
{tradeExceptions.map((tradeException, index: number) => (
<TradeExceptionRow
key={tradeException.entry1.executingParty}
key={`${tradeException.entry1.executingParty}-${index}`}
isActive={tradeException === selectedException}
tradeException={tradeException}
onClick={
Expand Down