Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 416: [Frontend] Add a download button to the Data Files view #859

Merged
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
73e3fff
Add download actions
riatzukiza Apr 16, 2021
2b297d3
Possible change comment
riatzukiza Apr 16, 2021
f2b86d4
Add download button
riatzukiza Apr 16, 2021
d96f7cc
Add hooks to get list of available files
riatzukiza Apr 16, 2021
e0a2954
Add initial test
riatzukiza Apr 16, 2021
535c0f4
add mirage
riatzukiza Apr 16, 2021
8e0589a
Merge remote-tracking branch 'origin/raft-tdp-main' into epics/89/iss…
riatzukiza Apr 22, 2021
f4c25de
Auto stash before merge of "epics/89/issues/416/download-files-fronte…
riatzukiza Apr 22, 2021
7d53cba
Start adding logic for faux preview of previously uploaded file
riatzukiza Apr 22, 2021
4a0ab29
remove additional mirage start call after conflict resolution
riatzukiza Apr 22, 2021
25427cf
Move logic from file upload component to a seperate utility file
riatzukiza Apr 28, 2021
3ed20a9
update button class for test
riatzukiza Apr 28, 2021
e2558c3
Add test expectation of there being two buttons
riatzukiza Apr 28, 2021
4a9243c
refactor file download reducer
riatzukiza Apr 28, 2021
6477607
Merge branch 'raft-tdp-main' into epics/89/issues/416/download-files-…
jtwillis92 Apr 28, 2021
c0a1dd2
Merge branch 'raft-tdp-main' into epics/89/issues/416/download-files-…
carltonsmith May 5, 2021
9a07163
Remove year and quarter from end file download action
riatzukiza May 5, 2021
bdda507
Add uuid to mirage outputs
riatzukiza May 5, 2021
0440dbc
Move download logic
riatzukiza May 6, 2021
f8a9b5a
Add reports action tests
riatzukiza May 6, 2021
5064b53
Use files over file list
riatzukiza May 6, 2021
6afdf22
Fix section names
riatzukiza May 6, 2021
b33b966
update call count
riatzukiza May 6, 2021
5c58fa7
remove downloaded file trigger after moving download logic
riatzukiza May 6, 2021
f8e0454
Add preview test
riatzukiza May 6, 2021
a3c5951
Remove unnessisary reducer logic
riatzukiza May 6, 2021
f7eb3a0
test set_file_list
riatzukiza May 6, 2021
7ca265a
Merge branch 'epics/89/issues/416/download-files-frontend' of github.…
riatzukiza May 6, 2021
4f8eb1f
Remove console logs
riatzukiza May 7, 2021
56944c8
Mock axios get method for tests
riatzukiza May 7, 2021
c0afefe
Add test for SET_FILE_LIST
riatzukiza May 7, 2021
2bd2158
Update error payload for test
riatzukiza May 7, 2021
059df39
Work on tests
riatzukiza May 7, 2021
17e408a
Over 90% test coverage
riatzukiza May 7, 2021
8edb851
Delint
riatzukiza May 10, 2021
10df056
Fix lint
riatzukiza May 10, 2021
8110676
Merge remote-tracking branch 'origin/raft-tdp-main' into epics/89/iss…
riatzukiza May 10, 2021
8e2eac8
Fix test failiures after merge conflict resolution
riatzukiza May 10, 2021
144f19e
Lint
riatzukiza May 10, 2021
389eb11
Hotfix header STT name
jorgegonzalez May 11, 2021
38db273
Merge branch 'raft-tdp-main' into epics/89/issues/416/download-files-…
jorgegonzalez May 11, 2021
ce30850
Revert accidental CSS linting
riatzukiza May 11, 2021
eec70f1
Remove dead code
riatzukiza May 11, 2021
a56e640
Add dependencies to useEffect call
riatzukiza May 11, 2021
5a2d6c7
Remove duplicate property
riatzukiza May 11, 2021
25dfba6
Remove dead test
riatzukiza May 11, 2021
e447012
Merge remote-tracking branch 'origin/raft-tdp-main' into epics/89/iss…
riatzukiza May 14, 2021
a36c0b7
delint
riatzukiza May 14, 2021
b36c038
Revert accidentally changed files
riatzukiza May 14, 2021
16811c5
Lint
riatzukiza May 14, 2021
e7c5afc
Merge branch 'raft-tdp-main' into epics/89/issues/416/download-files-…
jtwillis92 May 18, 2021
94553be
Merge branch 'raft-tdp-main' into epics/89/issues/416/download-files-…
jtwillis92 May 24, 2021
c74b23c
Merge branch 'raft-tdp-main' into epics/89/issues/416/download-files-…
jtwillis92 Jun 1, 2021
f9de1bb
Merge branch 'raft-tdp-main' into epics/89/issues/416/download-files-…
jtwillis92 Jun 2, 2021
8be2003
Apply suggestions from code review
riatzukiza Jun 4, 2021
85b3911
Merge branch 'raft-tdp-main' into epics/89/issues/416/download-files-…
jtwillis92 Jun 8, 2021
05710a6
Fix bad comments
riatzukiza Jun 17, 2021
c6ae760
Add code to remove old previews
riatzukiza Jun 17, 2021
151443d
lint
riatzukiza Jun 17, 2021
6570ba5
Move call to removeOldPreviews to after guard clause
riatzukiza Jun 17, 2021
879304a
Merge remote-tracking branch 'origin/raft-tdp-main' into epics/89/iss…
riatzukiza Jun 22, 2021
3b45379
remove extra new line for linter
riatzukiza Jun 22, 2021
49975d9
Remove unused import
riatzukiza Jun 22, 2021
e8df394
Remove blank import
riatzukiza Jun 22, 2021
09a8aa9
Merge branch 'raft-tdp-main' into epics/89/issues/416/download-files-…
jtwillis92 Jun 29, 2021
9dd7d00
Merge branch 'raft-tdp-main' into epics/89/issues/416/download-files-…
jtwillis92 Jun 30, 2021
92d237e
Review feedback
jtwillis92 Jul 1, 2021
7983e0c
Merge branch 'raft-tdp-main' into epics/89/issues/416/download-files-…
riatzukiza Jul 2, 2021
d9438a9
Merge branch 'raft-tdp-main' into epics/89/issues/416/download-files-…
jtwillis92 Jul 2, 2021
21b2188
Merge branch 'raft-tdp-main' into epics/89/issues/416/download-files-…
jtwillis92 Jul 6, 2021
e5a6780
Add section number to download button
riatzukiza Jul 6, 2021
c6f86b3
Merge branch 'raft-tdp-main' into epics/89/issues/416/download-files-…
ADPennington Jul 7, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions scripts/.#set-backend-env-vars.sh
86 changes: 86 additions & 0 deletions tdrs-frontend/src/actions/reports.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,86 @@
import { v4 as uuidv4 } from 'uuid'
import axios from 'axios'

export const SET_FILE = 'SET_FILE'
export const CLEAR_FILE = 'CLEAR_FILE'
export const SET_FILE_ERROR = 'SET_FILE_ERROR'
export const CLEAR_ERROR = 'CLEAR_ERROR'

export const START_FILE_DOWNLOAD = 'START_FILE_DOWNLOAD'
export const END_FILE_DOWNLOAD = 'END_FILE_DOWNLOAD'
export const FILE_DOWNLOAD_ERROR = 'FILE_DOWNLOAD_ERROR'

export const FETCH_FILE_LIST = 'FETCH_FILE_LIST'
export const SET_FILE_LIST = 'SET_FILE_LIST'
export const FETCH_FILE_LIST_ERROR = 'FETCH_FILE_LIST_ERROR'
export const DOWNLOAD_DIALOG_OPEN = 'DOWNLOAD_DIALOG_OPEN'

export const clearFile = ({ section }) => (dispatch) => {
dispatch({ type: CLEAR_FILE, payload: { section } })
}

export const clearError = ({ section }) => (dispatch) => {
dispatch({ type: CLEAR_ERROR, payload: { section } })
}
/**
Get a list of files that can be downloaded, mainly used to decide if the download button should be present.
*/
export const getAvailableFileList = ({ year, quarter = 'Q1' }) => async (
dispatch
) => {
dispatch({
type: FETCH_FILE_LIST,
})
try {
const response = await axios({
url: `/mock_api/reports/${year}/${quarter}`,
method: 'get',
responseType: 'json',
})
dispatch({
type: SET_FILE_LIST,
payload: {
data: response.data,
},
})
} catch (error) {
dispatch({
type: FETCH_FILE_LIST_ERROR,
})
}
}

export const download = ({ year, quarter = 'Q1', section }) => async (
dispatch
) => {
try {
dispatch({ type: START_FILE_DOWNLOAD })

const response = await axios({
url: `/mock_api/reports/data-files/${year}/${quarter}/${section}`,
method: 'get',
responseType: 'blob',
})
const { data } = response

dispatch({
type: END_FILE_DOWNLOAD,
payload: {
data,
year,
quarter,
section,
},
})
} catch (error) {
dispatch({
type: FILE_DOWNLOAD_ERROR,
payload: { error, year, quarter, section },
})
return false
}
return true
}

// Main Redux action to add files to the state
export const upload = ({ file, section }) => async (dispatch) => {
Expand Down Expand Up @@ -45,3 +114,20 @@ export const setStt = (stt) => (dispatch) => {
export const setYear = (year) => (dispatch) => {
dispatch({ type: SET_SELECTED_YEAR, payload: { year } })
}

export const triggerDownloadDialog = ({ year, quarter, section, data }) => (
dispatch
) => {
const url = window.URL.createObjectURL(new Blob([data]))
const link = document.createElement('a')

link.href = url
link.setAttribute('download', `${year}.${quarter}.${section}.txt`)

document.body.appendChild(link)

link.click()

document.body.removeChild(link)
dispatch({ type: DOWNLOAD_DIALOG_OPEN })
}
1 change: 1 addition & 0 deletions tdrs-frontend/src/actions/sttList.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const fetchSttList = () => async (dispatch) => {
})

if (data) {
// shouldn't this logic be done by the backend serializer?
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this may not be worthy of an entire issue, but when I was working through this I saw this code and it seems to me like like this is the sort of thing django should be handling before the data ever gets to the react UI.

I am open to thoughts on if/how we should deal with this.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this supposed to be removing Federal Government from the options list? If so, I definitely agree it should be done by the backend based on the permissions of the person requesting. Also, it doesn't appear to work because I still see the option for "Federal Government" in both the STT combobox on the upload form and the Profile page.

I'd think a separate issue would be warranted to implement that correctly on the backend. The only people who should see that are OFA admins as far as I know.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree. i'd only expect to see fedgov on the frontend request access and backend profile comboboxes because this is the expected STT for any OFA staff (sys admin, ofa admin, ofa data analyst, regional). good to set this up so that these user groups cannot upload/download on behalf of that STT (e.g. when profile STT = fedgov, data files STT != fedgov)

data.forEach((item, i) => {
if (item.name === 'Federal Government') {
data.splice(i, 1)
Expand Down
4 changes: 3 additions & 1 deletion tdrs-frontend/src/assets/App.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
@import 'theme/_global.scss';

html, body, div#root {
html,
body,
div#root {
height: 100%;
min-height: 100%;
padding: 0;
Expand Down
2 changes: 1 addition & 1 deletion tdrs-frontend/src/assets/Button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
.usa-button:hover {
font-size: 1rem;
background-color: $primary-medium-blue;
}
}
4 changes: 2 additions & 2 deletions tdrs-frontend/src/assets/EditProfile.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.usa-combo-box__input--error {
border: .25rem solid #b50909;
}
border: 0.25rem solid #b50909;
}
4 changes: 2 additions & 2 deletions tdrs-frontend/src/assets/FileUpload.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Override the default white background color of the USWDS Inputs
.usa-file-input__box {
background: #F0F0F0;
}
background: #f0f0f0;
}
4 changes: 2 additions & 2 deletions tdrs-frontend/src/assets/Footer.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
}

.usa-footer__primary-link {
color: $primary-acf-blue
}
color: $primary-acf-blue;
}
8 changes: 4 additions & 4 deletions tdrs-frontend/src/assets/GovBanner.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@include media(">=medium") {
@include media('>=medium') {
.usa-banner {
background-color: #ebf3fa;
&__header {
Expand All @@ -21,9 +21,9 @@
}
}
}
&__button[aria-expanded=true]::after,
&__button[aria-expanded=true]:hover::after {
&__button[aria-expanded='true']::after,
&__button[aria-expanded='true']:hover::after {
background-color: white;
}
}
}
}
7 changes: 4 additions & 3 deletions tdrs-frontend/src/assets/Header.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
color: $accent-magenta;
}

.usa-header--extended .usa-nav__primary-item > .usa-current::after,
.usa-header--extended .usa-nav__primary-item > .usa-current::after,
.usa-header--extended .usa-nav__primary-item > .usa-nav__link:hover::after {
background-color: $accent-magenta;
}
Expand All @@ -18,7 +18,8 @@
}
}

.usa-menu-btn, .usa-menu-btn:hover {
.usa-menu-btn,
.usa-menu-btn:hover {
background-color: $primary-medium-blue;
}

Expand All @@ -29,4 +30,4 @@

.usa-nav__primary > .usa-nav__primary-item > .usa-current {
font-weight: 700;
}
}
28 changes: 17 additions & 11 deletions tdrs-frontend/src/assets/IdleTimer.scss
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
.modal {
position: fixed;
z-index: 1;
position: fixed;
z-index: 1;
left: 0;
top: 0;
width: 100%;
height: 100%;
width: 100%;
height: 100%;
overflow: auto;
background-color: rgb(0,0,0);
background-color: rgba(0,0,0,0.4);
background-color: rgb(0, 0, 0);
background-color: rgba(0, 0, 0, 0.4);
}

/* Modal Content/Box */
Expand Down Expand Up @@ -42,13 +42,19 @@
padding: 0;
border: 1px solid #888;
width: 80%;
box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2),0 6px 20px 0 rgba(0,0,0,0.19);
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
animation-name: animatetop;
animation-duration: 0.4s
animation-duration: 0.4s;
}

/* Add Animation */
@keyframes animatetop {
from {top: -300px; opacity: 0}
to {top: 0; opacity: 1}
}
from {
top: -300px;
opacity: 0;
}
to {
top: 0;
opacity: 1;
}
}
Loading