Skip to content
Snippets Groups Projects
Unverified Commit bb6a4d0b authored by Romeo Van Snick's avatar Romeo Van Snick Committed by GitHub
Browse files

Run selected text loses parameters (#38095)

* Reproduction: Run selected text does not use parameter values correctly

* Use question instead of card when overriding

* Switch to overrideWithQuestion in RELOAD_CARD

* Rename run to dataset in e2e test

* Use cypress builtins instead of custom selectors

* Remove async from e2e test

* Avoid assigning editor to variable

* Type closing }} on editor

* Set type delay to 0

* Add explainer about why the reproduction differs from the issue

* Add limit to test case

* Test actual vizualisation results instead of implementation detauls of dataset

* Clarify that the space is not needed

* Simplify cypress check
parent 7de3ad24
No related branches found
No related tags found
No related merge requests found
import { restore, openNativeEditor, runNativeQuery } from "e2e/support/helpers";
describe("issue 16584", () => {
beforeEach(() => {
restore();
cy.signInAsNormalUser();
});
it("should pass parameters when running with 'Run select text' (metabase#16584)", () => {
// The bug described in is #16584 can be further simplified:
// - the issue persists even when selecting the *entire* query
// - the issue is unrelated to using a date filter, using a text filter works too
// - the issue is unrelated to whether or not the parameter is required or if default value is set
// - the space at the end of the query is not needed to reproduce this issue
openNativeEditor()
.type(
"SELECT COUNTRY FROM ACCOUNTS WHERE COUNTRY = {{ country }} LIMIT 1",
{
parseSpecialCharSequences: false,
delay: 0,
},
)
.type("{selectAll}");
cy.findByPlaceholderText("Country").type("NL", { delay: 0 });
runNativeQuery();
cy.get(".Visualization").findByText("NL").should("exist");
});
});
......@@ -20,6 +20,7 @@ import { ModelIndexes } from "metabase/entities/model-indexes";
import { fetchAlertsForQuestion } from "metabase/alert/alert";
import Revision from "metabase/entities/revisions";
import * as Lib from "metabase-lib";
import { getMetadata } from "metabase/selectors/metadata";
import {
cardIsEquivalent,
cardQueryIsEquivalent,
......@@ -75,12 +76,17 @@ export const reloadCard = createThunkAction(RELOAD_CARD, () => {
Questions.actions.fetch({ id: outdatedQuestion.id() }, { reload: true }),
);
const card = Questions.HACK_getObjectFromAction(action);
const question = new Question(
card,
getMetadata(getState()),
outdatedQuestion.parameters(),
);
dispatch(loadMetadataForCard(card));
dispatch(
runQuestionQuery({
overrideWithCard: card,
overrideWithQuestion: question,
shouldUpdateUrl: false,
}),
);
......
......@@ -8,13 +8,10 @@ import { defer } from "metabase/lib/promise";
import { createThunkAction } from "metabase/lib/redux";
import { runQuestionQuery as apiRunQuestionQuery } from "metabase/services";
import { getMetadata } from "metabase/selectors/metadata";
import { getSensibleDisplays } from "metabase/visualizations";
import { getWhiteLabeledLoadingMessage } from "metabase/selectors/whitelabel";
import { isSameField } from "metabase-lib/queries/utils/field-ref";
import Question from "metabase-lib/Question";
import { isAdHocModelQuestion } from "metabase-lib/metadata/utils/models";
import {
getIsRunning,
......@@ -90,22 +87,20 @@ export const runDirtyQuestionQuery = () => async (dispatch, getState) => {
};
/**
* Queries the result for the currently active question or alternatively for the card provided in `overrideWithCard`.
* Queries the result for the currently active question or alternatively for the card question provided in `overrideWithQuestion`.
* The API queries triggered by this action creator can be cancelled using the deferred provided in RUN_QUERY action.
*/
export const RUN_QUERY = "metabase/qb/RUN_QUERY";
export const runQuestionQuery = ({
shouldUpdateUrl = true,
ignoreCache = false,
overrideWithCard = null,
overrideWithQuestion = null,
} = {}) => {
return async (dispatch, getState) => {
dispatch(loadStartUIControls());
const questionFromCard = card =>
card && new Question(card, getMetadata(getState()));
const question = overrideWithCard
? questionFromCard(overrideWithCard)
const question = overrideWithQuestion
? overrideWithQuestion
: getQuestion(getState());
const originalQuestion = getOriginalQuestion(getState());
......
......@@ -128,7 +128,7 @@ type OwnProps = typeof NativeQueryEditor.defaultProps & {
cardAutocompleteResultsFn: (prefix: string) => Promise<CardCompletionItem[]>;
setDatasetQuery: (query: NativeQuery) => Promise<Question>;
runQuestionQuery: (opts?: {
overrideWithCard?: Card;
overrideWithQuestion?: Question;
shouldUpdateUrl?: boolean;
}) => void;
setNativeEditorSelectedRange: (range: Ace.Range) => void;
......@@ -384,10 +384,10 @@ export class NativeQueryEditor extends Component<
const selectedText = this._editor?.getSelectedText();
if (selectedText) {
const temporaryCard = query.setQueryText(selectedText).question().card();
const temporaryQuestion = query.setQueryText(selectedText).question();
runQuestionQuery({
overrideWithCard: temporaryCard,
overrideWithQuestion: temporaryQuestion,
shouldUpdateUrl: false,
});
} else if (query.canRun()) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment