forked from parse-community/parse-dashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSchemaOverview.react.js
More file actions
74 lines (69 loc) · 2.32 KB
/
SchemaOverview.react.js
File metadata and controls
74 lines (69 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
* Copyright (c) 2016-present, Parse, LLC
* All rights reserved.
*
* This source code is licensed under the license found in the LICENSE file in
* the root directory of this source tree.
*/
import CategoryList from 'components/CategoryList/CategoryList.react';
import DashboardView from 'dashboard/DashboardView.react';
import React from 'react';
import SidebarAction from 'components/Sidebar/SidebarAction';
import subscribeTo from 'lib/subscribeTo';
import Toolbar from 'components/Toolbar/Toolbar.react';
import { ActionTypes } from 'lib/stores/SchemaStore';
import { SpecialClasses } from 'lib/Constants';
import stringCompare from 'lib/stringCompare';
import prettyNumber from 'lib/prettyNumber';
export default
@subscribeTo('Schema', 'schema')
class Browser extends DashboardView {
constructor() {
super();
this.section = 'Core';
this.subsection = 'Browser'
this.action = new SidebarAction('Create a class', () => this.setState({ showCreateClassDialog: true }));
this.state = {
counts: {},
};
}
componentWillMount() {
this.props.schema.dispatch(ActionTypes.FETCH);
}
renderSidebar() {
//TODO: refactor this to share code with Browser.react and actually fetch counts
let classes = this.props.schema.data.get('classes');
if (!classes) {
return null;
}
let special = [];
let categories = [];
classes.forEach((value, key) => {
let count = this.state.counts[key];
if (count === undefined) {
count = '';
} else if (count >= 1000) {
count = prettyNumber(count);
}
if (SpecialClasses.includes(key)) {
special.push({ name: key, id: key, count: count });
} else {
categories.push({ name: key, count: count });
}
});
special.sort((a, b) => stringCompare(a.name, b.name));
categories.sort((a, b) => stringCompare(a.name, b.name));
return (
<CategoryList
linkPrefix={'browser/'}
categories={special.concat(categories)} />
);
}
renderContent() {
return (
<div>
<Toolbar section='Schema' subsection='overview'/>
</div>
);
}
}