Skip to content

Commit abe35dd

Browse files
committed
feat(frontend): paste connection url for mongodb easily
1 parent 62d3e37 commit abe35dd

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

core/src/plugins/mongodb/db.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
func DB(config *engine.PluginConfig) (*mongo.Client, error) {
1414
ctx := context.Background()
1515
port := common.GetRecordValueOrDefault(config.Credentials.Advanced, "Port", "27017")
16-
queryParams := common.GetRecordValueOrDefault(config.Credentials.Advanced, "Query Params", "")
16+
queryParams := common.GetRecordValueOrDefault(config.Credentials.Advanced, "URL Params", "")
1717
var connectionString string
1818
// TODO: add TLS enabled logic to work instead of hard coded domains
1919
if config.Credentials.Hostname == "localhost" || config.Credentials.Hostname == "host.docker.internal" {

frontend/src/components/loading.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ type ILoadingProps = {
1111

1212
export const Loading: FC<ILoadingProps> = ({ className, hideText, loadingText, textClassName }) => {
1313
return (
14-
<div className="h-full w-full flex flex-col justify-center items-center gap-2 dark:bg-white/10" role="status">
14+
<div className="h-full w-full flex flex-col justify-center items-center gap-2" role="status">
1515
<svg aria-hidden="true" className={twMerge(classNames("w-8 h-8 text-gray-200 animate-spin fill-[#ca6f1e] ", className))} viewBox="0 0 100 101" fill="none" xmlns="http://www.w3.org/2000/svg">
1616
<path d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z" fill="currentColor"/>
1717
<path d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z" fill="currentFill"/>

frontend/src/pages/auth/login.tsx

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const databaseTypeDropdownItems: IDropdownItem<Record<string, string>>[] = [
4545
id: "MongoDB",
4646
label: "MongoDB",
4747
icon: Icons.Logos.MongoDB,
48-
extra: {"Port": "27017", "URL Params [starts with ?]": "?"},
48+
extra: {"Port": "27017", "URL Params": "?"},
4949
},
5050
{
5151
id: "Redis",
@@ -159,6 +159,21 @@ export const LoginPage: FC = () => {
159159
}
160160
}, [searchParams]);
161161

162+
const handleHoseNameChange = useCallback((newHostName: string) => {
163+
if (databaseType.id !== DatabaseType.MongoDb || !newHostName.startsWith("mongodb+srv://")) {
164+
return setHostName(newHostName);
165+
}
166+
const url = new URL(newHostName);
167+
setHostName(url.hostname);
168+
setUsername(url.username);
169+
setPassword(url.password);
170+
setDatabase(url.pathname.substring(1));
171+
setAdvancedForm({ "Port": url.port, "URL Params": `?${url.searchParams.toString()}` });
172+
if (url.port != null || url.searchParams.size !== 0) {
173+
setShowAdvanced(true);
174+
}
175+
}, [databaseType.id]);
176+
162177
const fields = useMemo(() => {
163178
if (databaseType.id === DatabaseType.Sqlite3) {
164179
return <>
@@ -174,19 +189,19 @@ export const LoginPage: FC = () => {
174189
</>
175190
}
176191
return <>
177-
<InputWithlabel label="Host Name" value={hostName} setValue={setHostName} />
192+
<InputWithlabel label={databaseType.id === DatabaseType.MongoDb ? "Host Name (or paste Connection URL)" : "Host Name"} value={hostName} setValue={handleHoseNameChange} />
178193
{ databaseType.id !== DatabaseType.Redis && <InputWithlabel label="Username" value={username} setValue={setUsername} /> }
179194
<InputWithlabel label="Password" value={password} setValue={setPassword} type="password" />
180195
{ (databaseType.id !== DatabaseType.MongoDb && databaseType.id !== DatabaseType.Redis && databaseType.id !== DatabaseType.ElasticSearch) && <InputWithlabel label="Database" value={database} setValue={setDatabase} /> }
181196
</>
182-
}, [database, databaseType.id, databasesLoading, foundDatabases?.Database, hostName, password, username]);
197+
}, [database, databaseType.id, databasesLoading, foundDatabases?.Database, handleHoseNameChange, hostName, password, username]);
183198

184199
if (loading) {
185200
return (
186201
<Page className="justify-center items-center">
187202
<div className={twMerge(BASE_CARD_CLASS, "w-[350px] h-fit flex-col gap-4 justify-center py-16")}>
188203
<Loading hideText={true} />
189-
<div className="text-gray-600 text-center">
204+
<div className="text-neutral-800 text-center dark:text-neutral-300">
190205
Logging in
191206
</div>
192207
</div>

0 commit comments

Comments
 (0)