(props)
| 48 | The Form used to create API connections |
| 49 | */ |
| 50 | function ApiConnectionForm(props) { |
| 51 | const { |
| 52 | editConnection, onComplete, addError, |
| 53 | } = props; |
| 54 | |
| 55 | const [loading, setLoading] = useState(false); |
| 56 | const [testLoading, setTestLoading] = useState(false); |
| 57 | const [connection, setConnection] = useState({ |
| 58 | type: "api", subType: "api", optionsArray: [] |
| 59 | }); |
| 60 | const [errors, setErrors] = useState({}); |
| 61 | const [menuType, setMenuType] = useState( |
| 62 | new URLSearchParams(window.location.search).get("tab") === "aiContext" |
| 63 | ? "aiContext" |
| 64 | : "authentication" |
| 65 | ); |
| 66 | const [testResult, setTestResult] = useState(null); |
| 67 | const [passwordVisible, setPasswordVisible] = useState(false); |
| 68 | |
| 69 | const { isDark } = useTheme(); |
| 70 | const initRef = useRef(null); |
| 71 | const dispatch = useDispatch(); |
| 72 | const team = useSelector(selectTeam); |
| 73 | |
| 74 | useEffect(() => { |
| 75 | if (!initRef.current) { |
| 76 | initRef.current = true; |
| 77 | _addOption(); |
| 78 | _init(); |
| 79 | } |
| 80 | }, []); |
| 81 | |
| 82 | const _init = () => { |
| 83 | if (editConnection) { |
| 84 | const newConnection = editConnection; |
| 85 | // format the options |
| 86 | if (newConnection.options && newConnection.options.length > 0) { |
| 87 | const formattedOptions = []; |
| 88 | for (let i = 0; i < newConnection.options.length; i++) { |
| 89 | if (newConnection.options[i]) { |
| 90 | formattedOptions.push({ |
| 91 | id: uuid(), |
| 92 | key: Object.keys(newConnection.options[i])[0], |
| 93 | value: newConnection.options[i][Object.keys(newConnection.options[i])[0]], |
| 94 | }); |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | newConnection.optionsArray = formattedOptions; |
| 99 | } else { |
| 100 | newConnection.optionsArray = []; |
| 101 | } |
| 102 | |
| 103 | setConnection(newConnection); |
| 104 | } |
| 105 | }; |
| 106 | |
| 107 | const _onTestRequest = (data) => { |
nothing calls this directly
no test coverage detected