@@ -18,7 +18,7 @@ require('./cluster-edit.css');
1818
1919import * as React from 'react' ;
2020import { List } from 'immutable' ;
21- import { Fn , pluralIfNeeded } from '../../../../common/utils/general/general' ;
21+ import { Fn , pluralIfNeeded , makeTitle } from '../../../../common/utils/general/general' ;
2222import { classNames } from '../../../utils/dom/dom' ;
2323import { firstUp , IP_REGEX , NUM_REGEX } from '../../../../common/utils/string/string' ;
2424import { STRINGS } from '../../../config/constants' ;
@@ -37,11 +37,11 @@ import { CLUSTER as LABELS } from '../../../../common/models/labels';
3737
3838export interface ClusterEditProps extends React . Props < any > {
3939 cluster ?: Cluster ;
40- onSave : ( newCluster : Cluster ) => void ;
40+ sources ?: string [ ] ;
41+ onSave : ( newCluster : Cluster , dataCubes : DataCube [ ] ) => void ;
4142 isNewCluster ?: boolean ;
4243 onCancel ?: ( ) => void ;
4344 getSuggestedCubes ?: ( ) => DataCube [ ] ;
44- addCubes ?: ( cubes : DataCube [ ] ) => void ;
4545}
4646
4747export interface ClusterEditState extends ImmutableFormState < Cluster > {
@@ -87,14 +87,11 @@ export class ClusterEdit extends React.Component<ClusterEditProps, ClusterEditSt
8787 }
8888
8989 save ( ) {
90- if ( this . props . onSave ) this . props . onSave ( this . state . newInstance ) ;
90+ if ( this . props . onSave ) this . props . onSave ( this . state . newInstance , null ) ;
9191 }
9292
9393 saveAndAddCubes ( dataCubes : DataCube [ ] ) {
94- const { addCubes } = this . props ;
95-
96- this . save ( ) ;
97- if ( addCubes ) addCubes ( dataCubes ) ;
94+ if ( this . props . onSave ) this . props . onSave ( this . state . newInstance , dataCubes ) ;
9895 }
9996
10097 goBack ( ) {
@@ -104,24 +101,39 @@ export class ClusterEdit extends React.Component<ClusterEditProps, ClusterEditSt
104101 }
105102
106103 openCreateCubesModal ( ) {
107- const { showCreateCubesModal } = this . state ;
104+ this . setState ( {
105+ showCreateCubesModal : true
106+ } ) ;
107+ }
108+
109+ closeCreateCubesModal ( ) {
108110 this . setState ( {
109111 showCreateCubesModal : true
110112 } ) ;
111113 }
112114
113115 renderCreateCubesModal ( ) : JSX . Element {
114- const { getSuggestedCubes, addCubes } = this . props ;
116+ const { sources } = this . props ;
117+ const { newInstance } = this . state ;
118+
119+ var sugestedDataCubes : DataCube [ ] = [ ] ;
120+ if ( sources ) {
121+ sugestedDataCubes = sources . map ( ( source , i ) => {
122+ // ToDo: make the name generation here better;
123+ return DataCube . fromClusterAndSource ( `${ newInstance . name } _${ i } ` , makeTitle ( source ) , newInstance , source ) ;
124+ } ) ;
125+ }
115126
116127 const CubesSuggestionModal = SuggestionModal . specialize < DataCube > ( ) ;
117128
118129 return < CubesSuggestionModal
119130 onAdd = { this . saveAndAddCubes . bind ( this ) }
120- onClose = { this . save . bind ( this ) }
131+ onNothing = { this . save . bind ( this ) }
132+ nothingLabel = { STRINGS . noIllCreateThem }
133+ onClose = { this . closeCreateCubesModal . bind ( this ) }
121134 getLabel = { ( m ) => `${ m . title } ` }
122- options = { getSuggestedCubes ( ) }
135+ options = { sugestedDataCubes }
123136 title = { STRINGS . createCubesFromCluster }
124- cancelLabel = { STRINGS . noIllCreateThem }
125137 okLabel = { ( n : number ) => `${ STRINGS . create } ${ pluralIfNeeded ( n , 'cube' ) } ` }
126138 /> ;
127139 }
0 commit comments