-
Notifications
You must be signed in to change notification settings - Fork 86
Expand file tree
/
Copy pathInteractiveDataSourcesPage.jsx
More file actions
232 lines (220 loc) · 9.36 KB
/
InteractiveDataSourcesPage.jsx
File metadata and controls
232 lines (220 loc) · 9.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
import React, { useState, useEffect } from 'react';
import { useNavigate } from 'react-router';
import { find, throttle, uniqueId } from 'lodash-es';
import { useDispatch } from 'react-redux';
import { ComingSoon, FlexGridCol } from 'data-transparency-ui';
import { combineQueryParams, getQueryParamString } from 'helpers/queryParams';
import { getBaseUrl, handleShareOptionClick } from 'helpers/socialShare';
import { stickyHeaderHeight } from 'dataMapping/stickyHeader/stickyHeader';
import { interactiveDataSourcesPageMetaTags } from 'helpers/metaTagHelper';
import PageWrapper from 'components/sharedComponents/PageWrapper';
import DownloadStaticFile from "components/sharedComponents/DownloadStaticFile";
import ShareIcon508 from 'components/sharedComponents/buttons/ShareIcon508';
import { showModal } from 'redux/actions/modal/modalActions';
import useQueryParams from "hooks/useQueryParams";
import InteractiveDataSourcesSection from './InteractiveDataSourcesSection';
import AboutSection from './sections/AboutSection';
import IntroSection from './sections/IntroSection';
import FederalSpendingOverview from './scrollerSections/FederalSpendingOverview';
import DataTypes from './scrollerSections/DataTypes';
import DataSubmissionExtraction from './scrollerSections/DataSubmissionExtraction';
import Frequency from './scrollerSections/Frequency';
import DataValidation from './scrollerSections/DataValidation';
import DataFeatures from './scrollerSections/DataFeatures';
import DataUseCases from './scrollerSections/DataUseCases';
import DataAvailable from './scrollerSections/DataAvailable';
import DataSourceSystems from './scrollerSections/DataSourceSystems';
import AccountData from './scrollerSections/AccountData';
import AwardData from './scrollerSections/AwardData';
import AdditionalData from './scrollerSections/AdditionalData';
require('pages/interactiveDataSources/index.scss');
const InteractiveDataSourcesPage = () => {
const [activeSection, setActiveSection] = useState('intro-section');
const query = useQueryParams();
const history = useNavigate();
const dispatch = useDispatch();
const handleShareDispatch = (url) => {
dispatch(showModal(url));
};
const sections = [
{
section: 'intro-section',
label: 'Introduction',
showSectionWrapper: false,
scroller: false,
component: <IntroSection />
},
{
section: 'history-section',
label: 'History of the DATA Act',
showSectionWrapper: false,
scroller: false,
component: <AboutSection />
},
{
section: 'federal-spending-overview',
label: 'Federal Spending Overview',
showSectionWrapper: false,
scroller: true,
component: <FederalSpendingOverview title="Federal Spending Overview" subtitle="How do federal dollars move from Congress to the American people?" />
},
{
section: 'data-available',
label: 'Data Available on USAspending.gov',
showSectionWrapper: false,
scroller: true,
component: <DataAvailable title="Data Available on USAspending.gov" subtitle="What kinds of data does USAspending.gov have?" />
},
{
section: 'data-types',
label: 'Data Types',
showSectionWrapper: false,
scroller: true,
component: <DataTypes title="Data Types" subtitle="How can I understand all the data types on USAspending.gov?" />
},
{
section: 'data-source-systems',
label: 'Source Systems',
showSectionWrapper: false,
scroller: true,
component: <DataSourceSystems title="Source Systems" subtitle="What government data systems flow into USAspending.gov?" />
},
{
section: 'account-data',
label: 'Account Data',
showSectionWrapper: false,
scroller: true,
component: <AccountData title="Account Data" subtitle="What are the sources for account data on USAspending.gov?" />
},
{
section: 'award-data',
label: 'Award Data',
showSectionWrapper: false,
scroller: true,
component: <AwardData title="Award Data" subtitle="What are the sources for award data on USAspending.gov?" />
},
{
section: 'additional-data',
label: 'Additional Data',
showSectionWrapper: false,
scroller: true,
component: <AdditionalData title="Additional Data" subtitle="What are the sources for additional data on USAspending.gov?" />
},
{
section: 'data-submission-extraction',
label: 'Data Submission and Extraction',
showSectionWrapper: false,
scroller: true,
component: <DataSubmissionExtraction title="Data Submission and Extraction" subtitle="What data are submitted to, versus extracted by, USAspending.gov?" />
},
{
section: 'frequency',
label: 'Frequency of Data Updates',
showSectionWrapper: false,
scroller: true,
component: <Frequency title="Frequency of Data Updates" subtitle="How often are data updated on USAspending.gov?" />
},
{
section: 'data-validation',
label: 'Data Validation',
showSectionWrapper: false,
scroller: true,
component: <DataValidation title="Data Validation" subtitle="How does the Data Broker validate data before they are publicly available?" />
},
{
section: 'data-access',
label: 'Features on USAspending.gov',
showSectionWrapper: false,
scroller: true,
component: <DataFeatures title="Features on USAspending.gov" subtitle="Where can I find data on USAspending.gov from these sources?" />
},
{
section: 'data-use-cases',
label: 'Use Cases',
showSectionWrapper: false,
scroller: true,
component: <DataUseCases title="Use Cases" subtitle="What can I do with the data on USAspending.gov?" />
}
];
const jumpToSection = (section = '') => {
// we've been provided a section to jump to
// check if it's a valid section
const sectionObj = find(sections, ['section', section]);
if (!sectionObj) return;
// find the section in dom
const sectionDom = document.querySelector(`#interactive-data-sources-${sectionObj.section}`);
if (!sectionDom) return;
// add section to url
const newQueryParams = combineQueryParams(query, { section: `${section}` });
history({
path: `${getQueryParamString(newQueryParams)}`
}, { replace: true });
setActiveSection(section);
const sectionTop = (sectionDom.offsetTop - stickyHeaderHeight);
window.scrollTo({
top: sectionTop + 200,
left: 0,
behavior: 'smooth'
});
};
useEffect(() => {
if (query.section) {
jumpToSection(query.section);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [query.section]);
useEffect(throttle(() => {
// prevents a console error about react unmounted component leak
let isMounted = true;
if (isMounted) {
const urlSection = query.section;
if (urlSection) {
setActiveSection(urlSection);
jumpToSection(urlSection);
}
}
return () => {
isMounted = false;
};
}, 100), [history, query.section]);
const emailData = {
subject: "USAspending Data Sources",
body: "View a visualization of USAspending data sources on this interactive page: https://www.usaspending.gov/data-sources"
};
const handleShare = (name) => {
handleShareOptionClick(name, `data-sources`, emailData, handleShareDispatch);
};
return (
<PageWrapper
pageName="interactive-data-sources"
classNames="usa-da-interactive-data-sources-page"
metaTagProps={interactiveDataSourcesPageMetaTags}
title="Data Sources"
toolBarComponents={[
<DownloadStaticFile
key={uniqueId()}
path="/data/data-sources-download.pdf" />,
<ShareIcon508
key={uniqueId()}
url={getBaseUrl('data-sources')}
onShareOptionClick={handleShare} />
]}
sections={sections}
activeSection={activeSection}
jumpToSection={jumpToSection}
inPageNav>
<main id="main-content" className="main-content usda__flex-row">
<FlexGridCol width={12} className="body usda__flex-col">
{sections.map((section) => (
<InteractiveDataSourcesSection
key={section.section}
section={section}>
{section.component || <ComingSoon />}
</InteractiveDataSourcesSection>
))}
</FlexGridCol>
</main>
</PageWrapper>
);
};
export default InteractiveDataSourcesPage;