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
This commit is contained in:
Michael Carner 2023-06-02 07:20:53 -05:00 committed by GitHub
parent f6c68284e5
commit a3fe54f217
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 21 additions and 1 deletions

View File

@ -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,

View File

@ -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",

View File

@ -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<boolean>,

View File

@ -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,
) => {

View File

@ -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<string>) {
yield put({
type: ReduxActionTypes.SAVING_WORKSPACE_INFO,
});
yield put(resetCurrentWorkspace());
const workspaceId: string = action.payload;
const response: ApiResponse = yield call(
WorkspaceApi.deleteWorkspace,