Skip to content
Snippets Groups Projects
Unverified Commit 7518844e authored by Anton Kulyk's avatar Anton Kulyk Committed by GitHub
Browse files

Get back missing `updateQuestion` option (#24532)

parent 408bf3e7
No related branches found
No related tags found
No related merge requests found
......@@ -109,6 +109,7 @@ function getNextTemplateTagEditorState({
type UpdateQuestionOpts = {
run?: boolean | "auto";
shouldUpdateUrl?: boolean;
shouldStartAdHocQuestion?: boolean;
};
/**
......@@ -117,13 +118,18 @@ type UpdateQuestionOpts = {
export const UPDATE_QUESTION = "metabase/qb/UPDATE_QUESTION";
export const updateQuestion = (
newQuestion: Question,
{ run = false, shouldUpdateUrl = false }: UpdateQuestionOpts = {},
{
run = false,
shouldStartAdHocQuestion = true,
shouldUpdateUrl = false,
}: UpdateQuestionOpts = {},
) => {
return async (dispatch: Dispatch, getState: GetState) => {
const currentQuestion = getQuestion(getState());
const queryBuilderMode = getQueryBuilderMode(getState());
const shouldTurnIntoAdHoc =
shouldStartAdHocQuestion &&
newQuestion.isSaved() &&
newQuestion.query().isEditable() &&
queryBuilderMode !== "dataset";
......
......@@ -46,6 +46,7 @@ type SetupOpts = {
originalQuestion?: Question;
run?: boolean;
shouldUpdateUrl?: boolean;
shouldStartAdHocQuestion?: boolean;
queryBuilderMode?: QueryBuilderMode;
isShowingTemplateTagsEditor?: boolean;
};
......@@ -66,6 +67,7 @@ async function setup({
isShowingTemplateTagsEditor = false,
run,
shouldUpdateUrl,
shouldStartAdHocQuestion,
}: SetupOpts) {
const dispatch = jest.fn().mockReturnValue({ mock: "mock" });
......@@ -90,7 +92,11 @@ async function setup({
qb: qbState,
});
await updateQuestion(question, { run, shouldUpdateUrl })(dispatch, getState);
await updateQuestion(question, {
run,
shouldUpdateUrl,
shouldStartAdHocQuestion,
})(dispatch, getState);
const actions = dispatch.mock.calls.find(
call => call[0]?.type === UPDATE_QUESTION,
......@@ -292,6 +298,21 @@ describe("QB Actions > updateQuestion", () => {
question.settings(),
);
});
it("doesn't turn question into ad-hoc if `shouldStartAdHocQuestion` option is disabled", async () => {
const { result } = await setup({
question,
shouldStartAdHocQuestion: false,
});
expect(result.card.id).toBe(question.id());
expect(result.card.name).toBe(question.displayName());
expect(result.card.description).toBe(question.description());
expect(result.card.dataset_query).toEqual(question.datasetQuery());
expect(result.card.visualization_settings).toEqual(
question.settings(),
);
});
});
});
});
......
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