2020-03-19 03:25:52 +00:00
|
|
|
import {
|
|
|
|
|
ActionData,
|
|
|
|
|
ActionDataState,
|
|
|
|
|
} from "reducers/entityReducers/actionsReducer";
|
2020-02-18 10:41:52 +00:00
|
|
|
import { WidgetProps } from "widgets/BaseWidget";
|
|
|
|
|
import { ActionResponse } from "api/ActionAPI";
|
2020-03-19 03:25:52 +00:00
|
|
|
import { CanvasWidgetsReduxState } from "reducers/entityReducers/canvasWidgetsReducer";
|
|
|
|
|
import { MetaState } from "reducers/entityReducers/metaReducer";
|
2020-04-20 05:42:46 +00:00
|
|
|
import { PageListPayload } from "constants/ReduxActionConstants";
|
2020-04-17 16:15:09 +00:00
|
|
|
import WidgetFactory from "utils/WidgetFactory";
|
2020-08-14 07:43:01 +00:00
|
|
|
import { ActionConfig, PluginType, Property } from "entities/Action";
|
|
|
|
|
import { AppDataState } from "reducers/entityReducers/appReducer";
|
2020-09-15 16:54:15 +00:00
|
|
|
import _ from "lodash";
|
2020-02-18 10:41:52 +00:00
|
|
|
|
|
|
|
|
export type ActionDescription<T> = {
|
|
|
|
|
type: string;
|
|
|
|
|
payload: T;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
type ActionDispatcher<T, A extends string[]> = (
|
|
|
|
|
...args: A
|
|
|
|
|
) => ActionDescription<T>;
|
|
|
|
|
|
|
|
|
|
export enum ENTITY_TYPE {
|
|
|
|
|
ACTION = "ACTION",
|
|
|
|
|
WIDGET = "WIDGET",
|
2020-08-07 14:24:26 +00:00
|
|
|
APPSMITH = "APPSMITH",
|
2020-02-18 10:41:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export type RunActionPayload = {
|
|
|
|
|
actionId: string;
|
|
|
|
|
onSuccess: string;
|
|
|
|
|
onError: string;
|
2020-07-17 12:55:34 +00:00
|
|
|
params: Record<string, any>;
|
2020-02-18 10:41:52 +00:00
|
|
|
};
|
|
|
|
|
|
2020-06-29 07:41:53 +00:00
|
|
|
export interface DataTreeAction extends Omit<ActionData, "data" | "config"> {
|
2020-02-18 10:41:52 +00:00
|
|
|
data: ActionResponse["body"];
|
2020-06-29 07:41:53 +00:00
|
|
|
actionId: string;
|
|
|
|
|
config: Partial<ActionConfig>;
|
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
|
|
|
pluginType: PluginType;
|
|
|
|
|
name: string;
|
2020-07-17 12:55:34 +00:00
|
|
|
run: ActionDispatcher<RunActionPayload, [string, string, string]> | {};
|
2020-06-04 13:49:22 +00:00
|
|
|
dynamicBindingPathList: Property[];
|
2020-02-18 10:41:52 +00:00
|
|
|
ENTITY_TYPE: ENTITY_TYPE.ACTION;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface DataTreeWidget extends WidgetProps {
|
|
|
|
|
ENTITY_TYPE: ENTITY_TYPE.WIDGET;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-14 07:43:01 +00:00
|
|
|
export interface DataTreeAppsmith extends AppDataState {
|
2020-08-07 14:24:26 +00:00
|
|
|
ENTITY_TYPE: ENTITY_TYPE.APPSMITH;
|
2020-08-24 12:09:17 +00:00
|
|
|
store: object;
|
2020-08-07 14:24:26 +00:00
|
|
|
}
|
|
|
|
|
|
2020-02-26 12:44:56 +00:00
|
|
|
export type DataTreeEntity =
|
|
|
|
|
| DataTreeAction
|
|
|
|
|
| DataTreeWidget
|
2020-04-20 05:42:46 +00:00
|
|
|
| PageListPayload
|
2020-08-07 14:24:26 +00:00
|
|
|
| DataTreeAppsmith
|
2020-02-26 12:44:56 +00:00
|
|
|
| ActionDispatcher<any, any>;
|
|
|
|
|
|
2020-02-18 10:41:52 +00:00
|
|
|
export type DataTree = {
|
2020-02-26 12:44:56 +00:00
|
|
|
[entityName: string]: DataTreeEntity;
|
2020-02-18 10:41:52 +00:00
|
|
|
} & { actionPaths?: string[] };
|
|
|
|
|
|
2020-03-19 03:25:52 +00:00
|
|
|
type DataTreeSeed = {
|
|
|
|
|
actions: ActionDataState;
|
|
|
|
|
widgets: CanvasWidgetsReduxState;
|
|
|
|
|
widgetsMeta: MetaState;
|
2020-04-20 05:42:46 +00:00
|
|
|
pageList: PageListPayload;
|
2020-08-14 07:43:01 +00:00
|
|
|
appData: AppDataState;
|
2020-03-19 03:25:52 +00:00
|
|
|
};
|
|
|
|
|
|
2020-02-18 10:41:52 +00:00
|
|
|
export class DataTreeFactory {
|
2020-06-19 13:06:45 +00:00
|
|
|
static create(
|
2020-08-14 07:43:01 +00:00
|
|
|
{ actions, widgets, widgetsMeta, pageList, appData }: DataTreeSeed,
|
2020-06-19 13:06:45 +00:00
|
|
|
// TODO(hetu)
|
|
|
|
|
// temporary fix for not getting functions while normal evals which crashes the app
|
|
|
|
|
// need to remove this after we get a proper solve
|
|
|
|
|
withFunctions?: boolean,
|
|
|
|
|
): DataTree {
|
2020-02-18 10:41:52 +00:00
|
|
|
const dataTree: DataTree = {};
|
2020-06-19 13:06:45 +00:00
|
|
|
const actionPaths = [];
|
2020-03-19 03:25:52 +00:00
|
|
|
actions.forEach(a => {
|
2020-07-03 08:58:58 +00:00
|
|
|
const config = a.config;
|
2020-06-04 13:49:22 +00:00
|
|
|
let dynamicBindingPathList: Property[] = [];
|
|
|
|
|
// update paths
|
|
|
|
|
if (
|
|
|
|
|
config.dynamicBindingPathList &&
|
|
|
|
|
config.dynamicBindingPathList.length
|
|
|
|
|
) {
|
|
|
|
|
dynamicBindingPathList = config.dynamicBindingPathList.map(d => ({
|
|
|
|
|
...d,
|
|
|
|
|
key: `config.${d.key}`,
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
dataTree[config.name] = {
|
2020-02-18 10:41:52 +00:00
|
|
|
...a,
|
2020-06-29 07:41:53 +00:00
|
|
|
actionId: config.id,
|
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
|
|
|
name: config.name,
|
|
|
|
|
pluginType: config.pluginType,
|
2020-06-29 07:41:53 +00:00
|
|
|
config: config.actionConfiguration,
|
2020-06-04 13:49:22 +00:00
|
|
|
dynamicBindingPathList,
|
2020-02-18 10:41:52 +00:00
|
|
|
data: a.data ? a.data.body : {},
|
2020-06-19 13:06:45 +00:00
|
|
|
run: withFunctions
|
2020-07-17 12:55:34 +00:00
|
|
|
? function(
|
|
|
|
|
this: DataTreeAction,
|
|
|
|
|
onSuccess: string,
|
|
|
|
|
onError: string,
|
|
|
|
|
params = "",
|
|
|
|
|
) {
|
2020-06-19 13:06:45 +00:00
|
|
|
return {
|
|
|
|
|
type: "RUN_ACTION",
|
|
|
|
|
payload: {
|
2020-06-29 07:41:53 +00:00
|
|
|
actionId: this.actionId,
|
2020-06-19 13:06:45 +00:00
|
|
|
onSuccess: onSuccess ? `{{${onSuccess.toString()}}}` : "",
|
|
|
|
|
onError: onError ? `{{${onError.toString()}}}` : "",
|
2020-07-17 12:55:34 +00:00
|
|
|
params,
|
2020-06-19 13:06:45 +00:00
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
: {},
|
2020-02-18 10:41:52 +00:00
|
|
|
ENTITY_TYPE: ENTITY_TYPE.ACTION,
|
|
|
|
|
};
|
2020-06-19 13:06:45 +00:00
|
|
|
if (withFunctions) {
|
|
|
|
|
actionPaths.push(`${config.name}.run`);
|
|
|
|
|
}
|
|
|
|
|
dataTree.actionPaths && dataTree.actionPaths.push();
|
2020-02-18 10:41:52 +00:00
|
|
|
});
|
2020-03-19 03:25:52 +00:00
|
|
|
Object.keys(widgets).forEach(w => {
|
2020-09-15 16:54:15 +00:00
|
|
|
const widget = { ...widgets[w] };
|
2020-03-19 03:25:52 +00:00
|
|
|
const widgetMetaProps = widgetsMeta[w];
|
2020-04-17 16:15:09 +00:00
|
|
|
const defaultMetaProps = WidgetFactory.getWidgetMetaPropertiesMap(
|
|
|
|
|
widget.type,
|
|
|
|
|
);
|
|
|
|
|
const derivedPropertyMap = WidgetFactory.getWidgetDerivedPropertiesMap(
|
|
|
|
|
widget.type,
|
|
|
|
|
);
|
|
|
|
|
const derivedProps: any = {};
|
|
|
|
|
const dynamicBindings = widget.dynamicBindings || {};
|
2020-09-15 16:54:15 +00:00
|
|
|
Object.keys(dynamicBindings).forEach(propertyName => {
|
|
|
|
|
if (_.isObject(widget[propertyName])) {
|
|
|
|
|
// Stringify this because composite controls may have bindings in the sub controls
|
|
|
|
|
widget[propertyName] = JSON.stringify(widget[propertyName]);
|
|
|
|
|
}
|
|
|
|
|
});
|
2020-04-17 16:15:09 +00:00
|
|
|
Object.keys(derivedPropertyMap).forEach(propertyName => {
|
|
|
|
|
derivedProps[propertyName] = derivedPropertyMap[propertyName].replace(
|
|
|
|
|
/this./g,
|
|
|
|
|
`${widget.widgetName}.`,
|
|
|
|
|
);
|
|
|
|
|
dynamicBindings[propertyName] = true;
|
|
|
|
|
});
|
2020-02-18 10:41:52 +00:00
|
|
|
dataTree[widget.widgetName] = {
|
|
|
|
|
...widget,
|
2020-04-17 16:15:09 +00:00
|
|
|
...defaultMetaProps,
|
2020-02-18 10:41:52 +00:00
|
|
|
...widgetMetaProps,
|
2020-04-17 16:15:09 +00:00
|
|
|
...derivedProps,
|
|
|
|
|
dynamicBindings,
|
2020-02-18 10:41:52 +00:00
|
|
|
ENTITY_TYPE: ENTITY_TYPE.WIDGET,
|
|
|
|
|
};
|
|
|
|
|
});
|
2020-06-19 13:06:45 +00:00
|
|
|
|
|
|
|
|
if (withFunctions) {
|
|
|
|
|
dataTree.navigateTo = function(pageNameOrUrl: string, params: object) {
|
|
|
|
|
return {
|
|
|
|
|
type: "NAVIGATE_TO",
|
|
|
|
|
payload: { pageNameOrUrl, params },
|
|
|
|
|
};
|
2020-02-18 10:41:52 +00:00
|
|
|
};
|
2020-06-19 13:06:45 +00:00
|
|
|
actionPaths.push("navigateTo");
|
2020-02-18 10:41:52 +00:00
|
|
|
|
2020-06-19 13:06:45 +00:00
|
|
|
dataTree.showAlert = function(message: string, style: string) {
|
|
|
|
|
return {
|
|
|
|
|
type: "SHOW_ALERT",
|
|
|
|
|
payload: { message, style },
|
|
|
|
|
};
|
2020-02-18 10:41:52 +00:00
|
|
|
};
|
2020-06-19 13:06:45 +00:00
|
|
|
actionPaths.push("showAlert");
|
2020-02-18 10:41:52 +00:00
|
|
|
|
2020-06-19 13:06:45 +00:00
|
|
|
// dataTree.url = url;
|
|
|
|
|
dataTree.showModal = function(modalName: string) {
|
|
|
|
|
return {
|
|
|
|
|
type: "SHOW_MODAL_BY_NAME",
|
|
|
|
|
payload: { modalName },
|
|
|
|
|
};
|
2020-03-27 09:02:11 +00:00
|
|
|
};
|
2020-06-19 13:06:45 +00:00
|
|
|
actionPaths.push("showModal");
|
|
|
|
|
|
|
|
|
|
dataTree.closeModal = function(modalName: string) {
|
|
|
|
|
return {
|
|
|
|
|
type: "CLOSE_MODAL",
|
|
|
|
|
payload: { modalName },
|
|
|
|
|
};
|
2020-03-27 09:02:11 +00:00
|
|
|
};
|
2020-06-19 13:06:45 +00:00
|
|
|
actionPaths.push("closeModal");
|
2020-08-24 12:09:17 +00:00
|
|
|
|
|
|
|
|
dataTree.storeValue = function(key: string, value: string) {
|
|
|
|
|
return {
|
|
|
|
|
type: "STORE_VALUE",
|
|
|
|
|
payload: { key, value },
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
actionPaths.push("storeValue");
|
2020-08-28 12:07:37 +00:00
|
|
|
|
|
|
|
|
dataTree.download = function(data: string, name: string, type: string) {
|
|
|
|
|
return {
|
|
|
|
|
type: "DOWNLOAD",
|
|
|
|
|
payload: { data, name, type },
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
actionPaths.push("download");
|
2020-06-19 13:06:45 +00:00
|
|
|
}
|
2020-03-27 09:02:11 +00:00
|
|
|
|
2020-04-20 05:42:46 +00:00
|
|
|
dataTree.pageList = pageList;
|
2020-06-19 13:06:45 +00:00
|
|
|
dataTree.actionPaths = actionPaths;
|
2020-08-07 14:24:26 +00:00
|
|
|
dataTree.appsmith = {
|
|
|
|
|
ENTITY_TYPE: ENTITY_TYPE.APPSMITH,
|
2020-08-14 07:43:01 +00:00
|
|
|
...appData,
|
2020-08-07 14:24:26 +00:00
|
|
|
};
|
2020-02-18 10:41:52 +00:00
|
|
|
return dataTree;
|
|
|
|
|
}
|
|
|
|
|
}
|