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

Fix issue where reverted question does not use parameter values (#38321)


Makes sure we pass the parameter values to the question when running it after a user reverts to an older version. Resolves metabase#38176.

* Pass correct shape of parameters to question
* Add reproduction for #38176, where a reverted question does not use the parameters
* Reduce paramterValues to the correct format instead of using internal field
* Add issue specifier to test
Co-authored-by: default avatarNemanja Glumac <31325167+nemanjaglumac@users.noreply.github.com>
* Create test question with relevant name
Co-authored-by: default avatarNemanja Glumac <31325167+nemanjaglumac@users.noreply.github.com>
* Avoid setting delay on input
* Fix text in cell
* Simplify selectors for button
* Add comment on parameterValues building

---------

Co-authored-by: default avatarNemanja Glumac <31325167+nemanjaglumac@users.noreply.github.com>
parent 649b99a1
No related branches found
No related tags found
No related merge requests found
import { restore, questionInfoButton, rightSidebar } from "e2e/support/helpers";
describe("issue 38176", () => {
beforeEach(() => {
restore();
cy.signInAsNormalUser();
cy.intercept("PUT", "/api/card/**").as("updateQuestion");
});
it("restoring a question to a previous version should preserve the variables (metabase#38176)", () => {
cy.createNativeQuestion(
{
name: "38176",
native: {
query:
'SELECT "COUNTRY" from "ACCOUNTS" WHERE country = {{ country }} LIMIT 5',
"template-tags": {
country: {
type: "text",
id: "dd06cd10-596b-41d0-9d6e-94e98ceaf989",
name: "country",
"display-name": "Country",
},
},
},
},
{ visitQuestion: true },
);
cy.findByPlaceholderText("Country").type("NL");
cy.findByTestId("query-builder-main").button("Get Answer").click();
questionInfoButton().click();
rightSidebar().within(() => {
cy.findByText("History");
cy.findByPlaceholderText("Add description")
.type("This is a question")
.blur();
cy.wait("@updateQuestion");
cy.findByText(/added a description/i);
cy.findByTestId("question-revert-button").click();
cy.findByText(/reverted to an earlier version/i).should("be.visible");
});
cy.findAllByRole("gridcell").should("contain", "NL");
});
});
......@@ -76,10 +76,22 @@ export const reloadCard = createThunkAction(RELOAD_CARD, () => {
Questions.actions.fetch({ id: outdatedQuestion.id() }, { reload: true }),
);
const card = Questions.HACK_getObjectFromAction(action);
// We need to manually massage the paramters into the parameterValues shape,
// to be able to pass them to new Question.
// We could use _parameterValues here but prefer not to use internal fields.
const parameterValues = outdatedQuestion.parameters().reduce(
(acc, next) => ({
...acc,
[next.id]: next.value,
}),
{},
);
const question = new Question(
card,
getMetadata(getState()),
outdatedQuestion.parameters(),
parameterValues,
);
dispatch(loadMetadataForCard(card));
......
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