Skip to content

Commit 3ed5a74

Browse files
committed
refactor: Use key={connector.id} to reset connector config forms then useEffect hooks from connector config components
1 parent 25b068f commit 3ed5a74

17 files changed

Lines changed: 16 additions & 221 deletions

surfsense_web/components/assistant-ui/connector-popup/connector-configs/components/baidu-search-api-config.tsx

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { KeyRound } from "lucide-react";
44
import type { FC } from "react";
5-
import { useEffect, useState } from "react";
5+
import { useState } from "react";
66
import { Input } from "@/components/ui/input";
77
import { Label } from "@/components/ui/label";
88
import type { ConnectorConfigProps } from "../index";
@@ -19,13 +19,6 @@ export const BaiduSearchApiConfig: FC<BaiduSearchApiConfigProps> = ({
1919
const [apiKey, setApiKey] = useState<string>((connector.config?.BAIDU_API_KEY as string) || "");
2020
const [name, setName] = useState<string>(connector.name || "");
2121

22-
// Update API key and name when connector changes
23-
useEffect(() => {
24-
const key = (connector.config?.BAIDU_API_KEY as string) || "";
25-
setApiKey(key);
26-
setName(connector.name || "");
27-
}, [connector.config, connector.name]);
28-
2922
const handleApiKeyChange = (value: string) => {
3023
setApiKey(value);
3124
if (onConfigChange) {

surfsense_web/components/assistant-ui/connector-popup/connector-configs/components/bookstack-config.tsx

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { KeyRound } from "lucide-react";
44
import type { FC } from "react";
5-
import { useEffect, useState } from "react";
5+
import { useState } from "react";
66
import { Input } from "@/components/ui/input";
77
import { Label } from "@/components/ui/label";
88
import type { ConnectorConfigProps } from "../index";
@@ -27,17 +27,6 @@ export const BookStackConfig: FC<BookStackConfigProps> = ({
2727
);
2828
const [name, setName] = useState<string>(connector.name || "");
2929

30-
// Update values when connector changes
31-
useEffect(() => {
32-
const url = (connector.config?.BOOKSTACK_BASE_URL as string) || "";
33-
const id = (connector.config?.BOOKSTACK_TOKEN_ID as string) || "";
34-
const secret = (connector.config?.BOOKSTACK_TOKEN_SECRET as string) || "";
35-
setBaseUrl(url);
36-
setTokenId(id);
37-
setTokenSecret(secret);
38-
setName(connector.name || "");
39-
}, [connector.config, connector.name]);
40-
4130
const handleBaseUrlChange = (value: string) => {
4231
setBaseUrl(value);
4332
if (onConfigChange) {

surfsense_web/components/assistant-ui/connector-popup/connector-configs/components/circleback-config.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,6 @@ export const CirclebackConfig: FC<CirclebackConfigProps> = ({ connector, onNameC
3434
const [isLoading, setIsLoading] = useState(true);
3535
const [copied, setCopied] = useState(false);
3636

37-
// Update name when connector changes
38-
useEffect(() => {
39-
setName(connector.name || "");
40-
}, [connector.name]);
41-
4237
// Fetch webhook info
4338
useEffect(() => {
4439
const fetchWebhookInfo = async () => {

surfsense_web/components/assistant-ui/connector-popup/connector-configs/components/clickup-config.tsx

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { Info, KeyRound } from "lucide-react";
44
import type { FC } from "react";
5-
import { useEffect, useState } from "react";
5+
import { useState } from "react";
66
import { Input } from "@/components/ui/input";
77
import { Label } from "@/components/ui/label";
88
import type { ConnectorConfigProps } from "../index";
@@ -24,15 +24,6 @@ export const ClickUpConfig: FC<ClickUpConfigProps> = ({
2424
);
2525
const [name, setName] = useState<string>(connector.name || "");
2626

27-
// Update values when connector changes (only for legacy connectors)
28-
useEffect(() => {
29-
if (!isOAuth) {
30-
const token = (connector.config?.CLICKUP_API_TOKEN as string) || "";
31-
setApiToken(token);
32-
}
33-
setName(connector.name || "");
34-
}, [connector.config, connector.name, isOAuth]);
35-
3627
const handleApiTokenChange = (value: string) => {
3728
setApiToken(value);
3829
if (onConfigChange) {

surfsense_web/components/assistant-ui/connector-popup/connector-configs/components/composio-drive-config.tsx

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
X,
1313
} from "lucide-react";
1414
import type { FC } from "react";
15-
import { useCallback, useEffect, useState } from "react";
15+
import { useCallback, useState } from "react";
1616
import { DriveFolderTree, type SelectedFolder } from "@/components/connectors/drive-folder-tree";
1717
import { Label } from "@/components/ui/label";
1818
import {
@@ -111,17 +111,6 @@ export const ComposioDriveConfig: FC<ConnectorConfigProps> = ({ connector, onCon
111111
const [isEditMode] = useState(() => existingFolders.length > 0 || existingFiles.length > 0);
112112
const [isFolderTreeOpen, setIsFolderTreeOpen] = useState(!isEditMode);
113113

114-
useEffect(() => {
115-
const folders = (connector.config?.selected_folders as SelectedFolder[] | undefined) || [];
116-
const files = (connector.config?.selected_files as SelectedFolder[] | undefined) || [];
117-
const options =
118-
(connector.config?.indexing_options as IndexingOptions | undefined) ||
119-
DEFAULT_INDEXING_OPTIONS;
120-
setSelectedFolders(folders);
121-
setSelectedFiles(files);
122-
setIndexingOptions(options);
123-
}, [connector.config]);
124-
125114
const updateConfig = (
126115
folders: SelectedFolder[],
127116
files: SelectedFolder[],

surfsense_web/components/assistant-ui/connector-popup/connector-configs/components/confluence-config.tsx

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { Info, KeyRound } from "lucide-react";
44
import type { FC } from "react";
5-
import { useEffect, useState } from "react";
5+
import { useState } from "react";
66
import { Input } from "@/components/ui/input";
77
import { Label } from "@/components/ui/label";
88
import type { ConnectorConfigProps } from "../index";
@@ -28,19 +28,6 @@ export const ConfluenceConfig: FC<ConfluenceConfigProps> = ({
2828
);
2929
const [name, setName] = useState<string>(connector.name || "");
3030

31-
// Update values when connector changes (only for legacy connectors)
32-
useEffect(() => {
33-
if (!isOAuth) {
34-
const url = (connector.config?.CONFLUENCE_BASE_URL as string) || "";
35-
const emailVal = (connector.config?.CONFLUENCE_EMAIL as string) || "";
36-
const token = (connector.config?.CONFLUENCE_API_TOKEN as string) || "";
37-
setBaseUrl(url);
38-
setEmail(emailVal);
39-
setApiToken(token);
40-
}
41-
setName(connector.name || "");
42-
}, [connector.config, connector.name, isOAuth]);
43-
4431
const handleBaseUrlChange = (value: string) => {
4532
setBaseUrl(value);
4633
if (onConfigChange) {

surfsense_web/components/assistant-ui/connector-popup/connector-configs/components/elasticsearch-config.tsx

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { KeyRound, Server } from "lucide-react";
44
import type { FC } from "react";
5-
import { useEffect, useId, useRef, useState } from "react";
5+
import { useId, useState } from "react";
66
import { Badge } from "@/components/ui/badge";
77
import { Input } from "@/components/ui/input";
88
import { Label } from "@/components/ui/label";
@@ -56,38 +56,6 @@ export const ElasticsearchConfig: FC<ElasticsearchConfigProps> = ({
5656
: ""
5757
);
5858

59-
// Update values when the connector identity changes (e.g. switching to a different connector)
60-
const connectorIdRef = useRef(connector.id);
61-
useEffect(() => {
62-
if (connectorIdRef.current === connector.id) return;
63-
connectorIdRef.current = connector.id;
64-
65-
setName(connector.name || "");
66-
setEndpointUrl((connector.config?.ELASTICSEARCH_URL as string) || "");
67-
setAuthMethod(
68-
(connector.config?.ELASTICSEARCH_API_KEY ? "api_key" : "basic") as "basic" | "api_key"
69-
);
70-
setUsername((connector.config?.ELASTICSEARCH_USERNAME as string) || "");
71-
setPassword((connector.config?.ELASTICSEARCH_PASSWORD as string) || "");
72-
setApiKey((connector.config?.ELASTICSEARCH_API_KEY as string) || "");
73-
setIndices(
74-
Array.isArray(connector.config?.ELASTICSEARCH_INDEX)
75-
? (connector.config?.ELASTICSEARCH_INDEX as string[]).join(", ")
76-
: (connector.config?.ELASTICSEARCH_INDEX as string) || ""
77-
);
78-
setQuery((connector.config?.ELASTICSEARCH_QUERY as string) || "*");
79-
setSearchFields(
80-
Array.isArray(connector.config?.ELASTICSEARCH_FIELDS)
81-
? (connector.config?.ELASTICSEARCH_FIELDS as string[]).join(", ")
82-
: ""
83-
);
84-
setMaxDocuments(
85-
connector.config?.ELASTICSEARCH_MAX_DOCUMENTS
86-
? String(connector.config.ELASTICSEARCH_MAX_DOCUMENTS)
87-
: ""
88-
);
89-
}, [connector]);
90-
9159
const stringToArray = (str: string): string[] => {
9260
const items = str
9361
.split(",")

surfsense_web/components/assistant-ui/connector-popup/connector-configs/components/github-config.tsx

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { KeyRound } from "lucide-react";
44
import type { FC } from "react";
5-
import { useEffect, useRef, useState } from "react";
5+
import { useState } from "react";
66
import { Badge } from "@/components/ui/badge";
77
import { Input } from "@/components/ui/input";
88
import { Label } from "@/components/ui/label";
@@ -33,9 +33,6 @@ export const GithubConfig: FC<GithubConfigProps> = ({
3333
onConfigChange,
3434
onNameChange,
3535
}) => {
36-
// Track internal changes to prevent useEffect from overwriting user input
37-
const isInternalChange = useRef(false);
38-
3936
const [githubPat, setGithubPat] = useState<string>(
4037
(connector.config?.GITHUB_PAT as string) || ""
4138
);
@@ -44,22 +41,7 @@ export const GithubConfig: FC<GithubConfigProps> = ({
4441
);
4542
const [name, setName] = useState<string>(connector.name || "");
4643

47-
// Update values when connector changes externally (not from our own input)
48-
useEffect(() => {
49-
// Skip if this is our own internal change
50-
if (isInternalChange.current) {
51-
isInternalChange.current = false;
52-
return;
53-
}
54-
const pat = (connector.config?.GITHUB_PAT as string) || "";
55-
const repos = arrayToString(stringToArray(connector.config?.repo_full_names));
56-
setGithubPat(pat);
57-
setRepoFullNames(repos);
58-
setName(connector.name || "");
59-
}, [connector.config, connector.name]);
60-
6144
const handleGithubPatChange = (value: string) => {
62-
isInternalChange.current = true;
6345
setGithubPat(value);
6446
if (onConfigChange) {
6547
onConfigChange({
@@ -70,7 +52,6 @@ export const GithubConfig: FC<GithubConfigProps> = ({
7052
};
7153

7254
const handleRepoFullNamesChange = (value: string) => {
73-
isInternalChange.current = true;
7455
setRepoFullNames(value);
7556
const repoList = stringToArray(value);
7657
if (onConfigChange) {
@@ -82,7 +63,6 @@ export const GithubConfig: FC<GithubConfigProps> = ({
8263
};
8364

8465
const handleNameChange = (value: string) => {
85-
isInternalChange.current = true;
8666
setName(value);
8767
if (onNameChange) {
8868
onNameChange(value);

surfsense_web/components/assistant-ui/connector-popup/connector-configs/components/google-drive-config.tsx

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
X,
1111
} from "lucide-react";
1212
import type { FC } from "react";
13-
import { useCallback, useEffect, useState } from "react";
13+
import { useCallback, useState } from "react";
1414
import { Button } from "@/components/ui/button";
1515
import { Label } from "@/components/ui/label";
1616
import {
@@ -92,17 +92,6 @@ export const GoogleDriveConfig: FC<ConnectorConfigProps> = ({ connector, onConfi
9292
const [selectedFiles, setSelectedFiles] = useState<SelectedItem[]>(existingFiles);
9393
const [indexingOptions, setIndexingOptions] = useState<IndexingOptions>(existingIndexingOptions);
9494

95-
useEffect(() => {
96-
const folders = (connector.config?.selected_folders as SelectedItem[] | undefined) || [];
97-
const files = (connector.config?.selected_files as SelectedItem[] | undefined) || [];
98-
const options =
99-
(connector.config?.indexing_options as IndexingOptions | undefined) ||
100-
DEFAULT_INDEXING_OPTIONS;
101-
setSelectedFolders(folders);
102-
setSelectedFiles(files);
103-
setIndexingOptions(options);
104-
}, [connector.config]);
105-
10695
const updateConfig = (
10796
folders: SelectedItem[],
10897
files: SelectedItem[],

surfsense_web/components/assistant-ui/connector-popup/connector-configs/components/jira-config.tsx

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { Info, KeyRound } from "lucide-react";
44
import type { FC } from "react";
5-
import { useEffect, useState } from "react";
5+
import { useState } from "react";
66
import { Input } from "@/components/ui/input";
77
import { Label } from "@/components/ui/label";
88
import type { ConnectorConfigProps } from "../index";
@@ -22,19 +22,6 @@ export const JiraConfig: FC<JiraConfigProps> = ({ connector, onConfigChange, onN
2222
);
2323
const [name, setName] = useState<string>(connector.name || "");
2424

25-
// Update values when connector changes (only for legacy connectors)
26-
useEffect(() => {
27-
if (!isOAuth) {
28-
const url = (connector.config?.JIRA_BASE_URL as string) || "";
29-
const emailVal = (connector.config?.JIRA_EMAIL as string) || "";
30-
const token = (connector.config?.JIRA_API_TOKEN as string) || "";
31-
setBaseUrl(url);
32-
setEmail(emailVal);
33-
setApiToken(token);
34-
}
35-
setName(connector.name || "");
36-
}, [connector.config, connector.name, isOAuth]);
37-
3825
const handleBaseUrlChange = (value: string) => {
3926
setBaseUrl(value);
4027
if (onConfigChange) {

0 commit comments

Comments
 (0)