Skip to content

Commit 3de9d94

Browse files
marcgurneyThomas Rueckstiess
authored andcommitted
zero state for instances without collections
progress on istance properties static styling for instance properties in sidebar [wip] port, enterprise/community, reload missing zero state for instances without collections styling, changed default window size moved sampling-message into refine view
1 parent 449c36f commit 3de9d94

File tree

20 files changed

+340
-81
lines changed

20 files changed

+340
-81
lines changed

src/collection-stats/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ var CollectionStatsView = AmpersandView.extend({
3434
format: function(propertyName) {
3535
var value = this.model.get(propertyName) || 0;
3636
var precision = value <= 1000 ? '0' : '0.0';
37-
var format = propertyName.indexOf('_size') > -1 ? 'b' : 'a';
37+
var format = propertyName.indexOf('_size') > -1 ? ' b' : 'a';
3838
return numeral(value).format(precision + format);
3939
},
4040
derived: {

src/collection-stats/index.less

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,42 +4,59 @@
44
position: absolute;
55
right: 20px;
66
text-align: right;
7-
min-width: 450px;
7+
min-width: 520px;
88
}
99
.collection-stats {
1010
display: inline-block;
11+
position: relative;
1112
font-weight: 200;
1213
list-style: none;
13-
padding: 0 30px 0 0;
14-
margin: 11px 30px 0 0;
15-
border-right: 1px solid @gray7;
14+
padding: 0 20px 0 0;
15+
margin: 0 20px 0 0;
16+
17+
&::after {
18+
content: '';
19+
display: block;
20+
position: absolute;
21+
right: 0;
22+
top: 2px;
23+
width: 1px;
24+
height: 24px;
25+
background: @gray7;
26+
}
1627

1728
&:last-child {
18-
border-right: none;
1929
padding: 0;
2030
margin: 11px 0 0 0;
31+
32+
&::after {
33+
display: none;
34+
}
2135
}
2236
}
2337
.collection-stats-item {
2438
display: inline-block;
25-
margin-right: 10px;
39+
margin-right: 12px;
2640

2741
&:last-child {
2842
margin-right: 0;
2943
}
3044
}
3145
.collection-stats-primary-label {
46+
display: inline-block;
3247
text-transform: uppercase;
33-
letter-spacing: 1px;
3448
font-size: 12px;
3549
color: @gray3;
50+
margin-right: 5px;
3651
}
3752
.collection-stats-primary-value {
38-
font-size: 36px;
39-
line-height: 36px;
53+
display: inline-block;
54+
font-size: 24px;
55+
line-height: 24px;
4056
}
4157
.collection-stats-label {
4258
font-size: 11px;
59+
line-height: 11px;
4360
color: @gray3;
4461
}
4562
.collection-stats-value {

src/field-list/field.jade

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
.schema-field.schema-field-basic
2-
hr.field-divider
32
.row
43
.col-sm-4
54
.schema-field-name
@@ -10,3 +9,4 @@
109
div(data-hook='minichart-container')
1110
div(data-hook='fields-subview')
1211
div(data-hook='arrayfields-subview')
12+
hr.field-divider

src/home/collection.jade

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
.collection-view.clearfix
2-
div(data-hook='sampling-message-subview')
32
div.modal.fade(tabindex='-1', role='dialog', arialabelledby='Share Schema Confirmation', data-hook='share-schema-confirmation')
43
div.modal-dialog.modal-sm
54
.modal-content

src/home/collection.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ var CollectionStatsView = require('../collection-stats');
33
var FieldListView = require('../field-list');
44
var DocumentListView = require('../document-list');
55
var RefineBarView = require('../refine-view');
6-
var SamplingMessageView = require('../sampling-message');
76
var MongoDBCollection = require('../models/mongodb-collection');
87
var SampledSchema = require('../models/sampled-schema');
98
var app = require('ampersand-app');
@@ -161,15 +160,6 @@ var MongoDBCollectionView = View.extend({
161160
collection: this.schema.documents
162161
});
163162
}
164-
},
165-
sampling_message: {
166-
hook: 'sampling-message-subview',
167-
prepareView: function(el) {
168-
return new SamplingMessageView({
169-
el: el,
170-
parent: this
171-
});
172-
}
173163
}
174164
}
175165
});

src/home/index.jade

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,9 @@
44
div.report-zero-state(data-hook='report-zero-state')
55
img(src='images/zero-state-arrow-collections.png', width="110")
66
span Choose a collection to analyze
7+
div.no-collections-zero-state(data-hook='no-collections-zero-state')
8+
span
9+
|The MongoDB instance you are connected to does not contain any collections.&nbsp;
10+
a.show-connect-window Connect to another instance
11+
|.
712
div(data-hook='sidebar')

src/home/index.js

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,30 @@ var HomeView = View.extend({
1616
allowNull: true,
1717
default: null
1818
},
19-
showZeroState: {
19+
showDefaultZeroState: {
2020
type: 'boolean',
21-
default: true
21+
default: false
22+
},
23+
showNoCollectionsZeroState: {
24+
type: 'boolean',
25+
default: false
2226
}
2327
},
2428
bindings: {
25-
showZeroState: {
29+
showDefaultZeroState: {
2630
hook: 'report-zero-state',
2731
type: 'booleanClass',
2832
no: 'hidden'
33+
},
34+
showNoCollectionsZeroState: {
35+
hook: 'no-collections-zero-state',
36+
type: 'booleanClass',
37+
no: 'hidden'
2938
}
3039
},
40+
events: {
41+
'click a.show-connect-window': 'onClickShowConnectWindow'
42+
},
3143
initialize: function() {
3244
this.listenTo(app.instance, 'sync', this.onInstanceFetched);
3345
this.listenTo(app.connection, 'change:name', this.updateTitle);
@@ -36,6 +48,11 @@ var HomeView = View.extend({
3648
app.instance.fetch();
3749
},
3850
onInstanceFetched: function() {
51+
if(_.size(app.instance.collections) === 0) {
52+
this.showNoCollectionsZeroState = true;
53+
} else {
54+
this.showDefaultZeroState = true;
55+
}
3956
if (!this.ns) {
4057
app.instance.collections.unselectAll();
4158
} else {
@@ -58,11 +75,14 @@ var HomeView = View.extend({
5875

5976
this.ns = model.getId();
6077
this.updateTitle(model);
61-
this.showZeroState = false;
78+
this.showDefaultZeroState = false;
6279
app.navigate(format('schema/%s', model.getId()), {
6380
silent: true
6481
});
6582
},
83+
onClickShowConnectWindow: function() {
84+
// code to close current connection window and open connect dialog
85+
},
6686
template: require('./index.jade'),
6787
subviews: {
6888
_collection: {

src/home/index.less

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
}
5454

5555
.report-zero-state {
56-
margin: 124px 0 0 20px;
56+
margin: 190px 0 0 20px;
5757

5858
img {
5959
margin-bottom: 7px;
@@ -65,13 +65,28 @@
6565
margin-left: 15px;
6666
}
6767
}
68+
.no-collections-zero-state {
69+
text-align: center;
70+
margin-top: 200px;
71+
padding: 50px 75px;
72+
font-size: 18px;
73+
color: @gray4;
74+
font-weight: 200;
75+
76+
a {
77+
cursor: pointer;
78+
}
79+
}
6880

6981
.collection-view {
7082
header {
71-
padding: 12px 25px;
83+
padding: 12px 25px 0;
7284
position: relative;
7385
z-index: 1;
7486
}
87+
h1 {
88+
margin-top: 0;
89+
}
7590
.column-container {
7691
display: flex;
7792
overflow: hidden;

src/models/sampled-schema.js

Lines changed: 85 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,24 @@ var filterableMixin = require('ampersand-collection-filterable');
66
var SampledDocumentCollection = require('./sampled-document-collection');
77
var es = require('event-stream');
88
var debug = require('debug')('scout:models:schema');
9+
var debugMetrics = require('debug')('scout:metrics');
910
var app = require('ampersand-app');
1011

12+
// @todo: stub for metrics module. currently just logs debug messages with scout:metrics marker
13+
var metrics = {
14+
track: function(label, err, obj) {
15+
if (!obj) {
16+
obj = err;
17+
err = null;
18+
}
19+
if (err) {
20+
debugMetrics('metrics error: ', err, obj);
21+
} else {
22+
debugMetrics('metrics log: ', obj);
23+
}
24+
}
25+
};
26+
1127
/**
1228
* wrapping mongodb-schema's FieldCollection with a filterable mixin
1329
*/
@@ -25,6 +41,8 @@ module.exports = Schema.extend({
2541
}
2642
},
2743
session: {
44+
// total number of documents counted under the given query
45+
total: 'number',
2846
is_fetching: {
2947
type: 'boolean',
3048
default: false
@@ -96,43 +114,93 @@ module.exports = Schema.extend({
96114
var model = this;
97115
wrapError(this, options);
98116

99-
var parse = function(doc, cb) {
100-
model.parse(doc);
101-
cb(null, doc);
117+
var success = options.success;
118+
options.success = function(resp) {
119+
if (success) {
120+
success(model, resp, options);
121+
}
122+
model.trigger('sync');
102123
};
124+
var start = new Date();
125+
var timeAtFirstDoc;
126+
var erroredOnDocs = [];
103127

104-
var docs = [];
128+
// No results found
129+
var onEmpty = function() {
130+
model.is_fetching = false;
131+
model.documents.reset();
132+
model.documents.trigger('sync');
133+
options.success({});
134+
};
105135

136+
var docs = [];
106137
var addToDocuments = function(doc, cb) {
107138
docs.push(doc);
108139
cb();
109140
};
110141

142+
var parse = function(doc, cb) {
143+
if (!timeAtFirstDoc) {
144+
timeAtFirstDoc = new Date();
145+
}
146+
try {
147+
model.parse(doc);
148+
} catch (err) {
149+
erroredOnDocs.push(doc);
150+
metrics.track('Schema: Error: Parse', err, {
151+
doc: doc,
152+
schema: model.serialize()
153+
});
154+
}
155+
cb(null, doc);
156+
};
157+
111158
var onEnd = function(err) {
112159
model.is_fetching = false;
113160
if (err) {
161+
metrics.track('Schema: Error: End', err, {
162+
schema: model
163+
});
114164
return options.error(model, err);
115165
}
116166
model.documents.reset(docs);
117167
model.documents.trigger('sync');
118-
options.success({});
119-
};
120168

121-
var success = options.success;
122-
options.success = function(resp) {
123-
if (success) {
124-
success(model, resp, options);
125-
}
126-
model.trigger('sync');
169+
// @note (imlucas): Any other metrics? Feedback on `Schema *`?
170+
metrics.track('Schema: Complete', {
171+
Duration: new Date() - start,
172+
'Total Document Count': model.total,
173+
'Document Count': model.documents,
174+
'Errored Document Count': erroredOnDocs.length,
175+
'Time to First Doc': timeAtFirstDoc - start,
176+
'Schema Height': model.height, // # of top level keys
177+
'Schema Width': model.width, // max nesting depth
178+
'Schema Sparsity': model.sparsity // lots of fields missing or consistent
179+
});
180+
options.success({});
127181
};
128182

129183
model.trigger('request', {}, {}, options);
130184

131-
debug('creating sample stream');
132-
app.client.sample(model.ns, options)
133-
.pipe(es.map(parse))
134-
.pipe(es.map(addToDocuments))
135-
.pipe(es.wait(onEnd));
185+
app.client.count(model.ns, options, function(err, count) {
186+
if (err) {
187+
metrics.track('Schema: Error: Count', err, {
188+
schema: model
189+
});
190+
return options.error(model, err);
191+
}
192+
debug('options', options, 'count', count.count);
193+
model.total = count.count;
194+
if (model.total === 0) {
195+
return onEmpty();
196+
}
197+
198+
debug('creating sample stream');
199+
app.client.sample(model.ns, options)
200+
.pipe(es.map(parse))
201+
.pipe(es.map(addToDocuments))
202+
.pipe(es.wait(onEnd));
203+
});
136204
},
137205
serialize: function() {
138206
var res = this.getAttributes({

src/refine-view/index.jade

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
.refine-view-container: .row: .col-md-12
2-
form: .input-group(data-hook='refine-input-group')
1+
.refine-view-container
2+
.query-input-container: .row: .col-md-12: form: .input-group(data-hook='refine-input-group')
33
input.form-control.input-sm(type='text', data-hook='refine-input')
44
span.input-group-btn
55
button.btn.btn-info.btn-sm(type='button', data-hook='refine-button') Apply
66
button.btn.btn-default.btn-sm(type='button', data-hook='reset-button') Reset
7+
div(data-hook='sampling-message-subview')
8+
9+
//- .sampling-message
10+
//- span Query returned 9867 documents. This report is based on a sample of 1000 documents (10.13%).

0 commit comments

Comments
 (0)