Skip to content

Commit 670a531

Browse files
committed
examples: web-analytics use meta for human readable measures' titles
1 parent f96f179 commit 670a531

File tree

4 files changed

+17
-8
lines changed

4 files changed

+17
-8
lines changed

examples/web-analytics/dashboard-app/src/pages/CustomReportPage.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import React, { useState } from "react";
1+
import React, { useState, useEffect, useContext } from "react";
22
import { useParams } from "react-router-dom";
33
import { useQuery } from "@apollo/react-hooks";
44
import Button from "@material-ui/core/Button";
5+
import { CubeContext } from "@cubejs-client/react";
56
import Grid from "@material-ui/core/Grid";
67
import { GET_CUSTOM_REPORT } from "../graphql/queries";
78
import OverTimeChart from "../components/OverTimeChart";
@@ -11,13 +12,22 @@ import { Link } from "react-router-dom";
1112

1213
const CustomReportPage = ({ withTime }) => {
1314
const [activeMeasure, setActiveMeasure] = useState(null);
15+
const [meta, setMeta] = useState(null);
1416
const { id } = useParams();
17+
const cubejsApi = useContext(CubeContext).cubejsApi;
1518
const { loading, error, data } = useQuery(GET_CUSTOM_REPORT, {
1619
variables: {
1720
id: id
1821
},
1922
});
20-
if (loading || error) {
23+
useEffect(() => {
24+
(async function loadMeta() {
25+
const meta = await cubejsApi.meta();
26+
setMeta(meta);
27+
})();
28+
}, []);
29+
30+
if (loading || error || !meta) {
2131
return "Loading";
2232
}
2333

@@ -51,10 +61,10 @@ const CustomReportPage = ({ withTime }) => {
5161
title={
5262
measures.length > 1 ?
5363
<Dropdown
54-
value={finalActiveMeasure}
64+
value={meta.resolveMember(finalActiveMeasure, "measures").shortTitle}
5565
options={
5666
measures.reduce((out, measure) => {
57-
out[measure] = () => setActiveMeasure(measure)
67+
out[meta.resolveMember(measure, "measures").shortTitle] = () => setActiveMeasure(measure)
5868
return out;
5969
}, {})
6070
}

examples/web-analytics/dashboard-app/src/pages/CustomReportsBuilderPage.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ const useStyles = makeStyles(theme => ({
5555
}
5656
}));
5757

58-
const CustomReportsBuilderPage = ({ cubejsApi, history }) => {
58+
const CustomReportsBuilderPage = ({ history }) => {
5959
const { id } = useParams();
6060
const [addCustomReport] = useMutation(CREATE_CUSTOM_REPORT, {
6161
refetchQueries: [
@@ -92,7 +92,6 @@ const CustomReportsBuilderPage = ({ cubejsApi, history }) => {
9292
<QueryBuilder
9393
query={(data && data.customReport.query && JSON.parse(data.customReport.query)) || {}}
9494
wrapWithQueryRenderer={false}
95-
cubejsApi={cubejsApi}
9695
render={({
9796
measures, availableMeasures, updateMeasures,
9897
dimensions, availableDimensions, updateDimensions,

examples/web-analytics/dashboard-app/src/pages/ReportPage.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ const ReportPage = ({ report: Component }) => {
7171
useEffect(() => {
7272
setUserPreference('daterange', [beginDate, endDate]);
7373
setUserPreference('segment', segment);
74-
})
74+
}, [beginDate, endDate, segment])
7575

7676
return (
7777
<Grid

examples/web-analytics/dashboard-app/yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1074,7 +1074,7 @@
10741074
url-search-params-polyfill "^7.0.0"
10751075
uuid "^3.4.0"
10761076

1077-
"@cubejs-client/react@^0.18.7":
1077+
"@cubejs-client/react@^0.18.4":
10781078
version "0.18.4"
10791079
resolved "https://registry.yarnpkg.com/@cubejs-client/react/-/react-0.18.4.tgz#82637946d81d94dde16701f7759f10ff29e6be39"
10801080
integrity sha512-DVOs+UzQTte5bAGVnFJzNlYmPJLcGIap4jrsYIfaCBrf1D4QMgMg1jRU13Dg1AUH5IyKt/z4yxOjZ/OXXjAhGA==

0 commit comments

Comments
 (0)