Skip to content

Commit d87f709

Browse files
feat(myopencre): enable CSV download of all CREs
1 parent a83b918 commit d87f709

File tree

6 files changed

+295
-228
lines changed

6 files changed

+295
-228
lines changed

.python-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.11
1+
3.11.9

application/frontend/src/pages/MyOpenCRE/MyOpenCRE.tsx

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,40 @@ import { useEnvironment } from '../../hooks';
55

66
export const MyOpenCRE = () => {
77
const { apiUrl } = useEnvironment();
8+
// console.log('API URL:', apiUrl);
89

9-
const downloadTemplate = () => {
10-
const headers = ['standard_name', 'standard_section', 'cre_id', 'notes'];
10+
const downloadCreCsv = async () => {
11+
try {
12+
const baseUrl = apiUrl || window.location.origin;
1113

12-
const csvContent = headers.join(',') + '\n';
14+
const backendUrl = baseUrl.includes('localhost') ? 'http://127.0.0.1:5000' : baseUrl;
1315

14-
const blob = new Blob([csvContent], {
15-
type: 'text/csv;charset=utf-8;',
16-
});
16+
const response = await fetch(`${backendUrl}/cre_csv`, {
17+
method: 'GET',
18+
headers: {
19+
Accept: 'text/csv',
20+
},
21+
});
1722

18-
const url = URL.createObjectURL(blob);
19-
const link = document.createElement('a');
23+
if (!response.ok) {
24+
throw new Error(`HTTP error ${response.status}`);
25+
}
2026

21-
link.href = url;
22-
link.setAttribute('download', 'myopencre_mapping_template.csv');
23-
document.body.appendChild(link);
24-
link.click();
25-
document.body.removeChild(link);
27+
const blob = await response.blob();
28+
const url = window.URL.createObjectURL(blob);
29+
30+
const link = document.createElement('a');
31+
link.href = url;
32+
link.download = 'opencre-cre-mapping.csv';
33+
document.body.appendChild(link);
34+
link.click();
35+
36+
document.body.removeChild(link);
37+
window.URL.revokeObjectURL(url);
38+
} catch (err) {
39+
console.error('CSV download failed:', err);
40+
alert('Failed to download CRE CSV');
41+
}
2642
};
2743

2844
return (
@@ -39,8 +55,10 @@ export const MyOpenCRE = () => {
3955
to CRE IDs.
4056
</p>
4157

42-
<Button primary onClick={downloadTemplate}>
43-
Download Mapping Template (CSV)
58+
59+
<Button primary onClick={downloadCreCsv}>
60+
Download CRE Catalogue (CSV)
61+
4462
</Button>
4563
</Container>
4664
);

application/frontend/src/pages/Search/components/SearchBar.scss

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
color: var(--muted-foreground);
2424
height: 1rem;
2525
width: 1rem;
26-
pointer-events: none;
27-
z-index: 1;
2826
}
2927
input {
3028
padding: 0.5rem 1rem 0.5rem 2.5rem;

application/frontend/www/bundle.js

Lines changed: 1 addition & 1 deletion
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
@@ -48,7 +48,7 @@
4848
"sass-loader": "^11.0.1",
4949
"style-loader": "2.0.0",
5050
"ts-jest": "^26.5.5",
51-
"webpack": "^5.92.1",
51+
"webpack": "^5.103.0",
5252
"webpack-cli": "^4.4.0",
5353
"webpack-dev-server": "^3.11.2"
5454
},

0 commit comments

Comments
 (0)