+
diff --git a/packages/nc-gui-v2/utils/projectCreateUtils.ts b/packages/nc-gui-v2/utils/projectCreateUtils.ts
index cade101656..10e3cd3d74 100644
--- a/packages/nc-gui-v2/utils/projectCreateUtils.ts
+++ b/packages/nc-gui-v2/utils/projectCreateUtils.ts
@@ -1,43 +1,75 @@
import { adjectives, animals, starWars, uniqueNamesGenerator } from 'unique-names-generator'
-import type { ClientType, ProjectCreateForm } from '~/lib/types'
+import { ClientType } from '~/lib/enums'
+
+export interface ProjectCreateForm {
+ title: string
+ dataSource: {
+ client: ClientType
+ connection:
+ | {
+ host: string
+ database: string
+ user: string
+ password: string
+ port: number | string
+ ssl?: Record
+ searchPath?: string[]
+ }
+ | {
+ client?: ClientType.SQLITE
+ database: string
+ connection?: {
+ filename?: string
+ }
+ useNullAsDefault?: boolean
+ }
+ }
+ inflection: {
+ inflectionColumn?: string
+ inflectionTable?: string
+ }
+ sslUse?: any
+}
+
+const defaultHost = 'localhost'
const testDataBaseNames = {
- mysql2: null,
+ [ClientType.MYSQL]: null,
mysql: null,
- pg: 'postgres',
+ [ClientType.PG]: 'postgres',
oracledb: 'xe',
- mssql: undefined,
- sqlite3: 'a.sqlite',
+ [ClientType.MSSQL]: undefined,
+ [ClientType.SQLITE]: 'a.sqlite',
}
export const getTestDatabaseName = (db: { client: ClientType; connection?: { database?: string } }) => {
- if (db.client === 'pg') return db.connection?.database
+ if (db.client === ClientType.PG) return db.connection?.database
return testDataBaseNames[db.client as keyof typeof testDataBaseNames]
}
export const clientTypes = [
{
text: 'MySql',
- value: 'mysql2',
+ value: ClientType.MYSQL,
},
{
text: 'MSSQL',
- value: 'mssql',
+ value: ClientType.MSSQL,
},
{
text: 'PostgreSQL',
- value: 'pg',
+ value: ClientType.PG,
},
{
text: 'SQLite',
- value: 'sqlite3',
+ value: ClientType.SQLITE,
},
]
const homeDir = ''
const sampleConnectionData: Record = {
- pg: {
- host: 'localhost',
+ [ClientType.PG]: {
+ host: defaultHost,
port: '5432',
user: 'postgres',
password: 'password',
@@ -49,8 +81,8 @@ const sampleConnectionData: Record {
diff --git a/packages/nc-gui-v2/utils/validation.ts b/packages/nc-gui-v2/utils/validation.ts
index 3ccb30db73..4b83ce57aa 100644
--- a/packages/nc-gui-v2/utils/validation.ts
+++ b/packages/nc-gui-v2/utils/validation.ts
@@ -78,11 +78,17 @@ export const projectTitleValidator = {
callback()
},
}
+
export const fieldRequiredValidator = {
required: true,
message: 'Field is required',
}
+export const getRequiredValidator = (field = 'Field') => ({
+ required: true,
+ message: `${field} is required`,
+})
+
export const importUrlValidator = {
validator: (rule: any, value: any, callback: (errMsg?: string) => void) => {
if (