Skip to content

Commit

Permalink
Merge pull request #88 from bento-platform/features/download-dats-file
Browse files Browse the repository at this point in the history
Features/download dats file
  • Loading branch information
noctillion authored Aug 7, 2023
2 parents 6d26683 + 69817a5 commit bcbdcc2
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 2 deletions.
29 changes: 29 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,19 @@ func main() {
return katsuRequest(path, nil, c, jsonDeserialize)
}

katsuRequestFormattedData := func(path string, c echo.Context) ([]byte, error) {
result, err := genericRequestJsonOnly(fmt.Sprintf("%s%s", cfg.KatsuUrl, path), nil, c, jsonDeserialize)
if err != nil {
return nil, err
}
// Convert the result data to formatted JSON
jsonFormattedData, err := json.MarshalIndent(result, "", " ")
if err != nil {
return nil, fmt.Errorf("error formatting JSON: %w", err)
}
return jsonFormattedData, nil
}

wesRequestWithDetailsAndPublic := func(c echo.Context) error {
qs := url.Values{}
qs.Add("with_details", "true")
Expand Down Expand Up @@ -353,6 +366,22 @@ func main() {
return katsuRequestBasic("/api/public_dataset", c)
})

e.GET("/datasets/:id/dats", func(c echo.Context) error {
id := c.Param("id")
relativeUrl := fmt.Sprintf("/api/datasets/%s/dats", id)

data, err := katsuRequestFormattedData(relativeUrl, c)
if err != nil {
return err
}

// Set the content type and disposition for download
c.Response().Header().Set("Content-Disposition", `attachment; filename="DATS.json"`)
c.Response().Header().Set("Content-Type", "application/json")

return c.String(http.StatusOK, string(data))
})

// Run
e.Logger.Fatal(e.Start(fmt.Sprintf(":%d", cfg.Port)))
}
Expand Down
4 changes: 4 additions & 0 deletions src/js/components/Provenance/DatasetProvenance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import SpatialCoverageTable from './Tables/SpatialCoverageTable';
import ExtraPropertiesTable from './Tables/ExtraPropertiesTable';
import PublicationsTable from './Tables/PublicationsTable';
import CreatedByTable from './Tables/CreatedByTable';
import DownloadDats from './DownloadDats';
import { DEFAULT_TRANSLATION, NON_DEFAULT_TRANSLATION } from '@/constants/configConstants';
import { ProvenanceStoreDataset } from '@/types/provenance';

Expand Down Expand Up @@ -90,6 +91,9 @@ const DatasetProvenance = ({ metadata, loading }: DatasetProvenanceProps) => {
{/* --- EXTRA PROPERTIES ---*/}
<TableTitleWitTranslation title="Extra Properties" />
<ExtraPropertiesTable extraProperties={metadata.extraProperties} />

{/* --- DOWNLOAD DATS --- */}
<DownloadDats metadata={metadata} />
</Card>
</div>
);
Expand Down
31 changes: 31 additions & 0 deletions src/js/components/Provenance/DownloadDats.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React from 'react';
import PropTypes from 'prop-types';
import { Button, Space } from 'antd';
import { DownloadOutlined } from '@ant-design/icons';
import { useTranslation } from 'react-i18next';
import { ProvenanceStoreDataset } from '@/types/provenance';

const DownloadDats = ({ metadata }: { metadata: ProvenanceStoreDataset }) => {
const { t } = useTranslation();

const exportData = () => {
const id = metadata.identifier;
window.location.href = `/datasets/${id}/dats`;
};

const isDatsFileEmpty = metadata && metadata.dats_file ? Object.keys(metadata.dats_file).length === 0 : true;

return (
<Space style={{ marginTop: '20px', justifyContent: 'center' }}>
<Button type="primary" icon={<DownloadOutlined />} onClick={exportData} disabled={isDatsFileEmpty}>
{t('Download DATS File')}
</Button>
</Space>
);
};

DownloadDats.propTypes = {
metadata: PropTypes.object.isRequired,
};

export default DownloadDats;
1 change: 1 addition & 0 deletions src/js/types/provenance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface Dataset {
description: string;
title: string;
version: string;
identifier: string;
}

export interface DatsFile {
Expand Down
3 changes: 2 additions & 1 deletion src/public/locales/en/translation_en.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
"MALE": "MALE",
"FEMALE": "FEMALE",
"I have no problems in walking about": "I have no problems in walking about",
"Results": "Results"
"Results": "Results",
"Download DATS File": "Download DATS File"
}
3 changes: 2 additions & 1 deletion src/public/locales/fr/translation_fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
"Lab Test Result": "Résultats des tests de laboratoire",
"Experiment Types": "Types d'expériences",
"I have no problems in walking about": "Je n’ai aucun problème à marcher",
"Results": "Résultats"
"Results": "Résultats",
"Download DATS File": "Télécharger le fichier DATS"
}

0 comments on commit bcbdcc2

Please sign in to comment.