Skip to content

Commit 3f529c6

Browse files
authored
BB2-3563: Allow loading of default data (#66)
* Add button to load default data * Missing piece of last commit * Control button for default data by client setting * Adjust based on linting errors * Updates to readme for hardcoded default data * Edits from self-review
1 parent 4157043 commit 3f529c6

File tree

6 files changed

+54323
-19
lines changed

6 files changed

+54323
-19
lines changed

README-bb2-dev.md

+15
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,21 @@ Note: --abort-on-container-exit will abort client and server containers when sel
2929

3030
Note: You may need to clean up already existing Docker containers, if you are having issues or have changed your configuration file.
3131

32+
## Use default data sets
33+
34+
Instead of using the BB2 API to retrieve data from a BB2 server every time you run the
35+
sample client, you can alternatively pre-populate json content to be loaded. To do so,
36+
replace the json files in `server/default_datasets/Dataset 1` with your desired default
37+
data, and then in `client/src/components/patientData.tsx`, update the
38+
`useDefaultDataButton` const to `true`.
39+
40+
Then on the landing page of the sample client, in addition to the normal button
41+
`Authorize` which can be used to query a BB2 server, there will also be a
42+
`Load default data` button which can be used to load the data from the json files.
43+
44+
This is useful when developing front-end content since it shortens the amount of time
45+
it takes to load sample data.
46+
3247
## Visual trouble shoot
3348

3449
Install VNC viewer and point browser to http://localhost:5900 to monitor web UI interactions

client/src/components/patientData.tsx

+20-14
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,18 @@
11
import { Button } from '@cmsgov/design-system';
22
import axios from 'axios';
33
import chart from '../images/who-charted.png'
4-
//import { SettingsType } from '../types/settings';
4+
import { SettingsType } from '../types/settings';
55
import React, { useState } from 'react';
66
import * as process from 'process';
77

88
export default function PatientData() {
99
const [header] = useState('Add your Medicare Prescription Drug data');
10-
// comment out below because the end point /api/authorize/authurl of
11-
// the server component (on port 3001), does not take parameter such as pkce, version, env
12-
// they are generated by the server component.
13-
//
14-
// const [settingsState] = useState<SettingsType>({
15-
// pkce: true,
16-
// version: 'v2',
17-
// env: 'sandbox'
18-
// });
10+
const [settingsState] = useState<SettingsType>({
11+
useDefaultDataButton: false, // Set to true to use hard coded data
12+
});
1913
async function goAuthorize() {
20-
// comment out '{ params: settingsState }' since /api/authorize/authurl does not take params
2114
const test_url = process.env.TEST_APP_API_URL ? process.env.TEST_APP_API_URL : ''
22-
const authUrlResponseData = await axios.get(`${test_url}/api/authorize/authurl`/*, { params: settingsState } */)
15+
const authUrlResponseData = await axios.get(`${test_url}/api/authorize/authurl`)
2316
.then(response => {
2417
return response.data;
2518
})
@@ -30,7 +23,11 @@ export default function PatientData() {
3023
window.location.href = "/";
3124
});
3225
console.log(authUrlResponseData);
33-
}
26+
}
27+
async function goLoadDefaults() {
28+
const loadDefaultsResponse = await axios.get(`/api/bluebutton/loadDefaults`);
29+
window.location.href = loadDefaultsResponse.data || '/';
30+
}
3431

3532
/* DEVELOPER NOTES:
3633
* Here we are hard coding the users information for the sake of saving time
@@ -50,7 +47,16 @@ export default function PatientData() {
5047
<div>
5148
<h4>{ header }</h4>
5249
</div>
53-
<Button id="auth_btn" variation="solid" onClick={goAuthorize}>Authorize</Button>
50+
<div className='ds-u-margin-top--2'>
51+
<Button id="auth_btn" variation="solid" onClick={goAuthorize}>Authorize</Button>
52+
</div>
53+
{
54+
settingsState.useDefaultDataButton ?
55+
<div className='ds-u-margin-top--2'>
56+
<Button id="load_defaults_btn" variation="solid" onClick={goLoadDefaults}>Load default data</Button>
57+
</div> :
58+
null
59+
}
5460
</div>
5561
</div>
5662
);

client/src/types/settings.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
export type SettingsType = {
2-
env: 'sandbox' | 'local' | 'production',
3-
version: 'v1' | 'v2',
4-
pkce: boolean,
2+
useDefaultDataButton: boolean,
53
}

0 commit comments

Comments
 (0)