Skip to content

Commit c99e63f

Browse files
committed
Merge branch 'release'
2 parents 66aed61 + 4873ac3 commit c99e63f

File tree

8 files changed

+82
-1
lines changed

8 files changed

+82
-1
lines changed

app/client/src/actions/pageActions.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,3 +213,10 @@ export const setAppMode = (payload: APP_MODE): ReduxAction<APP_MODE> => {
213213
payload,
214214
};
215215
};
216+
217+
export const updateAppStore = (payload: object): ReduxAction<object> => {
218+
return {
219+
type: ReduxActionTypes.UPDATE_APP_STORE,
220+
payload,
221+
};
222+
};

app/client/src/constants/AppConstants.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,8 @@ export const appCardColors = [
1515
"#CC293F",
1616
"#6BA3FD",
1717
];
18+
19+
const APP_STORE_NAMESPACE = "APPSMITH_LOCAL_STORE";
20+
21+
export const getAppStoreName = (appId: string) =>
22+
`${APP_STORE_NAMESPACE}-${appId}`;

app/client/src/constants/ReduxActionConstants.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ export const ReduxActionTypes: { [key: string]: string } = {
251251
SET_APP_MODE: "SET_APP_MODE",
252252
TOGGLE_PROPERTY_PANE_WIDGET_NAME_EDIT:
253253
"TOGGLE_PROPERTY_PANE_WIDGET_NAME_EDIT",
254+
UPDATE_APP_STORE: "UPDATE_APP_STORE",
254255
};
255256

256257
export type ReduxActionType = typeof ReduxActionTypes[keyof typeof ReduxActionTypes];

app/client/src/entities/DataTree/dataTreeFactory.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export interface DataTreeWidget extends WidgetProps {
5050

5151
export interface DataTreeAppsmith extends AppDataState {
5252
ENTITY_TYPE: ENTITY_TYPE.APPSMITH;
53+
store: object;
5354
}
5455

5556
export type DataTreeEntity =
@@ -188,6 +189,14 @@ export class DataTreeFactory {
188189
};
189190
};
190191
actionPaths.push("closeModal");
192+
193+
dataTree.storeValue = function(key: string, value: string) {
194+
return {
195+
type: "STORE_VALUE",
196+
payload: { key, value },
197+
};
198+
};
199+
actionPaths.push("storeValue");
191200
}
192201

193202
dataTree.pageList = pageList;

app/client/src/reducers/entityReducers/appReducer.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export type AppDataState = {
2828
mode?: APP_MODE;
2929
user: AuthUserState;
3030
URL: UrlDataState;
31+
store: object;
3132
};
3233

3334
const initialState: AppDataState = {
@@ -46,6 +47,7 @@ const initialState: AppDataState = {
4647
hash: "",
4748
fullPath: "",
4849
},
50+
store: {},
4951
};
5052

5153
const appReducer = createReducer(initialState, {
@@ -76,6 +78,15 @@ const appReducer = createReducer(initialState, {
7678
URL: action.payload,
7779
};
7880
},
81+
[ReduxActionTypes.UPDATE_APP_STORE]: (
82+
state: AppDataState,
83+
action: ReduxAction<object>,
84+
) => {
85+
return {
86+
...state,
87+
store: action.payload,
88+
};
89+
},
7990
});
8091

8192
export default appReducer;

app/client/src/sagas/ActionExecutionSagas.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ import { validateResponse } from "sagas/ErrorSagas";
7171
import { ToastType } from "react-toastify";
7272
import { PLUGIN_TYPE_API } from "constants/ApiEditorConstants";
7373
import { DEFAULT_EXECUTE_ACTION_TIMEOUT_MS } from "constants/ApiConstants";
74+
import { updateAppStore } from "actions/pageActions";
75+
import { getAppStoreName } from "constants/AppConstants";
7476

7577
function* navigateActionSaga(
7678
action: { pageNameOrUrl: string; params: Record<string, string> },
@@ -111,6 +113,25 @@ function* navigateActionSaga(
111113
}
112114
}
113115

116+
function* storeValueLocally(
117+
action: { key: string; value: string },
118+
event: ExecuteActionPayloadEvent,
119+
) {
120+
try {
121+
const appId = yield select(getCurrentApplicationId);
122+
const appStoreName = getAppStoreName(appId);
123+
const existingStore = yield localStorage.getItem(appStoreName) || "{}";
124+
const storeObj = JSON.parse(existingStore);
125+
storeObj[action.key] = action.value;
126+
const storeString = JSON.stringify(storeObj);
127+
yield localStorage.setItem(appStoreName, storeString);
128+
yield put(updateAppStore(storeObj));
129+
if (event.callback) event.callback({ success: true });
130+
} catch (err) {
131+
if (event.callback) event.callback({ success: false });
132+
}
133+
}
134+
114135
export const getActionTimeout = (
115136
state: AppState,
116137
actionId: string,
@@ -357,6 +378,9 @@ function* executeActionTriggers(
357378
yield put(trigger);
358379
if (event.callback) event.callback({ success: true });
359380
break;
381+
case "STORE_VALUE":
382+
yield call(storeValueLocally, trigger.payload, event);
383+
break;
360384
default:
361385
yield put(
362386
executeActionError({

app/client/src/sagas/InitSagas.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@ import {
88
} from "constants/ReduxActionConstants";
99

1010
import { fetchEditorConfigs } from "actions/configsActions";
11-
import { fetchPage, fetchPageList, setAppMode } from "actions/pageActions";
11+
import {
12+
fetchPage,
13+
fetchPageList,
14+
setAppMode,
15+
updateAppStore,
16+
} from "actions/pageActions";
1217
import { fetchDatasources } from "actions/datasourceActions";
1318
import { fetchPlugins } from "actions/pluginActions";
1419
import { fetchActions, fetchActionsForView } from "actions/actionActions";
@@ -20,6 +25,19 @@ import PageApi, { FetchPageResponse } from "api/PageApi";
2025
import { validateResponse } from "./ErrorSagas";
2126
import { extractCurrentDSL } from "utils/WidgetPropsUtils";
2227
import { APP_MODE } from "reducers/entityReducers/appReducer";
28+
import { getAppStoreName } from "constants/AppConstants";
29+
30+
const getAppStore = (appId: string) => {
31+
const appStoreName = getAppStoreName(appId);
32+
const storeString = localStorage.getItem(appStoreName) || "{}";
33+
let store;
34+
try {
35+
store = JSON.parse(storeString);
36+
} catch (e) {
37+
store = {};
38+
}
39+
return store;
40+
};
2341

2442
function* initializeEditorSaga(
2543
initializeEditorAction: ReduxAction<InitializeEditorPayload>,
@@ -52,6 +70,7 @@ function* initializeEditorSaga(
5270

5371
// Step 5: Set app mode
5472
yield put(setAppMode(APP_MODE.EDIT));
73+
yield put(updateAppStore(getAppStore(applicationId)));
5574

5675
const currentApplication = yield select(getCurrentApplication);
5776

@@ -142,6 +161,7 @@ export function* initializeAppViewerSaga(
142161
]);
143162

144163
yield put(setAppMode(APP_MODE.PUBLISHED));
164+
yield put(updateAppStore(getAppStore(applicationId)));
145165

146166
yield put({
147167
type: ReduxActionTypes.INITIALIZE_PAGE_VIEWER_SUCCESS,

app/client/src/utils/autocomplete/EntityDefinitions.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,4 +233,8 @@ export const GLOBAL_FUNCTIONS = {
233233
"!doc": "Close a modal",
234234
"!type": "fn(modalName: string) -> void",
235235
},
236+
storeValue: {
237+
"!doc": "Store key value data locally",
238+
"!type": "fn(key: string, value: any) -> void",
239+
},
236240
};

0 commit comments

Comments
 (0)