@@ -5,7 +5,7 @@ import copy from 'copy-to-clipboard';
55import CopyThis from '../assets/images/copy-this.png' ;
66import LeftPane from '../assets/images/left-pane-instructions.png' ;
77
8- import { BsFillPencilFill } from ' react-icons/bs' ;
8+ import { FaRegEdit } from " react-icons/fa" ;
99import { AiFillCheckCircle } from "react-icons/ai" ;
1010import { BiLinkExternal } from 'react-icons/bi' ;
1111import { IoMdClose , IoMdCloseCircle } from "react-icons/io" ;
@@ -14,7 +14,7 @@ import { RxCopy } from 'react-icons/rx';
1414import { ClipLoader } from "react-spinners" ;
1515import { toast } from 'react-toastify' ;
1616import { api } from "../api" ;
17- import { ConfigField , DataSourceType } from "../data-source" ;
17+ import { ConfigField , ConnectedDataSource , DataSourceType } from "../data-source" ;
1818
1919
2020export interface SelectOption {
@@ -34,8 +34,10 @@ export interface DataSourcePanelState {
3434
3535export interface DataSourcePanelProps {
3636 dataSourceTypesDict : { [ key : string ] : DataSourceType }
37- connectedDataSources : string [ ]
38- onAdded : ( dataSourceType : string ) => void
37+ connectedDataSources : ConnectedDataSource [ ]
38+ inIndexing : boolean
39+ onAdded : ( newlyConnected : ConnectedDataSource ) => void
40+ onRemoved : ( removed : ConnectedDataSource ) => void
3941 onClose : ( ) => void
4042}
4143
@@ -136,19 +138,19 @@ export default class DataSourcePanel extends React.Component<DataSourcePanelProp
136138 ! this . state . isAdding && (
137139 < div className = "w-full" >
138140 < h1 className = "text-2xl block text-white mb-4" >
139- { this . props . connectedDataSources . length > 0 ? ' Active data sources:' : 'No Active Data Sources. Add Now!' }
140- < BsFillPencilFill key = "pencil" onClick = { this . swithcMode } className = 'text-white float-right inline hover:text-[#9875d4] hover:cursor-pointer' />
141+ { this . props . connectedDataSources . length > 0 ? ( this . state . editMode ? 'Edit mode:' : ' Active data sources:') : 'No Active Data Sources. Add Now!' }
142+ { this . props . connectedDataSources . length > 0 && < FaRegEdit key = "pencil" onClick = { this . swithcMode } className = 'text-white mt-1 float-right inline hover:text-[#9875d4] hover:cursor-pointer' /> }
141143 </ h1 >
142144 < div className = "flex flex-row w-[100%] flex-wrap" >
143- { this . props . connectedDataSources . map ( ( data_source ) => {
145+ { this . props . connectedDataSources . map ( ( dataSource ) => {
144146 return (
145147 // connected data source
146148 < div className = "flex py-2 pl-5 pr-3 m-2 flex-row items-center justify-center bg-[#352C45] hover:shadow-inner shadow-blue-500/50 rounded-lg font-poppins leading-[28px] border-b-[#916CCD] border-b-2" >
147- < img alt = "data-source" className = { "mr-2 h-[20px]" } src = { this . props . dataSourceTypesDict [ data_source ] . image_base64 } > </ img >
148- < h1 className = "text-white width-full" > { this . props . dataSourceTypesDict [ data_source ] . display_name } </ h1 >
149+ < img alt = "data-source" className = { "mr-2 h-[20px]" } src = { this . props . dataSourceTypesDict [ dataSource . name ] . image_base64 } > </ img >
150+ < h1 className = "text-white width-full" > { this . props . dataSourceTypesDict [ dataSource . name ] . display_name } </ h1 >
149151
150152 { this . state . editMode ? (
151- < IoMdCloseCircle onClick = { this . removeDataSource } className = "ml-6 fill-[#df335e] text-2xl hover:fill-[#ff85c2 ]" />
153+ < IoMdCloseCircle onClick = { ( ) => this . removeDataSource ( dataSource ) } className = "transition duration-150 ease-in-out ml-6 fill-[#7d4ac3] hover:cursor-pointer text-2xl hover:fill-[#d80b0b ]" />
152154 ) : (
153155 < AiFillCheckCircle className = "ml-6 text-[#9875d4] text-2xl" />
154156 )
@@ -161,7 +163,7 @@ export default class DataSourcePanel extends React.Component<DataSourcePanelProp
161163 {
162164 Object . keys ( this . props . dataSourceTypesDict ) . map ( ( key ) => {
163165 let dataSource = this . props . dataSourceTypesDict [ key ] ;
164- if ( ! this . props . connectedDataSources . includes ( dataSource . name ) && ! this . state . editMode ) {
166+ if ( ! this . state . editMode && ! this . props . connectedDataSources . find ( ( connectedDataSource ) => connectedDataSource . name === dataSource . name ) ) {
165167 return (
166168 // unconnected data source
167169 < div onClick = { ( ) => this . dataSourceToAddSelected ( dataSource ) } className = "flex hover:text-[#9875d4] py-2 pl-5 pr-3 m-2 flex-row items-center justify-center bg-[#36323b] hover:border-[#9875d4] rounded-lg font-poppins leading-[28px] border-[#777777] border-b-[.5px] transition duration-300 ease-in-out" >
@@ -407,7 +409,7 @@ export default class DataSourcePanel extends React.Component<DataSourcePanelProp
407409 field . value = '' ;
408410 } ) ;
409411 this . setState ( { selectedDataSource : selectedDataSource } ) ;
410- this . props . onAdded ( this . state . selectedDataSource . value ) ;
412+ this . props . onAdded ( { name : this . state . selectedDataSource . value , id : response . data } ) ;
411413 this . setState ( { isAddingLoading : false , isAdding : false , selectedDataSource : this . state . selectOptions [ 0 ] } ) ;
412414 } ) . catch ( error => {
413415 toast . error ( "Error adding data source: " + error . response . data , { autoClose : 10000 } ) ;
@@ -419,10 +421,19 @@ export default class DataSourcePanel extends React.Component<DataSourcePanelProp
419421 this . setState ( { selectedDataSource : event } )
420422 }
421423
422- removeDataSource = ( ) => {
423- let connected = this . props . connectedDataSources ;
424- let index = connected . indexOf ( this . state . selectedDataSource . value ) ;
425- connected . splice ( index , 1 ) ;
424+ removeDataSource = ( connectedDataSource : ConnectedDataSource ) => {
425+ if ( this . props . inIndexing ) {
426+ toast . error ( "Cannot remove data source while indexing is in progress" ) ;
427+ return ;
428+ }
429+
430+ api . delete ( `/data-sources/${ connectedDataSource . id } ` ) . then ( response => {
431+ toast . success ( `${ this . capitilize ( connectedDataSource . name ) } removed.` ) ;
432+ this . props . onRemoved ( connectedDataSource ) ;
433+ } ) . catch ( error => {
434+ toast . error ( "Error adding data source: " + error . response . data , { autoClose : 10000 } ) ;
435+ this . setState ( { isAddingLoading : false } ) ;
436+ } ) ;
426437 }
427438
428439
0 commit comments