Files
redash/client/app/components/EditVisualizationButton/QueryResultsLink.jsx
Arik Fraimovich 56d3be2248 Prettier all the Javascript code & GitHub Action (#4433)
* Prettier all the JS files

* Add GitHub Action to autoformat code pushed to master

* Fix eslint violation due to formatting.

* Remove GitHub actions for styling

* Add restyled.io config
2019-12-11 17:05:38 +02:00

42 lines
1.2 KiB
JavaScript

import React from "react";
import PropTypes from "prop-types";
export default function QueryResultsLink(props) {
let href = "";
const { query, queryResult, fileType } = props;
const resultId = queryResult.getId && queryResult.getId();
const resultData = queryResult.getData && queryResult.getData();
if (resultId && resultData && query.name) {
if (query.id) {
href = `api/queries/${query.id}/results/${resultId}.${fileType}${props.embed ? `?api_key=${props.apiKey}` : ""}`;
} else {
href = `api/query_results/${resultId}.${fileType}`;
}
}
return (
<a target="_blank" rel="noopener noreferrer" disabled={props.disabled} href={href} download>
{props.children}
</a>
);
}
QueryResultsLink.propTypes = {
query: PropTypes.object.isRequired, // eslint-disable-line react/forbid-prop-types
queryResult: PropTypes.object, // eslint-disable-line react/forbid-prop-types
fileType: PropTypes.string,
disabled: PropTypes.bool.isRequired,
embed: PropTypes.bool,
apiKey: PropTypes.string,
children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]).isRequired,
};
QueryResultsLink.defaultProps = {
queryResult: {},
fileType: "csv",
embed: false,
apiKey: "",
};