Skip to content

Commit 96d8cfd

Browse files
committed
Merge branch 'release/23.06.0'
2 parents 80b6411 + 03a28ab commit 96d8cfd

File tree

26 files changed

+933
-710
lines changed

26 files changed

+933
-710
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

7+
## [23.06.0] - 2023-03-27
8+
### Changed
9+
- Removed Keen dependencies
10+
711
## [23.05.0] - 2023-03-16
812
### Changed
913
- Fixed `ember-classic` deprecation
@@ -1917,6 +1921,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
19171921
### Added
19181922
- Quick Files
19191923

1924+
[23.05.0]: https://github.com/CenterForOpenScience/ember-osf-web/releases/tag/23.06.0
19201925
[23.05.0]: https://github.com/CenterForOpenScience/ember-osf-web/releases/tag/23.05.0
19211926
[23.04.0]: https://github.com/CenterForOpenScience/ember-osf-web/releases/tag/23.04.0
19221927
[23.03.0]: https://github.com/CenterForOpenScience/ember-osf-web/releases/tag/23.03.0

app/services/analytics.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import { assert, debug, runInDebug } from '@ember/debug';
33
import { action } from '@ember/object';
44
import RouterService from '@ember/routing/router-service';
5+
import RouteInfo from '@ember/routing/-private/route-info';
56
import Service, { inject as service } from '@ember/service';
67
import { waitFor } from '@ember/test-waiters';
78
import { restartableTask, waitForQueue } from 'ember-concurrency';
@@ -380,10 +381,11 @@ export default class Analytics extends Service {
380381
// for merging, ordered from root to leaf (so values from leafier
381382
// routes can override those from rootier routes)
382383
const metricsMetadatums = [];
383-
let currentRouteInfo = this.router.currentRoute;
384+
let currentRouteInfo: RouteInfo | null = this.router.currentRoute;
384385
while (currentRouteInfo) {
385-
if (currentRouteInfo.metadata?.osfMetrics) {
386-
metricsMetadatums.unshift(currentRouteInfo.metadata.osfMetrics);
386+
const { metadata } = currentRouteInfo as any;
387+
if (metadata && metadata.osfMetrics) {
388+
metricsMetadatums.unshift(metadata.osfMetrics);
387389
}
388390
currentRouteInfo = currentRouteInfo.parent;
389391
}

config/environment.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ declare const config: {
8080
status: string;
8181
keenUserId: string;
8282
keenSessionId: string;
83-
analyticsDismissAdblock: string;
8483
cookieConsent: string;
8584
newFeaturePopover: string;
8685
maintenance: string;

config/environment.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ module.exports = function(environment) {
147147
status: statusCookie,
148148
keenUserId: 'keenUserId',
149149
keenSessionId: 'keenSessionId',
150-
analyticsDismissAdblock: 'adBlockDismiss',
151150
cookieConsent: 'osf_cookieconsent',
152151
newFeaturePopover: 'metadataFeaturePopover',
153152
maintenance: 'maintenance',

lib/analytics-page/addon/application/controller.ts

Lines changed: 25 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -2,63 +2,38 @@ import Store from '@ember-data/store';
22
import Controller from '@ember/controller';
33
import { action, computed } from '@ember/object';
44
import { reads } from '@ember/object/computed';
5+
import RouterService from '@ember/routing/router-service';
56
import { inject as service } from '@ember/service';
6-
import Cookies from 'ember-cookies/services/cookies';
7-
import config from 'ember-get-config';
8-
import moment, { Moment } from 'moment';
97

108
import Node from 'ember-osf-web/models/node';
119
import AnalyticsService from 'ember-osf-web/services/analytics';
12-
13-
const {
14-
OSF: {
15-
cookies: {
16-
analyticsDismissAdblock: dismissAdblockCookie,
17-
},
18-
},
19-
} = config;
20-
21-
interface DateRange {
22-
key: string;
23-
start: Moment;
24-
end: Moment;
25-
}
10+
import { Timespan, TIMESPANS } from './route';
2611

2712
export default class ApplicationController extends Controller {
28-
@service cookies!: Cookies;
2913
@service analytics!: AnalyticsService;
14+
@service router!: RouterService;
3015
@service store!: Store;
3116

32-
dateRanges: DateRange[] = [
33-
{
34-
key: 'pastWeek',
35-
start: moment().subtract(1, 'weeks'),
36-
end: moment(),
37-
},
38-
{
39-
key: 'pastTwoWeeks',
40-
start: moment().subtract(2, 'weeks'),
41-
end: moment(),
42-
},
43-
{
44-
key: 'pastMonth',
45-
start: moment().subtract(1, 'months'),
46-
end: moment(),
47-
},
48-
];
49-
50-
activeDateRange = this.dateRanges[0];
17+
queryParams = ['timespan'];
18+
timespan: Timespan = 'week';
19+
allTimespans = TIMESPANS;
20+
21+
timespanIntlKeys: Record<Timespan, string> = {
22+
week: 'analytics.dateRanges.pastWeek',
23+
fortnight: 'analytics.dateRanges.pastTwoWeeks',
24+
month: 'analytics.dateRanges.pastMonth',
25+
};
26+
5127
linksModalShown = false;
5228

53-
hideAdblockWarning = Boolean(this.cookies.read(dismissAdblockCookie));
5429
userIsBot = navigator.userAgent.includes('Prerender');
5530

5631
linkedByQueryParams = { embed: 'bibliographic_contributors' };
5732

58-
@reads('model.taskInstance.value')
33+
@reads('model.nodeWithCountsTaskInstance.value.taskInstance.value')
5934
node?: Node;
6035

61-
@reads('model.taskInstance.isRunning')
36+
@reads('model.nodeWithCountsTaskInstance.isRunning')
6237
loading?: boolean;
6338

6439
@reads('node.relationshipLinks.forks.links.related.meta.count')
@@ -70,34 +45,24 @@ export default class ApplicationController extends Controller {
7045
@reads('node.apiMeta.templated_by_count')
7146
templatedByCount?: number;
7247

73-
@computed('node.public', 'model.{id,modelName}')
74-
get nodePublic() {
75-
const node: Node | null = this.node || this.store.peekRecord(this.model.modelName, this.model.id);
76-
return node && node.public;
77-
}
78-
79-
@computed('nodePublic', 'userIsBot')
80-
get chartsEnabled() {
81-
return this.nodePublic && !this.userIsBot;
48+
@computed('node.public')
49+
get nodePrivate(): boolean {
50+
const { node } = this;
51+
return Boolean(node && !node.public);
8252
}
8353

84-
@action
85-
dismissAdblockWarning() {
86-
this.cookies.write(dismissAdblockCookie, 1, { path: '/' });
87-
this.set('hideAdblockWarning', true);
88-
this.analytics.click(
89-
'button',
90-
'Analytics - Dismiss adblock warning',
91-
);
54+
@computed('node', 'nodePrivate', 'userIsBot')
55+
get chartsEnabled(): boolean {
56+
return Boolean(this.node && !this.nodePrivate && !this.userIsBot);
9257
}
9358

9459
@action
95-
setDateRange(dateRange: DateRange) {
96-
this.set('activeDateRange', dateRange);
60+
setTimespan(timespan: Timespan) {
9761
this.analytics.click(
9862
'button',
99-
`Analytics - Choose date range "${dateRange.key}"`,
63+
`Analytics - Choose date range "${timespan}"`,
10064
);
65+
this.router.transitionTo({ queryParams: { timespan } });
10166
}
10267

10368
@action

lib/analytics-page/addon/application/route.ts

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,40 @@ import { assert } from '@ember/debug';
33
import { action } from '@ember/object';
44
import Transition from '@ember/routing/-private/transition';
55
import Route from '@ember/routing/route';
6+
import RouterService from '@ember/routing/router-service';
67
import { inject as service } from '@ember/service';
78
import { waitFor } from '@ember/test-waiters';
89
import { task, TaskInstance } from 'ember-concurrency';
910
import { taskFor } from 'ember-concurrency-ts';
11+
import config from 'ember-get-config';
1012

1113
import Node from 'ember-osf-web/models/node';
1214
import AnalyticsService from 'ember-osf-web/services/analytics';
15+
import CurrentUser from 'ember-osf-web/services/current-user';
1316
import Ready, { Blocker } from 'ember-osf-web/services/ready';
17+
import captureException from 'ember-osf-web/utils/capture-exception';
18+
19+
const { OSF: { apiUrl } } = config;
20+
21+
export const TIMESPANS = ['week', 'fortnight', 'month'] as const;
22+
export type Timespan = (typeof TIMESPANS)[number];
23+
function isValidTimespan(maybeTimespan: string): maybeTimespan is Timespan {
24+
return TIMESPANS.includes(maybeTimespan as Timespan);
25+
}
1426

1527
export default class AnalyticsPageRoute extends Route {
1628
@service analytics!: AnalyticsService;
29+
@service currentUser!: CurrentUser;
1730
@service ready!: Ready;
31+
@service router!: RouterService;
1832
@service store!: Store;
1933

34+
queryParams = {
35+
timespan: {
36+
refreshModel: true,
37+
},
38+
};
39+
2040
@task
2141
@waitFor
2242
async reloadNode(model: Node, blocker: Blocker) {
@@ -49,7 +69,25 @@ export default class AnalyticsPageRoute extends Route {
4969
};
5070
}
5171

52-
model(_: {}, transition: Transition) {
72+
@task
73+
@waitFor
74+
async loadChartsData(nodeTaskInstance: TaskInstance<Node>, timespan: string) {
75+
const node = await nodeTaskInstance;
76+
if (!node.public) {
77+
return null;
78+
}
79+
try {
80+
const responseJson = await this.currentUser.authenticatedAJAX({
81+
url: `${apiUrl}/_/metrics/query/node_analytics/${node.id}/${timespan}/`,
82+
});
83+
return responseJson.data.attributes;
84+
} catch (e) {
85+
captureException(e);
86+
throw e;
87+
}
88+
}
89+
90+
model({timespan}: {timespan: string}, transition: Transition) {
5391
const guidRouteInfo = transition.routeInfos.find(
5492
routeInfo => Boolean(routeInfo.params) && 'guid' in routeInfo.params!,
5593
)!;
@@ -64,13 +102,23 @@ export default class AnalyticsPageRoute extends Route {
64102
model.taskInstance && model.taskInstance.isRunning !== undefined,
65103
);
66104

67-
return taskFor(this.getNodeWithCounts).perform(model.taskInstance);
105+
if (!isValidTimespan(timespan)) {
106+
this.router.transitionTo({ queryParams: { timespan: TIMESPANS[0] } });
107+
return null;
108+
}
109+
110+
return {
111+
nodeId: model.guid,
112+
timespan,
113+
nodeWithCountsTaskInstance: taskFor(this.getNodeWithCounts).perform(model.taskInstance),
114+
chartsDataTaskInstance: taskFor(this.loadChartsData).perform(model.taskInstance, timespan),
115+
};
68116
}
69117

70118
buildRouteInfoMetadata() {
71119
return {
72120
osfMetrics: {
73-
itemGuid: (this.controller as any).model.id as string,
121+
itemGuid: this.controller.model.nodeId as string,
74122
},
75123
};
76124
}

lib/analytics-page/addon/application/styles.scss

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,17 @@
1616
.CountBox {
1717
text-align: center;
1818

19-
h2,
2019
h3 {
2120
margin-top: 0;
2221
}
22+
23+
.Count {
24+
font-size: var(--stepUp2);
25+
font-weight: lighter;
26+
line-height: 1.1;
27+
min-height: 1em;
28+
margin-bottom: 10px;
29+
}
2330
}
2431

2532
.PickDateRange {
@@ -69,6 +76,11 @@
6976
margin-left: 15px;
7077
margin-right: 15px;
7178
}
79+
80+
.PageContainer {
81+
width: 99vw;
82+
padding: 0;
83+
}
7284
}
7385

7486
@media screen and (max-device-height: 500px) {

0 commit comments

Comments
 (0)