PromucFlow_constructor/app/client/src/sagas/ActionExecution/StoreActionSaga.ts
Arsalan Yaldram f58451aa5f
feat: upgrade to create react app 5 (#14000)
* Updated Typescript types.

* Typefixes after merge with release.

* chore: GenericApiResponse Removed alltogether.

* chore: resolved ApiResponse unknown errors removed PageListPayload.

* Added shouldBeDefined.

* fix: Resolved type errors.

* fix: Typescript upgrade to 4.5 and type fixes.

* feat: upgrade to cra 5

* feat: uncomment service worker registeration

* force secure websocket protocol

* jest test fixes

* fix: react function lint rule removed

* fix: klona test case.

* fix: typescirpt issues resolved

* fix: timeout for colorpicker test and change env.

* feat: update client-build.yml file

* fix: remove brotliplugin use compression plugin

* fix: build config fixed

* fix: upgrade webpack plugin

* fix: add branchbutton test to todo.

* fix: remove branch button test.

* fix: Add tailwind theme values, fix cypress tests

* fix: Typescript type fixes.

* feat: run jest tests in silent mode

* fix: cypress rgb values add branchbutton jest test

* fix: review comments, fixes for error.message

* fix: increase cache size for the workbox

* fix: remove OrgApi.ts file

* fix: cypress.json file remove credentials

* fix: downgrade react and react-dom packages

Co-authored-by: rahulramesha <rahul@appsmith.com>
2022-06-21 19:27:34 +05:30

60 lines
2.4 KiB
TypeScript

import { put, select, take } from "redux-saga/effects";
import { getAppStoreName } from "constants/AppConstants";
import localStorage from "utils/localStorage";
import {
updateAppPersistentStore,
updateAppTransientStore,
} from "actions/pageActions";
import AppsmithConsole from "utils/AppsmithConsole";
import { getAppStoreData } from "selectors/entitiesSelector";
import { StoreValueActionDescription } from "entities/DataTree/actionTriggers";
import { getCurrentGitBranch } from "selectors/gitSyncSelectors";
import { getCurrentApplicationId } from "selectors/editorSelectors";
import { AppStoreState } from "reducers/entityReducers/appReducer";
import { ReduxActionTypes } from "@appsmith/constants/ReduxActionConstants";
export default function* storeValueLocally(
action: StoreValueActionDescription["payload"],
) {
if (action.persist) {
const applicationId: string = yield select(getCurrentApplicationId);
const branch: string | undefined = yield select(getCurrentGitBranch);
const appStoreName = getAppStoreName(applicationId, branch);
const existingStore = localStorage.getItem(appStoreName) || "{}";
const parsedStore = JSON.parse(existingStore);
parsedStore[action.key] = action.value;
const storeString = JSON.stringify(parsedStore);
localStorage.setItem(appStoreName, storeString);
yield put(updateAppPersistentStore(parsedStore, action));
AppsmithConsole.info({
text: `store('${action.key}', '${action.value}', true)`,
});
} else {
const existingStore: AppStoreState = yield select(getAppStoreData);
const newTransientStore = {
...existingStore.transient,
[action.key]: action.value,
};
yield put(updateAppTransientStore(newTransientStore, action));
AppsmithConsole.info({
text: `store('${action.key}', '${action.value}', false)`,
});
}
/* It is possible that user calls multiple storeValue function together, in such case we need to track completion of each action separately
We use uniqueActionRequestId to differentiate each storeValueAction here.
*/
while (true) {
const returnedAction: StoreValueActionDescription = yield take(
ReduxActionTypes.UPDATE_APP_STORE_EVALUATED,
);
if (!returnedAction?.payload?.uniqueActionRequestId) {
break;
}
const { uniqueActionRequestId } = returnedAction.payload;
if (uniqueActionRequestId === action.uniqueActionRequestId) {
break;
}
}
}