Skip to content

Commit ed2f3a0

Browse files
authored
fix/ensemble-response-mapping (#969)
fix ensemble response mapping with screenData
1 parent 63302e9 commit ed2f3a0

File tree

6 files changed

+20
-11
lines changed

6 files changed

+20
-11
lines changed

.changeset/smooth-parents-type.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@ensembleui/react-framework": patch
3+
"@ensembleui/react-runtime": patch
4+
---
5+
6+
fix ensemble api response mapping with screendata

packages/framework/src/api/data.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ export const invokeAPI = async (
3939
// Now, because the API exists, set its state to loading
4040
set(update, api.name, {
4141
isLoading: true,
42-
isError: false,
43-
isSuccess: false,
42+
statusCode: undefined,
4443
});
4544
setter(screenDataAtom, update);
4645
}

packages/framework/src/hooks/useScreenContext.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export const useScreenContext = ():
110110
const screenContext = useAtomValue(screenAtom);
111111
const setDataAtom = useSetAtom(screenDataAtom);
112112
const setData = useCallback(
113-
(name: string, response: Response | WebSocketConnection) => {
113+
(name: string, response: Partial<Response> | WebSocketConnection) => {
114114
const data = screenContext.data;
115115
data[name] = response;
116116
setDataAtom(clone(data));

packages/framework/src/hooks/useScreenData.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ export const useScreenData = (): {
1616
apis?: EnsembleAPIModel[];
1717
sockets?: EnsembleSocketModel[];
1818
data: ScreenContextData;
19-
setData: (name: string, response: Response | WebSocketConnection) => void;
19+
setData: (
20+
name: string,
21+
response: Partial<Response> | WebSocketConnection,
22+
) => void;
2023
mockResponses: {
2124
[apiName: string]: EnsembleMockResponse | string | undefined;
2225
};
@@ -41,7 +44,7 @@ export const useScreenData = (): {
4144
const mockResponses = useEvaluate(apiMockResponses);
4245

4346
const setData = useCallback(
44-
(name: string, response: Response | WebSocketConnection) => {
47+
(name: string, response: Partial<Response> | WebSocketConnection) => {
4548
if (isEqual(data[name], response)) {
4649
return;
4750
}

packages/framework/src/state/screen.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,15 @@ export interface ScreenContextDefinition {
1515
}
1616

1717
export interface ScreenContextData {
18-
[key: string]: Response | WebSocketConnection;
18+
[key: string]: Partial<Response> | WebSocketConnection;
1919
}
2020

2121
export interface ScreenContextActions {
2222
setWidget: (id: string, state: WidgetState) => void;
23-
setData: (name: string, response: Response | WebSocketConnection) => void;
23+
setData: (
24+
name: string,
25+
response: Partial<Response> | WebSocketConnection,
26+
) => void;
2427
setCustom: (id: string, data: unknown) => void;
2528
}
2629

packages/runtime/src/runtime/hooks/useEnsembleAction.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,15 +195,13 @@ export const useInvokeAPI: EnsembleActionHook<InvokeAPIAction> = (action) => {
195195
// Set initial loading state
196196
setData(currentApi.name, {
197197
isLoading: true,
198-
isSuccess: false,
199-
isError: false,
198+
statusCode: undefined,
200199
});
201200

202201
if (action.id) {
203202
setData(action.id, {
204203
isLoading: true,
205-
isSuccess: false,
206-
isError: false,
204+
statusCode: undefined,
207205
});
208206
}
209207

0 commit comments

Comments
 (0)