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

Trigger a query run on tab change if the query is dirty (#25721)

* Trigger a query run on tab change if the query is dirty

* Ensure field is focused after a query run
parent 2083161a
Branches
Tags
No related merge requests found
......@@ -16,6 +16,7 @@ import { setQueryBuilderMode } from "./ui";
export const setDatasetEditorTab = datasetEditorTab => dispatch => {
dispatch(setQueryBuilderMode("dataset", { datasetEditorTab }));
dispatch(runDirtyQuestionQuery());
};
export const CANCEL_DATASET_CHANGES = "metabase/qb/CANCEL_DATASET_CHANGES";
......
......@@ -253,10 +253,10 @@ function DatasetEditor(props) {
// Focused field has to be set once the query is completed and the result is rendered
// Visualization render can remove the focus
const hasQueryResults = !!result;
if (!focusedFieldRef && hasQueryResults && !result.error) {
if (!focusedField && hasQueryResults && !result.error) {
focusFirstField();
}
}, [result, focusedFieldRef, focusFirstField]);
}, [result, focusedFieldRef, fields, focusFirstField, focusedField]);
const inheritMappedFieldProperties = useCallback(
changes => {
......
......@@ -153,7 +153,7 @@ function DatasetFieldMetadataSidebar({
setShouldAnimateFieldChange(true);
// setTimeout is required as form fields are rerendered pretty frequently
setTimeout(() => {
displayNameInputRef.current?.select();
displayNameInputRef.current?.select?.();
});
}
}, [field, previousField]);
......
......@@ -152,6 +152,34 @@ describe("scenarios > models metadata", () => {
cy.findByText("Pre-tax ($)");
});
it("should keep metadata in sync with the query", () => {
cy.createNativeQuestion(
{
name: "Native Model",
dataset: true,
native: {
query: "SELECT * FROM ORDERS",
},
},
{ visitQuestion: true },
);
openQuestionActions();
popover().within(() => {
cy.findByText("Edit query definition").click();
});
cy.get(".ace_content").type(
"{selectAll}{backspace}SELECT TOTAL FROM ORDERS",
);
cy.findByTestId("editor-tabs-metadata-name").click();
cy.wait("@dataset");
cy.findByTestId("header-cell").should("have.length", 1);
cy.findByLabelText("Display name").should("have.value", "TOTAL");
});
it("should allow reverting to a specific metadata revision", () => {
cy.intercept("POST", "/api/revision/revert").as("revert");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment