nextjs-chatbot-ui 1.1.2 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/AdminSetup.tsx +18 -5
- package/package.json +2 -1
- package/types/admin.ts +6 -0
- package/utils/connectionHelpers.ts +40 -0
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import React, { useState } from 'react';
|
|
4
4
|
import { DatabaseType, DatabaseConnection, ColumnSelection, DatabaseConfig, AdminSetupProps } from '../types/admin';
|
|
5
|
+
import { normalizeConnection, transformConnectionForBackend } from '../utils/connectionHelpers';
|
|
5
6
|
import clsx from 'clsx';
|
|
6
7
|
|
|
7
8
|
const AdminSetup: React.FC<AdminSetupProps> = ({
|
|
@@ -59,11 +60,17 @@ const AdminSetup: React.FC<AdminSetupProps> = ({
|
|
|
59
60
|
setConnectionSuccess(false);
|
|
60
61
|
|
|
61
62
|
try {
|
|
63
|
+
// Ensure default ports are set
|
|
64
|
+
const normalizedConnection = normalizeConnection(connection, dbType);
|
|
65
|
+
|
|
66
|
+
// Transform to backend format
|
|
67
|
+
const backendRequest = transformConnectionForBackend(connection, dbType);
|
|
68
|
+
|
|
62
69
|
let isValid: boolean;
|
|
63
70
|
|
|
64
71
|
if (onTestConnection) {
|
|
65
|
-
// Use provided handler
|
|
66
|
-
isValid = await onTestConnection(
|
|
72
|
+
// Use provided handler - send normalized connection
|
|
73
|
+
isValid = await onTestConnection(normalizedConnection);
|
|
67
74
|
} else {
|
|
68
75
|
// Default: Try to call backend API
|
|
69
76
|
try {
|
|
@@ -72,7 +79,7 @@ const AdminSetup: React.FC<AdminSetupProps> = ({
|
|
|
72
79
|
headers: {
|
|
73
80
|
'Content-Type': 'application/json',
|
|
74
81
|
},
|
|
75
|
-
body: JSON.stringify(
|
|
82
|
+
body: JSON.stringify(backendRequest), // Send transformed format
|
|
76
83
|
});
|
|
77
84
|
|
|
78
85
|
if (!response.ok) {
|
|
@@ -118,11 +125,17 @@ const AdminSetup: React.FC<AdminSetupProps> = ({
|
|
|
118
125
|
setConnectionError(null);
|
|
119
126
|
|
|
120
127
|
try {
|
|
128
|
+
// Ensure default ports are set
|
|
129
|
+
const normalizedConnection = normalizeConnection(connection, dbType);
|
|
130
|
+
|
|
131
|
+
// Transform to backend format
|
|
132
|
+
const backendRequest = transformConnectionForBackend(connection, dbType);
|
|
133
|
+
|
|
121
134
|
let columns: string[];
|
|
122
135
|
|
|
123
136
|
if (onFetchColumns) {
|
|
124
137
|
// Use provided handler
|
|
125
|
-
columns = await onFetchColumns(
|
|
138
|
+
columns = await onFetchColumns(normalizedConnection);
|
|
126
139
|
} else {
|
|
127
140
|
// Default: Try to call backend API
|
|
128
141
|
try {
|
|
@@ -131,7 +144,7 @@ const AdminSetup: React.FC<AdminSetupProps> = ({
|
|
|
131
144
|
headers: {
|
|
132
145
|
'Content-Type': 'application/json',
|
|
133
146
|
},
|
|
134
|
-
body: JSON.stringify(
|
|
147
|
+
body: JSON.stringify(backendRequest), // Send transformed format
|
|
135
148
|
});
|
|
136
149
|
|
|
137
150
|
if (!response.ok) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nextjs-chatbot-ui",
|
|
3
3
|
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.2.0",
|
|
5
5
|
"description": "A configurable chatbot UI component for Next.js with Tailwind CSS",
|
|
6
6
|
"main": "./index.tsx",
|
|
7
7
|
"module": "./index.tsx",
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
"files": [
|
|
30
30
|
"components",
|
|
31
31
|
"types",
|
|
32
|
+
"utils",
|
|
32
33
|
"index.tsx",
|
|
33
34
|
"README.md"
|
|
34
35
|
],
|
package/types/admin.ts
CHANGED
|
@@ -27,3 +27,9 @@ export interface AdminSetupProps {
|
|
|
27
27
|
onTestConnection?: (connection: DatabaseConnection) => Promise<boolean>;
|
|
28
28
|
onFetchColumns?: (connection: DatabaseConnection) => Promise<string[]>;
|
|
29
29
|
}
|
|
30
|
+
|
|
31
|
+
// Backend request format
|
|
32
|
+
export interface BackendConnectionRequest {
|
|
33
|
+
databaseType: 'mongodb' | 'postgresql';
|
|
34
|
+
connection: Omit<DatabaseConnection, 'type'>;
|
|
35
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { DatabaseConnection, DatabaseType } from '../types/admin';
|
|
2
|
+
|
|
3
|
+
export interface BackendConnectionRequest {
|
|
4
|
+
databaseType: 'mongodb' | 'postgresql';
|
|
5
|
+
connection: Omit<DatabaseConnection, 'type'>;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Normalizes connection data with defaults
|
|
10
|
+
*/
|
|
11
|
+
export function normalizeConnection(
|
|
12
|
+
connection: DatabaseConnection,
|
|
13
|
+
dbType: DatabaseType
|
|
14
|
+
): DatabaseConnection {
|
|
15
|
+
return {
|
|
16
|
+
...connection,
|
|
17
|
+
port: connection.port || (dbType === 'mongodb' ? 27017 : 5432),
|
|
18
|
+
host: connection.host || 'localhost',
|
|
19
|
+
database: connection.database || '',
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Transforms DatabaseConnection to backend format
|
|
25
|
+
*/
|
|
26
|
+
export function transformConnectionForBackend(
|
|
27
|
+
connection: DatabaseConnection,
|
|
28
|
+
dbType: DatabaseType
|
|
29
|
+
): BackendConnectionRequest {
|
|
30
|
+
const normalized = normalizeConnection(connection, dbType);
|
|
31
|
+
|
|
32
|
+
const backendConnection = { ...normalized };
|
|
33
|
+
// Remove type from connection object
|
|
34
|
+
delete (backendConnection as any).type;
|
|
35
|
+
|
|
36
|
+
return {
|
|
37
|
+
databaseType: dbType === 'postgres' ? 'postgresql' : 'mongodb',
|
|
38
|
+
connection: backendConnection,
|
|
39
|
+
};
|
|
40
|
+
}
|