@@ -103,12 +103,59 @@ export const localeContains = (str: string, sub: string): boolean => {
103103 return ascii ( str ) . includes ( ascii ( sub ) ) ;
104104}
105105
106+ // Define interfaces
107+ interface Category {
108+ label : string ;
109+ filter : ( t : DataSourceTypeInfo ) => boolean ;
110+ }
111+
112+ interface SectionProps {
113+ label : string ;
114+ filter : ( t : DataSourceTypeInfo ) => boolean ;
115+ datasourceTypes : DataSourceTypeInfo [ ] ;
116+ searchValue : string ;
117+ onSelect : ( t : DataSourceTypeInfo ) => void ;
118+ }
119+
120+ const categories : Category [ ] = [
121+ { label : trans ( "query.database" ) , filter : ( t ) => databasePlugins . includes ( t . id ) || t . id == "googleSheets" || t . definition ?. category === "database" } ,
122+ { label : trans ( "query.categoryBigdata" ) , filter : ( t ) => t . definition ?. category === "Big Data" } ,
123+ { label : trans ( "query.categoryAi" ) , filter : ( t ) => t . definition ?. category === "AI" } ,
124+ { label : trans ( "query.categoryDevops" ) , filter : ( t ) => t . definition ?. category === "DevOps" } ,
125+ { label : trans ( "query.categoryAppdevelopment" ) , filter : ( t ) => t . id == "restApi" || t . id == "graphql" || t . definition ?. category === "App Development" } ,
126+ { label : trans ( "query.categoryWorkflow" ) , filter : ( t ) => t . definition ?. category === "Workflow" } ,
127+ { label : trans ( "query.categoryMessaging" ) , filter : ( t ) => t . id == "smtp" || t . definition ?. category === "Messaging" } ,
128+ { label : trans ( "query.categoryAssets" ) , filter : ( t ) => t . definition ?. category === "Assets" } ,
129+ { label : trans ( "query.categoryProjectManagement" ) , filter : ( t ) => t . definition ?. category === "Project Management" } ,
130+ { label : trans ( "query.categoryCrm" ) , filter : ( t ) => t . definition ?. category === "CRM" } ,
131+ { label : trans ( "query.categoryEcommerce" ) , filter : ( t ) => t . definition ?. category === "eCommerce" } ,
132+ { label : trans ( "query.categoryApis" ) , filter : ( t ) => t . definition ?. category === "api" } ,
133+ ] ;
134+
135+ // Section component
136+ const Section : React . FC < SectionProps > = ( { label, filter, datasourceTypes, searchValue, onSelect } ) => (
137+ < SectionWrapper >
138+ < SectionLabel > { label } </ SectionLabel >
139+ < SectionBody >
140+ { datasourceTypes
141+ . filter ( filter )
142+ . filter ( ( t ) => localeContains ( t . name , searchValue ) )
143+ . map ( ( t ) => (
144+ < DataSourceButton key = { t . id } onClick = { ( ) => onSelect ( t ) } >
145+ { t . id && getBottomResIcon ( t . id , "large" , t . definition ?. icon ) }
146+ { t . name }
147+ </ DataSourceButton >
148+ ) ) }
149+ </ SectionBody >
150+ </ SectionWrapper >
151+ ) ;
152+
106153export const PluginPanel = ( props : { onSelect : ( t : DataSourceTypeInfo ) => void } ) => {
107154 const datasourceTypes = useSelector ( getDataSourceTypes ) ;
108155 const currentPage = useCurrentPage ( ) ;
109156 const [ searchValue , setSearchValue ] = useState ( "" ) ;
110157 const apiList = currentPage === "queryLibrary" ? apiPluginsForQueryLibrary : apiPlugins ;
111-
158+
112159 return (
113160 < PanelWrapper >
114161 < OperationRightWrapper >
@@ -119,36 +166,16 @@ export const PluginPanel = (props: { onSelect: (t: DataSourceTypeInfo) => void }
119166 style = { { width : "192px" , height : "32px" , margin : "0" } }
120167 />
121168 </ OperationRightWrapper >
122- < SectionWrapper >
123- < SectionLabel > { trans ( "query.database" ) } </ SectionLabel >
124- < SectionBody >
125- { datasourceTypes
126- . filter ( ( t ) => databasePlugins . includes ( t . id ) || t . definition ?. category === "database" )
127- . filter ( ( t ) => localeContains ( t . name , searchValue ) )
128- . map ( ( t ) => {
129- return (
130- < DataSourceButton key = { t . id } onClick = { ( ) => props . onSelect ( t ) } >
131- { t . id && getBottomResIcon ( t . id , "large" , t . definition ?. icon ) }
132- { t . name }
133- </ DataSourceButton >
134- ) ;
135- } ) }
136- </ SectionBody >
137- </ SectionWrapper >
138- < SectionWrapper >
139- < SectionLabel > APIs</ SectionLabel >
140- < SectionBody >
141- { datasourceTypes
142- . filter ( ( t ) => apiList . includes ( t . id ) || t . definition ?. category === "api" )
143- . filter ( ( t ) => localeContains ( t . name , searchValue ) )
144- . map ( ( t ) => (
145- < DataSourceButton key = { t . id } onClick = { ( ) => props . onSelect ( t ) } >
146- { t . id && getBottomResIcon ( t . id , "large" , t . definition ?. icon ) }
147- { t . name }
148- </ DataSourceButton >
149- ) ) }
150- </ SectionBody >
151- </ SectionWrapper >
169+ { categories . map ( ( { label, filter } ) => (
170+ < Section
171+ key = { label }
172+ label = { label }
173+ filter = { filter }
174+ datasourceTypes = { datasourceTypes }
175+ searchValue = { searchValue }
176+ onSelect = { props . onSelect }
177+ />
178+ ) ) }
152179 </ PanelWrapper >
153180 ) ;
154- } ;
181+ } ;
0 commit comments