Skip to content

Commit 0db7220

Browse files
fix: construct db_icon from datasource_name when missing in API response
The create/update connection API response doesn't include db_icon, causing broken image icons in the connection dropdown after creating a new connection. Now constructs the icon URL from datasource_name when db_icon is missing.
1 parent 5d912de commit 0db7220

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

frontend/src/base/components/environment/NewEnv.jsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -252,15 +252,21 @@ const NewEnv = ({
252252
const getAllConnections = useCallback(
253253
async (updatedConnection) => {
254254
if (updatedConnection?.id) {
255+
const conn = { ...updatedConnection };
256+
if (!conn.db_icon && conn.datasource_name) {
257+
const iconName =
258+
conn.datasource_name === "postgres"
259+
? "postgresql"
260+
: conn.datasource_name;
261+
conn.db_icon = `https://storage.googleapis.com/visitran-static/adapter/${iconName}.png`;
262+
}
255263
setConnectionList((prev) => {
256264
const list = prev || [];
257-
const exists = list.some((c) => c?.id === updatedConnection.id);
265+
const exists = list.some((c) => c?.id === conn.id);
258266
if (exists) {
259-
return list.map((c) =>
260-
c?.id === updatedConnection.id ? updatedConnection : c
261-
);
267+
return list.map((c) => (c?.id === conn.id ? conn : c));
262268
}
263-
return [...list, updatedConnection];
269+
return [...list, conn];
264270
});
265271
return;
266272
}

frontend/src/base/new-project/NewProject.jsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,21 @@ function NewProject({ open, setOpen, getAllProject, id }) {
6969
const getAllConnections = useCallback(
7070
async (updatedConnection) => {
7171
if (updatedConnection?.id) {
72+
const conn = { ...updatedConnection };
73+
if (!conn.db_icon && conn.datasource_name) {
74+
const iconName =
75+
conn.datasource_name === "postgres"
76+
? "postgresql"
77+
: conn.datasource_name;
78+
conn.db_icon = `https://storage.googleapis.com/visitran-static/adapter/${iconName}.png`;
79+
}
7280
setConnectionList((prev) => {
7381
const list = prev || [];
74-
const exists = list.some((c) => c?.id === updatedConnection.id);
82+
const exists = list.some((c) => c?.id === conn.id);
7583
if (exists) {
76-
return list.map((c) =>
77-
c?.id === updatedConnection.id ? updatedConnection : c
78-
);
84+
return list.map((c) => (c?.id === conn.id ? conn : c));
7985
}
80-
return [...list, updatedConnection];
86+
return [...list, conn];
8187
});
8288
return;
8389
}

0 commit comments

Comments
 (0)