Skip to content

Commit 463b2d1

Browse files
lorem--ipsumvogievetsky
authored andcommitted
Auto adding datacubes from the new cluster flow now fills them as well
1 parent 40971f0 commit 463b2d1

File tree

2 files changed

+49
-10
lines changed

2 files changed

+49
-10
lines changed

src/client/views/settings-view/cluster-edit/cluster-edit.tsx

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
require('./cluster-edit.css');
1818

1919
import * as React from 'react';
20+
import * as Q from 'q';
21+
import { AttributeInfo, Attributes } from 'plywood';
22+
23+
import { Ajax } from '../../../utils/ajax/ajax';
2024
import { List } from 'immutable';
2125
import { Fn, pluralIfNeeded, makeTitle } from '../../../../common/utils/general/general';
2226
import { classNames } from '../../../utils/dom/dom';
@@ -38,7 +42,8 @@ import { CLUSTER as LABELS } from '../../../../common/models/labels';
3842
export interface ClusterEditProps extends React.Props<any> {
3943
cluster?: Cluster;
4044
sources?: string[];
41-
onSave: (newCluster: Cluster, dataCubes: DataCube[]) => void;
45+
onSave: (newCluster: Cluster) => Q.Promise<void>;
46+
onAddDataCubes?: (dataCubes: DataCube[]) => Q.Promise<void>;
4247
isNewCluster?: boolean;
4348
onCancel?: () => void;
4449
getSuggestedCubes?: () => DataCube[];
@@ -87,11 +92,33 @@ export class ClusterEdit extends React.Component<ClusterEditProps, ClusterEditSt
8792
}
8893

8994
save() {
90-
if (this.props.onSave) this.props.onSave(this.state.newInstance, null);
95+
if (this.props.onSave) this.props.onSave(this.state.newInstance);
9196
}
9297

9398
saveAndAddCubes(dataCubes: DataCube[]) {
94-
if (this.props.onSave) this.props.onSave(this.state.newInstance, dataCubes);
99+
if (this.props.onSave) {
100+
this.props.onSave(this.state.newInstance)
101+
.then(() => {
102+
Q.all(dataCubes.map(this.fetchSuggestions)).then((attributes: Attributes[]) => {
103+
let newDataCubes = dataCubes.map((dc, i) => dc.fillAllFromAttributes(attributes[i]));
104+
this.props.onAddDataCubes(newDataCubes);
105+
});
106+
});
107+
}
108+
}
109+
110+
fetchSuggestions(dataCube: DataCube): Q.Promise<Attributes> {
111+
return Ajax.query({
112+
method: "POST",
113+
url: 'settings/attributes',
114+
data: {
115+
clusterName: dataCube.clusterName,
116+
source: dataCube.source
117+
}
118+
}).then(
119+
(resp) => AttributeInfo.fromJSs(resp.attributes)
120+
);
121+
;
95122
}
96123

97124
goBack() {

src/client/views/settings-view/settings-view.tsx

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -162,15 +162,11 @@ export class SettingsView extends React.Component<SettingsViewProps, SettingsVie
162162
});
163163
}
164164

165-
addClusterAndDataCubes(newCluster: Cluster, newDataCubes: DataCube[]) {
165+
addCluster(newCluster: Cluster): Q.Promise<any> {
166166
var settings = ImmutableUtils.addInArray(this.state.settings, 'clusters', newCluster);
167167
var message = 'Cluster created';
168-
if (newDataCubes && newDataCubes.length) {
169-
settings = settings.appendDataCubes(newDataCubes);
170-
message = 'Cluster and data cubes created';
171-
}
172168

173-
this.onSave(settings, message).then(this.backToClustersView.bind(this));
169+
return this.onSave(settings, message).then(this.backToClustersView.bind(this));
174170
}
175171

176172
backToClustersView() {
@@ -191,6 +187,20 @@ export class SettingsView extends React.Component<SettingsViewProps, SettingsVie
191187
ImmutableUtils.addInArray(settings, 'clusters', newCluster, index)
192188
).then(this.backToClustersView.bind(this));
193189
}
190+
191+
addDataCubes(dataCubes: DataCube[]) {
192+
if (!dataCubes || !dataCubes.length) {
193+
return;
194+
}
195+
196+
this.onSave(
197+
this.state.settings.appendDataCubes(dataCubes),
198+
'Data cubes created'
199+
)
200+
.then(this.backToClustersView.bind(this))
201+
;
202+
}
203+
194204
// !-- Cluster creation flow
195205

196206
// -- DataCubes creation flow
@@ -207,6 +217,7 @@ export class SettingsView extends React.Component<SettingsViewProps, SettingsVie
207217
).then(this.backToDataCubesView.bind(this));
208218
}
209219

220+
210221
backToDataCubesView() {
211222
window.location.hash = `#settings/${PATHS.dataCubes}`;
212223

@@ -291,7 +302,8 @@ export class SettingsView extends React.Component<SettingsViewProps, SettingsVie
291302
isNewCluster={true}
292303
cluster={tempCluster}
293304
sources={tempClusterSources}
294-
onSave={this.addClusterAndDataCubes.bind(this)}
305+
onSave={this.addCluster.bind(this)}
306+
onAddDataCubes={this.addDataCubes.bind(this)}
295307
onCancel={this.backToClustersView.bind(this)}
296308
/>
297309
: <ClusterSeedModal

0 commit comments

Comments
 (0)