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

Remove not used `isCardDirty` helper (#20367)

parent 08e60aa0
No related branches found
No related tags found
No related merge requests found
......@@ -35,40 +35,6 @@ export async function loadCard(cardId) {
}
}
// TODO Atte Keinänen 5/31/17 Deprecated, we should migrate existing references to this method to `question.isCardDirty`
// predicate function that dermines if a given card is "dirty" compared to the last known version of the card
export function isCardDirty(card, originalCard) {
// The rules:
// - if it's new, then it's dirty when
// 1) there is a database/table chosen or
// 2) when there is any content on the native query
// - if it's saved, then it's dirty when
// 1) the current card doesn't match the last saved version
if (!card) {
return false;
} else if (!card.id) {
if (card.dataset_query.query && card.dataset_query.query["source-table"]) {
return true;
} else if (
card.dataset_query.native &&
!_.isEmpty(card.dataset_query.native.query)
) {
return true;
} else {
return false;
}
} else {
const origCardSerialized = originalCard
? serializeCardForUrl(originalCard)
: null;
const newCardSerialized = card
? serializeCardForUrl(_.omit(card, "original_card_id"))
: null;
return newCardSerialized !== origCardSerialized;
}
}
// TODO Atte Keinänen 5/31/17 Deprecated, we should move tests to Questions.spec.js
export function serializeCardForUrl(card) {
const dataset_query = Utils.copy(card.dataset_query);
......
import {
createCard,
isCardDirty,
serializeCardForUrl,
deserializeCardFromUrl,
} from "metabase/lib/card";
......@@ -103,40 +102,6 @@ describe("lib/card", () => {
});
});
describe("isCardDirty", () => {
it("should consider a new card clean if no db table or native query is defined", () => {
expect(isCardDirty(getCard({ newCard: true }), null)).toBe(false);
});
it("should consider a new card dirty if a db table is chosen", () => {
expect(isCardDirty(getCard({ newCard: true, table: 5 }), null)).toBe(
true,
);
});
it("should consider a new card dirty if there is any content on the native query", () => {
expect(isCardDirty(getCard({ newCard: true, table: 5 }), null)).toBe(
true,
);
});
it("should consider a saved card and a matching original card identical", () => {
expect(
isCardDirty(
getCard({ hasOriginalCard: true }),
getCard({ hasOriginalCard: false }),
),
).toBe(false);
});
it("should consider a saved card dirty if the current card doesn't match the last saved version", () => {
expect(
isCardDirty(
getCard({
hasOriginalCard: true,
queryFields: [["field", 21, null]],
}),
getCard({ hasOriginalCard: false }),
),
).toBe(true);
});
});
describe("serializeCardForUrl", () => {
it("should include `original_card_id` property to the serialized URL", () => {
const cardAfterSerialization = deserializeCardFromUrl(
......
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