Skip to content

Commit f365c5f

Browse files
committed
Update queries in reports
1 parent 840cefb commit f365c5f

File tree

6 files changed

+28
-44
lines changed

6 files changed

+28
-44
lines changed

frontend/src/modules/widget/components/activity/widget-activities-kpi.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,10 @@ const widgets = computed(() => [
8989
{
9090
title: `${ACTIVITIES_KPI_WIDGET.name} today`,
9191
query: query(
92-
ONE_DAY_PERIOD_FILTER,
92+
{
93+
...ONE_DAY_PERIOD_FILTER,
94+
value: 2,
95+
},
9396
DAILY_GRANULARITY_FILTER,
9497
),
9598
period: 'day',

frontend/src/modules/widget/components/activity/widget-total-activities.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
:chart-options="widgetChartOptions"
5151
:granularity="granularity"
5252
:is-grid-min-max="true"
53+
:pivot-modifier="(pivot) => pivot.splice(0, 1)"
5354
:show-min-as-value="true"
5455
/>
5556
</div>

frontend/src/modules/widget/components/member/widget-active-members-kpi.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,10 @@ const widgets = computed(() => [
130130
{
131131
title: `${ACTIVE_MEMBERS_KPI_WIDGET.name} today`,
132132
query: query(
133-
ONE_DAY_PERIOD_FILTER,
133+
{
134+
...ONE_DAY_PERIOD_FILTER,
135+
value: 2,
136+
},
134137
DAILY_GRANULARITY_FILTER,
135138
),
136139
period: 'day',

frontend/src/modules/widget/components/member/widget-total-members.vue

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,13 @@
4646
</div>
4747
<div class="col-span-7 chart">
4848
<app-widget-area
49-
:result-set="chartResultSet(resultSet)"
49+
:result-set="resultSet"
5050
:datasets="datasets"
5151
:chart-options="widgetChartOptions"
5252
:granularity="granularity"
5353
:is-grid-min-max="true"
5454
:show-min-as-value="true"
55+
:pivot-modifier="(pivot) => pivot.splice(0, 1)"
5556
@on-view-more-click="onViewMoreClick"
5657
/>
5758
</div>
@@ -78,8 +79,6 @@
7879
</app-widget-api-drawer>
7980
</template>
8081
<script setup>
81-
import moment from 'moment';
82-
import cloneDeep from 'lodash/cloneDeep';
8382
import { ref, computed, defineProps } from 'vue';
8483
import { QueryRenderer } from '@cubejs-client/vue3';
8584
import { SEVEN_DAYS_PERIOD_FILTER } from '@/modules/widget/widget-constants';
@@ -164,35 +163,6 @@ const kpiPreviousValue = (resultSet) => {
164163
return Number(data[0]['Members.cumulativeCount']) || 0;
165164
};
166165
167-
const spliceFirstValue = (data) => cloneDeep(data).reduce((acc, item, index) => {
168-
if (index !== 0) {
169-
acc.push({
170-
...item,
171-
});
172-
}
173-
return acc;
174-
}, []);
175-
176-
const chartResultSet = (resultSet) => {
177-
const clone = cloneDeep(resultSet);
178-
179-
// We'll be excluding the first data point, since it's related to the last period
180-
clone.loadResponses[0].data = spliceFirstValue(
181-
clone.loadResponses[0].data,
182-
);
183-
184-
// Then we also fix the first entry of the dateRange
185-
clone.loadResponses[0].query.timeDimensions[0].dateRange[0] = moment(
186-
clone.loadResponses[0].query.timeDimensions[0]
187-
.dateRange[0],
188-
)
189-
.utc()
190-
.add(1, 'day')
191-
.format('YYYY-MM-DD');
192-
193-
return clone;
194-
};
195-
196166
// Fetch function to pass to detail drawer
197167
const getTotalMembers = async ({ pagination }) => {
198168
const res = await MemberService.listMembers({

frontend/src/modules/widget/components/shared/widget-area.vue

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
<script setup>
1414
import {
15-
computed, defineEmits, defineProps, onMounted, ref,
15+
computed, onMounted, ref,
1616
} from 'vue';
1717
import cloneDeep from 'lodash/cloneDeep';
1818
import { externalTooltipHandler } from '@/modules/report/tooltip';
@@ -46,6 +46,10 @@ const props = defineProps({
4646
type: Boolean,
4747
default: false,
4848
},
49+
pivotModifier: {
50+
type: Function,
51+
default: () => {},
52+
},
4953
});
5054
5155
const highestValue = ref(0);
@@ -103,6 +107,11 @@ const buildSeriesDataset = (d, index) => {
103107
const series = (resultSet) => {
104108
// For line & area charts
105109
const pivot = resultSet.chartPivot();
110+
111+
if (props.pivotModifier) {
112+
props.pivotModifier(pivot);
113+
}
114+
106115
const computedSeries = [];
107116
108117
if (resultSet.loadResponses.length > 0) {

frontend/src/modules/widget/widget-queries.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export const TOTAL_ACTIVE_MEMBERS_QUERY = ({
102102
dateRange: [
103103
moment()
104104
.utc()
105-
.subtract(period.value, period.granularity)
105+
.subtract(period.granularity === 'day' ? period.value - 1 : period.value, period.granularity)
106106
.format('YYYY-MM-DD'),
107107
moment().utc().format('YYYY-MM-DD'),
108108
],
@@ -128,7 +128,7 @@ export const TOTAL_ACTIVE_RETURNING_MEMBERS_QUERY = ({
128128
dateRange: [
129129
moment()
130130
.utc()
131-
.subtract(period.value, period.granularity)
131+
.subtract(period.granularity === 'day' ? period.value - 1 : period.value, period.granularity)
132132
.format('YYYY-MM-DD'),
133133
moment().utc().format('YYYY-MM-DD'),
134134
],
@@ -166,9 +166,8 @@ export const TOTAL_MEMBERS_QUERY = ({
166166
const end = moment().utc().format('YYYY-MM-DD');
167167
const start = moment()
168168
.utc()
169-
.subtract(periodValue.value, periodValue.granularity)
170169
// we're subtracting one more day, to get the last value of the previous period within the same request
171-
.subtract(1, 'day')
170+
.subtract(periodValue.value, periodValue.granularity)
172171
.format('YYYY-MM-DD');
173172

174173
return [start, end];
@@ -285,7 +284,7 @@ export const ACTIVITIES_QUERY = ({
285284
dateRange: [
286285
moment()
287286
.utc()
288-
.subtract(period.value, period.granularity)
287+
.subtract(period.granularity === 'day' ? period.value - 1 : period.value, period.granularity)
289288
.format('YYYY-MM-DD'),
290289
moment().utc().format('YYYY-MM-DD'),
291290
],
@@ -314,7 +313,7 @@ export const LEADERBOARD_ACTIVITIES_TYPES_QUERY = ({
314313
dateRange: [
315314
moment()
316315
.utc()
317-
.subtract(period.value, period.granularity)
316+
.subtract(period.granularity === 'day' ? period.value - 1 : period.value, period.granularity)
318317
.format('YYYY-MM-DD'),
319318
moment().utc().format('YYYY-MM-DD'),
320319
],
@@ -340,7 +339,7 @@ export const LEADERBOARD_ACTIVITIES_COUNT_QUERY = ({
340339
dateRange: [
341340
moment()
342341
.utc()
343-
.subtract(period.value, period.granularity)
342+
.subtract(period.granularity === 'day' ? period.value - 1 : period.value, period.granularity)
344343
.format('YYYY-MM-DD'),
345344
moment().utc().format('YYYY-MM-DD'),
346345
],
@@ -365,9 +364,8 @@ export const TOTAL_ACTIVITIES_QUERY = ({
365364
const end = moment().utc().format('YYYY-MM-DD');
366365
const start = moment()
367366
.utc()
368-
.subtract(periodValue.value, periodValue.granularity)
369367
// we're subtracting one more day, to get the last value of the previous period within the same request
370-
.subtract(1, 'day')
368+
.subtract(periodValue.value, periodValue.granularity)
371369
.format('YYYY-MM-DD');
372370

373371
return [start, end];

0 commit comments

Comments
 (0)