Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,62 @@
// CDS-RDM is free software; you can redistribute it and/or modify it
// under the terms of the GPL-2.0 License; see LICENSE file for more details.

import React from "react";
import React, { useState } from "react";
import PropTypes from "prop-types";
import { Button, Icon } from "semantic-ui-react";
import { i18next } from "@translations/invenio_administration/i18next";

export const DownloadButton = ({ runId }) => (
<div className="ui horizontal list">
<div className="item">
<Button
icon
labelPosition="left"
onClick={() => {
if (!runId) return;
const q = new URLSearchParams({ run_id: runId });
window.location.href = `/harvester-reports/download?${q}`;
}}
disabled={!runId}
className="harvester-download-log-button"
size="small"
>
<Icon name="download" />
{i18next.t("Download error logs")}
</Button>
</div>
<div className="item">
<Button
icon
labelPosition="left"
onClick={() => {
if (!runId) return;
window.location.assign(`/administration/harvester-reports/${runId}/report`);
}}
disabled={!runId}
className="harvester-view-logs-button"
size="small"
>
<Icon name="file alternate outline" />
{i18next.t("View error logs")}
</Button>
export const DownloadButton = ({ runId }) => {
const [isLoadingReport, setIsLoadingReport] = useState(false);

const handleViewReport = () => {
if (!runId || isLoadingReport) return;

setIsLoadingReport(true);
window.location.assign(`/administration/harvester-reports/${runId}/report`);
};

return (
<div className="ui horizontal list">
<div className="item">
<Button
icon
labelPosition="left"
onClick={() => {
if (!runId) return;
const q = new URLSearchParams({ run_id: runId });
window.location.href = `/harvester-reports/download?${q}`;
}}
disabled={!runId}
className="harvester-download-log-button"
size="small"
>
<Icon name="download" />
{i18next.t("Download error logs")}
</Button>
</div>
<div className="item">
<Button
icon
labelPosition="left"
onClick={handleViewReport}
loading={isLoadingReport}
disabled={!runId || isLoadingReport}
className="harvester-view-logs-button"
size="small"
>
<Icon name="file alternate outline" />
{i18next.t("View error logs")}
</Button>
</div>
</div>
</div>
);
);
};

DownloadButton.propTypes = {
runId: PropTypes.string,
};

DownloadButton.defaultProps = {
runId: null,
};
Loading