()
| 14 | } |
| 15 | |
| 16 | const ConnectionList = () => { |
| 17 | const { t } = useTranslation(); |
| 18 | const connectionStore = useConnectionStore(); |
| 19 | const [state, setState] = useState<State>({ |
| 20 | showCreateConnectionModal: false, |
| 21 | showUpdateConversationModal: false, |
| 22 | }); |
| 23 | const [editConnectionModalContext, setEditConnectionModalContext] = useState<Connection>(); |
| 24 | const connectionList = connectionStore.connectionList; |
| 25 | const currentConnectionCtx = connectionStore.currentConnectionCtx; |
| 26 | |
| 27 | const toggleCreateConnectionModal = (show = true) => { |
| 28 | setState({ |
| 29 | ...state, |
| 30 | showCreateConnectionModal: show, |
| 31 | }); |
| 32 | setEditConnectionModalContext(undefined); |
| 33 | }; |
| 34 | |
| 35 | const handleConnectionSelect = async (connection: Connection) => { |
| 36 | const databaseList = await connectionStore.getOrFetchDatabaseList(connection); |
| 37 | connectionStore.setCurrentConnectionCtx({ |
| 38 | connection, |
| 39 | database: head(databaseList), |
| 40 | }); |
| 41 | }; |
| 42 | |
| 43 | const handleEditConnection = (connection: Connection) => { |
| 44 | setState({ |
| 45 | ...state, |
| 46 | showCreateConnectionModal: true, |
| 47 | }); |
| 48 | setEditConnectionModalContext(connection); |
| 49 | }; |
| 50 | |
| 51 | return ( |
| 52 | <> |
| 53 | <button |
| 54 | className={`w-full h-12 rounded-l-lg p-2 mt-1 group ${currentConnectionCtx === undefined && "bg-gray-100 dark:bg-zinc-700 shadow"}`} |
| 55 | onClick={() => connectionStore.setCurrentConnectionCtx(undefined)} |
| 56 | > |
| 57 | <img src="/chat-logo-bot.webp" className="w-7 h-auto mx-auto" alt="" /> |
| 58 | </button> |
| 59 | {connectionList.map((connection) => ( |
| 60 | <Tooltip key={connection.id} title={connection.title} side="right"> |
| 61 | <button |
| 62 | className={`relative w-full h-12 rounded-l-lg p-2 mt-2 group ${ |
| 63 | currentConnectionCtx?.connection.id === connection.id && "bg-gray-100 dark:bg-zinc-700 shadow" |
| 64 | }`} |
| 65 | onClick={() => handleConnectionSelect(connection)} |
| 66 | > |
| 67 | <span |
| 68 | className="absolute right-0.5 -mt-1.5 opacity-60 hidden group-hover:block hover:opacity-80" |
| 69 | onClick={(e) => { |
| 70 | e.stopPropagation(); |
| 71 | handleEditConnection(connection); |
| 72 | }} |
| 73 | > |
nothing calls this directly
no test coverage detected