mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-07-12 22:42:13 +02:00
Fix: Use live API data for Slack channel discovery
Replaced mock data in the Slack connector's channel management UI with a real API call to the backend. - Implemented `discoverSlackChannelsAPI` in the `useConnectorEditPage` hook to fetch channels from `/api/search-source-connectors/slack/:connectorId/discover-channels`. - Updated the `handleDiscoverChannels` function in `EditConnectorPage` to use this new API function. - Ensured consistent `SlackChannelInfo` type usage. This fixes a bug where incorrect Slack channel names were displayed due to the UI using stale mock data instead of actual data reflecting the bot's true channel memberships.
This commit is contained in:
parent
16c7dedba0
commit
9311e12c87
2 changed files with 71 additions and 19 deletions
|
|
@ -74,9 +74,8 @@ export default function EditConnectorPage() {
|
|||
isFetchingRepos,
|
||||
handleFetchRepositories,
|
||||
handleRepoSelectionChange,
|
||||
// Placeholder functions that would ideally come from the hook
|
||||
// discoverSlackChannels: hookDiscoverSlackChannels,
|
||||
// triggerSlackReindex: hookTriggerSlackReindex,
|
||||
discoverSlackChannelsAPI, // Added the actual API function from the hook
|
||||
// triggerSlackReindex: hookTriggerSlackReindex, // Placeholder for reindex
|
||||
} = useConnectorEditPage(connectorId, searchSpaceId);
|
||||
|
||||
// State for Slack Channel Management
|
||||
|
|
@ -110,22 +109,18 @@ export default function EditConnectorPage() {
|
|||
const handleDiscoverChannels = async () => {
|
||||
setIsDiscoveringChannels(true);
|
||||
toast.info("Discovering Slack channels...");
|
||||
// Replace with actual API call:
|
||||
// const channels = await hookDiscoverSlackChannels(connectorId);
|
||||
// For now, using mock data:
|
||||
await new Promise(resolve => setTimeout(resolve, 1500)); // Simulate API delay
|
||||
const mockChannels: SlackChannelInfo[] = [
|
||||
{ id: "C123", name: "general", is_private: false, is_member: true },
|
||||
{ id: "C456", name: "random", is_private: false, is_member: true },
|
||||
{ id: "C789", name: "dev-team-private", is_private: true, is_member: true },
|
||||
{ id: "CABC", name: "marketing", is_private: false, is_member: false }, // Bot not member
|
||||
];
|
||||
const memberChannels = mockChannels.filter(ch => ch.is_member);
|
||||
setDiscoveredChannels(memberChannels);
|
||||
if (memberChannels.length > 0) {
|
||||
toast.success(`Discovered ${memberChannels.length} channels where bot is a member.`);
|
||||
|
||||
// Call the actual API function from the hook
|
||||
const actualChannels = await discoverSlackChannelsAPI(connectorId);
|
||||
|
||||
setDiscoveredChannels(actualChannels);
|
||||
|
||||
if (actualChannels.length > 0) {
|
||||
toast.success(`Discovered ${actualChannels.length} channels where the bot is a member.`);
|
||||
} else {
|
||||
toast.warning("No channels found where the bot is a member, or discovery failed.");
|
||||
// The API function itself should show an error toast on failure.
|
||||
// This warning can be for cases where the API call succeeded but returned no channels.
|
||||
toast.warning("No channels found where the bot is a member, or discovery returned no channels.");
|
||||
}
|
||||
setIsDiscoveringChannels(false);
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue