Skip to content
Snippets Groups Projects
Unverified Commit e14dc58b authored by Nemanja's avatar Nemanja
Browse files

Remove `withAnalytics` entities helper

parent 54160764
No related branches found
No related tags found
No related merge requests found
......@@ -18,7 +18,6 @@ import {
import {
compose,
withAction,
withAnalytics,
withNormalize,
withRequestState,
} from "metabase/lib/redux";
......@@ -129,7 +128,6 @@ const Dashboards = createEntity({
dashboard.id,
"copy",
]),
withAnalytics("entities", "dashboard", "copy"),
)(
(entityObject, overrides, { notify } = {}) =>
async (dispatch, getState) => {
......
......@@ -81,7 +81,6 @@ import {
handleEntities,
compose,
withAction,
withAnalytics,
withRequestState,
withCachedDataAndRequestState,
} from "metabase/lib/redux";
......@@ -195,16 +194,6 @@ export function createEntity(def) {
]);
}
// same as withRequestState, but with category/label
function withEntityAnalytics(action) {
return withAnalytics(
"entities",
entity.name,
action,
entity.getAnalyticsMetadata,
);
}
function withEntityActionDecorators(action) {
return entity.actionDecorators[action] || (_ => _);
}
......@@ -230,7 +219,6 @@ export function createEntity(def) {
create: compose(
withAction(CREATE_ACTION),
withEntityAnalytics("create"),
withEntityRequestState(() => ["create"]),
withEntityActionDecorators("create"),
)(entityObject => async (dispatch, getState) => {
......@@ -245,7 +233,6 @@ export function createEntity(def) {
update: compose(
withAction(UPDATE_ACTION),
withEntityAnalytics("update"),
withEntityRequestState(object => [object.id, "update"]),
withEntityActionDecorators("update"),
)(
......@@ -301,7 +288,6 @@ export function createEntity(def) {
delete: compose(
withAction(DELETE_ACTION),
withEntityAnalytics("delete"),
withEntityRequestState(object => [object.id, "delete"]),
withEntityActionDecorators("delete"),
)(entityObject => async (dispatch, getState) => {
......
......@@ -4,7 +4,6 @@ import moment from "moment-timezone"; // eslint-disable-line no-restricted-impor
import { normalize } from "normalizr";
import _ from "underscore";
import * as MetabaseAnalytics from "metabase/lib/analytics";
import { delay } from "metabase/lib/promise";
import {
setRequestLoading,
......@@ -336,31 +335,6 @@ function withCachedData(
};
}
export function withAnalytics(categoryOrFn, actionOrFn, labelOrFn, valueOrFn) {
// thunk decorator:
return thunkCreator =>
// thunk creator:
(...args) =>
// thunk:
(dispatch, getState) => {
function get(valueOrFn, extra = {}) {
if (typeof valueOrFn === "function") {
return valueOrFn(args, { ...extra }, getState);
}
}
try {
const category = get(categoryOrFn);
const action = get(actionOrFn, { category });
const label = get(labelOrFn, { category, action });
const value = get(valueOrFn, { category, action, label });
MetabaseAnalytics.trackStructEvent(category, action, label, value);
} catch (error) {
console.warn("withAnalytics threw an error:", error);
}
return thunkCreator(...args)(dispatch, getState);
};
}
export function withNormalize(schema) {
return thunkCreator =>
(...args) =>
......
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