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-11-12 11:23:32 +00:00
|
|
|
import { ActionConfig, PluginType } from "entities/Action";
|
2020-08-14 07:43:01 +00:00
|
|
|
import { AppDataState } from "reducers/entityReducers/appReducer";
|
2020-09-15 16:54:15 +00:00
|
|
|
import _ from "lodash";
|
2020-11-12 11:23:32 +00:00
|
|
|
import {
|
|
|
|
|
DynamicPath,
|
|
|
|
|
getEntityDynamicBindingPathList,
|
|
|
|
|
} from "../../utils/DynamicBindingUtils";
|
2020-02-18 10:41:52 +00:00
|
|
|
|
|
|
|
|
export type ActionDescription<T> = {
|
|
|
|
|
type: string;
|
|
|
|
|
payload: T;
|
|
|
|
|
};
|
|
|
|
|
|
2020-10-21 04:25:32 +00:00
|
|
|
export type ActionDispatcher<T, A extends string[]> = (
|
2020-02-18 10:41:52 +00:00
|
|
|
...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-10-12 13:06:05 +00:00
|
|
|
run:
|
|
|
|
|
| ActionDispatcher<RunActionPayload, [string, string, string]>
|
|
|
|
|
| Record<string, any>;
|
2020-11-12 11:23:32 +00:00
|
|
|
dynamicBindingPathList: DynamicPath[];
|
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-10-12 13:06:05 +00:00
|
|
|
store: Record<string, unknown>;
|
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-10-21 04:25:32 +00:00
|
|
|
static create({
|
|
|
|
|
actions,
|
|
|
|
|
widgets,
|
|
|
|
|
widgetsMeta,
|
|
|
|
|
pageList,
|
|
|
|
|
appData,
|
|
|
|
|
}: DataTreeSeed): DataTree {
|
2020-02-18 10:41:52 +00:00
|
|
|
const dataTree: DataTree = {};
|
2020-10-21 04:25:32 +00:00
|
|
|
actions.forEach(action => {
|
2020-11-12 11:23:32 +00:00
|
|
|
let dynamicBindingPathList: DynamicPath[] = [];
|
2020-06-04 13:49:22 +00:00
|
|
|
// update paths
|
|
|
|
|
if (
|
2020-10-21 04:25:32 +00:00
|
|
|
action.config.dynamicBindingPathList &&
|
|
|
|
|
action.config.dynamicBindingPathList.length
|
2020-06-04 13:49:22 +00:00
|
|
|
) {
|
2020-10-21 04:25:32 +00:00
|
|
|
dynamicBindingPathList = action.config.dynamicBindingPathList.map(
|
|
|
|
|
d => ({
|
|
|
|
|
...d,
|
|
|
|
|
key: `config.${d.key}`,
|
|
|
|
|
}),
|
|
|
|
|
);
|
2020-06-04 13:49:22 +00:00
|
|
|
}
|
2020-10-21 04:25:32 +00:00
|
|
|
dataTree[action.config.name] = {
|
|
|
|
|
run: {},
|
|
|
|
|
actionId: action.config.id,
|
|
|
|
|
name: action.config.name,
|
|
|
|
|
pluginType: action.config.pluginType,
|
|
|
|
|
config: action.config.actionConfiguration,
|
2020-06-04 13:49:22 +00:00
|
|
|
dynamicBindingPathList,
|
2020-10-21 04:25:32 +00:00
|
|
|
data: action.data ? action.data.body : {},
|
2020-02-18 10:41:52 +00:00
|
|
|
ENTITY_TYPE: ENTITY_TYPE.ACTION,
|
2020-10-21 04:25:32 +00:00
|
|
|
isLoading: action.isLoading,
|
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 = {};
|
2020-11-12 11:23:32 +00:00
|
|
|
const dynamicBindingPathList = getEntityDynamicBindingPathList(widget);
|
|
|
|
|
dynamicBindingPathList.forEach(dynamicPath => {
|
|
|
|
|
const propertyPath = dynamicPath.key;
|
|
|
|
|
const propertyValue = _.get(widget, propertyPath);
|
|
|
|
|
if (_.isObject(propertyValue)) {
|
2020-09-15 16:54:15 +00:00
|
|
|
// Stringify this because composite controls may have bindings in the sub controls
|
2020-11-12 11:23:32 +00:00
|
|
|
_.set(widget, propertyPath, JSON.stringify(propertyValue));
|
2020-09-15 16:54:15 +00:00
|
|
|
}
|
|
|
|
|
});
|
2020-04-17 16:15:09 +00:00
|
|
|
Object.keys(derivedPropertyMap).forEach(propertyName => {
|
|
|
|
|
derivedProps[propertyName] = derivedPropertyMap[propertyName].replace(
|
|
|
|
|
/this./g,
|
|
|
|
|
`${widget.widgetName}.`,
|
|
|
|
|
);
|
2020-11-12 11:23:32 +00:00
|
|
|
dynamicBindingPathList.push({
|
|
|
|
|
key: propertyName,
|
|
|
|
|
});
|
2020-04-17 16:15:09 +00:00
|
|
|
});
|
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,
|
2020-11-12 11:23:32 +00:00
|
|
|
dynamicBindingPathList,
|
2020-02-18 10:41:52 +00:00
|
|
|
ENTITY_TYPE: ENTITY_TYPE.WIDGET,
|
|
|
|
|
};
|
|
|
|
|
});
|
2020-06-19 13:06:45 +00:00
|
|
|
|
2020-04-20 05:42:46 +00:00
|
|
|
dataTree.pageList = pageList;
|
2020-10-12 13:06:05 +00:00
|
|
|
dataTree.appsmith = { ...appData } as DataTreeAppsmith;
|
|
|
|
|
(dataTree.appsmith as DataTreeAppsmith).ENTITY_TYPE = ENTITY_TYPE.APPSMITH;
|
2020-02-18 10:41:52 +00:00
|
|
|
return dataTree;
|
|
|
|
|
}
|
|
|
|
|
}
|