From a3fe54f217d3302e811189c870ad28a4c8bd2acc Mon Sep 17 00:00:00 2001 From: Michael Carner Date: Fri, 2 Jun 2023 07:20:53 -0500 Subject: [PATCH] fix: reset workspace before deleting a workspace (#23782) ## Description Fixes [#12057](https://github.com/appsmithorg/appsmith/issues/12057) In specific scenarios, the currentWorkspace is not up to date and uses a previous workspace, which can cause certain API calls to fail. The end result is the user sees a "No Resource Found" error with no clear explanation. This changes adds a new ReduxAction RESET_CURRENT_WORKSPACE with returns it to it's initial value. The only place I've added that is at the begining of deleteWorkspaceSaga() #### PR fixes following issue(s) Fixes # (12057) #### Type of change - Bug fix (non-breaking change which fixes an issue) ## Testing #### How Has This Been Tested? - [x] Manual ## Checklist: #### Dev activity - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my own code - [x] My changes generate no new warnings - [x] New and existing unit tests pass locally with my changes #### QA activity: - [ ] [Speedbreak features](https://github.com/appsmithorg/TestSmith/wiki/Test-plan-implementation#speedbreaker-features-to-consider-for-every-change) have been covered - [ ] Test plan covers all impacted features and [areas of interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans/_edit#areas-of-interest) - [ ] Test plan has been peer reviewed by project stakeholders and other QA members - [ ] Manually tested functionality on DP - [ ] We had an implementation alignment call with stakeholders post QA Round 2 - [ ] Cypress test cases have been added and approved by SDET/manual QA - [ ] Added `Test Plan Approved` label after Cypress tests were reviewed - [ ] Added `Test Plan Approved` label after JUnit tests were reviewed --- app/client/src/ce/actions/workspaceActions.ts | 6 ++++++ app/client/src/ce/constants/ReduxActionConstants.tsx | 1 + .../src/ce/reducers/uiReducers/applicationsReducer.tsx | 5 ++++- app/client/src/ce/reducers/uiReducers/workspaceReducer.ts | 8 ++++++++ app/client/src/ce/sagas/WorkspaceSagas.ts | 2 ++ 5 files changed, 21 insertions(+), 1 deletion(-) diff --git a/app/client/src/ce/actions/workspaceActions.ts b/app/client/src/ce/actions/workspaceActions.ts index 334c9c8339..4e6c8a4d11 100644 --- a/app/client/src/ce/actions/workspaceActions.ts +++ b/app/client/src/ce/actions/workspaceActions.ts @@ -17,6 +17,12 @@ export const fetchWorkspace = ( }; }; +export const resetCurrentWorkspace = () => { + return { + type: ReduxActionTypes.RESET_CURRENT_WORKSPACE, + }; +}; + export const deleteWorkspace = (workspaceId: string) => { return { type: ReduxActionTypes.DELETE_WORKSPACE_INIT, diff --git a/app/client/src/ce/constants/ReduxActionConstants.tsx b/app/client/src/ce/constants/ReduxActionConstants.tsx index 2b2ae9a9c7..b422002fbc 100644 --- a/app/client/src/ce/constants/ReduxActionConstants.tsx +++ b/app/client/src/ce/constants/ReduxActionConstants.tsx @@ -538,6 +538,7 @@ const ActionTypes = { RUN_FORM_EVALUATION: "RUN_FORM_EVALUATION", SET_LOADING_ENTITIES: "SET_LOADING_ENTITIES", RESET_CURRENT_APPLICATION: "RESET_CURRENT_APPLICATION", + RESET_CURRENT_WORKSPACE: "RESET_CURRENT_WORKSPACE", SELECT_WIDGETS_IN_AREA: "SELECT_WIDGETS_IN_AREA", RESET_APPLICATION_WIDGET_STATE_REQUEST: "RESET_APPLICATION_WIDGET_STATE_REQUEST", diff --git a/app/client/src/ce/reducers/uiReducers/applicationsReducer.tsx b/app/client/src/ce/reducers/uiReducers/applicationsReducer.tsx index c489a6f558..be83f8fb67 100644 --- a/app/client/src/ce/reducers/uiReducers/applicationsReducer.tsx +++ b/app/client/src/ce/reducers/uiReducers/applicationsReducer.tsx @@ -446,7 +446,10 @@ export const handlers = { }, [ReduxActionTypes.RESET_CURRENT_APPLICATION]: ( state: ApplicationsReduxState, - ) => ({ ...state, currentApplication: null }), + ) => ({ + ...state, + currentApplication: null, + }), [ReduxActionTypes.SET_SHOW_APP_INVITE_USERS_MODAL]: ( state: ApplicationsReduxState, action: ReduxAction, diff --git a/app/client/src/ce/reducers/uiReducers/workspaceReducer.ts b/app/client/src/ce/reducers/uiReducers/workspaceReducer.ts index 63057c0a52..6dcb06c269 100644 --- a/app/client/src/ce/reducers/uiReducers/workspaceReducer.ts +++ b/app/client/src/ce/reducers/uiReducers/workspaceReducer.ts @@ -154,6 +154,14 @@ export const handlers = { ) => { draftState.currentWorkspace = action.payload; }, + [ReduxActionTypes.RESET_CURRENT_WORKSPACE]: ( + draftState: WorkspaceReduxState, + ) => { + draftState.currentWorkspace = { + id: "", + name: "", + }; + }, [ReduxActionTypes.FETCH_CURRENT_WORKSPACE]: ( draftState: WorkspaceReduxState, ) => { diff --git a/app/client/src/ce/sagas/WorkspaceSagas.ts b/app/client/src/ce/sagas/WorkspaceSagas.ts index b8c3b1cb01..e3f28f200f 100644 --- a/app/client/src/ce/sagas/WorkspaceSagas.ts +++ b/app/client/src/ce/sagas/WorkspaceSagas.ts @@ -41,6 +41,7 @@ import { DELETE_WORKSPACE_SUCCESSFUL, } from "@appsmith/constants/messages"; import { toast } from "design-system"; +import { resetCurrentWorkspace } from "../actions/workspaceActions"; export function* fetchRolesSaga() { try { @@ -234,6 +235,7 @@ export function* deleteWorkspaceSaga(action: ReduxAction) { yield put({ type: ReduxActionTypes.SAVING_WORKSPACE_INFO, }); + yield put(resetCurrentWorkspace()); const workspaceId: string = action.payload; const response: ApiResponse = yield call( WorkspaceApi.deleteWorkspace,