Skip to content
Merged
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
6 changes: 6 additions & 0 deletions .changeset/smooth-parents-type.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@ensembleui/react-framework": patch
"@ensembleui/react-runtime": patch
---

fix ensemble api response mapping with screendata
3 changes: 1 addition & 2 deletions packages/framework/src/api/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ export const invokeAPI = async (
// Now, because the API exists, set its state to loading
set(update, api.name, {
isLoading: true,
isError: false,
isSuccess: false,
statusCode: undefined,
});
setter(screenDataAtom, update);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/framework/src/hooks/useScreenContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export const useScreenContext = ():
const screenContext = useAtomValue(screenAtom);
const setDataAtom = useSetAtom(screenDataAtom);
const setData = useCallback(
(name: string, response: Response | WebSocketConnection) => {
(name: string, response: Partial<Response> | WebSocketConnection) => {
const data = screenContext.data;
data[name] = response;
setDataAtom(clone(data));
Expand Down
7 changes: 5 additions & 2 deletions packages/framework/src/hooks/useScreenData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ export const useScreenData = (): {
apis?: EnsembleAPIModel[];
sockets?: EnsembleSocketModel[];
data: ScreenContextData;
setData: (name: string, response: Response | WebSocketConnection) => void;
setData: (
name: string,
response: Partial<Response> | WebSocketConnection,
) => void;
mockResponses: {
[apiName: string]: EnsembleMockResponse | string | undefined;
};
Expand All @@ -41,7 +44,7 @@ export const useScreenData = (): {
const mockResponses = useEvaluate(apiMockResponses);

const setData = useCallback(
(name: string, response: Response | WebSocketConnection) => {
(name: string, response: Partial<Response> | WebSocketConnection) => {
if (isEqual(data[name], response)) {
return;
}
Expand Down
7 changes: 5 additions & 2 deletions packages/framework/src/state/screen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@ export interface ScreenContextDefinition {
}

export interface ScreenContextData {
[key: string]: Response | WebSocketConnection;
[key: string]: Partial<Response> | WebSocketConnection;
}

export interface ScreenContextActions {
setWidget: (id: string, state: WidgetState) => void;
setData: (name: string, response: Response | WebSocketConnection) => void;
setData: (
name: string,
response: Partial<Response> | WebSocketConnection,
) => void;
setCustom: (id: string, data: unknown) => void;
}

Expand Down
6 changes: 2 additions & 4 deletions packages/runtime/src/runtime/hooks/useEnsembleAction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -195,15 +195,13 @@ export const useInvokeAPI: EnsembleActionHook<InvokeAPIAction> = (action) => {
// Set initial loading state
setData(currentApi.name, {
isLoading: true,
isSuccess: false,
isError: false,
statusCode: undefined,
});

if (action.id) {
setData(action.id, {
isLoading: true,
isSuccess: false,
isError: false,
statusCode: undefined,
});
}

Expand Down
Loading