Skip to content

Commit 8f67b9d

Browse files
Fix the csv download issue
1 parent 19bd006 commit 8f67b9d

File tree

4 files changed

+74
-8
lines changed

4 files changed

+74
-8
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@undp-data/undp-visualization-library",
3-
"version": "1.0.37",
3+
"version": "1.0.38",
44
"main": "./dist/index.cjs",
55
"module": "./dist/index.js",
66
"browser": "./dist/index.umd.js",

src/App.tsx

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,60 @@
1-
import { MultiGraphDashboardFromConfig } from './Components/Dashboard/MultiGraphDashboardFromConfig';
21
import './styles/styles.css';
32

43
function App() {
5-
return <MultiGraphDashboardFromConfig config='./config.json' />;
4+
return (
5+
<div
6+
style={{
7+
height: '90vh',
8+
maxWidth: '712px',
9+
margin: '0 auto',
10+
padding: '2rem',
11+
display: 'flex',
12+
flexDirection: 'column',
13+
justifyContent: 'center',
14+
alignItems: 'center',
15+
}}
16+
>
17+
<img width='56' alt='undp-logo' src='/undp-logo-blue.svg' />
18+
<h3
19+
className='undp-viz-typography'
20+
style={{ textAlign: 'center', paddingTop: '24px' }}
21+
>
22+
UNDP Data Visualization Library
23+
</h3>
24+
<p className='undp-viz-typography' style={{ textAlign: 'center' }}>
25+
This open-source graphing library, developed by the United Nations
26+
Development Programme, offers ready-to-use charts, including bar charts,
27+
line charts, area charts, and more. You can access the documentation{' '}
28+
<a
29+
href='https://data-viz.data.undp.org/'
30+
target='_blank'
31+
rel='noreferrer'
32+
className='undp-viz-style'
33+
>
34+
here
35+
</a>
36+
.
37+
</p>
38+
<p
39+
className='undp-viz-typography'
40+
style={{
41+
fontSize: '16px',
42+
textAlign: 'center',
43+
}}
44+
>
45+
{' '}
46+
For any feedback or inquiries, please feel free to reach out to us at{' '}
47+
<a
48+
href='mailto:data@undp.org'
49+
target='_blank'
50+
rel='noreferrer'
51+
className='undp-viz-style'
52+
>
53+
data@undp.org
54+
</a>{' '}
55+
</p>
56+
</div>
57+
);
658
}
759

860
export default App;

src/Components/Actions/CsvDownloadButton.tsx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,27 @@ interface Props {
1919
mode: 'dark' | 'light';
2020
}
2121

22+
const transformDataForCsv = (data: any) => {
23+
if (!data) return {};
24+
return data.map((obj: any) => {
25+
const newObj = { ...obj };
26+
27+
Object.entries(newObj).forEach(([key, value]) => {
28+
if (Array.isArray(value)) {
29+
newObj[key] = `${value.join(',')}`;
30+
}
31+
});
32+
33+
return newObj;
34+
});
35+
};
2236
export function CsvDownloadButton(props: Props) {
2337
const {
2438
buttonContent,
2539
buttonType = 'quaternary',
2640
buttonArrow = false,
2741
csvData,
28-
fileName = 'data',
42+
fileName = 'data13',
2943
headers,
3044
separator = ',',
3145
buttonSmall = false,
@@ -34,9 +48,9 @@ export function CsvDownloadButton(props: Props) {
3448
return (
3549
<CSVLink
3650
headers={headers}
37-
enclosingCharacter=''
51+
enclosingCharacter='"'
3852
separator={separator}
39-
data={csvData}
53+
data={transformDataForCsv(csvData)}
4054
filename={`${fileName}.csv`}
4155
asyncOnClick
4256
target='_blank'

0 commit comments

Comments
 (0)