Browse Source

fix: PR requested changes

Signed-off-by: mertmit <mertmit99@gmail.com>
pull/3306/head
mertmit 2 years ago
parent
commit
4a0f7a5764
  1. 44
      packages/nc-gui-v2/pages/index/index/create-external.vue
  2. 37
      packages/nc-gui-v2/utils/projectCreateUtils.ts

44
packages/nc-gui-v2/pages/index/index/create-external.vue

@ -2,6 +2,7 @@
import { Form, Modal, message } from 'ant-design-vue' import { Form, Modal, message } from 'ant-design-vue'
import type { SelectHandler } from 'ant-design-vue/es/vc-select/Select' import type { SelectHandler } from 'ant-design-vue/es/vc-select/Select'
import { import {
certTypes,
clientTypes, clientTypes,
computed, computed,
extractSdkResponseErrorMsg, extractSdkResponseErrorMsg,
@ -46,7 +47,7 @@ let formState = $ref<ProjectCreateForm>({
inflectionColumn: 'camelize', inflectionColumn: 'camelize',
inflectionTable: 'camelize', inflectionTable: 'camelize',
}, },
sslUse: 'No', sslUse: sslUsage.No,
extraParameters: [], extraParameters: [],
}) })
@ -57,7 +58,7 @@ const customFormState = ref<ProjectCreateForm>({
inflectionColumn: 'camelize', inflectionColumn: 'camelize',
inflectionTable: 'camelize', inflectionTable: 'camelize',
}, },
sslUse: 'No', sslUse: sslUsage.No,
extraParameters: [], extraParameters: [],
}) })
@ -102,12 +103,12 @@ const onClientChange = () => {
populateName(formState.title) populateName(formState.title)
} }
const onSSLModeChange = ((mode: 'No' | 'Allow' | string) => { const onSSLModeChange = ((mode: sslUsage) => {
switch (mode) { switch (mode) {
case 'No': case sslUsage.No:
delete formState.dataSource.connection.ssl delete formState.dataSource.connection.ssl
break break
case 'Allowed': case sslUsage.Allowed:
formState.dataSource.connection.ssl = 'true' formState.dataSource.connection.ssl = 'true'
break break
default: default:
@ -118,17 +119,17 @@ const onSSLModeChange = ((mode: 'No' | 'Allow' | string) => {
} }
break break
} }
}) as unknown as SelectHandler }) as SelectHandler
const updateSSLUse = () => { const updateSSLUse = () => {
if (formState?.dataSource?.connection?.ssl) { if (formState.dataSource.connection.ssl) {
if (typeof formState.dataSource.connection.ssl === 'string') { if (typeof formState.dataSource.connection.ssl === 'string') {
formState.sslUse = 'Allowed' formState.sslUse = sslUsage.Allowed
} else { } else {
formState.sslUse = 'Preferred' formState.sslUse = sslUsage.Preferred
} }
} else { } else {
formState.sslUse = 'No' formState.sslUse = sslUsage.No
} }
} }
@ -149,7 +150,7 @@ const caFileInput = ref<HTMLInputElement>()
const keyFileInput = ref<HTMLInputElement>() const keyFileInput = ref<HTMLInputElement>()
const certFileInput = ref<HTMLInputElement>() const certFileInput = ref<HTMLInputElement>()
const onFileSelect = (key: 'ca' | 'cert' | 'key', el?: HTMLInputElement) => { const onFileSelect = (key: certTypes, el?: HTMLInputElement) => {
if (!el) return if (!el) return
readFile(el, (content) => { readFile(el, (content) => {
@ -158,7 +159,9 @@ const onFileSelect = (key: 'ca' | 'cert' | 'key', el?: HTMLInputElement) => {
}) })
} }
const sslFilesRequired = computed(() => !!formState.sslUse && formState.sslUse !== 'No' && formState.sslUse !== 'Allowed') const sslFilesRequired = computed(
() => !!formState.sslUse && formState.sslUse !== sslUsage.No && formState.sslUse !== sslUsage.Allowed,
)
function getConnectionConfig() { function getConnectionConfig() {
const extraParameters = Object.fromEntries(new Map(formState.extraParameters.map((object) => [object.key, object.value]))) const extraParameters = Object.fromEntries(new Map(formState.extraParameters.map((object) => [object.key, object.value])))
@ -169,7 +172,10 @@ function getConnectionConfig() {
} }
if ('ssl' in connection && connection.ssl) { if ('ssl' in connection && connection.ssl) {
if (formState.sslUse === 'No' || (typeof connection.ssl === 'object' && Object.values(connection.ssl).every((v) => !v))) { if (
formState.sslUse === sslUsage.No ||
(typeof connection.ssl === 'object' && Object.values(connection.ssl).every((v) => !v))
) {
delete connection.ssl delete connection.ssl
} }
} }
@ -293,14 +299,14 @@ const handleOk = () => {
// reset test status on config change // reset test status on config change
watch( watch(
() => formState?.dataSource, () => formState.dataSource,
() => (testSuccess.value = false), () => (testSuccess.value = false),
{ deep: true }, { deep: true },
) )
// populate database name based on title // populate database name based on title
watch( watch(
() => formState?.title, () => formState.title,
(v) => populateName(v), (v) => populateName(v),
) )
@ -415,7 +421,7 @@ onMounted(() => {
<!-- todo: add in i18n --> <!-- todo: add in i18n -->
<a-form-item label="SSL mode"> <a-form-item label="SSL mode">
<a-select v-model:value="formState.sslUse" @select="onSSLModeChange"> <a-select v-model:value="formState.sslUse" @select="onSSLModeChange">
<a-select-option v-for="opt in sslUsage" :key="opt" :value="opt">{{ opt }}</a-select-option> <a-select-option v-for="opt in Object.values(sslUsage)" :key="opt" :value="opt">{{ opt }}</a-select-option>
</a-select> </a-select>
</a-form-item> </a-form-item>
@ -455,11 +461,11 @@ onMounted(() => {
</div> </div>
</a-form-item> </a-form-item>
<input ref="caFileInput" type="file" class="!hidden" @change="onFileSelect('ca', caFileInput)" /> <input ref="caFileInput" type="file" class="!hidden" @change="onFileSelect(certTypes.ca, caFileInput)" />
<input ref="certFileInput" type="file" class="!hidden" @change="onFileSelect('cert', certFileInput)" /> <input ref="certFileInput" type="file" class="!hidden" @change="onFileSelect(certTypes.cert, certFileInput)" />
<input ref="keyFileInput" type="file" class="!hidden" @change="onFileSelect('key', keyFileInput)" /> <input ref="keyFileInput" type="file" class="!hidden" @change="onFileSelect(certTypes.key, keyFileInput)" />
<a-divider /> <a-divider />

37
packages/nc-gui-v2/utils/projectCreateUtils.ts

@ -4,30 +4,14 @@ export interface ProjectCreateForm {
title: string title: string
dataSource: { dataSource: {
client: ClientType client: ClientType
connection: connection: Record<string, any>
| {
host: string
database: string
user: string
password: string
port: number | string
ssl?: Record<'ca' | 'cert' | 'key', string> | string
}
| {
client?: ClientType.SQLITE
database: string
connection?: {
filename?: string
}
useNullAsDefault?: boolean
}
searchPath?: string[] searchPath?: string[]
} }
inflection: { inflection: {
inflectionColumn?: string inflectionColumn?: string
inflectionTable?: string inflectionTable?: string
} }
sslUse?: 'No' | 'Allowed' | string sslUse?: sslUsage
extraParameters: Record<string, string>[] extraParameters: Record<string, string>[]
} }
@ -160,4 +144,19 @@ export const getDefaultConnectionConfig = (client: ClientType): ProjectCreateFor
} }
} }
export const sslUsage = ['No', 'Allowed', 'Preferred', 'Required', 'Required-CA', 'Required-IDENTITY'] enum sslUsage {
No = 'No',
Allowed = 'Allowed',
Preferred = 'Preferred',
Required = 'Required',
RequiredWithCa = 'Required-CA',
RequiredWithIdentity = 'Required-Identity',
}
enum certTypes {
ca = 'ca',
cert = 'cert',
key = 'key',
}
export { sslUsage, certTypes }

Loading…
Cancel
Save