mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-17 18:35:19 +02:00
Add logic to make the toast dynamic
This commit is contained in:
parent
485c9dc4e4
commit
ab0582cb1d
1 changed files with 46 additions and 28 deletions
|
|
@ -1047,6 +1047,16 @@ export const useConnectorDialog = () => {
|
||||||
const startDateStr = startDate ? format(startDate, "yyyy-MM-dd") : undefined;
|
const startDateStr = startDate ? format(startDate, "yyyy-MM-dd") : undefined;
|
||||||
const endDateStr = endDate ? format(endDate, "yyyy-MM-dd") : undefined;
|
const endDateStr = endDate ? format(endDate, "yyyy-MM-dd") : undefined;
|
||||||
|
|
||||||
|
// For MCP connectors, track original server count for toast messages
|
||||||
|
let originalServerCount = 0;
|
||||||
|
let newServerCount = 0;
|
||||||
|
if (editingConnector.connector_type === "MCP_CONNECTOR") {
|
||||||
|
const originalServerConfigs = editingConnector.config?.server_configs;
|
||||||
|
originalServerCount = Array.isArray(originalServerConfigs) ? originalServerConfigs.length : 0;
|
||||||
|
const newServerConfigs = connectorConfig?.server_configs;
|
||||||
|
newServerCount = Array.isArray(newServerConfigs) ? newServerConfigs.length : 0;
|
||||||
|
}
|
||||||
|
|
||||||
// For MCP connectors, check if all servers were removed (empty array)
|
// For MCP connectors, check if all servers were removed (empty array)
|
||||||
if (editingConnector.connector_type === "MCP_CONNECTOR") {
|
if (editingConnector.connector_type === "MCP_CONNECTOR") {
|
||||||
const serverConfigs = connectorConfig?.server_configs;
|
const serverConfigs = connectorConfig?.server_configs;
|
||||||
|
|
@ -1217,35 +1227,43 @@ export const useConnectorDialog = () => {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
toast.success(
|
// Generate toast message based on connector type
|
||||||
editingConnector.connector_type === "MCP_CONNECTOR"
|
let toastTitle = `${editingConnector.name} updated successfully`;
|
||||||
? "MCPs updated successfully"
|
if (editingConnector.connector_type === "MCP_CONNECTOR") {
|
||||||
: `${editingConnector.name} updated successfully`,
|
const serverDiff = newServerCount - originalServerCount;
|
||||||
{
|
if (serverDiff > 0) {
|
||||||
description: periodicEnabled
|
toastTitle = `${serverDiff} MCP ${serverDiff === 1 ? "server" : "servers"} added`;
|
||||||
? `Periodic sync ${frequency ? `enabled every ${getFrequencyLabel(frequencyMinutes)}` : "enabled"}. ${indexingDescription}`
|
} else if (serverDiff < 0) {
|
||||||
: indexingDescription,
|
toastTitle = `${Math.abs(serverDiff)} MCP ${Math.abs(serverDiff) === 1 ? "server" : "servers"} removed`;
|
||||||
}
|
} else {
|
||||||
);
|
toastTitle = "MCPs updated successfully";
|
||||||
|
}
|
||||||
// Update URL - the effect will handle closing the modal and clearing state
|
|
||||||
const url = new URL(window.location.href);
|
|
||||||
url.searchParams.delete("modal");
|
|
||||||
url.searchParams.delete("tab");
|
|
||||||
url.searchParams.delete("view");
|
|
||||||
url.searchParams.delete("connectorId");
|
|
||||||
router.replace(url.pathname + url.search, { scroll: false });
|
|
||||||
|
|
||||||
refreshConnectors();
|
|
||||||
queryClient.invalidateQueries({
|
|
||||||
queryKey: cacheKeys.logs.summary(Number(searchSpaceId)),
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
console.error("Error saving connector:", error);
|
|
||||||
toast.error("Failed to save connector changes");
|
|
||||||
} finally {
|
|
||||||
setIsSaving(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
toast.success(toastTitle, {
|
||||||
|
description: periodicEnabled
|
||||||
|
? `Periodic sync ${frequency ? `enabled every ${getFrequencyLabel(frequencyMinutes)}` : "enabled"}. ${indexingDescription}`
|
||||||
|
: indexingDescription,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Update URL - the effect will handle closing the modal and clearing state
|
||||||
|
const url = new URL(window.location.href);
|
||||||
|
url.searchParams.delete("modal");
|
||||||
|
url.searchParams.delete("tab");
|
||||||
|
url.searchParams.delete("view");
|
||||||
|
url.searchParams.delete("connectorId");
|
||||||
|
router.replace(url.pathname + url.search, { scroll: false });
|
||||||
|
|
||||||
|
refreshConnectors();
|
||||||
|
queryClient.invalidateQueries({
|
||||||
|
queryKey: cacheKeys.logs.summary(Number(searchSpaceId)),
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error saving connector:", error);
|
||||||
|
toast.error("Failed to save connector changes");
|
||||||
|
} finally {
|
||||||
|
setIsSaving(false);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
[
|
[
|
||||||
editingConnector,
|
editingConnector,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue