Skip to content

Commit cdb2e41

Browse files
committed
feat: add filter per space in dashboard
1 parent 4af66bc commit cdb2e41

File tree

7 files changed

+154
-146
lines changed

7 files changed

+154
-146
lines changed

src/components/dashboard/ActionBarChart.js

+7-28
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React, { PureComponent } from 'react';
2-
import { connect } from 'react-redux';
32
import { withTranslation } from 'react-i18next';
43
import _ from 'lodash';
54
import PropTypes from 'prop-types';
@@ -15,7 +14,6 @@ import {
1514
} from 'recharts';
1615
import Typography from '@material-ui/core/Typography';
1716
import { withStyles } from '@material-ui/core';
18-
import { getDatabase, setDatabase } from '../../actions';
1917
import Loader from '../common/Loader';
2018
import Styles from '../../Styles';
2119

@@ -47,29 +45,26 @@ class ActionBarChart extends PureComponent {
4745
i18n: PropTypes.shape({
4846
changeLanguage: PropTypes.func.isRequired,
4947
}).isRequired,
50-
database: PropTypes.shape({
51-
user: PropTypes.object,
52-
spaces: PropTypes.array,
53-
actions: PropTypes.array,
54-
}),
5548
t: PropTypes.func.isRequired,
49+
actions: PropTypes.arrayOf(PropTypes.object),
50+
spaces: PropTypes.arrayOf(PropTypes.object),
5651
};
5752

5853
static defaultProps = {
59-
database: {},
54+
actions: [],
55+
spaces: [],
6056
};
6157

6258
render() {
63-
const { database, theme, t } = this.props;
59+
const { spaces, theme, t, actions } = this.props;
6460
const {
6561
palette: { primary, type },
6662
} = theme;
6763

68-
if (!database || _.isEmpty(database)) {
64+
if (!actions || _.isEmpty(actions) || !spaces || _.isEmpty(spaces)) {
6965
return <Loader />;
7066
}
7167

72-
const { spaces, actions } = database;
7368
const data =
7469
// group actions by space id
7570
Object.entries(_.groupBy(actions, 'spaceId'))
@@ -114,23 +109,7 @@ class ActionBarChart extends PureComponent {
114109
}
115110
}
116111

117-
const mapStateToProps = ({ Developer }) => ({
118-
database: Developer.get('database'),
119-
});
120-
121-
const mapDispatchToProps = {
122-
dispatchGetDatabase: getDatabase,
123-
dispatchSetDatabase: setDatabase,
124-
};
125-
126-
const ConnectedComponent = connect(
127-
mapStateToProps,
128-
mapDispatchToProps
129-
)(ActionBarChart);
130-
131-
const StyledComponent = withStyles(Styles, { withTheme: true })(
132-
ConnectedComponent
133-
);
112+
const StyledComponent = withStyles(Styles, { withTheme: true })(ActionBarChart);
134113

135114
const TranslatedComponent = withTranslation()(StyledComponent);
136115

src/components/dashboard/ActionEditor.js

+13-18
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import PropTypes from 'prop-types';
66
import Typography from '@material-ui/core/Typography';
77
import { withTranslation } from 'react-i18next';
88
import { withStyles } from '@material-ui/core';
9-
import { getDatabase, setDatabase } from '../../actions';
9+
import { getDatabase } from '../../actions';
1010
import Loader from '../common/Loader';
1111
import Styles from '../../Styles';
12-
import SampleDatabase from '../../data/sample.json';
12+
import { FILTER_ALL_SPACE_ID } from '../../config/constants';
1313

1414
export class ActionEditor extends Component {
1515
static propTypes = {
@@ -18,44 +18,40 @@ export class ActionEditor extends Component {
1818
button: PropTypes.string.isRequired,
1919
}).isRequired,
2020
dispatchGetDatabase: PropTypes.func.isRequired,
21-
dispatchSetDatabase: PropTypes.func.isRequired,
2221
database: PropTypes.shape({
2322
user: PropTypes.object,
24-
spaces: PropTypes.array,
25-
actions: PropTypes.array,
23+
spaces: PropTypes.arrayOf(PropTypes.object),
24+
actions: PropTypes.arrayOf(PropTypes.object),
2625
}),
26+
spaceId: PropTypes.string,
2727
};
2828

2929
static defaultProps = {
3030
database: {},
31+
spaceId: FILTER_ALL_SPACE_ID,
3132
};
3233

3334
componentDidMount() {
3435
const { dispatchGetDatabase } = this.props;
3536
dispatchGetDatabase();
3637
}
3738

38-
handleEdit = ({ updated_src: updatedSrc }) => {
39-
const { dispatchSetDatabase } = this.props;
40-
dispatchSetDatabase(updatedSrc);
41-
};
42-
43-
handleUseSampleDatabase = () => {
44-
const { dispatchSetDatabase } = this.props;
45-
dispatchSetDatabase(SampleDatabase);
46-
};
47-
4839
render() {
49-
const { database, t } = this.props;
40+
const { database, t, spaceId } = this.props;
5041

5142
if (!database || _.isEmpty(database)) {
5243
return <Loader />;
5344
}
5445

46+
let { actions } = database;
47+
if (spaceId !== FILTER_ALL_SPACE_ID) {
48+
actions = actions.filter(({ spaceId: id }) => id === spaceId);
49+
}
50+
5551
return (
5652
<div>
5753
<Typography variant="h6">{t('View Action Database')}</Typography>
58-
<ReactJson name="actions" collapsed src={database.actions} />
54+
<ReactJson name="actions" collapsed src={actions} />
5955
</div>
6056
);
6157
}
@@ -67,7 +63,6 @@ const mapStateToProps = ({ Developer }) => ({
6763

6864
const mapDispatchToProps = {
6965
dispatchGetDatabase: getDatabase,
70-
dispatchSetDatabase: setDatabase,
7166
};
7267

7368
const StyledComponent = withStyles(Styles, { withTheme: true })(ActionEditor);

src/components/dashboard/ActionLineChart.js

+5-26
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React, { PureComponent } from 'react';
2-
import { connect } from 'react-redux';
32
import { withTranslation } from 'react-i18next';
43
import PropTypes from 'prop-types';
54
import {
@@ -14,7 +13,6 @@ import {
1413
import _ from 'lodash';
1514
import { withStyles } from '@material-ui/core';
1615
import Typography from '@material-ui/core/Typography';
17-
import { getDatabase, setDatabase } from '../../actions';
1816
import Loader from '../common/Loader';
1917
import Styles from '../../Styles';
2018

@@ -46,16 +44,12 @@ class ActionLineChart extends PureComponent {
4644
i18n: PropTypes.shape({
4745
changeLanguage: PropTypes.func.isRequired,
4846
}).isRequired,
49-
database: PropTypes.shape({
50-
user: PropTypes.object,
51-
spaces: PropTypes.array,
52-
actions: PropTypes.array,
53-
}),
5447
t: PropTypes.func.isRequired,
48+
actions: PropTypes.arrayOf(PropTypes.object),
5549
};
5650

5751
static defaultProps = {
58-
database: {},
52+
actions: [],
5953
};
6054

6155
formatDate = date => {
@@ -64,16 +58,15 @@ class ActionLineChart extends PureComponent {
6458
};
6559

6660
render() {
67-
const { database, theme, t } = this.props;
61+
const { theme, t, actions } = this.props;
6862
const {
6963
palette: { primary, type },
7064
} = theme;
7165

72-
if (!database || _.isEmpty(database)) {
66+
if (!actions || _.isEmpty(actions)) {
7367
return <Loader />;
7468
}
7569

76-
const { actions } = database;
7770
const dataWithDateFormatted = actions.map(action => ({
7871
date: [this.formatDate(action.createdAt)],
7972
data: action.data,
@@ -125,22 +118,8 @@ class ActionLineChart extends PureComponent {
125118
}
126119
}
127120

128-
const mapStateToProps = ({ Developer }) => ({
129-
database: Developer.get('database'),
130-
});
131-
132-
const mapDispatchToProps = {
133-
dispatchGetDatabase: getDatabase,
134-
dispatchSetDatabase: setDatabase,
135-
};
136-
137-
const ConnectedComponent = connect(
138-
mapStateToProps,
139-
mapDispatchToProps
140-
)(ActionLineChart);
141-
142121
const StyledComponent = withStyles(Styles, { withTheme: true })(
143-
ConnectedComponent
122+
ActionLineChart
144123
);
145124
const TranslatedComponent = withTranslation()(StyledComponent);
146125

src/components/dashboard/ActionPieChart.js

+5-28
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import React, { PureComponent } from 'react';
22
import { PieChart, Pie, Cell, ResponsiveContainer, Tooltip } from 'recharts';
3-
import { connect } from 'react-redux';
43
import { withTranslation } from 'react-i18next';
54
import _ from 'lodash';
65
import PropTypes from 'prop-types';
76
import { withStyles } from '@material-ui/core';
87
import Typography from '@material-ui/core/Typography';
9-
import { getDatabase, setDatabase } from '../../actions';
108
import Loader from '../common/Loader';
119

1210
const COLORS = ['#0088FE', '#00C49F', '#FFBB28', '#FF8042'];
@@ -87,16 +85,12 @@ class ActionPieChart extends PureComponent {
8785
i18n: PropTypes.shape({
8886
changeLanguage: PropTypes.func.isRequired,
8987
}).isRequired,
90-
database: PropTypes.shape({
91-
user: PropTypes.object,
92-
spaces: PropTypes.array,
93-
actions: PropTypes.array,
94-
}),
9588
t: PropTypes.func.isRequired,
89+
actions: PropTypes.arrayOf(PropTypes.object),
9690
};
9791

9892
static defaultProps = {
99-
database: {},
93+
actions: [],
10094
};
10195

10296
renderCustomizedLabel = ({
@@ -125,13 +119,12 @@ class ActionPieChart extends PureComponent {
125119
};
126120

127121
render() {
128-
const { database, classes, t } = this.props;
122+
const { actions, classes, t } = this.props;
129123

130-
if (!database || _.isEmpty(database)) {
124+
if (!actions || _.isEmpty(actions)) {
131125
return <Loader />;
132126
}
133127

134-
const { actions } = database;
135128
const data =
136129
// group actions by space id
137130
Object.entries(_.groupBy(actions, 'verb'))
@@ -171,23 +164,7 @@ class ActionPieChart extends PureComponent {
171164
}
172165
}
173166

174-
const mapStateToProps = ({ Developer }) => ({
175-
database: Developer.get('database'),
176-
});
177-
178-
const mapDispatchToProps = {
179-
dispatchGetDatabase: getDatabase,
180-
dispatchSetDatabase: setDatabase,
181-
};
182-
183-
const ConnectedComponent = connect(
184-
mapStateToProps,
185-
mapDispatchToProps
186-
)(ActionPieChart);
187-
188-
const StyledComponent = withStyles(styles, { withTheme: true })(
189-
ConnectedComponent
190-
);
167+
const StyledComponent = withStyles(styles, { withTheme: true })(ActionPieChart);
191168

192169
const TranslatedComponent = withTranslation()(StyledComponent);
193170

src/components/dashboard/ActionTotalCount.js

+5-33
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@ import React, { PureComponent } from 'react';
22
import PropTypes from 'prop-types';
33
import { withStyles } from '@material-ui/core';
44
import { withTranslation } from 'react-i18next';
5-
import { connect } from 'react-redux';
65
import Typography from '@material-ui/core/Typography';
76
import Grid from '@material-ui/core/Grid';
87
import CountUp from 'react-countup';
98
import _ from 'lodash';
10-
import { getDatabase, setDatabase } from '../../actions';
119
import Loader from '../common/Loader';
1210

1311
const styles = () => ({
@@ -20,35 +18,24 @@ const styles = () => ({
2018

2119
class ActionTotalCount extends PureComponent {
2220
static propTypes = {
23-
database: PropTypes.shape({
24-
user: PropTypes.object,
25-
spaces: PropTypes.array,
26-
actions: PropTypes.array,
27-
}),
28-
dispatchGetDatabase: PropTypes.func.isRequired,
21+
actions: PropTypes.arrayOf(PropTypes.object),
2922
t: PropTypes.func.isRequired,
3023
classes: PropTypes.shape({
3124
actionCounter: PropTypes.string.isRequired,
3225
}).isRequired,
3326
};
3427

3528
static defaultProps = {
36-
database: {},
29+
actions: [],
3730
};
3831

39-
componentDidMount() {
40-
const { dispatchGetDatabase } = this.props;
41-
dispatchGetDatabase();
42-
}
43-
4432
render() {
45-
const { database, classes, t } = this.props;
33+
const { classes, t, actions } = this.props;
4634

47-
if (!database || _.isEmpty(database)) {
35+
if (!actions || _.isEmpty(actions)) {
4836
return <Loader />;
4937
}
5038

51-
const { actions } = database;
5239
const count = actions.length;
5340

5441
return (
@@ -61,23 +48,8 @@ class ActionTotalCount extends PureComponent {
6148
);
6249
}
6350
}
64-
65-
const mapStateToProps = ({ Developer }) => ({
66-
database: Developer.get('database'),
67-
});
68-
69-
const mapDispatchToProps = {
70-
dispatchGetDatabase: getDatabase,
71-
dispatchSetDatabase: setDatabase,
72-
};
73-
74-
const ConnectedComponent = connect(
75-
mapStateToProps,
76-
mapDispatchToProps
77-
)(ActionTotalCount);
78-
7951
const StyledComponent = withStyles(styles, { withTheme: true })(
80-
ConnectedComponent
52+
ActionTotalCount
8153
);
8254

8355
const TranslatedComponent = withTranslation()(StyledComponent);

0 commit comments

Comments
 (0)