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

Show a toast when action executeOnLoad status updates #3042

Merged
merged 2 commits into from
Feb 15, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion app/client/src/actions/actionActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions app/client/src/api/PageApi.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}>;
};
}

Expand Down
14 changes: 11 additions & 3 deletions app/client/src/reducers/entityReducers/actionsReducer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
});
});
Expand Down
23 changes: 16 additions & 7 deletions app/client/src/sagas/PageSagas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -322,14 +324,21 @@ function* savePageSaga() {
savePageRequest,
);
const isValidResponse = yield validateResponse(savePageResponse);
console.log({ savePageResponse });
hetunandu marked this conversation as resolved.
Show resolved Hide resolved
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(
Expand Down