Skip to content

Commit e5ed21e

Browse files
authored
Download should be incremented as soon as you click on downloads (#1120)
* Download should be incremented as soon as you click on downloads * Revert "Download should be incremented as soon as you click on downloads" This reverts commit b8d7e11. * reverted to old download logic and incrmenting download count on clientside on clicking download button
1 parent 63498d6 commit e5ed21e

File tree

13 files changed

+98
-6
lines changed

13 files changed

+98
-6
lines changed

frontend/src/actions/dataset.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,3 +495,5 @@ export function fetchDatasetRoles(datasetId) {
495495
});
496496
};
497497
}
498+
499+
export const INCREMENT_DATASET_DOWNLOADS = "INCREMENT_DATASET_DOWNLOADS";

frontend/src/actions/file.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,3 +393,5 @@ export function submitFileExtractionAction(fileId, extractorName, requestBody) {
393393
// document.body.removeChild(anchor);
394394
// }
395395
// });
396+
397+
export const INCREMENT_FILE_DOWNLOADS = "INCREMENT_FILE_DOWNLOADS";

frontend/src/actions/public_dataset.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,3 +192,6 @@ export function fetchPublicFoldersFilesInDataset(
192192
});
193193
};
194194
}
195+
196+
export const INCREMENT_PUBLIC_DATASET_DOWNLOADS =
197+
"INCREMENT_PUBLIC_DATASET_DOWNLOADS";

frontend/src/actions/public_file.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,3 +159,6 @@ export function filePublicDownloaded(
159159
}
160160
};
161161
}
162+
163+
export const INCREMENT_PUBLIC_FILE_DOWNLOADS =
164+
"INCREMENT_PUBLIC_FILE_DOWNLOADS";

frontend/src/components/datasets/ActionsMenu.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import { Button, Stack } from "@mui/material";
22
import React from "react";
3-
import { useSelector } from "react-redux";
3+
import { useDispatch, useSelector } from "react-redux";
44
import { RootState } from "../../types/data";
55
import { Download } from "@mui/icons-material";
66
import { NewMenu } from "./NewMenu";
77
import { OtherMenu } from "./OtherMenu";
88
import { ShareMenu } from "./ShareMenu";
99
import { AuthWrapper } from "../auth/AuthWrapper";
1010
import config from "../../app.config";
11+
import { INCREMENT_DATASET_DOWNLOADS } from "../../actions/dataset";
1112

1213
type ActionsMenuProps = {
1314
datasetId: string;
@@ -21,6 +22,7 @@ export const ActionsMenu = (props: ActionsMenuProps): JSX.Element => {
2122
const datasetRole = useSelector(
2223
(state: RootState) => state.dataset.datasetRole
2324
);
25+
const dispatch = useDispatch();
2426

2527
return (
2628
<Stack
@@ -32,7 +34,13 @@ export const ActionsMenu = (props: ActionsMenuProps): JSX.Element => {
3234
<Button
3335
sx={{ minWidth: "auto" }}
3436
variant="contained"
35-
href={`${config.hostname}/api/v2/datasets/${datasetId}/download`}
37+
onClick={() => {
38+
dispatch({
39+
type: INCREMENT_DATASET_DOWNLOADS,
40+
receivedAt: Date.now(),
41+
});
42+
window.location.href = `${config.hostname}/api/v2/datasets/${datasetId}/download`;
43+
}}
3644
endIcon={<Download />}
3745
>
3846
Download

frontend/src/components/datasets/PublicActionsMenu.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { Button, Stack } from "@mui/material";
22
import React from "react";
33
import { Download } from "@mui/icons-material";
44
import config from "../../app.config";
5+
import { useDispatch } from "react-redux";
6+
import { INCREMENT_PUBLIC_DATASET_DOWNLOADS } from "../../actions/public_dataset";
57

68
type ActionsMenuProps = {
79
datasetId: string;
@@ -10,6 +12,7 @@ type ActionsMenuProps = {
1012
export const PublicActionsMenu = (props: ActionsMenuProps): JSX.Element => {
1113
const { datasetId } = props;
1214

15+
const dispatch = useDispatch();
1316
return (
1417
<Stack
1518
direction="row"
@@ -20,7 +23,13 @@ export const PublicActionsMenu = (props: ActionsMenuProps): JSX.Element => {
2023
<Button
2124
sx={{ minWidth: "auto" }}
2225
variant="contained"
23-
href={`${config.hostname}/api/v2/public_datasets/${datasetId}/download`}
26+
onClick={() => {
27+
dispatch({
28+
type: INCREMENT_PUBLIC_DATASET_DOWNLOADS,
29+
receivedAt: Date.now(),
30+
});
31+
window.location.href = `${config.hostname}/api/v2/public_datasets/${datasetId}/download`;
32+
}}
2433
endIcon={<Download />}
2534
>
2635
Download

frontend/src/components/files/FileActionsMenu.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
fetchFileSummary,
1414
fileDeleted,
1515
generateFilePresignedUrl as generateFilePresignedUrlAction,
16+
INCREMENT_FILE_DOWNLOADS,
1617
RESET_FILE_PRESIGNED_URL,
1718
} from "../../actions/file";
1819
import { useDispatch, useSelector } from "react-redux";
@@ -150,7 +151,10 @@ export const FileActionsMenu = (props: FileActionsMenuProps): JSX.Element => {
150151
sx={{ minWidth: "auto" }}
151152
variant="contained"
152153
onClick={() => {
153-
listFileSummary(fileId);
154+
dispatch({
155+
type: INCREMENT_FILE_DOWNLOADS,
156+
receivedAt: Date.now(),
157+
});
154158
window.location.href = `${config.hostname}/api/v2/files/${fileId}`;
155159
}}
156160
endIcon={<Download />}

frontend/src/components/files/PublicFileActionsMenu.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ import {
99
Stack,
1010
} from "@mui/material";
1111
import React, { useState } from "react";
12-
import { fetchPublicFileSummary } from "../../actions/public_file";
12+
import {
13+
fetchPublicFileSummary,
14+
INCREMENT_PUBLIC_FILE_DOWNLOADS,
15+
} from "../../actions/public_file";
1316
import { useDispatch, useSelector } from "react-redux";
1417
import { Download, MoreHoriz, Upload } from "@mui/icons-material";
1518
import { useNavigate } from "react-router-dom";
@@ -56,7 +59,10 @@ export const PublicFileActionsMenu = (
5659
sx={{ minWidth: "auto" }}
5760
variant="contained"
5861
onClick={() => {
59-
listFileSummary(fileId);
62+
dispatch({
63+
type: INCREMENT_PUBLIC_FILE_DOWNLOADS,
64+
receivedAt: Date.now(),
65+
});
6066
window.location.href = `${config.hostname}/api/v2/public_files/${fileId}`;
6167
}}
6268
endIcon={<Download />}

frontend/src/reducers/dataset.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
DELETE_DATASET,
44
FOLDER_ADDED,
55
FOLDER_UPDATED,
6+
INCREMENT_DATASET_DOWNLOADS,
67
RECEIVE_DATASET_ABOUT,
78
RECEIVE_DATASET_LICENSE,
89
RECEIVE_DATASET_ROLES,
@@ -102,6 +103,13 @@ const dataset = (state = defaultState, action: DataAction) => {
102103
});
103104
case RECEIVE_DATASET_ABOUT:
104105
return Object.assign({}, state, { about: action.about });
106+
case INCREMENT_DATASET_DOWNLOADS:
107+
return Object.assign({}, state, {
108+
about: {
109+
...state.about,
110+
downloads: state.about.downloads + 1,
111+
},
112+
});
105113
case RECEIVE_DATASET_LICENSE:
106114
return Object.assign({}, state, { license: action.license });
107115
case UPDATE_DATASET_LICENSE:

frontend/src/reducers/file.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
CHANGE_SELECTED_VERSION,
33
DOWNLOAD_FILE,
4+
INCREMENT_FILE_DOWNLOADS,
45
RECEIVE_FILE_EXTRACTED_METADATA,
56
RECEIVE_FILE_METADATA_JSONLD,
67
RECEIVE_FILE_PRESIGNED_URL,
@@ -13,6 +14,7 @@ import { DataAction } from "../types/action";
1314
import { FileState } from "../types/data";
1415
import { FileOut as FileSummary } from "../openapi/v2";
1516
import { RECEIVE_FILE_ROLE } from "../actions/authorization";
17+
import { INCREMENT_DATASET_DOWNLOADS } from "../actions/dataset";
1618

1719
const defaultState: FileState = {
1820
fileSummary: <FileSummary>{},
@@ -30,6 +32,13 @@ const file = (state = defaultState, action: DataAction) => {
3032
switch (action.type) {
3133
case RECEIVE_FILE_SUMMARY:
3234
return Object.assign({}, state, { fileSummary: action.fileSummary });
35+
case INCREMENT_FILE_DOWNLOADS:
36+
return Object.assign({}, state, {
37+
fileSummary: {
38+
...state.fileSummary,
39+
downloads: state.fileSummary.downloads + 1,
40+
},
41+
});
3342
case RECEIVE_FILE_ROLE:
3443
return Object.assign({}, state, { fileRole: action.role });
3544
case RECEIVE_FILE_EXTRACTED_METADATA:

0 commit comments

Comments
 (0)