PromucFlow_constructor/app/client/src/sagas/ActionExecution/PluginActionSagaUtils.ts
Ayangade Adeoluwa 2ffd942e06
fix: Add null checks for empty datatypes in api/query responses (#14208)
* Add null checks for empty datatypes in api/query responses

* Add jest cases for failing tests

* Add one more test case
2022-06-06 13:27:19 +05:30

26 lines
774 B
TypeScript

import { put } from "redux-saga/effects";
import { setActionResponseDisplayFormat } from "actions/pluginActionActions";
import { ActionResponse } from "api/ActionAPI";
import { Plugin } from "api/PluginApi";
export function* setDefaultActionDisplayFormat(
actionId: string,
plugin: Plugin | undefined,
payload: ActionResponse,
) {
if (!!plugin && payload?.dataTypes?.length > 0) {
const responseType = payload?.dataTypes.find(
(type) => plugin?.responseType && type.dataType === plugin?.responseType,
);
yield put(
setActionResponseDisplayFormat({
id: actionId,
field: "responseDisplayFormat",
value: responseType
? responseType?.dataType
: payload?.dataTypes[0]?.dataType,
}),
);
}
}