2020-02-18 10:41:52 +00:00
|
|
|
import { AppState } from "reducers";
|
2020-05-05 07:50:30 +00:00
|
|
|
import {
|
|
|
|
|
ActionData,
|
2020-07-03 08:58:58 +00:00
|
|
|
ActionDataState,
|
2020-05-05 07:50:30 +00:00
|
|
|
} from "reducers/entityReducers/actionsReducer";
|
2020-01-30 13:23:04 +00:00
|
|
|
import { ActionResponse } from "api/ActionAPI";
|
2020-05-05 07:50:30 +00:00
|
|
|
import { QUERY_CONSTANT } from "constants/QueryEditorConstants";
|
2020-03-19 03:25:52 +00:00
|
|
|
import { createSelector } from "reselect";
|
2021-01-12 04:17:28 +00:00
|
|
|
import { Datasource } from "entities/Datasource";
|
2020-07-03 08:58:58 +00:00
|
|
|
import { Action } from "entities/Action";
|
|
|
|
|
import { find } from "lodash";
|
2020-07-21 10:36:53 +00:00
|
|
|
import ImageAlt from "assets/images/placeholder-image.svg";
|
2020-10-21 04:25:32 +00:00
|
|
|
import { CanvasWidgetsReduxState } from "../reducers/entityReducers/canvasWidgetsReducer";
|
2019-11-14 09:28:51 +00:00
|
|
|
|
2020-02-18 10:41:52 +00:00
|
|
|
export const getEntities = (state: AppState): AppState["entities"] =>
|
|
|
|
|
state.entities;
|
2019-11-29 05:22:49 +00:00
|
|
|
|
2020-12-30 07:31:20 +00:00
|
|
|
export const getDatasources = (state: AppState): Datasource[] => {
|
|
|
|
|
return state.entities.datasources.list;
|
|
|
|
|
};
|
|
|
|
|
|
2020-04-28 06:52:53 +00:00
|
|
|
export const getPluginIdsOfNames = (
|
|
|
|
|
state: AppState,
|
|
|
|
|
names: Array<string>,
|
|
|
|
|
): Array<string> | undefined => {
|
2020-12-24 04:32:25 +00:00
|
|
|
const plugins = state.entities.plugins.list.filter((plugin) =>
|
2020-04-28 06:52:53 +00:00
|
|
|
names.includes(plugin.name),
|
|
|
|
|
);
|
2020-12-24 04:32:25 +00:00
|
|
|
const pluginIds = plugins.map((plugin) => plugin.id);
|
2020-04-28 06:52:53 +00:00
|
|
|
|
|
|
|
|
if (!pluginIds.length) return undefined;
|
|
|
|
|
return pluginIds;
|
|
|
|
|
};
|
|
|
|
|
|
2020-05-05 07:50:30 +00:00
|
|
|
export const getPluginIdsOfPackageNames = (
|
|
|
|
|
state: AppState,
|
|
|
|
|
names: Array<string>,
|
|
|
|
|
): Array<string> | undefined => {
|
2020-12-24 04:32:25 +00:00
|
|
|
const plugins = state.entities.plugins.list.filter((plugin) =>
|
2020-05-05 07:50:30 +00:00
|
|
|
names.includes(plugin.packageName),
|
|
|
|
|
);
|
2020-12-24 04:32:25 +00:00
|
|
|
const pluginIds = plugins.map((plugin) => plugin.id);
|
2020-05-05 07:50:30 +00:00
|
|
|
|
|
|
|
|
if (!pluginIds.length) return undefined;
|
|
|
|
|
return pluginIds;
|
|
|
|
|
};
|
|
|
|
|
|
2020-04-28 06:52:53 +00:00
|
|
|
export const getPluginNameFromDatasourceId = (
|
|
|
|
|
state: AppState,
|
|
|
|
|
datasourceId: string,
|
|
|
|
|
): string | undefined => {
|
|
|
|
|
const datasource = state.entities.datasources.list.find(
|
2020-12-24 04:32:25 +00:00
|
|
|
(datasource) => datasource.id === datasourceId,
|
2020-04-28 06:52:53 +00:00
|
|
|
);
|
|
|
|
|
const plugin = state.entities.plugins.list.find(
|
2020-12-24 04:32:25 +00:00
|
|
|
(plugin) => plugin.id === datasource?.pluginId,
|
2020-04-28 06:52:53 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (!plugin) return undefined;
|
|
|
|
|
return plugin.name;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const getPluginPackageFromId = (state: AppState, pluginId: string) => {
|
|
|
|
|
const plugin = state.entities.plugins.list.find(
|
2020-12-24 04:32:25 +00:00
|
|
|
(plugin) => plugin.id === pluginId,
|
2020-04-28 06:52:53 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (!plugin) return "";
|
|
|
|
|
return plugin.packageName;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const getPluginPackageFromDatasourceId = (
|
|
|
|
|
state: AppState,
|
|
|
|
|
datasourceId: string,
|
|
|
|
|
): string | undefined => {
|
|
|
|
|
const datasource = state.entities.datasources.list.find(
|
2020-12-24 04:32:25 +00:00
|
|
|
(datasource) => datasource.id === datasourceId,
|
2020-04-28 06:52:53 +00:00
|
|
|
);
|
|
|
|
|
const plugin = state.entities.plugins.list.find(
|
2020-12-24 04:32:25 +00:00
|
|
|
(plugin) => plugin.id === datasource?.pluginId,
|
2020-04-28 06:52:53 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (!plugin) return undefined;
|
|
|
|
|
return plugin.packageName;
|
|
|
|
|
};
|
|
|
|
|
|
2020-05-05 07:50:30 +00:00
|
|
|
export const getPluginNameFromId = (state: AppState, pluginId: string) => {
|
|
|
|
|
const plugin = state.entities.plugins.list.find(
|
2020-12-24 04:32:25 +00:00
|
|
|
(plugin) => plugin.id === pluginId,
|
2020-05-05 07:50:30 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (!plugin) return "";
|
|
|
|
|
return plugin.name;
|
|
|
|
|
};
|
|
|
|
|
|
2020-10-12 13:06:05 +00:00
|
|
|
export const getPluginForm = (state: AppState, pluginId: string): any[] => {
|
2020-04-29 09:23:23 +00:00
|
|
|
return state.entities.plugins.formConfigs[pluginId];
|
|
|
|
|
};
|
|
|
|
|
|
2021-02-11 11:47:21 +00:00
|
|
|
export const getEditorConfig = (state: AppState, pluginId: string): any[] => {
|
|
|
|
|
return state.entities.plugins.editorConfigs[pluginId];
|
|
|
|
|
};
|
|
|
|
|
|
2020-01-30 13:23:04 +00:00
|
|
|
export const getActions = (state: AppState): ActionDataState =>
|
|
|
|
|
state.entities.actions;
|
|
|
|
|
|
2020-05-19 06:10:59 +00:00
|
|
|
export const getDatasource = (
|
|
|
|
|
state: AppState,
|
|
|
|
|
datasourceId: string,
|
2020-08-26 05:24:44 +00:00
|
|
|
): Datasource | undefined =>
|
2020-05-19 06:10:59 +00:00
|
|
|
state.entities.datasources.list.find(
|
2020-12-24 04:32:25 +00:00
|
|
|
(datasource) => datasource.id === datasourceId,
|
2020-05-19 06:10:59 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
export const getDatasourceDraft = (state: AppState, id: string) => {
|
|
|
|
|
const drafts = state.ui.datasourcePane.drafts;
|
|
|
|
|
if (id in drafts) return drafts[id];
|
|
|
|
|
return {};
|
|
|
|
|
};
|
|
|
|
|
|
2020-04-28 06:52:53 +00:00
|
|
|
export const getPlugins = (state: AppState) => state.entities.plugins.list;
|
2020-08-12 06:27:35 +00:00
|
|
|
export const getPluginEditorConfigs = (state: AppState) =>
|
|
|
|
|
state.entities.plugins.editorConfigs;
|
2020-05-05 07:50:30 +00:00
|
|
|
|
2020-12-24 04:32:25 +00:00
|
|
|
export const getDBPlugins = createSelector(getPlugins, (plugins) =>
|
|
|
|
|
plugins.filter((plugin) => plugin.type === QUERY_CONSTANT),
|
2020-07-21 12:12:35 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
export const getDBDatasources = createSelector(
|
|
|
|
|
getDBPlugins,
|
|
|
|
|
getEntities,
|
|
|
|
|
(dbPlugins, entities) => {
|
|
|
|
|
const datasources = entities.datasources.list;
|
2020-12-24 04:32:25 +00:00
|
|
|
const dbPluginIds = dbPlugins.map((plugin) => plugin.id);
|
2020-07-21 12:12:35 +00:00
|
|
|
|
2020-12-24 04:32:25 +00:00
|
|
|
return datasources.filter((datasource) =>
|
2020-07-21 12:12:35 +00:00
|
|
|
dbPluginIds.includes(datasource.pluginId),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
|
2020-05-05 07:50:30 +00:00
|
|
|
export const getQueryName = (state: AppState, actionId: string): string => {
|
|
|
|
|
const action = state.entities.actions.find((action: ActionData) => {
|
|
|
|
|
return action.config.id === actionId;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return action?.config.name ?? "";
|
|
|
|
|
};
|
|
|
|
|
|
2020-03-19 03:25:52 +00:00
|
|
|
const getCurrentPageId = (state: AppState) =>
|
|
|
|
|
state.entities.pageList.currentPageId;
|
|
|
|
|
|
2020-12-24 04:32:25 +00:00
|
|
|
export const getDatasourcePlugins = createSelector(getPlugins, (plugins) => {
|
|
|
|
|
return plugins.filter((plugin) => plugin?.allowUserDatasources ?? true);
|
2020-06-03 05:40:48 +00:00
|
|
|
});
|
2020-05-05 09:03:03 +00:00
|
|
|
|
2020-12-24 04:32:25 +00:00
|
|
|
export const getPluginImages = createSelector(getPlugins, (plugins) => {
|
2020-07-21 10:36:53 +00:00
|
|
|
const pluginImages: Record<string, string> = {};
|
|
|
|
|
|
2020-12-24 04:32:25 +00:00
|
|
|
plugins.forEach((plugin) => {
|
2020-07-21 10:36:53 +00:00
|
|
|
pluginImages[plugin.id] = plugin?.iconLocation ?? ImageAlt;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return pluginImages;
|
|
|
|
|
});
|
|
|
|
|
|
2020-12-24 04:32:25 +00:00
|
|
|
export const getPluginTemplates = createSelector(getPlugins, (plugins) => {
|
2020-07-21 10:36:53 +00:00
|
|
|
const pluginTemplates: Record<string, any> = {};
|
|
|
|
|
|
2020-12-24 04:32:25 +00:00
|
|
|
plugins.forEach((plugin) => {
|
2020-07-21 10:36:53 +00:00
|
|
|
pluginTemplates[plugin.id] = plugin.templates;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return pluginTemplates;
|
|
|
|
|
});
|
|
|
|
|
|
2020-12-24 04:32:25 +00:00
|
|
|
export const getPluginResponseTypes = createSelector(getPlugins, (plugins) => {
|
2020-07-21 10:36:53 +00:00
|
|
|
const pluginResponseTypes: Record<string, any> = {};
|
|
|
|
|
|
2020-12-24 04:32:25 +00:00
|
|
|
plugins.forEach((plugin) => {
|
2020-07-21 10:36:53 +00:00
|
|
|
pluginResponseTypes[plugin.id] = plugin.responseType;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return pluginResponseTypes;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export const getPluginDocumentationLinks = createSelector(
|
|
|
|
|
getPlugins,
|
2020-12-24 04:32:25 +00:00
|
|
|
(plugins) => {
|
2020-07-21 10:36:53 +00:00
|
|
|
const pluginDocumentationLinks: Record<string, string | undefined> = {};
|
|
|
|
|
|
2020-12-24 04:32:25 +00:00
|
|
|
plugins.forEach((plugin) => {
|
2020-07-21 10:36:53 +00:00
|
|
|
pluginDocumentationLinks[plugin.id] = plugin.documentationLink;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return pluginDocumentationLinks;
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
|
2020-03-19 03:25:52 +00:00
|
|
|
export const getActionsForCurrentPage = createSelector(
|
|
|
|
|
getCurrentPageId,
|
|
|
|
|
getActions,
|
|
|
|
|
(pageId, actions) => {
|
|
|
|
|
if (!pageId) return [];
|
2020-12-24 04:32:25 +00:00
|
|
|
return actions.filter((a) => a.config.pageId === pageId);
|
2020-03-19 03:25:52 +00:00
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
|
2020-10-20 09:00:02 +00:00
|
|
|
export const getQueryActionsForCurrentPage = createSelector(
|
|
|
|
|
getActionsForCurrentPage,
|
2020-12-24 04:32:25 +00:00
|
|
|
(actions) => {
|
2021-01-12 04:17:28 +00:00
|
|
|
return actions.filter((action) => {
|
2020-10-20 09:00:02 +00:00
|
|
|
return action.config.pluginType === QUERY_CONSTANT;
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
|
2020-10-12 13:37:18 +00:00
|
|
|
export const getPlugin = (state: AppState, pluginId: string) => {
|
2020-12-24 04:32:25 +00:00
|
|
|
return state.entities.plugins.list.find((plugin) => plugin.id === pluginId);
|
2020-10-12 13:37:18 +00:00
|
|
|
};
|
|
|
|
|
|
2020-12-24 04:32:25 +00:00
|
|
|
export const getActionResponses = createSelector(getActions, (actions) => {
|
2020-01-30 13:23:04 +00:00
|
|
|
const responses: Record<string, ActionResponse | undefined> = {};
|
2020-06-03 05:40:48 +00:00
|
|
|
|
2020-12-24 04:32:25 +00:00
|
|
|
actions.forEach((a) => {
|
2020-01-30 13:23:04 +00:00
|
|
|
responses[a.config.id] = a.data;
|
|
|
|
|
});
|
2020-05-05 07:50:30 +00:00
|
|
|
|
2020-01-30 13:23:04 +00:00
|
|
|
return responses;
|
2020-06-03 05:40:48 +00:00
|
|
|
});
|
2020-07-21 10:36:53 +00:00
|
|
|
|
2020-07-03 08:58:58 +00:00
|
|
|
export const getAction = (
|
|
|
|
|
state: AppState,
|
|
|
|
|
actionId: string,
|
|
|
|
|
): Action | undefined => {
|
2020-12-24 04:32:25 +00:00
|
|
|
const action = find(state.entities.actions, (a) => a.config.id === actionId);
|
2020-07-03 08:58:58 +00:00
|
|
|
return action ? action.config : undefined;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export function getCurrentPageNameByActionId(
|
|
|
|
|
state: AppState,
|
|
|
|
|
actionId: string,
|
|
|
|
|
): string {
|
2020-12-24 04:32:25 +00:00
|
|
|
const action = state.entities.actions.find((action) => {
|
2020-07-03 08:58:58 +00:00
|
|
|
return action.config.id === actionId;
|
|
|
|
|
});
|
|
|
|
|
const pageId = action ? action.config.pageId : "";
|
|
|
|
|
return getPageNameByPageId(state, pageId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function getPageNameByPageId(state: AppState, pageId: string): string {
|
|
|
|
|
const page = state.entities.pageList.pages.find(
|
2020-12-24 04:32:25 +00:00
|
|
|
(page) => page.pageId === pageId,
|
2020-07-03 08:58:58 +00:00
|
|
|
);
|
|
|
|
|
return page ? page.pageName : "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const getQueryPaneSavingMap = (state: AppState) => state.ui.queryPane.isSaving;
|
|
|
|
|
const getApiPaneSavingMap = (state: AppState) => state.ui.apiPane.isSaving;
|
|
|
|
|
const getActionDirtyState = (state: AppState) => state.ui.apiPane.isDirty;
|
|
|
|
|
|
|
|
|
|
export const isActionSaving = (id: string) =>
|
|
|
|
|
createSelector(
|
|
|
|
|
[getQueryPaneSavingMap, getApiPaneSavingMap],
|
|
|
|
|
(querySavingMap, apiSavingsMap) => {
|
|
|
|
|
return (
|
|
|
|
|
(id in querySavingMap && querySavingMap[id]) ||
|
|
|
|
|
(id in apiSavingsMap && apiSavingsMap[id])
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
export const isActionDirty = (id: string) =>
|
2020-12-24 04:32:25 +00:00
|
|
|
createSelector([getActionDirtyState], (actionDirtyMap) => {
|
2020-07-03 08:58:58 +00:00
|
|
|
return id in actionDirtyMap && actionDirtyMap[id];
|
|
|
|
|
});
|
2020-08-07 14:24:26 +00:00
|
|
|
|
2020-08-14 07:43:01 +00:00
|
|
|
export const getAppData = (state: AppState) => state.entities.app;
|
2020-10-21 04:25:32 +00:00
|
|
|
|
|
|
|
|
export const getCanvasWidgets = (state: AppState): CanvasWidgetsReduxState =>
|
|
|
|
|
state.entities.canvasWidgets;
|