2020-08-14 07:43:01 +00:00
|
|
|
import { all, call, put, select, take, takeLatest } from "redux-saga/effects";
|
2019-11-08 11:02:00 +00:00
|
|
|
import {
|
2019-11-22 14:02:55 +00:00
|
|
|
InitializeEditorPayload,
|
Feature/entity browse (#220)
# New Feature: Entity Explorer
- Entities are actions (apis and queries), datasources, pages, and widgets
- With this new feature, all entities in the application will be available
to view in the new entity explorer sidebar
- All existing application features from the api sidebar, query sidebar, datasource sidebar and pages sidebar
now are avialable on the entity explorer sidebar
- Users are now able to quickly switch to any entity in the application from the entity explorer sidebar.
- Users can also search all entities in the application from the new sidebar. Use cmd + f or ctrl + f to focus on the search input
- Users can rename entities from the new sidebar
- Users can also perform contextual actions on these entities like set a page as home page, copy/move actions, delete entity, etc from the context menu available alongside the entities in the sidebar
- Users can view the properties of the entities in the sidebar, as well as copy bindings to use in the application.
2020-08-10 08:52:45 +00:00
|
|
|
Page,
|
2020-08-14 07:43:01 +00:00
|
|
|
ReduxAction,
|
Feature/entity browse (#220)
# New Feature: Entity Explorer
- Entities are actions (apis and queries), datasources, pages, and widgets
- With this new feature, all entities in the application will be available
to view in the new entity explorer sidebar
- All existing application features from the api sidebar, query sidebar, datasource sidebar and pages sidebar
now are avialable on the entity explorer sidebar
- Users are now able to quickly switch to any entity in the application from the entity explorer sidebar.
- Users can also search all entities in the application from the new sidebar. Use cmd + f or ctrl + f to focus on the search input
- Users can rename entities from the new sidebar
- Users can also perform contextual actions on these entities like set a page as home page, copy/move actions, delete entity, etc from the context menu available alongside the entities in the sidebar
- Users can view the properties of the entities in the sidebar, as well as copy bindings to use in the application.
2020-08-10 08:52:45 +00:00
|
|
|
ReduxActionErrorTypes,
|
2020-08-14 07:43:01 +00:00
|
|
|
ReduxActionTypes,
|
2019-11-22 14:02:55 +00:00
|
|
|
} from "constants/ReduxActionConstants";
|
|
|
|
|
|
2019-11-25 05:07:27 +00:00
|
|
|
import { fetchEditorConfigs } from "actions/configsActions";
|
2020-08-24 12:09:17 +00:00
|
|
|
import {
|
|
|
|
|
fetchPage,
|
|
|
|
|
fetchPageList,
|
2020-10-21 04:25:32 +00:00
|
|
|
fetchPublishedPage,
|
2020-08-24 12:09:17 +00:00
|
|
|
setAppMode,
|
|
|
|
|
updateAppStore,
|
|
|
|
|
} from "actions/pageActions";
|
2020-04-28 06:52:53 +00:00
|
|
|
import { fetchDatasources } from "actions/datasourceActions";
|
2019-11-29 05:22:49 +00:00
|
|
|
import { fetchPlugins } from "actions/pluginActions";
|
2020-07-15 13:01:35 +00:00
|
|
|
import { fetchActions, fetchActionsForView } from "actions/actionActions";
|
2020-06-17 10:19:56 +00:00
|
|
|
import { fetchApplication } from "actions/applicationActions";
|
2020-03-06 04:59:24 +00:00
|
|
|
import AnalyticsUtil from "utils/AnalyticsUtil";
|
2020-03-09 05:46:32 +00:00
|
|
|
import { getCurrentApplication } from "selectors/applicationSelectors";
|
Feature/entity browse (#220)
# New Feature: Entity Explorer
- Entities are actions (apis and queries), datasources, pages, and widgets
- With this new feature, all entities in the application will be available
to view in the new entity explorer sidebar
- All existing application features from the api sidebar, query sidebar, datasource sidebar and pages sidebar
now are avialable on the entity explorer sidebar
- Users are now able to quickly switch to any entity in the application from the entity explorer sidebar.
- Users can also search all entities in the application from the new sidebar. Use cmd + f or ctrl + f to focus on the search input
- Users can rename entities from the new sidebar
- Users can also perform contextual actions on these entities like set a page as home page, copy/move actions, delete entity, etc from the context menu available alongside the entities in the sidebar
- Users can view the properties of the entities in the sidebar, as well as copy bindings to use in the application.
2020-08-10 08:52:45 +00:00
|
|
|
import { AppState } from "reducers";
|
|
|
|
|
import PageApi, { FetchPageResponse } from "api/PageApi";
|
|
|
|
|
import { validateResponse } from "./ErrorSagas";
|
|
|
|
|
import { extractCurrentDSL } from "utils/WidgetPropsUtils";
|
2020-08-14 07:43:01 +00:00
|
|
|
import { APP_MODE } from "reducers/entityReducers/appReducer";
|
2020-08-24 12:09:17 +00:00
|
|
|
import { getAppStoreName } from "constants/AppConstants";
|
2020-10-21 04:25:32 +00:00
|
|
|
import { getDefaultPageId } from "./selectors";
|
2020-08-24 12:09:17 +00:00
|
|
|
|
|
|
|
|
const getAppStore = (appId: string) => {
|
|
|
|
|
const appStoreName = getAppStoreName(appId);
|
|
|
|
|
const storeString = localStorage.getItem(appStoreName) || "{}";
|
|
|
|
|
let store;
|
|
|
|
|
try {
|
|
|
|
|
store = JSON.parse(storeString);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
store = {};
|
|
|
|
|
}
|
|
|
|
|
return store;
|
|
|
|
|
};
|
2019-11-01 07:11:32 +00:00
|
|
|
|
2019-11-22 14:02:55 +00:00
|
|
|
function* initializeEditorSaga(
|
|
|
|
|
initializeEditorAction: ReduxAction<InitializeEditorPayload>,
|
|
|
|
|
) {
|
2020-03-24 14:05:19 +00:00
|
|
|
const { applicationId, pageId } = initializeEditorAction.payload;
|
2019-11-22 14:02:55 +00:00
|
|
|
// Step 1: Start getting all the data needed by the
|
2019-11-01 07:11:32 +00:00
|
|
|
yield all([
|
2019-11-22 14:02:55 +00:00
|
|
|
put(fetchPageList(applicationId)),
|
2019-11-22 12:15:33 +00:00
|
|
|
put(fetchEditorConfigs()),
|
2020-01-24 09:54:40 +00:00
|
|
|
put(fetchActions(applicationId)),
|
2020-03-24 14:05:19 +00:00
|
|
|
put(fetchPage(pageId)),
|
2020-07-23 12:28:42 +00:00
|
|
|
put(fetchApplication(applicationId)),
|
2019-11-01 07:11:32 +00:00
|
|
|
]);
|
|
|
|
|
// Step 2: Wait for all data to be in the state
|
|
|
|
|
yield all([
|
|
|
|
|
take(ReduxActionTypes.FETCH_PAGE_LIST_SUCCESS),
|
2020-03-24 14:05:19 +00:00
|
|
|
take(ReduxActionTypes.FETCH_PAGE_SUCCESS),
|
2020-04-29 09:41:30 +00:00
|
|
|
take(ReduxActionTypes.SWITCH_CURRENT_PAGE_ID),
|
2019-11-01 07:11:32 +00:00
|
|
|
take(ReduxActionTypes.FETCH_ACTIONS_SUCCESS),
|
2020-06-17 10:19:56 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
// Step 3: Call all the APIs which needs Organization Id from PageList API response.
|
|
|
|
|
yield all([put(fetchPlugins()), put(fetchDatasources())]);
|
|
|
|
|
|
|
|
|
|
// Step 4: Wait for all data to be in the state
|
|
|
|
|
yield all([
|
|
|
|
|
take(ReduxActionTypes.FETCH_PLUGINS_SUCCESS),
|
2019-11-07 09:32:38 +00:00
|
|
|
take(ReduxActionTypes.FETCH_DATASOURCES_SUCCESS),
|
2019-11-01 07:11:32 +00:00
|
|
|
]);
|
2019-11-22 14:02:55 +00:00
|
|
|
|
2020-08-14 07:43:01 +00:00
|
|
|
// Step 5: Set app mode
|
|
|
|
|
yield put(setAppMode(APP_MODE.EDIT));
|
2020-08-24 12:09:17 +00:00
|
|
|
yield put(updateAppStore(getAppStore(applicationId)));
|
2020-08-14 07:43:01 +00:00
|
|
|
|
2020-03-09 05:46:32 +00:00
|
|
|
const currentApplication = yield select(getCurrentApplication);
|
2020-03-06 04:59:24 +00:00
|
|
|
|
|
|
|
|
const appName = currentApplication ? currentApplication.name : "";
|
|
|
|
|
const appId = currentApplication ? currentApplication.id : "";
|
|
|
|
|
|
|
|
|
|
AnalyticsUtil.logEvent("EDITOR_OPEN", {
|
|
|
|
|
appId: appId,
|
|
|
|
|
appName: appName,
|
|
|
|
|
});
|
|
|
|
|
|
2019-11-22 14:02:55 +00:00
|
|
|
// Step 6: Notify UI that the editor is ready to go
|
2019-11-13 07:34:59 +00:00
|
|
|
yield put({
|
2019-11-14 11:17:36 +00:00
|
|
|
type: ReduxActionTypes.INITIALIZE_EDITOR_SUCCESS,
|
2019-11-13 07:34:59 +00:00
|
|
|
});
|
2020-08-14 07:43:01 +00:00
|
|
|
yield call(populatePageDSLsSaga);
|
Feature/entity browse (#220)
# New Feature: Entity Explorer
- Entities are actions (apis and queries), datasources, pages, and widgets
- With this new feature, all entities in the application will be available
to view in the new entity explorer sidebar
- All existing application features from the api sidebar, query sidebar, datasource sidebar and pages sidebar
now are avialable on the entity explorer sidebar
- Users are now able to quickly switch to any entity in the application from the entity explorer sidebar.
- Users can also search all entities in the application from the new sidebar. Use cmd + f or ctrl + f to focus on the search input
- Users can rename entities from the new sidebar
- Users can also perform contextual actions on these entities like set a page as home page, copy/move actions, delete entity, etc from the context menu available alongside the entities in the sidebar
- Users can view the properties of the entities in the sidebar, as well as copy bindings to use in the application.
2020-08-10 08:52:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function* fetchPageDSLSaga(action: ReduxAction<{ pageId: string }>) {
|
|
|
|
|
try {
|
|
|
|
|
const fetchPageResponse: FetchPageResponse = yield call(PageApi.fetchPage, {
|
|
|
|
|
id: action.payload.pageId,
|
|
|
|
|
});
|
|
|
|
|
const isValidResponse = yield validateResponse(fetchPageResponse);
|
|
|
|
|
if (isValidResponse) {
|
|
|
|
|
yield put({
|
|
|
|
|
type: ReduxActionTypes.FETCH_PAGE_DSL_SUCCESS,
|
|
|
|
|
payload: {
|
|
|
|
|
pageId: action.payload.pageId,
|
|
|
|
|
dsl: extractCurrentDSL(fetchPageResponse),
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
yield put({
|
|
|
|
|
type: ReduxActionTypes.FETCH_PAGE_DSL_ERROR,
|
|
|
|
|
payload: {
|
|
|
|
|
pageId: action.payload.pageId,
|
|
|
|
|
error,
|
|
|
|
|
show: false,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-14 07:43:01 +00:00
|
|
|
export function* populatePageDSLsSaga() {
|
Feature/entity browse (#220)
# New Feature: Entity Explorer
- Entities are actions (apis and queries), datasources, pages, and widgets
- With this new feature, all entities in the application will be available
to view in the new entity explorer sidebar
- All existing application features from the api sidebar, query sidebar, datasource sidebar and pages sidebar
now are avialable on the entity explorer sidebar
- Users are now able to quickly switch to any entity in the application from the entity explorer sidebar.
- Users can also search all entities in the application from the new sidebar. Use cmd + f or ctrl + f to focus on the search input
- Users can rename entities from the new sidebar
- Users can also perform contextual actions on these entities like set a page as home page, copy/move actions, delete entity, etc from the context menu available alongside the entities in the sidebar
- Users can view the properties of the entities in the sidebar, as well as copy bindings to use in the application.
2020-08-10 08:52:45 +00:00
|
|
|
try {
|
|
|
|
|
yield put({
|
|
|
|
|
type: ReduxActionTypes.POPULATE_PAGEDSLS_INIT,
|
|
|
|
|
});
|
|
|
|
|
const pageIds: string[] = yield select((state: AppState) =>
|
|
|
|
|
state.entities.pageList.pages.map((page: Page) => page.pageId),
|
|
|
|
|
);
|
|
|
|
|
yield all(
|
|
|
|
|
pageIds.map((pageId: string) => {
|
|
|
|
|
return call(fetchPageDSLSaga, {
|
|
|
|
|
type: ReduxActionTypes.FETCH_PAGE_DSL_INIT,
|
|
|
|
|
payload: { pageId },
|
|
|
|
|
});
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
yield put({
|
|
|
|
|
type: ReduxActionTypes.POPULATE_PAGEDSLS_SUCCESS,
|
|
|
|
|
});
|
|
|
|
|
} catch (error) {
|
|
|
|
|
yield put({
|
|
|
|
|
type: ReduxActionErrorTypes.POPULATE_PAGEDSLS_ERROR,
|
|
|
|
|
payload: {
|
|
|
|
|
error,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
2019-11-01 07:11:32 +00:00
|
|
|
}
|
|
|
|
|
|
2019-11-08 11:02:00 +00:00
|
|
|
export function* initializeAppViewerSaga(
|
2020-10-21 04:25:32 +00:00
|
|
|
action: ReduxAction<{ applicationId: string }>,
|
2019-11-08 11:02:00 +00:00
|
|
|
) {
|
2019-11-22 14:02:55 +00:00
|
|
|
const { applicationId } = action.payload;
|
2020-01-24 09:54:40 +00:00
|
|
|
yield all([
|
2020-07-15 13:01:35 +00:00
|
|
|
put(fetchActionsForView(applicationId)),
|
2020-01-24 09:54:40 +00:00
|
|
|
put(fetchPageList(applicationId)),
|
2020-06-17 10:19:56 +00:00
|
|
|
put(fetchApplication(applicationId)),
|
2020-01-24 09:54:40 +00:00
|
|
|
]);
|
2019-11-22 14:02:55 +00:00
|
|
|
|
2019-11-08 11:02:00 +00:00
|
|
|
yield all([
|
2020-07-15 13:01:35 +00:00
|
|
|
take(ReduxActionTypes.FETCH_ACTIONS_VIEW_MODE_SUCCESS),
|
2020-01-24 09:54:40 +00:00
|
|
|
take(ReduxActionTypes.FETCH_PAGE_LIST_SUCCESS),
|
2019-11-08 11:02:00 +00:00
|
|
|
]);
|
2020-08-03 14:18:48 +00:00
|
|
|
|
2020-10-21 04:25:32 +00:00
|
|
|
const pageId = yield select(getDefaultPageId);
|
|
|
|
|
|
|
|
|
|
if (pageId) {
|
|
|
|
|
yield put(fetchPublishedPage(pageId, true));
|
|
|
|
|
yield take(ReduxActionTypes.FETCH_PUBLISHED_PAGE_SUCCESS);
|
|
|
|
|
|
|
|
|
|
yield put(setAppMode(APP_MODE.PUBLISHED));
|
|
|
|
|
yield put(updateAppStore(getAppStore(applicationId)));
|
2020-08-14 07:43:01 +00:00
|
|
|
|
2020-05-06 05:56:07 +00:00
|
|
|
yield put({
|
2020-10-21 04:25:32 +00:00
|
|
|
type: ReduxActionTypes.INITIALIZE_PAGE_VIEWER_SUCCESS,
|
2020-05-06 05:56:07 +00:00
|
|
|
});
|
2020-10-21 04:25:32 +00:00
|
|
|
if ("serviceWorker" in navigator) {
|
|
|
|
|
yield put({
|
|
|
|
|
type: ReduxActionTypes.FETCH_ALL_PUBLISHED_PAGES,
|
|
|
|
|
});
|
|
|
|
|
}
|
2020-05-06 05:56:07 +00:00
|
|
|
}
|
2019-11-08 11:02:00 +00:00
|
|
|
}
|
|
|
|
|
|
2019-11-01 07:11:32 +00:00
|
|
|
export default function* watchInitSagas() {
|
2019-11-08 11:02:00 +00:00
|
|
|
yield all([
|
2019-11-14 11:17:36 +00:00
|
|
|
takeLatest(ReduxActionTypes.INITIALIZE_EDITOR, initializeEditorSaga),
|
2019-11-08 11:02:00 +00:00
|
|
|
takeLatest(
|
|
|
|
|
ReduxActionTypes.INITIALIZE_PAGE_VIEWER,
|
|
|
|
|
initializeAppViewerSaga,
|
|
|
|
|
),
|
|
|
|
|
]);
|
2019-11-01 07:11:32 +00:00
|
|
|
}
|