Skip to content

Commit ab35aa4

Browse files
fix: update getAllConnections to accept response data and skip re-fetch
When connection data is passed from create/update response, update the connection list state directly instead of making an extra API call. Applied to both NewEnv.jsx and NewProject.jsx.
1 parent e645975 commit ab35aa4

2 files changed

Lines changed: 51 additions & 21 deletions

File tree

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

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -249,18 +249,33 @@ const NewEnv = ({
249249
[connectionDataSource, selectedOrgId, csrfToken, connType, connection]
250250
);
251251

252-
const getAllConnections = useCallback(async () => {
253-
setLoading(true);
254-
try {
255-
const data = await fetchAllConnections(axiosRef, selectedOrgId);
256-
setConnectionList(data?.filter((el) => !el?.is_sample_project));
257-
} catch (error) {
258-
console.error(error);
259-
notify({ error });
260-
} finally {
261-
setLoading(false);
262-
}
263-
}, [selectedOrgId]);
252+
const getAllConnections = useCallback(
253+
async (connectionData) => {
254+
if (connectionData) {
255+
setConnectionList((prev) => {
256+
const exists = prev.some((c) => c.id === connectionData.id);
257+
if (exists) {
258+
return prev.map((c) =>
259+
c.id === connectionData.id ? connectionData : c
260+
);
261+
}
262+
return [...prev, connectionData];
263+
});
264+
return;
265+
}
266+
setLoading(true);
267+
try {
268+
const data = await fetchAllConnections(axiosRef, selectedOrgId);
269+
setConnectionList(data?.filter((el) => !el?.is_sample_project));
270+
} catch (error) {
271+
console.error(error);
272+
notify({ error });
273+
} finally {
274+
setLoading(false);
275+
}
276+
},
277+
[selectedOrgId]
278+
);
264279

265280
const getProjectDependency = useCallback(async () => {
266281
try {

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

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,30 @@ function NewProject({ open, setOpen, getAllProject, id }) {
6666
setOpen(false);
6767
}, [form, setOpen]);
6868

69-
const getAllConnections = useCallback(async () => {
70-
try {
71-
const data = await getAllConnectionsApi(axiosPrivate, selectedOrgId);
72-
setConnectionList(data);
73-
} catch (error) {
74-
console.error(error);
75-
notify({ error });
76-
}
77-
}, [selectedOrgId]);
69+
const getAllConnections = useCallback(
70+
async (connectionData) => {
71+
if (connectionData) {
72+
setConnectionList((prev) => {
73+
const exists = prev.some((c) => c.id === connectionData.id);
74+
if (exists) {
75+
return prev.map((c) =>
76+
c.id === connectionData.id ? connectionData : c
77+
);
78+
}
79+
return [...prev, connectionData];
80+
});
81+
return;
82+
}
83+
try {
84+
const data = await getAllConnectionsApi(axiosPrivate, selectedOrgId);
85+
setConnectionList(data);
86+
} catch (error) {
87+
console.error(error);
88+
notify({ error });
89+
}
90+
},
91+
[selectedOrgId]
92+
);
7893

7994
const getAllEnvironments = useCallback(async () => {
8095
try {

0 commit comments

Comments
 (0)