mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-04-25 00:36:31 +02:00
Merge pull request #1177 from SohamBhattacharjee2003/perf/dynamic-connector-imports
perf: dynamic connector imports
This commit is contained in:
commit
ca2fe959fd
2 changed files with 59 additions and 106 deletions
|
|
@ -1,14 +1,5 @@
|
||||||
|
import dynamic from "next/dynamic";
|
||||||
import type { FC } from "react";
|
import type { FC } from "react";
|
||||||
import { BaiduSearchApiConnectForm } from "./components/baidu-search-api-connect-form";
|
|
||||||
import { BookStackConnectForm } from "./components/bookstack-connect-form";
|
|
||||||
import { CirclebackConnectForm } from "./components/circleback-connect-form";
|
|
||||||
import { ElasticsearchConnectForm } from "./components/elasticsearch-connect-form";
|
|
||||||
import { GithubConnectForm } from "./components/github-connect-form";
|
|
||||||
import { LinkupApiConnectForm } from "./components/linkup-api-connect-form";
|
|
||||||
import { LumaConnectForm } from "./components/luma-connect-form";
|
|
||||||
import { MCPConnectForm } from "./components/mcp-connect-form";
|
|
||||||
import { ObsidianConnectForm } from "./components/obsidian-connect-form";
|
|
||||||
import { TavilyApiConnectForm } from "./components/tavily-api-connect-form";
|
|
||||||
|
|
||||||
export interface ConnectFormProps {
|
export interface ConnectFormProps {
|
||||||
onSubmit: (data: {
|
onSubmit: (data: {
|
||||||
|
|
@ -33,32 +24,31 @@ export interface ConnectFormProps {
|
||||||
|
|
||||||
export type ConnectFormComponent = FC<ConnectFormProps>;
|
export type ConnectFormComponent = FC<ConnectFormProps>;
|
||||||
|
|
||||||
|
const formMap: Record<string, () => Promise<{ default: FC<ConnectFormProps> }>> = {
|
||||||
|
TAVILY_API: () => import("./components/tavily-api-connect-form").then(m => ({ default: m.TavilyApiConnectForm })),
|
||||||
|
LINKUP_API: () => import("./components/linkup-api-connect-form").then(m => ({ default: m.LinkupApiConnectForm })),
|
||||||
|
BAIDU_SEARCH_API: () => import("./components/baidu-search-api-connect-form").then(m => ({ default: m.BaiduSearchApiConnectForm })),
|
||||||
|
ELASTICSEARCH_CONNECTOR: () => import("./components/elasticsearch-connect-form").then(m => ({ default: m.ElasticsearchConnectForm })),
|
||||||
|
BOOKSTACK_CONNECTOR: () => import("./components/bookstack-connect-form").then(m => ({ default: m.BookStackConnectForm })),
|
||||||
|
GITHUB_CONNECTOR: () => import("./components/github-connect-form").then(m => ({ default: m.GithubConnectForm })),
|
||||||
|
LUMA_CONNECTOR: () => import("./components/luma-connect-form").then(m => ({ default: m.LumaConnectForm })),
|
||||||
|
CIRCLEBACK_CONNECTOR: () => import("./components/circleback-connect-form").then(m => ({ default: m.CirclebackConnectForm })),
|
||||||
|
MCP_CONNECTOR: () => import("./components/mcp-connect-form").then(m => ({ default: m.MCPConnectForm })),
|
||||||
|
OBSIDIAN_CONNECTOR: () => import("./components/obsidian-connect-form").then(m => ({ default: m.ObsidianConnectForm })),
|
||||||
|
};
|
||||||
|
|
||||||
|
const componentCache = new Map<string, ConnectFormComponent>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Factory function to get the appropriate connect form component for a connector type
|
* Factory function to get the appropriate connect form component for a connector type
|
||||||
*/
|
*/
|
||||||
export function getConnectFormComponent(connectorType: string): ConnectFormComponent | null {
|
export function getConnectFormComponent(connectorType: string): ConnectFormComponent | null {
|
||||||
switch (connectorType) {
|
const loader = formMap[connectorType];
|
||||||
case "TAVILY_API":
|
if (!loader) return null;
|
||||||
return TavilyApiConnectForm;
|
|
||||||
case "LINKUP_API":
|
if (!componentCache.has(connectorType)) {
|
||||||
return LinkupApiConnectForm;
|
componentCache.set(connectorType, dynamic(loader, { ssr: false }));
|
||||||
case "BAIDU_SEARCH_API":
|
|
||||||
return BaiduSearchApiConnectForm;
|
|
||||||
case "ELASTICSEARCH_CONNECTOR":
|
|
||||||
return ElasticsearchConnectForm;
|
|
||||||
case "BOOKSTACK_CONNECTOR":
|
|
||||||
return BookStackConnectForm;
|
|
||||||
case "GITHUB_CONNECTOR":
|
|
||||||
return GithubConnectForm;
|
|
||||||
case "LUMA_CONNECTOR":
|
|
||||||
return LumaConnectForm;
|
|
||||||
case "CIRCLEBACK_CONNECTOR":
|
|
||||||
return CirclebackConnectForm;
|
|
||||||
case "MCP_CONNECTOR":
|
|
||||||
return MCPConnectForm;
|
|
||||||
case "OBSIDIAN_CONNECTOR":
|
|
||||||
return ObsidianConnectForm;
|
|
||||||
default:
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return componentCache.get(connectorType)!;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,30 +1,8 @@
|
||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
|
import dynamic from "next/dynamic";
|
||||||
import type { FC } from "react";
|
import type { FC } from "react";
|
||||||
import type { SearchSourceConnector } from "@/contracts/types/connector.types";
|
import type { SearchSourceConnector } from "@/contracts/types/connector.types";
|
||||||
import { BaiduSearchApiConfig } from "./components/baidu-search-api-config";
|
|
||||||
import { BookStackConfig } from "./components/bookstack-config";
|
|
||||||
import { CirclebackConfig } from "./components/circleback-config";
|
|
||||||
import { ClickUpConfig } from "./components/clickup-config";
|
|
||||||
import { ComposioCalendarConfig } from "./components/composio-calendar-config";
|
|
||||||
import { ComposioDriveConfig } from "./components/composio-drive-config";
|
|
||||||
import { ComposioGmailConfig } from "./components/composio-gmail-config";
|
|
||||||
import { ConfluenceConfig } from "./components/confluence-config";
|
|
||||||
import { DiscordConfig } from "./components/discord-config";
|
|
||||||
import { DropboxConfig } from "./components/dropbox-config";
|
|
||||||
import { ElasticsearchConfig } from "./components/elasticsearch-config";
|
|
||||||
import { GithubConfig } from "./components/github-config";
|
|
||||||
import { GoogleDriveConfig } from "./components/google-drive-config";
|
|
||||||
import { JiraConfig } from "./components/jira-config";
|
|
||||||
import { LinkupApiConfig } from "./components/linkup-api-config";
|
|
||||||
import { LumaConfig } from "./components/luma-config";
|
|
||||||
import { MCPConfig } from "./components/mcp-config";
|
|
||||||
import { ObsidianConfig } from "./components/obsidian-config";
|
|
||||||
import { OneDriveConfig } from "./components/onedrive-config";
|
|
||||||
import { SlackConfig } from "./components/slack-config";
|
|
||||||
import { TavilyApiConfig } from "./components/tavily-api-config";
|
|
||||||
import { TeamsConfig } from "./components/teams-config";
|
|
||||||
import { WebcrawlerConfig } from "./components/webcrawler-config";
|
|
||||||
|
|
||||||
export interface ConnectorConfigProps {
|
export interface ConnectorConfigProps {
|
||||||
connector: SearchSourceConnector;
|
connector: SearchSourceConnector;
|
||||||
|
|
@ -35,61 +13,46 @@ export interface ConnectorConfigProps {
|
||||||
|
|
||||||
export type ConnectorConfigComponent = FC<ConnectorConfigProps>;
|
export type ConnectorConfigComponent = FC<ConnectorConfigProps>;
|
||||||
|
|
||||||
|
const configMap: Record<string, () => Promise<{ default: FC<ConnectorConfigProps> }>> = {
|
||||||
|
GOOGLE_DRIVE_CONNECTOR: () => import("./components/google-drive-config").then(m => ({ default: m.GoogleDriveConfig })),
|
||||||
|
TAVILY_API: () => import("./components/tavily-api-config").then(m => ({ default: m.TavilyApiConfig })),
|
||||||
|
LINKUP_API: () => import("./components/linkup-api-config").then(m => ({ default: m.LinkupApiConfig })),
|
||||||
|
BAIDU_SEARCH_API: () => import("./components/baidu-search-api-config").then(m => ({ default: m.BaiduSearchApiConfig })),
|
||||||
|
WEBCRAWLER_CONNECTOR: () => import("./components/webcrawler-config").then(m => ({ default: m.WebcrawlerConfig })),
|
||||||
|
ELASTICSEARCH_CONNECTOR: () => import("./components/elasticsearch-config").then(m => ({ default: m.ElasticsearchConfig })),
|
||||||
|
SLACK_CONNECTOR: () => import("./components/slack-config").then(m => ({ default: m.SlackConfig })),
|
||||||
|
DISCORD_CONNECTOR: () => import("./components/discord-config").then(m => ({ default: m.DiscordConfig })),
|
||||||
|
TEAMS_CONNECTOR: () => import("./components/teams-config").then(m => ({ default: m.TeamsConfig })),
|
||||||
|
DROPBOX_CONNECTOR: () => import("./components/dropbox-config").then(m => ({ default: m.DropboxConfig })),
|
||||||
|
ONEDRIVE_CONNECTOR: () => import("./components/onedrive-config").then(m => ({ default: m.OneDriveConfig })),
|
||||||
|
CONFLUENCE_CONNECTOR: () => import("./components/confluence-config").then(m => ({ default: m.ConfluenceConfig })),
|
||||||
|
BOOKSTACK_CONNECTOR: () => import("./components/bookstack-config").then(m => ({ default: m.BookStackConfig })),
|
||||||
|
GITHUB_CONNECTOR: () => import("./components/github-config").then(m => ({ default: m.GithubConfig })),
|
||||||
|
JIRA_CONNECTOR: () => import("./components/jira-config").then(m => ({ default: m.JiraConfig })),
|
||||||
|
CLICKUP_CONNECTOR: () => import("./components/clickup-config").then(m => ({ default: m.ClickUpConfig })),
|
||||||
|
LUMA_CONNECTOR: () => import("./components/luma-config").then(m => ({ default: m.LumaConfig })),
|
||||||
|
CIRCLEBACK_CONNECTOR: () => import("./components/circleback-config").then(m => ({ default: m.CirclebackConfig })),
|
||||||
|
MCP_CONNECTOR: () => import("./components/mcp-config").then(m => ({ default: m.MCPConfig })),
|
||||||
|
OBSIDIAN_CONNECTOR: () => import("./components/obsidian-config").then(m => ({ default: m.ObsidianConfig })),
|
||||||
|
COMPOSIO_GOOGLE_DRIVE_CONNECTOR: () => import("./components/composio-drive-config").then(m => ({ default: m.ComposioDriveConfig })),
|
||||||
|
COMPOSIO_GMAIL_CONNECTOR: () => import("./components/composio-gmail-config").then(m => ({ default: m.ComposioGmailConfig })),
|
||||||
|
COMPOSIO_GOOGLE_CALENDAR_CONNECTOR: () => import("./components/composio-calendar-config").then(m => ({ default: m.ComposioCalendarConfig })),
|
||||||
|
};
|
||||||
|
|
||||||
|
const componentCache = new Map<string, ConnectorConfigComponent>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Factory function to get the appropriate config component for a connector type
|
* Factory function to get the appropriate config component for a connector type
|
||||||
*/
|
*/
|
||||||
export function getConnectorConfigComponent(
|
export function getConnectorConfigComponent(
|
||||||
connectorType: string
|
connectorType: string
|
||||||
): ConnectorConfigComponent | null {
|
): ConnectorConfigComponent | null {
|
||||||
switch (connectorType) {
|
const loader = configMap[connectorType];
|
||||||
case "GOOGLE_DRIVE_CONNECTOR":
|
if (!loader) return null;
|
||||||
return GoogleDriveConfig;
|
|
||||||
case "TAVILY_API":
|
if (!componentCache.has(connectorType)) {
|
||||||
return TavilyApiConfig;
|
componentCache.set(connectorType, dynamic(loader, { ssr: false }));
|
||||||
case "LINKUP_API":
|
|
||||||
return LinkupApiConfig;
|
|
||||||
case "BAIDU_SEARCH_API":
|
|
||||||
return BaiduSearchApiConfig;
|
|
||||||
case "WEBCRAWLER_CONNECTOR":
|
|
||||||
return WebcrawlerConfig;
|
|
||||||
case "ELASTICSEARCH_CONNECTOR":
|
|
||||||
return ElasticsearchConfig;
|
|
||||||
case "SLACK_CONNECTOR":
|
|
||||||
return SlackConfig;
|
|
||||||
case "DISCORD_CONNECTOR":
|
|
||||||
return DiscordConfig;
|
|
||||||
case "TEAMS_CONNECTOR":
|
|
||||||
return TeamsConfig;
|
|
||||||
case "DROPBOX_CONNECTOR":
|
|
||||||
return DropboxConfig;
|
|
||||||
case "ONEDRIVE_CONNECTOR":
|
|
||||||
return OneDriveConfig;
|
|
||||||
case "CONFLUENCE_CONNECTOR":
|
|
||||||
return ConfluenceConfig;
|
|
||||||
case "BOOKSTACK_CONNECTOR":
|
|
||||||
return BookStackConfig;
|
|
||||||
case "GITHUB_CONNECTOR":
|
|
||||||
return GithubConfig;
|
|
||||||
case "JIRA_CONNECTOR":
|
|
||||||
return JiraConfig;
|
|
||||||
case "CLICKUP_CONNECTOR":
|
|
||||||
return ClickUpConfig;
|
|
||||||
case "LUMA_CONNECTOR":
|
|
||||||
return LumaConfig;
|
|
||||||
case "CIRCLEBACK_CONNECTOR":
|
|
||||||
return CirclebackConfig;
|
|
||||||
case "MCP_CONNECTOR":
|
|
||||||
return MCPConfig;
|
|
||||||
case "OBSIDIAN_CONNECTOR":
|
|
||||||
return ObsidianConfig;
|
|
||||||
case "COMPOSIO_GOOGLE_DRIVE_CONNECTOR":
|
|
||||||
return ComposioDriveConfig;
|
|
||||||
case "COMPOSIO_GMAIL_CONNECTOR":
|
|
||||||
return ComposioGmailConfig;
|
|
||||||
case "COMPOSIO_GOOGLE_CALENDAR_CONNECTOR":
|
|
||||||
return ComposioCalendarConfig;
|
|
||||||
// OAuth connectors (Gmail, Calendar, Airtable, Notion) and others don't need special config UI
|
|
||||||
default:
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return componentCache.get(connectorType)!;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue