Add logic to make the toast dynamic

This commit is contained in:
Manoj Aggarwal 2026-01-16 12:13:58 -08:00
parent 485c9dc4e4
commit ab0582cb1d

View file

@ -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,16 +1227,24 @@ 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) {
toastTitle = `${serverDiff} MCP ${serverDiff === 1 ? "server" : "servers"} added`;
} else if (serverDiff < 0) {
toastTitle = `${Math.abs(serverDiff)} MCP ${Math.abs(serverDiff) === 1 ? "server" : "servers"} removed`;
} else {
toastTitle = "MCPs updated successfully";
}
}
toast.success(toastTitle, {
description: periodicEnabled description: periodicEnabled
? `Periodic sync ${frequency ? `enabled every ${getFrequencyLabel(frequencyMinutes)}` : "enabled"}. ${indexingDescription}` ? `Periodic sync ${frequency ? `enabled every ${getFrequencyLabel(frequencyMinutes)}` : "enabled"}. ${indexingDescription}`
: indexingDescription, : indexingDescription,
} });
);
// Update URL - the effect will handle closing the modal and clearing state // Update URL - the effect will handle closing the modal and clearing state
const url = new URL(window.location.href); const url = new URL(window.location.href);