Skip to content
Snippets Groups Projects
Unverified Commit e2522f4f authored by metamben's avatar metamben Committed by GitHub
Browse files

Fix model conversion (#50215)

parent 5be95100
No related branches found
No related tags found
No related merge requests found
......@@ -28,6 +28,7 @@ import {
openNotebook,
openOrdersTable,
openProductsTable,
openQuestionActions,
openTable,
popover,
queryBuilderFooter,
......@@ -2436,3 +2437,51 @@ describe("issue 50038", () => {
});
});
});
describe("issue 47940", () => {
const questionDetails = {
name: "Issue 47940",
query: {
"source-table": ORDERS_ID,
limit: 5,
},
};
beforeEach(() => {
restore();
cy.signInAsAdmin();
cy.intercept("PUT", "/api/card/*").as("updateCard");
cy.intercept("POST", "/api/card/*/query").as("cardQuery");
});
it("should be able to convert a question with date casting to a model", () => {
cy.log("create a question without any column casting");
createQuestion(questionDetails, { visitQuestion: true });
cy.wait("@cardQuery");
cy.log("add coercion");
cy.request("PUT", `/api/field/${ORDERS.PRODUCT_ID}`, {
semantic_type: "type/Category",
coercion_strategy: "Coercion/UNIXMicroSeconds->DateTime",
});
cy.log("get new query results with coercion applied");
queryBuilderHeader().findByTestId("run-button").click();
cy.wait("@cardQuery");
queryBuilderHeader().button("Save").click();
modal().button("Save").click();
cy.wait("@updateCard");
cy.log("turn into a model");
openQuestionActions();
popover().findByText("Turn into a model").click();
cy.findByRole("dialog").findByText("Turn this into a model").click();
cy.wait("@updateCard");
cy.log("verify there is a table displayed");
cy.findByTestId("visualization-root").should(
"contain",
"December 31, 1969, 4:00 PM",
);
});
});
......@@ -2,16 +2,13 @@ import { push } from "react-router-redux";
import { createAction } from "redux-actions";
import { t } from "ttag";
import Questions from "metabase/entities/questions";
import { loadMetadataForCard } from "metabase/questions/actions";
import { addUndo } from "metabase/redux/undo";
import { getMetadata } from "metabase/selectors/metadata";
import type { Dispatch, GetState } from "metabase-types/store";
import { getQuestion } from "../selectors";
import { API_UPDATE_QUESTION, apiUpdateQuestion, updateQuestion } from "./core";
import { runDirtyQuestionQuery, runQuestionQuery } from "./querying";
import { apiUpdateQuestion, updateQuestion } from "./core";
import { runDirtyQuestionQuery } from "./querying";
import { setQueryBuilderMode } from "./ui";
export const setDatasetEditorTab =
......@@ -29,41 +26,16 @@ export const onCancelCreateNewModel = () => async (dispatch: Dispatch) => {
export const turnQuestionIntoModel =
() => async (dispatch: Dispatch, getState: GetState) => {
const question = getQuestion(getState());
if (!question) {
return;
}
await dispatch(
Questions.actions.update(
{
id: question.id(),
},
question
.setType("model")
.setPinned(true)
.setDisplay("table")
.setSettings({})
.card(),
),
);
const metadata = getMetadata(getState());
const dataset = metadata.question(question.id());
if (!dataset) {
return;
}
await dispatch(loadMetadataForCard(dataset.card()));
await dispatch({ type: API_UPDATE_QUESTION, payload: dataset.card() });
await dispatch(
runQuestionQuery({
shouldUpdateUrl: true,
}),
);
const model = question
.setType("model")
.setPinned(true)
.setDisplay("table")
.setSettings({});
await dispatch(apiUpdateQuestion(model, { rerunQuery: true }));
dispatch(
addUndo({
......@@ -76,7 +48,6 @@ export const turnQuestionIntoModel =
export const turnModelIntoQuestion =
() => async (dispatch: Dispatch, getState: GetState) => {
const model = getQuestion(getState());
if (!model) {
return;
}
......
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