Skip to content
Snippets Groups Projects
Unverified Commit 1fe1c7a6 authored by Alexander Kiselev's avatar Alexander Kiselev Committed by GitHub
Browse files

Fix #16810: Dashboard "isDirty" property is set to true after the Dashboard...

Fix #16810: Dashboard "isDirty" property is set to true after the Dashboard title is updated. (#17955)

* added isDirty flag to SET_DASHBOARD_ATTRIBUTES action

* added reducer tests for SET_DASHBOARD_ATTRIBUTES with isDirty

* lint
parent 0bb97c20
Branches
Tags
No related merge requests found
......@@ -45,7 +45,7 @@ class DashboardDetailsModal extends React.Component {
const { id, ...attributes } = dashboard;
// hack: dashboards are stored both in entities.dashboards and dashboard.dashboards
// calling setDashboardAttributes sync this change made using the entity form into dashboard.dashboards
setDashboardAttributes({ id, attributes });
setDashboardAttributes({ id, attributes, isDirty: false });
onChangeLocation(Urls.dashboard(dashboard));
}}
overwriteOnInitialValuesChange
......
......@@ -54,12 +54,12 @@ const isEditing = handleActions(
{},
);
function newDashboard(before, after) {
function newDashboard(before, after, isDirty) {
return {
...before,
...after,
embedding_params: syncParametersAndEmbeddingParams(before, after),
isDirty: true,
isDirty: isDirty ?? true,
};
}
......@@ -72,10 +72,10 @@ const dashboards = handleActions(
}),
},
[SET_DASHBOARD_ATTRIBUTES]: {
next: (state, { payload: { id, attributes } }) => {
next: (state, { payload: { id, attributes, isDirty } }) => {
return {
...state,
[id]: newDashboard(state[id], attributes),
[id]: newDashboard(state[id], attributes, isDirty),
};
},
},
......
......@@ -5,6 +5,7 @@ import {
SET_SIDEBAR,
CLOSE_SIDEBAR,
REMOVE_PARAMETER,
SET_DASHBOARD_ATTRIBUTES,
} from "./actions";
describe("dashboard reducers", () => {
......@@ -135,4 +136,82 @@ describe("dashboard reducers", () => {
).toEqual({ ...initState, parameterValues: { 456: "def" } });
});
});
describe("SET_DASHBOARD_ATTRIBUTES", () => {
const emptyDashboard = {
archived: false,
ordered_cards: [],
can_write: true,
enable_embedding: false,
show_in_getting_started: false,
name: "Dashboard",
creator_id: 1,
updated_at: "2021-01-01T01:01:01.001",
id: 1,
"last-edit-info": {
id: 1,
email: "testin@metabase.com",
first_name: "Test",
last_name: "Metabase",
timestamp: "2021-01-01T01:01:01.001",
},
parameters: [],
created_at: "2021-01-01T01:01:01.001",
};
it("should set attribute and isDirty", () => {
expect(
reducer(
{
...initState,
dashboards: { 1: emptyDashboard },
},
{
type: SET_DASHBOARD_ATTRIBUTES,
payload: {
id: 1,
attributes: { name: "New Name" },
},
},
),
).toEqual({
...initState,
dashboards: {
1: {
...emptyDashboard,
name: "New Name",
isDirty: true,
},
},
});
});
it("should set isDirty to false", () => {
expect(
reducer(
{
...initState,
dashboards: { 1: emptyDashboard },
},
{
type: SET_DASHBOARD_ATTRIBUTES,
payload: {
id: 1,
attributes: { name: "New Name" },
isDirty: false,
},
},
),
).toEqual({
...initState,
dashboards: {
1: {
...emptyDashboard,
name: "New Name",
isDirty: false,
},
},
});
});
});
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment