Skip to content
Snippets Groups Projects
Unverified Commit 9f575cd1 authored by Mahatthana (Kelvin) Nomsawadi's avatar Mahatthana (Kelvin) Nomsawadi Committed by GitHub
Browse files

Merge Track disabling auto-apply filters in Snowplow to master #30796 (#31020)

* Consolidate auto-apply filters toggle action (#30978)

So that when we start tracking the event on Snowplow, we can only do that in a single place.

* Track disabling auto-apply filters in Snowplow (#30987)

* Fix dashboard ID type
parent 3090dfaf
No related branches found
No related tags found
No related merge requests found
import {
dashboardHeader,
dashboardParametersContainer,
describeWithSnowplow,
editDashboard,
enableTracking,
expectGoodSnowplowEvents,
expectNoBadSnowplowEvents,
filterWidget,
getDashboardCard,
popover,
resetSnowplow,
restore,
rightSidebar,
saveDashboard,
......@@ -281,6 +286,63 @@ describe("scenarios > dashboards > filters > auto apply", () => {
});
});
describeWithSnowplow("scenarios > dashboards > filters > auto apply", () => {
const NUMBERS_OF_GOOD_SNOWPLOW_EVENTS_BEFORE_DISABLING_AUTO_APPLY_FILTERS = 2;
beforeEach(() => {
restore();
resetSnowplow();
cy.signInAsAdmin();
enableTracking();
cy.intercept("PUT", "/api/dashboard/*").as("updateDashboard");
});
afterEach(() => {
expectNoBadSnowplowEvents();
});
it("should send snowplow events when disabling auto-apply filters", () => {
createDashboard();
openDashboard();
cy.wait("@cardQuery");
dashboardHeader().within(() => {
cy.icon("info").click();
});
rightSidebar().within(() => {
expectGoodSnowplowEvents(
NUMBERS_OF_GOOD_SNOWPLOW_EVENTS_BEFORE_DISABLING_AUTO_APPLY_FILTERS,
);
cy.findByLabelText("Auto-apply filters").click();
cy.wait("@updateDashboard");
cy.findByLabelText("Auto-apply filters").should("not.be.checked");
expectGoodSnowplowEvents(
NUMBERS_OF_GOOD_SNOWPLOW_EVENTS_BEFORE_DISABLING_AUTO_APPLY_FILTERS + 1,
);
});
});
it("should not send snowplow events when enabling auto-apply filters", () => {
createDashboard({ auto_apply_filters: false });
openDashboard();
cy.wait("@cardQuery");
dashboardHeader().within(() => {
cy.icon("info").click();
});
rightSidebar().within(() => {
expectGoodSnowplowEvents(
NUMBERS_OF_GOOD_SNOWPLOW_EVENTS_BEFORE_DISABLING_AUTO_APPLY_FILTERS,
);
cy.findByLabelText("Auto-apply filters").click();
cy.wait("@updateDashboard");
cy.findByLabelText("Auto-apply filters").should("be.checked");
expectGoodSnowplowEvents(
NUMBERS_OF_GOOD_SNOWPLOW_EVENTS_BEFORE_DISABLING_AUTO_APPLY_FILTERS,
);
});
});
});
const createDashboard = (dashboardOpts = {}) => {
cy.createQuestionAndDashboard({
questionDetails: QUESTION_DETAILS,
......
......@@ -26,6 +26,7 @@ import {
} from "../selectors";
import { isVirtualDashCard } from "../utils";
import { trackAutoApplyFiltersDisabled } from "../analytics";
import { setDashboardAttributes, setDashCardAttributes } from "./core";
import { setSidebar, closeSidebar } from "./ui";
......@@ -334,13 +335,18 @@ export const toggleAutoApplyFilters = createThunkAction(
isEnabled => (dispatch, getState) => {
const dashboardId = getDashboardId(getState());
dispatch(
setDashboardAttributes({
id: dashboardId,
attributes: { auto_apply_filters: isEnabled },
}),
);
dispatch(saveDashboardAndCards(true));
if (dashboardId) {
dispatch(
setDashboardAttributes({
id: dashboardId,
attributes: { auto_apply_filters: isEnabled },
}),
);
dispatch(saveDashboardAndCards(true));
if (!isEnabled) {
trackAutoApplyFiltersDisabled(dashboardId);
}
}
},
);
......
import { trackSchemaEvent } from "metabase/lib/analytics";
import type { DashboardId } from "metabase-types/api";
export const trackAutoApplyFiltersDisabled = (dashboardId: DashboardId) => {
trackSchemaEvent("dashboard", "1-0-1", {
event: "auto_apply_filters_disabled",
dashboard_id: dashboardId,
});
};
......@@ -15,11 +15,15 @@ import Revision from "metabase/entities/revisions";
import { getRevisionEventsForTimeline } from "metabase/lib/revisions";
import { getUser } from "metabase/selectors/user";
import { revertToRevision } from "metabase/dashboard/actions";
import {
revertToRevision,
toggleAutoApplyFilters,
} from "metabase/dashboard/actions";
import Toggle from "metabase/core/components/Toggle";
import FormField from "metabase/core/components/FormField";
import { useUniqueId } from "metabase/hooks/use-unique-id";
import { useDispatch } from "metabase/lib/redux";
import {
DashboardInfoSidebarRoot,
HistoryHeader,
......@@ -67,12 +71,12 @@ const DashboardInfoSidebar = ({
[saveDashboardAndCards, setDashboardAttribute],
);
const dispatch = useDispatch();
const handleToggleAutoApplyFilters = useCallback(
(isAutoApplyingFilters: boolean) => {
setDashboardAttribute("auto_apply_filters", isAutoApplyingFilters);
saveDashboardAndCards(true);
dispatch(toggleAutoApplyFilters(isAutoApplyingFilters));
},
[saveDashboardAndCards, setDashboardAttribute],
[dispatch],
);
const events = useMemo(
......
{
"$schema": "http://iglucentral.com/schemas/com.snowplowanalytics.self-desc/schema/jsonschema/1-0-0#",
"description": "Dashboard events",
"self": {
"vendor": "com.metabase",
"name": "dashboard",
"format": "jsonschema",
"version": "1-0-0"
},
"type": "object",
"properties": {
"event": {
"description": "Event name",
"type": "string",
"enum": [
"dashboard_created",
"question_added_to_dashboard",
"auto_apply_filters_disabled"
],
"maxLength": 1024
},
"dashboard_id": {
"description": "Unique identifier for a dashboard within the Metabase instance",
"type": "integer",
"minimum": 0,
"maximum": 2147483647
},
"question_id": {
"description": "Unique identifier for a question added to a dashboard",
"type": [
"integer",
"null"
],
"minimum": 0,
"maximum": 2147483647
}
},
"required": [
"event",
"dashboard_id"
],
"additionalProperties": true
}
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