Skip to content

Commit

Permalink
Location dimensions and fixed to custom reports
Browse files Browse the repository at this point in the history
  • Loading branch information
keydunov committed Mar 12, 2020
1 parent 4e6f4a3 commit d9b657b
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ const TypeToChartComponent = {
))}
</CartesianChart>
),
pie: ({ resultSet }) => (
pie: ({ resultSet, legend }) => (
<ResponsiveContainer width="100%" height={350}>
<PieChart>
<Pie
Expand All @@ -154,7 +154,7 @@ const TypeToChartComponent = {
<Cell key={index} fill={colors[index % colors.length]} />
))}
</Pie>
<Legend />
{ legend && <Legend layout={legend} align="right" /> }
<Tooltip />
</PieChart>
</ResponsiveContainer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import Chart from "../components/Chart";
const queries = {
topSources: {
chartType: 'pie',
legend: 'vertical',
query: {
measures: ['SessionUsers.usersCount'],
dimensions: ['SessionUsers.referrerSource'],
dimensions: ['SessionUsers.sourceMedium'],
timeDimensions: [{
dimension: 'SessionUsers.sessionStart'
}]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ const CustomReportPage = ({ withTime }) => {
granularity: 'day'
}]
};
const dataTableQuery = null;
const dataTableQuery = {
...query,
timeDimensions: [{
dimension: query.timeDimensions[0].dimension,
}]
};
return (
<>
<Grid item xs={12}>
Expand All @@ -44,7 +49,7 @@ const CustomReportPage = ({ withTime }) => {
/>
</Grid>
<Grid item xs={12}>
<DataTable query={query} />
<DataTable query={withTime({ query: dataTableQuery, chartType: 'table' })} />
</Grid>
</>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const CustomReportsBuilderPage = ({ cubejsApi, history }) => {
enableReinitialize
initialValues={{ title: title || (data && data.dashboardItem.name) || "", query: query }}
onSubmit={async values => {
await (id ? updateDashboardItem : addDashboardItem)({
const { data } = await (id ? updateDashboardItem : addDashboardItem)({
variables: {
id: id,
input: {
Expand All @@ -91,7 +91,7 @@ const CustomReportsBuilderPage = ({ cubejsApi, history }) => {
}
}
});
history.push("/custom-reports-overview");
history.push(`/custom-reports/${id || data.createDashboardItem.id}`);
}}
validationSchema={Yup.object().shape({
title: Yup.string().required("Required"),
Expand Down
9 changes: 9 additions & 0 deletions examples/web-analytics/schema/Events.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ cube(`Events`, {
br_lang,
br_name,
-- Location
geo_country,
geo_region,
geo_city,
geo_zipcode,
geo_latitude,
geo_longitude,
geo_region_name,
-- referrer
refr_urlhost || refr_urlpath AS referrer_url,
refr_urlscheme AS referrer_url_scheme,
Expand Down
41 changes: 35 additions & 6 deletions examples/web-analytics/schema/Sessions.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ cube(`Sessions`, {

measures: {
count: {
type: `count`
type: `count`,
title: `Sessions`
},

usersCount: {
Expand Down Expand Up @@ -119,11 +120,23 @@ cube(`Sessions`, {


// Audience
// Demographics
language: {
sql: `br_lang`,
type: `string`
},

country: {
sql: `geo_country`,
type: `string`
},

city: {
sql: `geo_city`,
type: `string`
},

// System
browser: {
sql: `br_name`,
type: `string`
Expand All @@ -145,13 +158,28 @@ cube(`Sessions`, {
},

referrerMedium: {
sql: `referrer_medium`,
type: `string`
type: `string`,
case: {
when: [
{ sql: `${CUBE}.referrer_medium != ''`, label: { sql: `${CUBE}.referrer_medium` } }
],
else: { label: '(none)' }
}
},

referrerSource: {
sql: `referrer_source`,
type: `string`
type: `string`,
case: {
when: [
{ sql: `${CUBE}.referrer_source != ''`, label: { sql: `${CUBE}.referrer_source` } }
],
else: { label: '(none)' }
}
},

sourceMedium: {
type: `string`,
sql: `concat(${CUBE.referrerSource}, " / ", ${CUBE.referrerMedium})`
}
},

Expand All @@ -177,7 +205,8 @@ cube(`SessionUsers`, {
session_id,
domain_userid,
session_index,
referrer_source
referrer_source,
referrer_medium
from ${Sessions.sql()}`,

preAggregations: {
Expand Down

0 comments on commit d9b657b

Please sign in to comment.