diff --git a/packages/nc-gui/components/dashboard/settings/data-sources/CreateBase.vue b/packages/nc-gui/components/dashboard/settings/data-sources/CreateBase.vue index 9fe262966e..7bc8a9597f 100644 --- a/packages/nc-gui/components/dashboard/settings/data-sources/CreateBase.vue +++ b/packages/nc-gui/components/dashboard/settings/data-sources/CreateBase.vue @@ -8,7 +8,7 @@ import { DefaultConnection, SQLiteConnection, SSLUsage, - clientTypes, + clientTypes as _clientTypes, computed, extractSdkResponseErrorMsg, fieldRequiredValidator, @@ -21,6 +21,7 @@ import { readFile, ref, useApi, + useGlobal, useI18n, useNuxtApp, watch, @@ -30,6 +31,8 @@ const { connectionType } = defineProps<{ connectionType: ClientType }>() const emit = defineEmits(['baseCreated']) +const { appInfo } = useGlobal() + const { project, loadProject } = useProject() const useForm = Form.useForm @@ -68,42 +71,54 @@ const customFormState = ref({ extraParameters: [], }) +const clientTypes = computed(() => { + return _clientTypes.filter((type) => { + return appInfo.value?.ee || type.value !== ClientType.SNOWFLAKE + }) +}) + const validators = computed(() => { + let clientValidations: Record = { + 'dataSource.connection.host': [fieldRequiredValidator()], + 'dataSource.connection.port': [fieldRequiredValidator()], + 'dataSource.connection.user': [fieldRequiredValidator()], + 'dataSource.connection.password': [fieldRequiredValidator()], + 'dataSource.connection.database': [fieldRequiredValidator()], + } + + switch (formState.dataSource.client) { + case ClientType.SQLITE: + clientValidations = { + 'dataSource.connection.connection.filename': [fieldRequiredValidator()], + } + break + case ClientType.SNOWFLAKE: + clientValidations = { + 'dataSource.connection.account': [fieldRequiredValidator()], + 'dataSource.connection.username': [fieldRequiredValidator()], + 'dataSource.connection.password': [fieldRequiredValidator()], + 'dataSource.connection.warehouse': [fieldRequiredValidator()], + 'dataSource.connection.database': [fieldRequiredValidator()], + 'dataSource.connection.schema': [fieldRequiredValidator()], + } + break + case ClientType.PG: + case ClientType.MSSQL: + clientValidations['dataSource.searchPath.0'] = [fieldRequiredValidator()] + break + } + return { 'title': [ { required: true, - message: 'Base name is required', + message: 'Project name is required', }, projectTitleValidator, ], 'extraParameters': [extraParameterValidator], 'dataSource.client': [fieldRequiredValidator()], - ...(formState.dataSource.client === ClientType.SQLITE - ? { - 'dataSource.connection.connection.filename': [fieldRequiredValidator()], - } - : formState.dataSource.client === ClientType.SNOWFLAKE - ? { - 'dataSource.connection.account': [fieldRequiredValidator()], - 'dataSource.connection.username': [fieldRequiredValidator()], - 'dataSource.connection.password': [fieldRequiredValidator()], - 'dataSource.connection.warehouse': [fieldRequiredValidator()], - 'dataSource.connection.database': [fieldRequiredValidator()], - 'dataSource.connection.schema': [fieldRequiredValidator()], - } - : { - 'dataSource.connection.host': [fieldRequiredValidator()], - 'dataSource.connection.port': [fieldRequiredValidator()], - 'dataSource.connection.user': [fieldRequiredValidator()], - 'dataSource.connection.password': [fieldRequiredValidator()], - 'dataSource.connection.database': [fieldRequiredValidator()], - ...([ClientType.PG, ClientType.MSSQL].includes(formState.dataSource.client) - ? { - 'dataSource.searchPath.0': [fieldRequiredValidator()], - } - : {}), - }), + ...clientValidations, } })