Browse Source

refactor(gui-v2): corrections and improvements

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/2730/head
Pranav C 2 years ago
parent
commit
24f5d57fdb
  1. 0
      packages/nc-gui-v2/components/monaco/Editor.vue
  2. 12
      packages/nc-gui-v2/lib/types.ts
  3. 2
      packages/nc-gui-v2/pages/project/index/[id].vue
  4. 34
      packages/nc-gui-v2/pages/project/index/create-external.vue
  5. 2
      packages/nc-gui-v2/pages/project/index/create.vue
  6. 1
      packages/nc-gui-v2/pages/projects/index.vue
  7. 17
      packages/nc-gui-v2/utils/projectCreateUtils.ts
  8. 17
      packages/nc-gui-v2/utils/validation.ts

0
packages/nc-gui-v2/components/monaco/index.vue → packages/nc-gui-v2/components/monaco/Editor.vue

12
packages/nc-gui-v2/lib/types.ts

@ -33,7 +33,13 @@ export type ReadonlyState = Readonly<Pick<State, 'token' | 'user'>> & Omit<State
export type GlobalState = Getters & Actions & ToRefs<ReadonlyState> export type GlobalState = Getters & Actions & ToRefs<ReadonlyState>
export type ClientType = 'mysql2' | 'mssql' | 'pg' | 'sqlite3' | 'vitess' export enum ClientType {
MYSQL = 'mysql2',
MSSQL = 'mssql',
PG = 'pg',
SQLITE = 'sqlite3',
VITESS = 'vitess',
}
export interface ProjectCreateForm { export interface ProjectCreateForm {
title: string title: string
@ -59,8 +65,8 @@ export interface ProjectCreateForm {
} }
} }
inflection: { inflection: {
inflection_column?: string inflectionColumn?: string
inflection_table?: string inflectionTable?: string
} }
sslUse?: any sslUse?: any
} }

2
packages/nc-gui-v2/pages/project/index/[id].vue

@ -6,7 +6,7 @@ import { ref } from 'vue'
import { useToast } from 'vue-toastification' import { useToast } from 'vue-toastification'
import { navigateTo, useNuxtApp, useRoute } from '#app' import { navigateTo, useNuxtApp, useRoute } from '#app'
import { extractSdkResponseErrorMsg } from '~/utils/errorUtils' import { extractSdkResponseErrorMsg } from '~/utils/errorUtils'
import { projectTitleValidator } from '~/utils/projectCreateUtils' import { projectTitleValidator } from '~/utils/validation'
import MaterialSymbolsRocketLaunchOutline from '~icons/material-symbols/rocket-launch-outline' import MaterialSymbolsRocketLaunchOutline from '~icons/material-symbols/rocket-launch-outline'
const loading = ref(false) const loading = ref(false)

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

@ -1,22 +1,22 @@
<script lang="ts" setup> <script lang="ts" setup>
import { onMounted } from '@vue/runtime-core' import { onMounted } from '@vue/runtime-core'
import { Form, Modal } from 'ant-design-vue'
import { useI18n } from 'vue-i18n' import { useI18n } from 'vue-i18n'
import { useToast } from 'vue-toastification' import { useToast } from 'vue-toastification'
import { Form, Modal } from 'ant-design-vue'
import { ref } from '#imports' import { ref } from '#imports'
import { navigateTo, useNuxtApp } from '#app' import { navigateTo, useNuxtApp } from '#app'
import type { ProjectCreateForm } from '~/lib/types' import type { ProjectCreateForm } from '~/lib/types'
import { ClientType } from '~/lib/types'
import { extractSdkResponseErrorMsg } from '~/utils/errorUtils' import { extractSdkResponseErrorMsg } from '~/utils/errorUtils'
import { readFile } from '~/utils/fileUtils'
import { import {
clientTypes, clientTypes,
fieldRequiredValidator,
generateUniqueName, generateUniqueName,
getDefaultConnectionConfig, getDefaultConnectionConfig,
getTestDatabaseName, getTestDatabaseName,
projectTitleValidator,
sslUsage, sslUsage,
} from '~/utils/projectCreateUtils' } from '~/utils/projectCreateUtils'
import { readFile } from '~/utils/fileUtils' import { fieldRequiredValidator, projectTitleValidator } from '~/utils/validation'
const useForm = Form.useForm const useForm = Form.useForm
const loading = ref(false) const loading = ref(false)
@ -28,10 +28,10 @@ const { t } = useI18n()
const formState = $ref<ProjectCreateForm>({ const formState = $ref<ProjectCreateForm>({
title: '', title: '',
dataSource: { ...getDefaultConnectionConfig('mysql2') }, dataSource: { ...getDefaultConnectionConfig(ClientType.MYSQL) },
inflection: { inflection: {
inflection_column: 'camelize', inflectionColumn: 'camelize',
inflection_table: 'camelize', inflectionTable: 'camelize',
}, },
sslUse: 'No', sslUse: 'No',
}) })
@ -46,7 +46,7 @@ const validators = computed(() => {
projectTitleValidator, projectTitleValidator,
], ],
'dataSource.client': [fieldRequiredValidator], 'dataSource.client': [fieldRequiredValidator],
...(formState.dataSource.client === 'sqlite3' ...(formState.dataSource.client === ClientType.SQLITE
? { ? {
'dataSource.connection.connection.filename': [fieldRequiredValidator], 'dataSource.connection.connection.filename': [fieldRequiredValidator],
} }
@ -56,7 +56,7 @@ const validators = computed(() => {
'dataSource.connection.user': [fieldRequiredValidator], 'dataSource.connection.user': [fieldRequiredValidator],
'dataSource.connection.password': [fieldRequiredValidator], 'dataSource.connection.password': [fieldRequiredValidator],
'dataSource.connection.database': [fieldRequiredValidator], 'dataSource.connection.database': [fieldRequiredValidator],
...(['pg', 'mssql'].includes(formState.dataSource.client) ...([ClientType.PG, ClientType.MSSQL].includes(formState.dataSource.client)
? { ? {
'dataSource.connection.searchPath.0': [fieldRequiredValidator], 'dataSource.connection.searchPath.0': [fieldRequiredValidator],
} }
@ -131,8 +131,8 @@ const createProject = async () => {
{ {
type: formState.dataSource.client, type: formState.dataSource.client,
config, config,
inflection_column: formState.inflection.inflection_column, inflection_column: formState.inflection.inflectionColumn,
inflection_table: formState.inflection.inflection_table, inflection_table: formState.inflection.inflectionTable,
}, },
], ],
external: true, external: true,
@ -155,7 +155,7 @@ const testConnection = async () => {
} }
$e('a:project:create:extdb:test-connection', []) $e('a:project:create:extdb:test-connection', [])
try { try {
if (formState.dataSource.client === 'sqlite3') { if (formState.dataSource.client === ClientType.SQLITE) {
testSuccess.value = true testSuccess.value = true
} else { } else {
const connection: any = getConnectionConfig() const connection: any = getConnectionConfig()
@ -242,7 +242,7 @@ onMounted(() => {
<!-- SQLite File --> <!-- SQLite File -->
<a-form-item <a-form-item
v-if="formState.dataSource.client === 'sqlite3'" v-if="formState.dataSource.client === ClientType.SQLITE"
:label="$t('labels.sqliteFile')" :label="$t('labels.sqliteFile')"
v-bind="validateInfos['dataSource.connection.connection.filename']" v-bind="validateInfos['dataSource.connection.connection.filename']"
> >
@ -286,7 +286,7 @@ onMounted(() => {
</a-form-item> </a-form-item>
<!-- Schema name --> <!-- Schema name -->
<a-form-item <a-form-item
v-if="['mssql', 'pg'].includes(formState.dataSource.client)" v-if="[ClientType.MSSQL, ClientType.PG].includes(formState.dataSource.client)"
:label="$t('labels.schemaName')" :label="$t('labels.schemaName')"
v-bind="validateInfos['dataSource.connection.searchPath.0']" v-bind="validateInfos['dataSource.connection.searchPath.0']"
> >
@ -339,12 +339,12 @@ onMounted(() => {
<input ref="keyFileInput" type="file" class="!hidden" @change="onFileSelect('key', keyFileInput)" /> <input ref="keyFileInput" type="file" class="!hidden" @change="onFileSelect('key', keyFileInput)" />
<a-form-item :label="$t('labels.inflection.tableName')"> <a-form-item :label="$t('labels.inflection.tableName')">
<a-select v-model:value="formState.inflection.inflection_table" size="small" @change="onClientChange"> <a-select v-model:value="formState.inflection.inflectionTable" size="small" @change="onClientChange">
<a-select-option v-for="type in inflectionTypes" :key="type" :value="type">{{ type }}</a-select-option> <a-select-option v-for="type in inflectionTypes" :key="type" :value="type">{{ type }}</a-select-option>
</a-select> </a-select>
</a-form-item> </a-form-item>
<a-form-item :label="$t('labels.inflection.columnName')"> <a-form-item :label="$t('labels.inflection.columnName')">
<a-select v-model:value="formState.inflection.inflection_column" size="small" @change="onClientChange"> <a-select v-model:value="formState.inflection.inflectionColumn" size="small" @change="onClientChange">
<a-select-option v-for="type in inflectionTypes" :key="type" :value="type">{{ type }}</a-select-option> <a-select-option v-for="type in inflectionTypes" :key="type" :value="type">{{ type }}</a-select-option>
</a-select> </a-select>
</a-form-item> </a-form-item>
@ -370,7 +370,7 @@ onMounted(() => {
<v-dialog v-model="configEditDlg"> <v-dialog v-model="configEditDlg">
<a-card> <a-card>
<Monaco v-if="configEditDlg" v-model="formState" class="h-[400px] w-[600px]"></Monaco> <MonacoEditor v-if="configEditDlg" v-model="formState" class="h-[400px] w-[600px]" />
</a-card> </a-card>
</v-dialog> </v-dialog>
</a-card> </a-card>

2
packages/nc-gui-v2/pages/project/index/create.vue

@ -5,7 +5,7 @@ import { useToast } from 'vue-toastification'
import { nextTick, ref } from '#imports' import { nextTick, ref } from '#imports'
import { navigateTo, useNuxtApp } from '#app' import { navigateTo, useNuxtApp } from '#app'
import { extractSdkResponseErrorMsg } from '~/utils/errorUtils' import { extractSdkResponseErrorMsg } from '~/utils/errorUtils'
import { projectTitleValidator } from '~/utils/projectCreateUtils' import { projectTitleValidator } from '~/utils/validation'
import MaterialSymbolsRocketLaunchOutline from '~icons/material-symbols/rocket-launch-outline' import MaterialSymbolsRocketLaunchOutline from '~icons/material-symbols/rocket-launch-outline'
const name = ref('') const name = ref('')

1
packages/nc-gui-v2/pages/projects/index.vue

@ -59,7 +59,6 @@ const deleteProject = (project: ProjectType) => {
}) })
} }
console.log(route.name)
const visible = ref(true) const visible = ref(true)
</script> </script>

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

@ -175,23 +175,6 @@ export const getDefaultConnectionConfig = (client: ClientType): ProjectCreateFor
} }
} }
export const projectTitleValidator = {
validator: (rule: any, value: any, callback: (errMsg?: string) => void) => {
if (value?.length > 50) {
callback('Project name exceeds 50 characters')
}
if (value[0] === ' ') {
callback('Project name cannot start with space')
}
callback()
},
}
export const fieldRequiredValidator = {
required: true,
message: 'Field is required',
}
export const sslUsage = ['No', 'Preferred', 'Required', 'Required-CA', 'Required-IDENTITY'] export const sslUsage = ['No', 'Preferred', 'Required', 'Required-CA', 'Required-IDENTITY']
export const generateUniqueName = () => { export const generateUniqueName = () => {

17
packages/nc-gui-v2/utils/validation.ts

@ -65,3 +65,20 @@ export function validateColumnName(v: string, isGQL = false) {
return true return true
} }
} }
export const projectTitleValidator = {
validator: (rule: any, value: any, callback: (errMsg?: string) => void) => {
if (value?.length > 50) {
callback('Project name exceeds 50 characters')
}
if (value[0] === ' ') {
callback('Project name cannot start with space')
}
callback()
},
}
export const fieldRequiredValidator = {
required: true,
message: 'Field is required',
}

Loading…
Cancel
Save