Show a toast when action executeOnLoad status updates (#3042)

This commit is contained in:
Hetu Nandu 2021-02-15 21:43:44 +05:30 committed by GitHub
parent 56170b0cdf
commit ebd61efcca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 39 additions and 11 deletions

View File

@ -229,7 +229,13 @@ export const updateActionProperty = (
});
};
export const setActionsToExecuteOnPageLoad = (actions: string[]) => {
export const setActionsToExecuteOnPageLoad = (
actions: Array<{
executeOnLoad: boolean;
id: string;
name: string;
}>,
) => {
return {
type: ReduxActionTypes.SET_ACTION_TO_EXECUTE_ON_PAGELOAD,
payload: actions,

View File

@ -49,6 +49,12 @@ export interface SavePageResponse extends ApiResponse {
id: string;
layoutOnLoadActions: PageAction[][];
dsl: Partial<ContainerWidgetProps<any>>;
messages: string[];
actionUpdates: Array<{
executeOnLoad: boolean;
id: string;
name: string;
}>;
};
}

View File

@ -339,12 +339,20 @@ const actionsReducer = createReducer(initialState, {
}),
[ReduxActionTypes.SET_ACTION_TO_EXECUTE_ON_PAGELOAD]: (
state: ActionDataState,
actionIds: ReduxAction<string[]>,
action: ReduxAction<
Array<{
executeOnLoad: boolean;
id: string;
name: string;
}>
>,
) => {
return produce(state, (draft) => {
const actionUpdateSearch = _.keyBy(action.payload, "id");
draft.forEach((action, index) => {
if (actionIds.payload.indexOf(action.config.id) > -1) {
draft[index].config.executeOnLoad = true;
if (action.config.id in actionUpdateSearch) {
draft[index].config.executeOnLoad =
actionUpdateSearch[action.config.id].executeOnLoad;
}
});
});

View File

@ -77,6 +77,8 @@ import PerformanceTracker, {
PerformanceTransactionName,
} from "utils/PerformanceTracker";
import { WidgetTypes } from "constants/WidgetConstants";
import { Toaster } from "components/ads/Toast";
import { Variant } from "components/ads/common";
const getWidgetName = (state: AppState, widgetId: string) =>
state.entities.canvasWidgets[widgetId];
@ -323,13 +325,19 @@ function* savePageSaga() {
);
const isValidResponse = yield validateResponse(savePageResponse);
if (isValidResponse) {
if (
savePageResponse.data.layoutOnLoadActions &&
savePageResponse.data.layoutOnLoadActions.length > 0
) {
for (const actionSet of savePageResponse.data.layoutOnLoadActions) {
yield put(setActionsToExecuteOnPageLoad(actionSet.map((a) => a.id)));
}
const { messages, actionUpdates } = savePageResponse.data;
// Show toast messages from the server
if (messages && messages.length) {
savePageResponse.data.messages.forEach((message) => {
Toaster.show({
text: message,
type: Variant.info,
});
});
}
// Update actions
if (actionUpdates && actionUpdates.length > 0) {
yield put(setActionsToExecuteOnPageLoad(actionUpdates));
}
yield put(savePageSuccess(savePageResponse));
PerformanceTracker.stopAsyncTracking(