| 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211 |
1x
1x
1x
1x
1x
1x
1x
1x
| import React from 'react';
import PropTypes from 'prop-types';
import styled, { css } from 'styled-components';
import { Table as SummaryTable, Title as SummaryTitle } from '@bufferapp/summary-table';
import { Table as HashtagsTable, Title as HashtagsTitle } from '@bufferapp/hashtags-table';
import { Table as PostsSummary, Title as PostsSummaryTitle } from '@bufferapp/posts-summary-table';
import { Table as AverageTable, Title as AverageTitle } from '@bufferapp/average-table';
import { Table as DemographicOverview, Title as DemographicOverviewTitle } from '@bufferapp/demographic-overview';
import { Chart as DemographicGenderAge, Title as DemographicGenderAgeTitle } from '@bufferapp/demographic-gender-age';
import { Chart as DemographicCities, Title as DemographicCitiesTitle } from '@bufferapp/demographic-cities';
import { Chart as DemographicCountries, Title as DemographicCountriesTitle } from '@bufferapp/demographic-countries';
import { Title as ContextualTitle } from '@bufferapp/contextual-compare';
import { Table as PostsTable, Title as PostsTitle } from '@bufferapp/posts-table';
import { Chart as CompareChart, Title as CompareTitle } from '@bufferapp/compare-chart';
import { Title as AudienceTitle } from '@bufferapp/audience-chart';
import { Chart as ComparisonChart, Title as ComparisonTitle } from '@bufferapp/comparison-chart';
import { Table as AggregateHeader, Title as AggregateHeaderTitle } from '@bufferapp/aggregate-header';
import { Table as AggregateMetric, Title as AggregateMetricTitle } from '@bufferapp/aggregated-metric';
import { Table as AnswersTable, Title as AnswersTitle } from '@bufferapp/answers-summary';
import { BreakdownContent as StoriesBreakdown, Title as StoriesBreakdownTitle } from '@bufferapp/stories-breakdown';
import { RecentPostsTable, Title as RecentPostsTitle } from '@bufferapp/recent-posts';
import { ChartContent as HourlyChart, Title as HourlyTitle } from '@bufferapp/hourly-chart';
import { Content as AnswersChart, Title as AnswersChartTitle } from '@bufferapp/answers-chart';
import { ErrorBoundary, CommonChart } from '@bufferapp/analyze-shared-components';
import ChartEditButtons from '../ChartEditButtons';
import ProfileLegend from '../ProfileLegend';
import MultiProfileLegends from '../MultiProfileLegends';
const CHARTS = {
'summary-table': {
chart: SummaryTable,
title: SummaryTitle,
},
'hashtags-table': {
chart: HashtagsTable,
title: HashtagsTitle,
},
'posts-summary': {
chart: PostsSummary,
title: PostsSummaryTitle,
},
average: {
chart: AverageTable,
title: AverageTitle,
},
posts: {
chart: PostsTable,
title: PostsTitle,
},
'contextual-compare': {
chart: CommonChart,
title: ContextualTitle,
},
compare: {
chart: CompareChart,
title: CompareTitle,
},
audience: {
chart: CommonChart,
title: AudienceTitle,
},
comparison: {
chart: ComparisonChart,
title: ComparisonTitle,
},
'hourly-engagements': {
chart: HourlyChart,
title: HourlyTitle,
},
'aggregate-header': {
chart: AggregateHeader,
title: AggregateHeaderTitle,
},
'aggregated-metric': {
chart: AggregateMetric,
title: AggregateMetricTitle,
},
'demographic-overview': {
chart: DemographicOverview,
title: DemographicOverviewTitle,
},
'demographic-gender-age': {
chart: DemographicGenderAge,
title: DemographicGenderAgeTitle,
},
'demographic-cities': {
chart: DemographicCities,
title: DemographicCitiesTitle,
},
'demographic-countries': {
chart: DemographicCountries,
title: DemographicCountriesTitle,
},
'answers-summary': {
chart: AnswersTable,
title: AnswersTitle,
},
'answers-chart': {
chart: AnswersChart,
title: AnswersChartTitle,
},
'stories-breakdown': {
chart: StoriesBreakdown,
title: StoriesBreakdownTitle,
},
'recent-posts': {
chart: RecentPostsTable,
title: RecentPostsTitle,
},
};
const Separator = styled.section`
position: relative;
background: #FFFFFF;
border: 1px solid #cdd7df;
border-radius: 3px;
padding: 1.5rem 2rem 1rem;
margin: 1.5rem 2rem;
page-break-inside: avoid;
&:last-of-type {
margin-bottom: 0;
}
aside {
opacity: 0;
}
&:hover aside {
opacity: 1;
}
${props => props.exporting && css`
margin-top: 2rem;
margin-bottom: 2rem;
`}
`;
const TitleWrapper = styled.div`
color: #333B43;
padding: 0.5rem 0.4rem 0.1rem 0;
`;
const ProfileWrapper = styled.div`
padding: 0.4rem 0.1rem 0.25rem;
`;
const Header = styled.div`
margin: 0 0 1rem;
`;
const ChartFactory = ({ charts, moveUp, moveDown, deleteChart, exporting }) =>
charts.map((chart, index) => (
<ErrorBoundary>
<Separator key={chart._id} exporting={exporting}>
<Header>
<TitleWrapper>
{React.createElement(CHARTS[chart.chart_id].title, {
...chart,
forReport: true,
})}
{!exporting && <ChartEditButtons
moveUp={moveUp}
moveDown={moveDown}
deleteChart={deleteChart}
id={chart._id}
first={index === 0}
last={index === charts.length - 1}
/>}
</TitleWrapper>
<ProfileWrapper>
{chart.profile_id && !chart.profileIds &&
<ProfileLegend
profile={chart.profile}
/>
}
{chart.profileIds &&
<MultiProfileLegends
profiles={chart.profiles}
comparedProfileIds={chart.profileIds}
/>
}
</ProfileWrapper>
</Header>
{React.createElement(CHARTS[chart.chart_id].chart, {
...chart,
forReport: true,
timezone: chart.profile.timezone,
service: chart.profile.service,
exporting,
})}
</Separator>
</ErrorBoundary>
));
ChartFactory.propTypes = {
charts: PropTypes.arrayOf(PropTypes.shape({
profile: PropTypes.shape({
service: PropTypes.string,
username: PropTypes.string,
}),
chart_id: PropTypes.string,
})),
moveUp: PropTypes.func.isRequired,
moveDown: PropTypes.func.isRequired,
deleteChart: PropTypes.func.isRequired,
};
export default ChartFactory;
|