2020-03-27 09:02:11 +00:00
|
|
|
import {
|
|
|
|
|
all,
|
|
|
|
|
select,
|
|
|
|
|
call,
|
|
|
|
|
put,
|
|
|
|
|
takeLatest,
|
|
|
|
|
takeEvery,
|
|
|
|
|
delay,
|
|
|
|
|
} from "redux-saga/effects";
|
|
|
|
|
|
|
|
|
|
import { generateReactKey } from "utils/generators";
|
|
|
|
|
import { WidgetAddChild } from "actions/pageActions";
|
|
|
|
|
import {
|
|
|
|
|
MAIN_CONTAINER_WIDGET_ID,
|
|
|
|
|
WidgetTypes,
|
|
|
|
|
} from "constants/WidgetConstants";
|
|
|
|
|
import {
|
|
|
|
|
ReduxActionErrorTypes,
|
|
|
|
|
ReduxActionTypes,
|
|
|
|
|
ReduxAction,
|
|
|
|
|
} from "constants/ReduxActionConstants";
|
|
|
|
|
|
|
|
|
|
import {
|
|
|
|
|
getWidgets,
|
|
|
|
|
getWidgetByName,
|
|
|
|
|
getWidgetsMeta,
|
|
|
|
|
getWidgetIdsByType,
|
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
|
|
|
getWidgetMetaProps,
|
2020-03-27 09:02:11 +00:00
|
|
|
} from "sagas/selectors";
|
|
|
|
|
import { FlattenedWidgetProps } from "reducers/entityReducers/canvasWidgetsReducer";
|
2021-02-11 06:25:11 +00:00
|
|
|
import {
|
|
|
|
|
resetChildrenMetaProperty,
|
|
|
|
|
updateWidgetMetaProperty,
|
|
|
|
|
} from "actions/metaActions";
|
2020-04-13 08:24:13 +00:00
|
|
|
import { focusWidget } from "actions/widgetActions";
|
2021-03-13 14:24:45 +00:00
|
|
|
import log from "loglevel";
|
2021-02-11 06:25:11 +00:00
|
|
|
import { flatten } from "lodash";
|
2021-04-23 13:50:55 +00:00
|
|
|
import AppsmithConsole from "utils/AppsmithConsole";
|
2020-03-27 09:02:11 +00:00
|
|
|
|
2020-04-03 09:32:13 +00:00
|
|
|
export function* createModalSaga(action: ReduxAction<{ modalName: string }>) {
|
2020-03-27 09:02:11 +00:00
|
|
|
try {
|
|
|
|
|
const modalWidgetId = generateReactKey();
|
|
|
|
|
const props: WidgetAddChild = {
|
|
|
|
|
widgetId: MAIN_CONTAINER_WIDGET_ID,
|
2020-04-03 09:32:13 +00:00
|
|
|
widgetName: action.payload.modalName,
|
2020-03-27 09:02:11 +00:00
|
|
|
type: WidgetTypes.MODAL_WIDGET,
|
|
|
|
|
newWidgetId: modalWidgetId,
|
|
|
|
|
parentRowSpace: 1,
|
|
|
|
|
parentColumnSpace: 1,
|
|
|
|
|
leftColumn: 0,
|
|
|
|
|
topRow: 0,
|
|
|
|
|
columns: 0,
|
|
|
|
|
rows: 0,
|
2020-04-15 11:42:11 +00:00
|
|
|
tabId: "",
|
2020-03-27 09:02:11 +00:00
|
|
|
};
|
|
|
|
|
yield put({
|
|
|
|
|
type: ReduxActionTypes.WIDGET_ADD_CHILD,
|
|
|
|
|
payload: props,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
yield put({
|
|
|
|
|
type: ReduxActionTypes.SHOW_MODAL,
|
|
|
|
|
payload: { modalId: modalWidgetId },
|
|
|
|
|
});
|
|
|
|
|
} catch (error) {
|
2021-03-13 14:24:45 +00:00
|
|
|
log.error(error);
|
2020-03-27 09:02:11 +00:00
|
|
|
yield put({
|
|
|
|
|
type: ReduxActionErrorTypes.CREATE_MODAL_ERROR,
|
|
|
|
|
payload: { error },
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function* showModalByNameSaga(
|
|
|
|
|
action: ReduxAction<{ modalName: string }>,
|
|
|
|
|
) {
|
|
|
|
|
const widgets: { [widgetId: string]: FlattenedWidgetProps } = yield select(
|
|
|
|
|
getWidgets,
|
|
|
|
|
);
|
|
|
|
|
const modal: FlattenedWidgetProps | undefined = Object.values(widgets).find(
|
|
|
|
|
(widget: FlattenedWidgetProps) =>
|
|
|
|
|
widget.widgetName === action.payload.modalName,
|
|
|
|
|
);
|
|
|
|
|
if (modal) {
|
2021-04-23 13:50:55 +00:00
|
|
|
AppsmithConsole.info({
|
|
|
|
|
text: action.payload.modalName
|
|
|
|
|
? `showModal('${action.payload.modalName}') was triggered`
|
|
|
|
|
: `showModal() was triggered`,
|
|
|
|
|
});
|
|
|
|
|
|
2020-03-27 09:02:11 +00:00
|
|
|
yield put({
|
|
|
|
|
type: ReduxActionTypes.SHOW_MODAL,
|
|
|
|
|
payload: {
|
|
|
|
|
modalId: modal.widgetId,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-23 04:18:23 +00:00
|
|
|
export function* showIfModalSaga(
|
|
|
|
|
action: ReduxAction<{ widgetId: string; type: string }>,
|
|
|
|
|
) {
|
|
|
|
|
if (action.payload.type === "MODAL_WIDGET") {
|
|
|
|
|
yield put({
|
|
|
|
|
type: ReduxActionTypes.SHOW_MODAL,
|
|
|
|
|
payload: { modalId: action.payload.widgetId },
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-27 09:02:11 +00:00
|
|
|
export function* showModalSaga(action: ReduxAction<{ modalId: string }>) {
|
|
|
|
|
// First we close the currently open modals (if any)
|
|
|
|
|
// Notice the empty payload.
|
|
|
|
|
yield call(closeModalSaga, {
|
|
|
|
|
type: ReduxActionTypes.CLOSE_MODAL,
|
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
|
|
|
payload: {
|
|
|
|
|
exclude: action.payload.modalId,
|
|
|
|
|
},
|
2020-03-27 09:02:11 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
yield put({
|
|
|
|
|
type: ReduxActionTypes.SELECT_WIDGET,
|
|
|
|
|
payload: { widgetId: action.payload.modalId },
|
|
|
|
|
});
|
2020-04-13 08:24:13 +00:00
|
|
|
yield put(focusWidget(action.payload.modalId));
|
2020-03-27 09:02:11 +00:00
|
|
|
|
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
|
|
|
const metaProps = yield select(getWidgetMetaProps, action.payload.modalId);
|
|
|
|
|
if (!metaProps || !metaProps.isVisible) {
|
|
|
|
|
// Then show the modal we would like to show.
|
|
|
|
|
yield put(
|
|
|
|
|
updateWidgetMetaProperty(action.payload.modalId, "isVisible", true),
|
|
|
|
|
);
|
|
|
|
|
yield delay(1000);
|
|
|
|
|
}
|
2020-03-27 09:02:11 +00:00
|
|
|
yield put({
|
|
|
|
|
type: ReduxActionTypes.SHOW_PROPERTY_PANE,
|
|
|
|
|
payload: {
|
|
|
|
|
widgetId: action.payload.modalId,
|
|
|
|
|
callForDragOrResize: undefined,
|
|
|
|
|
force: true,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
export function* closeModalSaga(
|
|
|
|
|
action: ReduxAction<{ modalName?: string; exclude?: string }>,
|
|
|
|
|
) {
|
2020-03-27 09:02:11 +00:00
|
|
|
try {
|
|
|
|
|
const { modalName } = action.payload;
|
|
|
|
|
let widgetIds: string[] = [];
|
|
|
|
|
// If modalName is provided, we just want to close this modal
|
|
|
|
|
if (modalName) {
|
|
|
|
|
const widget = yield select(getWidgetByName, modalName);
|
|
|
|
|
widgetIds = [widget.widgetId];
|
|
|
|
|
yield put({
|
|
|
|
|
type: ReduxActionTypes.SHOW_PROPERTY_PANE,
|
|
|
|
|
payload: {},
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
// If modalName is not provided, find all open modals
|
|
|
|
|
// Get all meta prop records
|
|
|
|
|
const metaProps: Record<string, any> = yield select(getWidgetsMeta);
|
|
|
|
|
|
|
|
|
|
// Get widgetIds of all widgets of type MODAL_WIDGET
|
|
|
|
|
const modalWidgetIds: string[] = yield select(
|
|
|
|
|
getWidgetIdsByType,
|
|
|
|
|
WidgetTypes.MODAL_WIDGET,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Loop through all modal widgetIds
|
|
|
|
|
modalWidgetIds.forEach((widgetId: string) => {
|
|
|
|
|
// Check if modal is open
|
|
|
|
|
if (metaProps[widgetId] && metaProps[widgetId].isVisible) {
|
|
|
|
|
// Add to our list of widgetIds
|
|
|
|
|
widgetIds.push(widgetId);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
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
|
|
|
widgetIds = action.payload.exclude
|
|
|
|
|
? widgetIds.filter((id: string) => id !== action.payload.exclude)
|
|
|
|
|
: widgetIds;
|
2020-03-27 09:02:11 +00:00
|
|
|
// If we have modals to close, set its isVisible to false to close.
|
|
|
|
|
if (widgetIds) {
|
|
|
|
|
yield all(
|
2021-02-11 06:25:11 +00:00
|
|
|
flatten(
|
|
|
|
|
widgetIds.map((widgetId: string) => {
|
|
|
|
|
return [
|
|
|
|
|
put(updateWidgetMetaProperty(widgetId, "isVisible", false)),
|
|
|
|
|
put(resetChildrenMetaProperty(widgetId)),
|
|
|
|
|
];
|
|
|
|
|
}),
|
2020-03-27 09:02:11 +00:00
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
2021-03-13 14:24:45 +00:00
|
|
|
log.error(error);
|
2020-03-27 09:02:11 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default function* modalSagas() {
|
|
|
|
|
yield all([
|
|
|
|
|
takeEvery(ReduxActionTypes.CLOSE_MODAL, closeModalSaga),
|
|
|
|
|
takeLatest(ReduxActionTypes.CREATE_MODAL_INIT, createModalSaga),
|
|
|
|
|
takeLatest(ReduxActionTypes.SHOW_MODAL, showModalSaga),
|
|
|
|
|
takeLatest(ReduxActionTypes.SHOW_MODAL_BY_NAME, showModalByNameSaga),
|
2021-02-23 04:18:23 +00:00
|
|
|
takeLatest(ReduxActionTypes.WIDGET_CHILD_ADDED, showIfModalSaga),
|
2020-03-27 09:02:11 +00:00
|
|
|
]);
|
|
|
|
|
}
|