feat: Add preview data for mongo mock db (#27031)

This PR introduces Preview data feature for Mock MongoDB Datasources.
This commit is contained in:
Ayangade Adeoluwa 2023-09-13 11:05:45 +01:00 committed by GitHub
parent 4f20df633a
commit d1de037ea4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 35 additions and 8 deletions

View File

@ -25,6 +25,7 @@ export const FEATURE_FLAG = {
release_git_connect_v2_enabled: "release_git_connect_v2_enabled", release_git_connect_v2_enabled: "release_git_connect_v2_enabled",
deprecate_custom_fusioncharts_enabled: deprecate_custom_fusioncharts_enabled:
"deprecate_custom_fusioncharts_enabled", "deprecate_custom_fusioncharts_enabled",
ab_mock_mongo_schema_enabled: "ab_mock_mongo_schema_enabled",
} as const; } as const;
export type FeatureFlag = keyof typeof FEATURE_FLAG; export type FeatureFlag = keyof typeof FEATURE_FLAG;
@ -52,6 +53,7 @@ export const DEFAULT_FEATURE_FLAG_VALUE: FeatureFlags = {
license_sso_oidc_enabled: false, license_sso_oidc_enabled: false,
release_git_connect_v2_enabled: false, release_git_connect_v2_enabled: false,
deprecate_custom_fusioncharts_enabled: false, deprecate_custom_fusioncharts_enabled: false,
ab_mock_mongo_schema_enabled: false,
}; };
export const AB_TESTING_EVENT_KEYS = { export const AB_TESTING_EVENT_KEYS = {

View File

@ -78,6 +78,7 @@ export interface QueryTemplate {
title: string; title: string;
body: string; body: string;
pluginSpecifiedTemplates?: Array<{ key?: string; value?: unknown }>; pluginSpecifiedTemplates?: Array<{ key?: string; value?: unknown }>;
suggested: boolean;
} }
export interface DatasourceTable { export interface DatasourceTable {
type: string; type: string;

View File

@ -31,7 +31,11 @@ import {
} from "selectors/editorSelectors"; } from "selectors/editorSelectors";
import { GENERATE_PAGE_MODE } from "../GeneratePage/components/GeneratePageForm/GeneratePageForm"; import { GENERATE_PAGE_MODE } from "../GeneratePage/components/GeneratePageForm/GeneratePageForm";
import { useDatasourceQuery } from "./hooks"; import { useDatasourceQuery } from "./hooks";
import type { Datasource, DatasourceTable } from "entities/Datasource"; import type {
Datasource,
DatasourceTable,
QueryTemplate,
} from "entities/Datasource";
import { getCurrentApplication } from "@appsmith/selectors/applicationSelectors"; import { getCurrentApplication } from "@appsmith/selectors/applicationSelectors";
import { import {
hasCreateDatasourceActionPermission, hasCreateDatasourceActionPermission,
@ -153,13 +157,24 @@ const DatasourceViewModeSchema = (props: Props) => {
datasourceStructure && datasourceStructure &&
datasourceStructure.tables datasourceStructure.tables
) { ) {
const templates = datasourceStructure.tables.find( const templates: QueryTemplate[] | undefined =
(structure: DatasourceTable) => structure.name === tableName, datasourceStructure.tables.find(
)?.templates; (structure: DatasourceTable) => structure.name === tableName,
)?.templates;
if (templates) { if (templates) {
let suggestedTemPlate: QueryTemplate | undefined = templates?.find(
(template) => template.suggested,
);
// if no suggested template exists, default to first template.
if (!suggestedTemPlate) {
suggestedTemPlate = templates[0];
}
fetchPreviewData({ fetchPreviewData({
datasourceId: props.datasourceId, datasourceId: props.datasourceId,
template: templates[0], template: suggestedTemPlate,
}); });
} }
} }

View File

@ -88,7 +88,7 @@ import type { ApiDatasourceForm } from "entities/Datasource/RestAPIForm";
import { formValuesToDatasource } from "transformers/RestAPIDatasourceFormTransformer"; import { formValuesToDatasource } from "transformers/RestAPIDatasourceFormTransformer";
import { DSFormHeader } from "./DSFormHeader"; import { DSFormHeader } from "./DSFormHeader";
import type { PluginType } from "entities/Action"; import type { PluginType } from "entities/Action";
import { PluginPackageName } from "entities/Action"; import { PluginName, PluginPackageName } from "entities/Action";
import DSDataFilter from "@appsmith/components/DSDataFilter"; import DSDataFilter from "@appsmith/components/DSDataFilter";
import { DEFAULT_ENV_ID } from "@appsmith/api/ApiUtils"; import { DEFAULT_ENV_ID } from "@appsmith/api/ApiUtils";
import { isStorageEnvironmentCreated } from "@appsmith/utils/Environments"; import { isStorageEnvironmentCreated } from "@appsmith/utils/Environments";
@ -1072,14 +1072,23 @@ const mapStateToProps = (state: AppState, props: any): ReduxStateProps => {
const featureFlags = selectFeatureFlags(state); const featureFlags = selectFeatureFlags(state);
// A/B feature flag for datasource view mode preview data. // A/B feature flag for datasource view mode preview data.
const isEnabledForDSViewModeSchema = selectFeatureFlagCheck( let isEnabledForDSViewModeSchema = selectFeatureFlagCheck(
state, state,
FEATURE_FLAG.ab_gsheet_schema_enabled, FEATURE_FLAG.ab_gsheet_schema_enabled,
); );
// for mongoDB, the feature flag should be based on ab_mock_mongo_schema_enabled.
if (plugin?.name === PluginName.MONGO) {
isEnabledForDSViewModeSchema = selectFeatureFlagCheck(
state,
FEATURE_FLAG.ab_mock_mongo_schema_enabled,
);
}
// should plugin be able to preview data // should plugin be able to preview data
const isPluginAllowedToPreviewData = const isPluginAllowedToPreviewData =
DATASOURCES_ALLOWED_FOR_PREVIEW_MODE.includes(plugin?.name || ""); DATASOURCES_ALLOWED_FOR_PREVIEW_MODE.includes(plugin?.name || "") ||
(plugin?.name === PluginName.MONGO && !!(datasource as Datasource)?.isMock);
return { return {
canCreateDatasourceActions, canCreateDatasourceActions,