@@ -11,8 +11,6 @@ import { Button, InlineNotice } from '@/platform/design-system/components'
1111import { Input } from '@/platform/design-system/components/field/inputs'
1212import {
1313 CredentialWorkspaceProvider ,
14- credentialSubmissionMessage ,
15- parseSearchTarget ,
1614 useCredentialWorkspace ,
1715 useFolderAccess ,
1816 useIntegrationsHref ,
@@ -21,7 +19,7 @@ import {
2119 useSecretSaver ,
2220 useUsageLink ,
2321} from '@/platform/lib/data/chat-credentials'
24- import { toast } from '@/platform/lib/data/toast '
22+ import type { SearchConnectionTarget } from '@/platform/lib/data/chat-types '
2523
2624function serviceName ( item : PlatformCredentialRequest ) : string {
2725 return ( item . provider ?? 'integration' ) . replace ( / [ - _ ] / g, ' ' )
@@ -61,9 +59,14 @@ function LinkRow({ item, controlId, onConnected }: RowProps) {
6159 )
6260}
6361
64- function SearchRow ( { item, controlId, onConnected } : RowProps ) {
62+ function SearchRow ( {
63+ item,
64+ target,
65+ controlId,
66+ onConnected,
67+ } : RowProps & { target : SearchConnectionTarget } ) {
6568 const name = serviceName ( item )
66- const connection = useSearchConnectionRow ( item , controlId , onConnected )
69+ const connection = useSearchConnectionRow ( target , controlId , onConnected )
6770 const label = connection . connected
6871 ? `Connected ${ name } `
6972 : connection . pending
@@ -135,9 +138,7 @@ export function LiveCredentialCard({
135138 const [ saving , setSaving ] = useState ( false )
136139 const [ submitted , setSubmitted ] = useState ( false )
137140 const secretRows = items . flatMap ( ( item , index ) =>
138- item . type === 'secret_input' && item . name
139- ? [ { item, index, name : item . name , scope : item . scope ?? 'workspace' } ]
140- : [ ]
141+ item . type === 'secret_input' && item . name ? [ { index, name : item . name } ] : [ ]
141142 )
142143 const integrationRows = items . flatMap ( ( item , index ) =>
143144 item . type === 'link' || item . type === 'service_account' ? [ { item, index } ] : [ ]
@@ -148,19 +149,21 @@ export function LiveCredentialCard({
148149 const named = [
149150 ...integrationRows . map ( ( { item, index } ) => ( {
150151 label : serviceName ( item ) ,
151- done : submission ? saved . has ( item . provider ?? '' ) : connected . has ( index ) ,
152+ status : ( submission ? saved . has ( item . provider ?? '' ) : connected . has ( index ) )
153+ ? 'Connected'
154+ : 'Skipped' ,
152155 } ) ) ,
153156 ...secretRows . map ( ( { name, index } ) => ( {
154157 label : name ,
155- done : submission ? saved . has ( name ) : savedRows . has ( index ) ,
158+ status : ( submission ? saved . has ( name ) : savedRows . has ( index ) ) ? 'Added' : 'Skipped' ,
156159 } ) ) ,
157160 ]
158161 return (
159162 < dl className = { styles . fields } >
160- { named . map ( ( { label, done } ) => (
163+ { named . map ( ( { label, status } ) => (
161164 < div key = { label } >
162165 < dt data-type = 'T052' > { label } </ dt >
163- < dd data-type = 'T048' > { done ? 'Added' : 'Skipped' } </ dd >
166+ < dd data-type = 'T048' > { status } </ dd >
164167 </ div >
165168 ) ) }
166169 </ dl >
@@ -171,34 +174,12 @@ export function LiveCredentialCard({
171174
172175 async function submit ( ) {
173176 setSaving ( true )
174- const groups = new Map < string , Record < string , string > > ( )
175- for ( const { index, name, scope } of secretRows ) {
176- const value = drafts [ index ] ?. trim ( )
177- if ( ! value || savedRows . has ( index ) ) continue
178- groups . set ( scope , { ...groups . get ( scope ) , [ name ] : value } )
179- }
180- const next = new Set ( savedRows )
181- const results = await Promise . allSettled (
182- [ ...groups ] . map ( async ( [ scope , variables ] ) => {
183- await saver . save ( scope , workspaceId , variables )
184- for ( const { index, name, scope : rowScope } of secretRows )
185- if ( rowScope === scope && Object . hasOwn ( variables , name ) ) next . add ( index )
186- } )
187- )
188- setSavedRows ( next )
177+ const result = await saver . submit ( { drafts, saved : savedRows , connected, workspaceId } )
178+ setSavedRows ( result . saved )
189179 setSaving ( false )
190- if ( results . some ( ( result ) => result . status === 'rejected' ) ) {
191- toast . error ( `Couldn't save all secrets. Retry the remaining entries.` )
192- return
193- }
194- const secretIndexes = new Set (
195- secretRows . flatMap ( ( { index } , position ) => ( next . has ( index ) ? [ position ] : [ ] ) )
196- )
197- const integrationIndexes = new Set (
198- integrationRows . flatMap ( ( { index } , position ) => ( connected . has ( index ) ? [ position ] : [ ] ) )
199- )
180+ if ( result . message === null ) return
200181 setSubmitted ( true )
201- onSubmit ( credentialSubmissionMessage ( items , integrationIndexes , secretIndexes ) )
182+ onSubmit ( result . message )
202183 }
203184
204185 const isCard = items . every ( ( item ) => CARD_TYPES . has ( item . type ) )
@@ -211,10 +192,11 @@ export function LiveCredentialCard({
211192 switch ( item . type ) {
212193 case 'link' :
213194 if ( ! item . provider ) return null
214- return parseSearchTarget ( item ) ? (
195+ return item . searchTarget ? (
215196 < SearchRow
216197 key = { controlId }
217198 item = { item }
199+ target = { item . searchTarget }
218200 controlId = { controlId }
219201 onConnected = { markConnected }
220202 />
0 commit comments