Skip to content

Commit e04a44d

Browse files
Merge pull request #262 from gopavasanth/T398335
fix: include continent in formData when parsing URL parameters
2 parents a88efe8 + 52765a1 commit e04a44d

File tree

3 files changed

+30
-25
lines changed

3 files changed

+30
-25
lines changed

src/api/fetchPageViewsCount.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ const fetchPageViewsCount = async (specification) => {
1212
end = `${todayYear}${todayMonth}${todayDay}`,
1313
} = specification;
1414
try {
15-
const response = await axios.get(
16-
`https://wikimedia.org/api/rest_v1/metrics/pageviews/per-article/${project}/${acess}/${agents}/${article}/${dateType}/${start}/${end}`,
17-
);
15+
const encodedArticle = encodeURIComponent((article || '').replace(/\s+/g, '_'));
16+
const url = `https://wikimedia.org/api/rest_v1/metrics/pageviews/per-article/${project}/${acess}/${agents}/${encodedArticle}/${dateType}/${start}/${end}`;
17+
const response = await axios.get(url);
1818
return response.data;
1919
} catch (error) {
20-
return;
20+
// On error (404 or network), return an empty items array so callers can
21+
// treat it as "no data" instead of triggering a fetch error UI.
22+
return { items: [] };
2123
}
2224
};
2325

src/components/PageViews/ArticleViewsGraph.jsx

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,32 +28,34 @@ export default function ArticleViewsGraph() {
2828
try {
2929
const results = await Promise.all(
3030
pages.map(async (page) => {
31-
const response = await fetchPageViewsCount({
32-
article: page,
33-
project,
34-
acess: platform,
35-
agents: agent,
36-
dateType: dateType?.toLowerCase(),
37-
start: dates.start,
38-
end: dates.end,
39-
});
31+
try {
32+
const response = await fetchPageViewsCount({
33+
article: page,
34+
project,
35+
acess: platform,
36+
agents: agent,
37+
dateType: dateType?.toLowerCase(),
38+
start: dates.start,
39+
end: dates.end,
40+
});
4041

41-
if (!response?.items) {
42-
throw new Error('Invalid response format');
43-
}
42+
const views = Array.isArray(response?.items) ? response.items : [];
4443

45-
const views = response.items;
46-
const dates = views.map((view) => {
47-
const year = view.timestamp.substring(0, 4);
48-
const month = view.timestamp.substring(4, 6);
49-
const day = view.timestamp.substring(6, 8);
50-
return `${year}-${month}-${day}`;
51-
});
52-
const counts = views.map((view) => view.views);
53-
return { article: page, dates, counts };
44+
const viewDates = views.map((view) => {
45+
const year = view.timestamp.substring(0, 4);
46+
const month = view.timestamp.substring(4, 6);
47+
const day = view.timestamp.substring(6, 8);
48+
return `${year}-${month}-${day}`;
49+
});
50+
const counts = views.map((view) => view.views);
51+
return { article: page, dates: viewDates, counts };
52+
} catch (e) {
53+
return { article: page, dates: [], counts: [] };
54+
}
5455
}),
5556
);
5657

58+
5759
const combinedDates = [...new Set(results.flatMap((data) => data.dates))].sort();
5860
const datasets = results.map((data, index) => ({
5961
label: decodeURIComponent(data.article),

src/pages/Home.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ function App() {
107107
const formData = {};
108108
formData.country = params[0];
109109
formData.access = params[1];
110+
formData.continent = params[3];
110111
formData.year = date[0];
111112
formData.month = date[1];
112113
formData.day = date[2];

0 commit comments

Comments
 (0)