16
16
17
17
import React , { useState , useEffect } from 'react' ;
18
18
import { useSelector , useDispatch } from 'react-redux' ;
19
+ import { useLocation } from 'react-router' ;
20
+ import qs from 'query-string' ;
21
+ import _isEqual from 'lodash/isEqual' ;
22
+
19
23
import { getPluginIcon , getPluginTypeDisplayName , orderPluginTypes } from '../utils/pluginUtils' ;
20
24
import { ILabeledArtifactSummary } from '../types' ;
21
25
import { fetchSystemArtifacts , setSelectedArtifact } from '../store/common/actions' ;
@@ -27,9 +31,8 @@ import { MyPipelineApi } from 'api/pipeline';
27
31
import { fetchPlugins } from '../store/availablePlugins/actions' ;
28
32
import { getCurrentNamespace } from 'services/NamespaceStore' ;
29
33
import VersionStore from 'services/VersionStore' ;
30
- import { fetchPluginsDefaultVersions } from '../store/plugins/actions' ;
31
- import { useLocation } from 'react-router' ;
32
- import qs from 'query-string' ;
34
+ import { fetchPluginsDefaultVersions , updatePluginDefaultVersion } from '../store/plugins/actions' ;
35
+
33
36
34
37
interface IStudioV2PageParams {
35
38
namespace : string ;
@@ -67,7 +70,7 @@ export function useLeftPanelController(): ILeftPanelController {
67
70
const selectedArtifact = useSelector ( ( state ) => state . common . selectedArtifact ) ;
68
71
69
72
const extensions = useSelector ( ( state ) => state . plugins . extensions ) ;
70
- const pluginsList = useSelector ( ( state ) => state . plugins . pluginTypes ) ;
73
+ const pluginTypes = useSelector ( ( state ) => state . plugins . pluginTypes ) ;
71
74
const availablePluginsMap = useSelector ( ( state ) => state . availablePlugins . pluginsMap ) ;
72
75
73
76
const location = useLocation ( ) ;
@@ -86,7 +89,7 @@ export function useLeftPanelController(): ILeftPanelController {
86
89
} ;
87
90
88
91
extensions . forEach ( ( ext ) => {
89
- const plugins = pluginsList [ ext ] ;
92
+ const plugins = pluginTypes [ ext ] ;
90
93
const fetchedPluginsMap = fetchPluginsFromMap ( ext ) ;
91
94
92
95
if ( ! fetchedPluginsMap . length ) {
@@ -176,8 +179,92 @@ export function useLeftPanelController(): ILeftPanelController {
176
179
177
180
// TODO: add correct types for node
178
181
async function addPluginToCanvas ( event : React . MouseEvent < HTMLElement > , node : any ) {
182
+ const getMatchedPlugin = ( plugin ) => {
183
+ if ( plugin . pluginTemplate ) {
184
+ return plugin ;
185
+ }
186
+ let item = [ plugin ] ;
187
+ const plugins = pluginTypes [ node . type ] ;
188
+ let matchedPlugin = plugins . filter ( ( plug ) => plug . name === node . name && ! plug . pluginTemplate ) ;
189
+ if ( matchedPlugin . length ) {
190
+ item = matchedPlugin [ 0 ] . allArtifacts . filter ( ( plug ) => _isEqual ( plug . artifact , plugin . defaultArtifact ) ) ;
191
+ }
192
+ return item [ 0 ] ;
193
+ } ;
179
194
195
+ let item ;
196
+ if ( node . templateName ) {
197
+ item = node ;
198
+ } else {
199
+ item = getMatchedPlugin ( node ) ;
200
+ updatePluginDefaultVersion ( item ) ;
201
+ }
202
+
203
+ ///////////////////////////////
204
+ this . hydratorNodeActions . resetSelectedNode ( ) ;
205
+ let name = item . name || item . pluginTemplate ;
206
+ const configProperties = { } ;
207
+ let configurationGroups ;
208
+ let widgets ;
209
+
210
+ if ( ! item . pluginTemplate ) {
211
+ let itemArtifact = item . artifact ;
212
+ let key = `${ item . name } -${ item . type } -${ itemArtifact . name } -${ itemArtifact . version } -${ itemArtifact . scope } ` ;
213
+ widgets = this . myHelpers . objectQuery ( this . availablePluginMap , key , 'widgets' ) ;
214
+ const displayName = this . myHelpers . objectQuery ( widgets , 'display-name' ) ;
215
+ configurationGroups = this . myHelpers . objectQuery ( widgets , 'configuration-groups' ) ;
216
+ if ( configurationGroups && configurationGroups . length > 0 ) {
217
+ configurationGroups . forEach ( cg => {
218
+ cg . properties . forEach ( prop => {
219
+ configProperties [ prop . name ] = this . myHelpers . objectQuery ( prop , 'widget-attributes' , 'default' ) ;
220
+ } ) ;
221
+ } ) ;
222
+ }
223
+
224
+ name = displayName || name ;
225
+ }
226
+
227
+ let filteredNodes = this . HydratorPlusPlusConfigStore . getNodes ( )
228
+ . filter ( node => ( node . plugin . label ? node . plugin . label . indexOf ( name ) !== - 1 : false ) ) ;
229
+ let config ;
230
+
231
+ if ( item . pluginTemplate ) {
232
+ config = {
233
+ plugin : {
234
+ label : ( filteredNodes . length > 0 ? item . pluginTemplate + ( filteredNodes . length + 1 ) : item . pluginTemplate ) ,
235
+ name : item . pluginName ,
236
+ artifact : item . artifact ,
237
+ properties : item . properties ,
238
+ } ,
239
+ icon : this . DAGPlusPlusFactory . getIcon ( item . pluginName ) , // use getPluginIcon from utils
240
+ type : item . pluginType ,
241
+ outputSchema : item . outputSchema ,
242
+ inputSchema : item . inputSchema ,
243
+ pluginTemplate : item . pluginTemplate ,
244
+ description : item . description ,
245
+ lock : item . lock ,
246
+ configGroups : configurationGroups ,
247
+ filters : widgets && widgets . filters
248
+ } ;
249
+ } else {
250
+ config = {
251
+ plugin : {
252
+ label : ( filteredNodes . length > 0 ? name + ( filteredNodes . length + 1 ) : name ) ,
253
+ artifact : item . artifact ,
254
+ name : item . name ,
255
+ properties : configProperties ,
256
+ } ,
257
+ icon : item . icon ,
258
+ description : item . description ,
259
+ type : item . type ,
260
+ warning : true ,
261
+ configGroups : configurationGroups ,
262
+ filters : widgets && widgets . filters
263
+ } ;
264
+ }
265
+ this . hydratorNodeActions . addNode ( config ) ;
180
266
}
267
+
181
268
182
269
return {
183
270
artifacts,
0 commit comments