diff --git a/app/client/src/ce/entities/FeatureFlag.ts b/app/client/src/ce/entities/FeatureFlag.ts index 6eb7debe96..07e99b7448 100644 --- a/app/client/src/ce/entities/FeatureFlag.ts +++ b/app/client/src/ce/entities/FeatureFlag.ts @@ -25,6 +25,7 @@ export const FEATURE_FLAG = { release_git_connect_v2_enabled: "release_git_connect_v2_enabled", deprecate_custom_fusioncharts_enabled: "deprecate_custom_fusioncharts_enabled", + ab_mock_mongo_schema_enabled: "ab_mock_mongo_schema_enabled", } as const; export type FeatureFlag = keyof typeof FEATURE_FLAG; @@ -52,6 +53,7 @@ export const DEFAULT_FEATURE_FLAG_VALUE: FeatureFlags = { license_sso_oidc_enabled: false, release_git_connect_v2_enabled: false, deprecate_custom_fusioncharts_enabled: false, + ab_mock_mongo_schema_enabled: false, }; export const AB_TESTING_EVENT_KEYS = { diff --git a/app/client/src/entities/Datasource/index.ts b/app/client/src/entities/Datasource/index.ts index 36fb15a98b..b9ca51279e 100644 --- a/app/client/src/entities/Datasource/index.ts +++ b/app/client/src/entities/Datasource/index.ts @@ -78,6 +78,7 @@ export interface QueryTemplate { title: string; body: string; pluginSpecifiedTemplates?: Array<{ key?: string; value?: unknown }>; + suggested: boolean; } export interface DatasourceTable { type: string; diff --git a/app/client/src/pages/Editor/DataSourceEditor/DatasourceViewModeSchema.tsx b/app/client/src/pages/Editor/DataSourceEditor/DatasourceViewModeSchema.tsx index cb0dfd72a7..a010323a59 100644 --- a/app/client/src/pages/Editor/DataSourceEditor/DatasourceViewModeSchema.tsx +++ b/app/client/src/pages/Editor/DataSourceEditor/DatasourceViewModeSchema.tsx @@ -31,7 +31,11 @@ import { } from "selectors/editorSelectors"; import { GENERATE_PAGE_MODE } from "../GeneratePage/components/GeneratePageForm/GeneratePageForm"; 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 { hasCreateDatasourceActionPermission, @@ -153,13 +157,24 @@ const DatasourceViewModeSchema = (props: Props) => { datasourceStructure && datasourceStructure.tables ) { - const templates = datasourceStructure.tables.find( - (structure: DatasourceTable) => structure.name === tableName, - )?.templates; + const templates: QueryTemplate[] | undefined = + datasourceStructure.tables.find( + (structure: DatasourceTable) => structure.name === tableName, + )?.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({ datasourceId: props.datasourceId, - template: templates[0], + template: suggestedTemPlate, }); } } diff --git a/app/client/src/pages/Editor/DataSourceEditor/index.tsx b/app/client/src/pages/Editor/DataSourceEditor/index.tsx index 13552b04c1..352d49a4dd 100644 --- a/app/client/src/pages/Editor/DataSourceEditor/index.tsx +++ b/app/client/src/pages/Editor/DataSourceEditor/index.tsx @@ -88,7 +88,7 @@ import type { ApiDatasourceForm } from "entities/Datasource/RestAPIForm"; import { formValuesToDatasource } from "transformers/RestAPIDatasourceFormTransformer"; import { DSFormHeader } from "./DSFormHeader"; import type { PluginType } from "entities/Action"; -import { PluginPackageName } from "entities/Action"; +import { PluginName, PluginPackageName } from "entities/Action"; import DSDataFilter from "@appsmith/components/DSDataFilter"; import { DEFAULT_ENV_ID } from "@appsmith/api/ApiUtils"; import { isStorageEnvironmentCreated } from "@appsmith/utils/Environments"; @@ -1072,14 +1072,23 @@ const mapStateToProps = (state: AppState, props: any): ReduxStateProps => { const featureFlags = selectFeatureFlags(state); // A/B feature flag for datasource view mode preview data. - const isEnabledForDSViewModeSchema = selectFeatureFlagCheck( + let isEnabledForDSViewModeSchema = selectFeatureFlagCheck( state, 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 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 { canCreateDatasourceActions,