2019-11-25 05:07:27 +00:00
|
|
|
import { AppState } from "reducers";
|
2020-02-21 12:16:49 +00:00
|
|
|
import { createSelector } from "reselect";
|
2019-11-25 05:07:27 +00:00
|
|
|
import { FlattenedWidgetProps } from "reducers/entityReducers/canvasWidgetsReducer";
|
|
|
|
|
import { WidgetProps } from "widgets/BaseWidget";
|
2020-03-27 09:02:11 +00:00
|
|
|
import _ from "lodash";
|
2019-11-25 05:07:27 +00:00
|
|
|
import { WidgetType } from "constants/WidgetConstants";
|
2020-04-29 10:20:12 +00:00
|
|
|
import { ActionData } from "reducers/entityReducers/actionsReducer";
|
|
|
|
|
import { Page } from "constants/ReduxActionConstants";
|
2020-03-27 09:02:11 +00:00
|
|
|
|
2019-09-19 22:25:37 +00:00
|
|
|
export const getWidgets = (
|
|
|
|
|
state: AppState,
|
|
|
|
|
): { [widgetId: string]: FlattenedWidgetProps } => {
|
|
|
|
|
return state.entities.canvasWidgets;
|
|
|
|
|
};
|
|
|
|
|
|
2020-03-19 03:25:52 +00:00
|
|
|
export const getWidgetsMeta = (state: AppState) => state.entities.meta;
|
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 const getWidgetMetaProps = (state: AppState, widgetId: string) =>
|
|
|
|
|
state.entities.meta[widgetId];
|
2020-03-19 03:25:52 +00:00
|
|
|
|
2019-09-19 22:25:37 +00:00
|
|
|
export const getWidget = (state: AppState, widgetId: string): WidgetProps => {
|
|
|
|
|
return state.entities.canvasWidgets[widgetId];
|
|
|
|
|
};
|
2019-09-22 20:25:05 +00:00
|
|
|
|
2020-03-27 09:02:11 +00:00
|
|
|
export const getWidgetIdsByType = (state: AppState, type: WidgetType) => {
|
|
|
|
|
return Object.values(state.entities.canvasWidgets)
|
|
|
|
|
.filter((widget: FlattenedWidgetProps) => widget.type === type)
|
|
|
|
|
.map((widget: FlattenedWidgetProps) => widget.widgetId);
|
|
|
|
|
};
|
|
|
|
|
|
2019-09-22 20:25:05 +00:00
|
|
|
export const getEditorConfigs = (
|
|
|
|
|
state: AppState,
|
2019-11-22 14:02:55 +00:00
|
|
|
): { pageId: string; layoutId: string } | undefined => {
|
2020-03-19 03:25:52 +00:00
|
|
|
const pageId = state.entities.pageList.currentPageId;
|
|
|
|
|
const layoutId = state.ui.editor.currentLayoutId;
|
|
|
|
|
if (!pageId || !layoutId) return undefined;
|
|
|
|
|
return { pageId, layoutId };
|
2019-09-22 20:25:05 +00:00
|
|
|
};
|
2019-09-25 18:33:56 +00:00
|
|
|
|
2019-10-02 18:13:04 +00:00
|
|
|
export const getDefaultWidgetConfig = (
|
|
|
|
|
state: AppState,
|
|
|
|
|
type: WidgetType,
|
|
|
|
|
): Partial<WidgetProps> => {
|
|
|
|
|
const configs = state.entities.widgetConfig.config;
|
2020-03-27 09:02:11 +00:00
|
|
|
if (configs.hasOwnProperty(type)) {
|
|
|
|
|
const widgetConfig = { ...configs[type] };
|
|
|
|
|
return widgetConfig;
|
|
|
|
|
}
|
|
|
|
|
return {};
|
2019-10-02 18:13:04 +00:00
|
|
|
};
|
2019-10-31 08:36:04 +00:00
|
|
|
|
2020-04-03 09:32:13 +00:00
|
|
|
export const getWidgetNamePrefix = (
|
|
|
|
|
state: AppState,
|
|
|
|
|
type: WidgetType,
|
|
|
|
|
): string => {
|
|
|
|
|
return state.entities.widgetConfig.config[type].widgetName;
|
|
|
|
|
};
|
|
|
|
|
|
2020-10-21 04:25:32 +00:00
|
|
|
export const getDefaultPageId = (state: AppState): string | undefined =>
|
|
|
|
|
state.entities.pageList.defaultPageId;
|
2020-02-21 12:16:49 +00:00
|
|
|
|
|
|
|
|
export const getExistingWidgetNames = createSelector(
|
|
|
|
|
getWidgets,
|
|
|
|
|
(widgets: { [widgetId: string]: FlattenedWidgetProps }) => {
|
|
|
|
|
return Object.values(widgets).map(widget => widget.widgetName);
|
|
|
|
|
},
|
|
|
|
|
);
|
2020-04-29 10:20:12 +00:00
|
|
|
export const getActions = (state: AppState) => {
|
|
|
|
|
return state.entities.actions;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const currentPageId = (state: AppState) => {
|
|
|
|
|
return state.entities.pageList.currentPageId;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const getExistingActionNames = createSelector(
|
|
|
|
|
getActions,
|
|
|
|
|
currentPageId,
|
|
|
|
|
(actions: ActionData[], pageId?: string) => {
|
|
|
|
|
return _.compact(
|
|
|
|
|
actions.map((action: ActionData) => {
|
|
|
|
|
return action.config.pageId === pageId ? action.config.name : undefined;
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
|
2020-11-23 09:27:00 +00:00
|
|
|
/**
|
|
|
|
|
* returns a objects of existing page name in data tree
|
|
|
|
|
*
|
|
|
|
|
* @param state
|
|
|
|
|
*/
|
|
|
|
|
export const getExistingPageNames = (state: AppState) => {
|
|
|
|
|
const map: Record<string, any> = {};
|
|
|
|
|
|
|
|
|
|
state.entities.pageList.pages.map((page: Page) => {
|
|
|
|
|
map[page.pageName] = page.pageName;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return map;
|
|
|
|
|
};
|
2020-03-27 09:02:11 +00:00
|
|
|
|
|
|
|
|
export const getWidgetByName = (
|
|
|
|
|
state: AppState,
|
|
|
|
|
widgetName: string,
|
|
|
|
|
): FlattenedWidgetProps | undefined => {
|
|
|
|
|
const widgets = state.entities.canvasWidgets;
|
|
|
|
|
return _.find(
|
|
|
|
|
Object.values(widgets),
|
|
|
|
|
widget => widget.widgetName === widgetName,
|
|
|
|
|
);
|
|
|
|
|
};
|
2020-04-20 08:26:19 +00:00
|
|
|
|
2020-05-05 12:16:51 +00:00
|
|
|
export const getAllPageIds = (state: AppState) => {
|
|
|
|
|
return state.entities.pageList.pages.map(page => page.pageId);
|
|
|
|
|
};
|
|
|
|
|
|
2020-04-20 08:26:19 +00:00
|
|
|
export const getPluginIdOfPackageName = (
|
|
|
|
|
state: AppState,
|
|
|
|
|
name: string,
|
|
|
|
|
): string | undefined => {
|
|
|
|
|
const plugins = state.entities.plugins.list;
|
|
|
|
|
const plugin = _.find(plugins, { packageName: name });
|
|
|
|
|
if (plugin) return plugin.id;
|
|
|
|
|
return undefined;
|
|
|
|
|
};
|
2020-09-16 10:28:01 +00:00
|
|
|
|
|
|
|
|
export const getSelectedWidget = (state: AppState) => {
|
|
|
|
|
const selectedWidgetId = state.ui.widgetDragResize.selectedWidget;
|
|
|
|
|
if (!selectedWidgetId) return;
|
|
|
|
|
return state.entities.canvasWidgets[selectedWidgetId];
|
|
|
|
|
};
|