Skip to content

Commit

Permalink
Test fix and some code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ranbena authored and openjck committed Apr 30, 2019
1 parent f7905f0 commit ab7048a
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export function QueryControlDropdown(props) {
)}
<Menu.Item>
<QueryResultsLink
target="_self"
disabled={props.queryExecuting || !props.queryResult.getData || !props.queryResult.getData()}
query={props.query}
queryResult={props.queryResult}
Expand All @@ -41,7 +40,6 @@ export function QueryControlDropdown(props) {
<Menu.Item>
<QueryResultsLink
fileType="xlsx"
target="_self"
disabled={props.queryExecuting || !props.queryResult.getData || !props.queryResult.getData()}
query={props.query}
queryResult={props.queryResult}
Expand Down
27 changes: 10 additions & 17 deletions client/app/components/EditVisualizationButton/QueryResultsLink.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,24 @@ import PropTypes from 'prop-types';


export default function QueryResultsLink(props) {
const extraProps = {};
let href = '';

if (
props.queryResult.getData && props.queryResult.getData() &&
props.query.name && props.queryResult.getId &&
props.queryResult.getId() != null
) {
const fileType = props.fileType ? props.fileType : 'csv';
const { query, queryResult, fileType } = props;
const resultId = queryResult.getId && queryResult.getId();
const resultData = queryResult.getData && queryResult.getData();

if (props.query.id) {
extraProps.href = `api/queries/${props.query.id}/results/${props.queryResult.getId()}.${fileType}${
if (resultId && resultData && query.name) {
if (query.id) {
href = `api/queries/${query.id}/results/${resultId}.${fileType}${
props.embed ? `?api_key=${props.apiKey}` : ''
}`;
} else {
extraProps.href = `api/query_results/${props.queryResult.getId()}.${fileType}`;
href = `api/query_results/${resultId}.${fileType}`;
}
}

return (
<a
target={props.target}
disabled={props.disabled}
{...extraProps}
>
<a target="_self" disabled={props.disabled} href={href}>
{props.children}
</a>
);
Expand All @@ -36,7 +30,6 @@ 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,
target: PropTypes.string.isRequired,
disabled: PropTypes.bool.isRequired,
embed: PropTypes.bool,
apiKey: PropTypes.string,
Expand All @@ -48,7 +41,7 @@ QueryResultsLink.propTypes = {

QueryResultsLink.defaultProps = {
queryResult: {},
fileType: '',
fileType: 'csv',
embed: false,
apiKey: '',
};
6 changes: 0 additions & 6 deletions client/app/components/EditVisualizationButton/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ import { react2angular } from 'react2angular';


export function EditVisualizationButton(props) {
if (props.query.isNew() || !props.canEdit) {
return null;
}

return (
<Button
data-test="EditVisualization"
Expand All @@ -25,8 +21,6 @@ export function EditVisualizationButton(props) {
}

EditVisualizationButton.propTypes = {
query: PropTypes.object.isRequired, // eslint-disable-line react/forbid-prop-types
canEdit: PropTypes.bool.isRequired,
openVisualizationEditor: PropTypes.func.isRequired,
selectedTab: PropTypes.oneOfType([
PropTypes.string,
Expand Down
3 changes: 1 addition & 2 deletions client/app/pages/queries/query.html
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,7 @@ <h3>
<div class="bottom-controller-container" ng-if="showDataset">
<div class="bottom-controller">
<edit-visualization-button
query="query"
can-edit="canEdit"
ng-if="!query.isNew() && canEdit"
open-visualization-editor="openVisualizationEditor"
selected-tab="selectedTab">
</edit-visualization-button>
Expand Down
19 changes: 15 additions & 4 deletions client/cypress/integration/embed/share_embed_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@ describe('Embedded Queries', () => {
ExecuteButton
SaveButton
`);
cy.getByTestId('QueryControlDropdownButton').click({ force: true });
cy.getByTestId('ShowEmbedDialogButton').click();

cy.location('search').should('eq', '?p_id=1');
cy.clickThrough(`
QueryControlDropdownButton
ShowEmbedDialogButton
`);

cy.getByTestId('EmbedIframe').invoke('text').then((iframe) => {
const embedUrl = iframe.match(/"(.*?)"/)[1];
cy.logout();
Expand All @@ -43,8 +48,14 @@ describe('Embedded Queries', () => {
ExecuteButton
SaveButton
`);
cy.getByTestId('QueryControlDropdownButton').click({ force: true });
cy.getByTestId('ShowEmbedDialogButton').click();


cy.location('search').should('eq', '?p_name=Redash');
cy.clickThrough(`
QueryControlDropdownButton
ShowEmbedDialogButton
`);

cy.getByTestId('EmbedIframe').invoke('text').then((iframe) => {
const embedUrl = iframe.match(/"(.*?)"/)[1];
cy.logout();
Expand Down

0 comments on commit ab7048a

Please sign in to comment.