2022-12-02 12:45:11 +00:00
|
|
|
import { ActionDataState } from "reducers/entityReducers/actionsReducer";
|
2020-02-18 10:41:52 +00:00
|
|
|
import { WidgetProps } from "widgets/BaseWidget";
|
2020-03-19 03:25:52 +00:00
|
|
|
import { CanvasWidgetsReduxState } from "reducers/entityReducers/canvasWidgetsReducer";
|
|
|
|
|
import { MetaState } from "reducers/entityReducers/metaReducer";
|
2022-06-21 13:57:34 +00:00
|
|
|
import { Page } from "@appsmith/constants/ReduxActionConstants";
|
2020-08-14 07:43:01 +00:00
|
|
|
import { AppDataState } from "reducers/entityReducers/appReducer";
|
2022-12-02 12:45:11 +00:00
|
|
|
import { DependencyMap } from "utils/DynamicBindingUtils";
|
2021-03-30 05:29:03 +00:00
|
|
|
import { generateDataTreeAction } from "entities/DataTree/dataTreeAction";
|
2021-09-08 17:32:22 +00:00
|
|
|
import { generateDataTreeJSAction } from "entities/DataTree/dataTreeJSAction";
|
2021-03-30 05:29:03 +00:00
|
|
|
import { generateDataTreeWidget } from "entities/DataTree/dataTreeWidget";
|
2021-09-08 17:32:22 +00:00
|
|
|
import { JSCollectionDataState } from "reducers/entityReducers/jsActionsReducer";
|
2022-05-04 09:45:57 +00:00
|
|
|
import { AppTheme } from "entities/AppTheming";
|
2022-05-18 05:21:53 +00:00
|
|
|
import log from "loglevel";
|
2022-12-02 12:45:11 +00:00
|
|
|
import { WidgetConfigProps } from "reducers/entityReducers/widgetConfigReducer";
|
|
|
|
|
import {
|
|
|
|
|
ActionDispatcher,
|
|
|
|
|
ActionEntityConfig,
|
|
|
|
|
ActionEntityEvalTree,
|
|
|
|
|
ENTITY_TYPE,
|
|
|
|
|
JSActionEntityConfig,
|
|
|
|
|
JSActionEvalTree,
|
|
|
|
|
WidgetConfig,
|
|
|
|
|
EvaluationSubstitutionType,
|
|
|
|
|
} from "./types";
|
|
|
|
|
|
|
|
|
|
export interface UnEvalTreeAction extends ActionEntityEvalTree {
|
|
|
|
|
__config__: ActionEntityConfig;
|
2020-02-18 10:41:52 +00:00
|
|
|
}
|
2022-12-02 12:45:11 +00:00
|
|
|
export interface DataTreeAction
|
|
|
|
|
extends ActionEntityEvalTree,
|
|
|
|
|
ActionEntityConfig {}
|
2020-02-18 10:41:52 +00:00
|
|
|
|
2022-12-02 12:45:11 +00:00
|
|
|
export interface UnEvalTreeJSAction extends JSActionEvalTree {
|
|
|
|
|
__config__: JSActionEntityConfig;
|
2021-04-26 05:41:32 +00:00
|
|
|
}
|
|
|
|
|
|
2022-12-02 12:45:11 +00:00
|
|
|
export type DataTreeJSAction = JSActionEvalTree & JSActionEntityConfig;
|
2022-01-20 10:59:03 +00:00
|
|
|
|
2022-12-02 12:45:11 +00:00
|
|
|
export interface WidgetEntityConfig
|
|
|
|
|
extends Partial<WidgetProps>,
|
|
|
|
|
Omit<WidgetConfigProps, "widgetName" | "rows" | "columns">,
|
|
|
|
|
WidgetConfig {
|
|
|
|
|
defaultMetaProps: Array<string>;
|
|
|
|
|
type: string;
|
2020-02-18 10:41:52 +00:00
|
|
|
}
|
|
|
|
|
|
2022-12-02 12:45:11 +00:00
|
|
|
export interface WidgetEvalTree extends WidgetProps {
|
|
|
|
|
meta: Record<string, unknown>;
|
|
|
|
|
ENTITY_TYPE: ENTITY_TYPE.WIDGET;
|
2021-09-08 17:32:22 +00:00
|
|
|
}
|
|
|
|
|
|
2022-12-02 12:45:11 +00:00
|
|
|
export interface UnEvalTreeWidget extends WidgetEvalTree {
|
|
|
|
|
__config__: WidgetEntityConfig;
|
2021-09-08 17:32:22 +00:00
|
|
|
}
|
2022-01-28 11:10:05 +00:00
|
|
|
|
2022-12-02 12:45:11 +00:00
|
|
|
export interface DataTreeWidget extends WidgetEvalTree, WidgetConfig {}
|
2020-02-18 10:41:52 +00:00
|
|
|
|
2021-03-24 05:09:47 +00:00
|
|
|
export interface DataTreeAppsmith extends Omit<AppDataState, "store"> {
|
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>;
|
2022-05-04 09:45:57 +00:00
|
|
|
theme: AppTheme["properties"];
|
2020-08-07 14:24:26 +00:00
|
|
|
}
|
2020-12-30 12:58:57 +00:00
|
|
|
export type DataTreeObjectEntity =
|
2020-02-26 12:44:56 +00:00
|
|
|
| DataTreeAction
|
2021-09-08 17:32:22 +00:00
|
|
|
| DataTreeJSAction
|
2020-02-26 12:44:56 +00:00
|
|
|
| DataTreeWidget
|
2020-12-30 12:58:57 +00:00
|
|
|
| DataTreeAppsmith;
|
|
|
|
|
|
2022-06-21 13:57:34 +00:00
|
|
|
export type DataTreeEntity = DataTreeObjectEntity | Page[] | ActionDispatcher;
|
2020-02-26 12:44:56 +00:00
|
|
|
|
2020-02-18 10:41:52 +00:00
|
|
|
export type DataTree = {
|
2020-02-26 12:44:56 +00:00
|
|
|
[entityName: string]: DataTreeEntity;
|
2021-08-27 09:25:28 +00:00
|
|
|
};
|
2020-02-18 10:41:52 +00:00
|
|
|
|
2022-12-02 12:45:11 +00:00
|
|
|
export type UnEvalTreeEntityObject =
|
|
|
|
|
| UnEvalTreeAction
|
|
|
|
|
| UnEvalTreeJSAction
|
|
|
|
|
| UnEvalTreeWidget;
|
|
|
|
|
|
|
|
|
|
export type UnEvalTreeEntity =
|
|
|
|
|
| UnEvalTreeEntityObject
|
|
|
|
|
| DataTreeAppsmith
|
|
|
|
|
| Page[];
|
|
|
|
|
|
|
|
|
|
export type UnEvalTree = {
|
|
|
|
|
[entityName: string]: UnEvalTreeEntity;
|
|
|
|
|
};
|
|
|
|
|
|
2020-03-19 03:25:52 +00:00
|
|
|
type DataTreeSeed = {
|
|
|
|
|
actions: ActionDataState;
|
2021-03-30 05:29:03 +00:00
|
|
|
editorConfigs: Record<string, any[]>;
|
2021-04-26 05:41:32 +00:00
|
|
|
pluginDependencyConfig: Record<string, DependencyMap>;
|
2020-03-19 03:25:52 +00:00
|
|
|
widgets: CanvasWidgetsReduxState;
|
|
|
|
|
widgetsMeta: MetaState;
|
2022-06-21 13:57:34 +00:00
|
|
|
pageList: Page[];
|
2020-08-14 07:43:01 +00:00
|
|
|
appData: AppDataState;
|
2021-09-08 17:32:22 +00:00
|
|
|
jsActions: JSCollectionDataState;
|
2022-05-04 09:45:57 +00:00
|
|
|
theme: AppTheme["properties"];
|
2020-03-19 03:25:52 +00:00
|
|
|
};
|
|
|
|
|
|
2022-12-02 12:45:11 +00:00
|
|
|
export type DataTreeEntityConfig =
|
|
|
|
|
| WidgetEntityConfig
|
|
|
|
|
| ActionEntityConfig
|
|
|
|
|
| JSActionEntityConfig
|
|
|
|
|
| DataTreeAppsmith;
|
|
|
|
|
|
2020-02-18 10:41:52 +00:00
|
|
|
export class DataTreeFactory {
|
2020-10-21 04:25:32 +00:00
|
|
|
static create({
|
|
|
|
|
actions,
|
|
|
|
|
appData,
|
2021-03-30 05:29:03 +00:00
|
|
|
editorConfigs,
|
2021-09-08 17:32:22 +00:00
|
|
|
jsActions,
|
2021-05-13 08:35:39 +00:00
|
|
|
pageList,
|
2021-04-26 05:41:32 +00:00
|
|
|
pluginDependencyConfig,
|
2022-05-04 09:45:57 +00:00
|
|
|
theme,
|
2021-05-13 08:35:39 +00:00
|
|
|
widgets,
|
|
|
|
|
widgetsMeta,
|
2022-12-02 12:45:11 +00:00
|
|
|
}: DataTreeSeed): UnEvalTree {
|
|
|
|
|
const dataTree: UnEvalTree = {};
|
2022-05-18 05:21:53 +00:00
|
|
|
const start = performance.now();
|
|
|
|
|
const startActions = performance.now();
|
|
|
|
|
|
2020-12-24 04:32:25 +00:00
|
|
|
actions.forEach((action) => {
|
2021-03-30 05:29:03 +00:00
|
|
|
const editorConfig = editorConfigs[action.config.pluginId];
|
2021-04-26 05:41:32 +00:00
|
|
|
const dependencyConfig = pluginDependencyConfig[action.config.pluginId];
|
2021-03-30 05:29:03 +00:00
|
|
|
dataTree[action.config.name] = generateDataTreeAction(
|
|
|
|
|
action,
|
|
|
|
|
editorConfig,
|
2021-04-26 05:41:32 +00:00
|
|
|
dependencyConfig,
|
2020-04-17 16:15:09 +00:00
|
|
|
);
|
2021-03-30 05:29:03 +00:00
|
|
|
});
|
2022-05-18 05:21:53 +00:00
|
|
|
const endActions = performance.now();
|
|
|
|
|
|
|
|
|
|
const startJsActions = performance.now();
|
|
|
|
|
|
2021-09-08 17:32:22 +00:00
|
|
|
jsActions.forEach((js) => {
|
|
|
|
|
dataTree[js.config.name] = generateDataTreeJSAction(js);
|
|
|
|
|
});
|
2022-05-18 05:21:53 +00:00
|
|
|
const endJsActions = performance.now();
|
|
|
|
|
|
|
|
|
|
const startWidgets = performance.now();
|
|
|
|
|
|
2021-03-30 05:29:03 +00:00
|
|
|
Object.values(widgets).forEach((widget) => {
|
|
|
|
|
dataTree[widget.widgetName] = generateDataTreeWidget(
|
2021-02-16 10:29:08 +00:00
|
|
|
widget,
|
2021-03-30 05:29:03 +00:00
|
|
|
widgetsMeta[widget.widgetId],
|
2021-02-16 10:29:08 +00:00
|
|
|
);
|
2020-02-18 10:41:52 +00:00
|
|
|
});
|
2022-05-18 05:21:53 +00:00
|
|
|
const endWidgets = performance.now();
|
2020-06-19 13:06:45 +00:00
|
|
|
|
2020-04-20 05:42:46 +00:00
|
|
|
dataTree.pageList = pageList;
|
2022-12-02 12:45:11 +00:00
|
|
|
|
2021-03-24 05:09:47 +00:00
|
|
|
dataTree.appsmith = {
|
|
|
|
|
...appData,
|
|
|
|
|
// combine both persistent and transient state with the transient state
|
|
|
|
|
// taking precedence in case the key is the same
|
2023-01-10 04:53:08 +00:00
|
|
|
store: appData.store,
|
2022-05-04 09:45:57 +00:00
|
|
|
theme,
|
2021-03-24 05:09:47 +00:00
|
|
|
} as DataTreeAppsmith;
|
2020-10-12 13:06:05 +00:00
|
|
|
(dataTree.appsmith as DataTreeAppsmith).ENTITY_TYPE = ENTITY_TYPE.APPSMITH;
|
2022-05-18 05:21:53 +00:00
|
|
|
const end = performance.now();
|
|
|
|
|
|
|
|
|
|
const out = {
|
|
|
|
|
total: end - start,
|
|
|
|
|
widgets: endWidgets - startWidgets,
|
|
|
|
|
actions: endActions - startActions,
|
|
|
|
|
jsActions: endJsActions - startJsActions,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
log.debug("### Create unevalTree timing", out);
|
|
|
|
|
|
2020-02-18 10:41:52 +00:00
|
|
|
return dataTree;
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-12-02 12:45:11 +00:00
|
|
|
|
|
|
|
|
export { ENTITY_TYPE, EvaluationSubstitutionType };
|