Skip to content

Commit

Permalink
Merge branch 'master' into 42093-extract-analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
romeovs committed May 3, 2024
2 parents d988382 + 0691779 commit 06a682e
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ import {
getNotebookStep,
openNotebook,
openOrdersTable,
openPeopleTable,
popover,
resetSnowplow,
restore,
visitQuestion,
visualize,
} from "e2e/support/helpers";

const { ORDERS, ORDERS_ID } = SAMPLE_DATABASE;
const { ORDERS, ORDERS_ID, PEOPLE } = SAMPLE_DATABASE;

const DATE_CASES = [
{
Expand Down Expand Up @@ -53,6 +54,37 @@ const DATE_CASES = [
},
];

const EMAIL_CASES = [
{
option: "Domain",
value: "yahoo",
example: "example, online",
},
{
option: "Host",
value: "yahoo.com",
example: "example.com, online.com",
},
];

const URL_CASES = [
{
option: "Domain",
value: "yahoo",
example: "example, online",
},
{
option: "Subdomain",
value: "",
example: "www, maps",
},
{
option: "Host",
value: "yahoo.com",
example: "example.com, online.com",
},
];

const DATE_QUESTION = {
query: {
"source-table": ORDERS_ID,
Expand Down Expand Up @@ -86,6 +118,7 @@ describeWithSnowplow("extract action", () => {
option,
value,
example,
extraction: "Extract day, month…",
});
});
});
Expand All @@ -97,6 +130,7 @@ describeWithSnowplow("extract action", () => {
extractColumnAndCheck({
column: "Created At",
option: "Year",
extraction: "Extract day, month…",
});
const columnIndex = 7;
checkColumnIndex({
Expand All @@ -114,6 +148,7 @@ describeWithSnowplow("extract action", () => {
extractColumnAndCheck({
column: "Created At",
option: "Year",
extraction: "Extract day, month…",
});
const columnIndex = 7;
checkColumnIndex({
Expand Down Expand Up @@ -168,6 +203,7 @@ describeWithSnowplow("extract action", () => {
extractColumnAndCheck({
column: "Created At",
option: "Year",
extraction: "Extract day, month…",
});
const columnIndex = 1;
checkColumnIndex({
Expand All @@ -187,6 +223,7 @@ describeWithSnowplow("extract action", () => {
column: "Created At: Month",
option: "Month of year",
value: "Apr",
extraction: "Extract day, month…",
});
});

Expand All @@ -196,6 +233,7 @@ describeWithSnowplow("extract action", () => {
column: "Min of Created At: Default",
option: "Year",
value: "2,022",
extraction: "Extract day, month…",
});
});

Expand All @@ -205,11 +243,13 @@ describeWithSnowplow("extract action", () => {
column: "Created At",
option: "Hour of day",
newColumn: "Hour of day",
extraction: "Extract day, month…",
});
extractColumnAndCheck({
column: "Created At",
option: "Hour of day",
newColumn: "Hour of day_2",
extraction: "Extract day, month…",
});
});

Expand All @@ -219,6 +259,7 @@ describeWithSnowplow("extract action", () => {
column: "Created At",
option: "Year",
value: "2,025",
extraction: "Extract day, month…",
});
openNotebook();
getNotebookStep("expression").findByText("Year").click();
Expand All @@ -237,6 +278,53 @@ describeWithSnowplow("extract action", () => {
column: "Created At",
option: "Tag der Woche",
value: "Dienstag",
extraction: "Extract day, month…",
});
});
});

describe("email columns", () => {
beforeEach(() => {
restore();
cy.signInAsAdmin();
});

EMAIL_CASES.forEach(({ option, value, example }) => {
it(option, () => {
openPeopleTable({ limit: 1 });
extractColumnAndCheck({
column: "Email",
option,
value,
example,
extraction: "Extract domain, host…",
});
});
});
});

describe("url columns", () => {
beforeEach(() => {
restore();
cy.signInAsAdmin();

// Make the Email column a URL column for these tests, to avoid having to create a new model
cy.request("PUT", `/api/field/${PEOPLE.EMAIL}`, {
semantic_type: "type/URL",
});
});

URL_CASES.forEach(({ option, value, example }) => {
it(option, () => {
openPeopleTable({ limit: 1 });

extractColumnAndCheck({
column: "Email",
option,
value,
example,
extraction: "Extract domain, subdomain…",
});
});
});
});
Expand All @@ -246,13 +334,14 @@ function extractColumnAndCheck({
column,
option,
newColumn = option,
extraction,
value,
example,
}) {
const requestAlias = _.uniqueId("dataset");
cy.intercept("POST", "/api/dataset").as(requestAlias);
cy.findByRole("columnheader", { name: column }).click();
popover().findByText("Extract day, month…").click();
popover().findByText(extraction).click();
cy.wait(1);

if (example) {
Expand Down Expand Up @@ -292,6 +381,7 @@ describeWithSnowplow("extract action", () => {
column: "Created At",
option: "Year",
value: "2,025",
extraction: "Extract day, month…",
});

expectGoodSnowplowEvent({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ export function getExample(info: Lib.ColumnExtractionInfo) {
case "year":
return "2023, 2024";
case "domain":
return "example.com, online.com";
case "host":
return "example, online";
case "host":
return "example.com, online.com";
case "subdomain":
return "www, maps";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ export function getExample(info: Lib.ColumnExtractionInfo) {
case "year":
return "2023, 2024";
case "domain":
return "example.com, online.com";
case "host":
return "example, online";
case "host":
return "example.com, online.com";
case "subdomain":
return "www, maps";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import * as MetabaseAnalytics from "metabase/lib/analytics";
import { formatNumber } from "metabase/lib/formatting";
import { equals } from "metabase/lib/utils";
import { getIsShowingRawTable } from "metabase/query_builder/selectors";
import { getIsEmbeddingSdk } from "metabase/selectors/embed";
import { getFont } from "metabase/styled-components/selectors";
import {
extractRemappings,
Expand Down Expand Up @@ -55,6 +56,7 @@ const defaultProps = {
isEditing: false,
isSettings: false,
isQueryBuilder: false,
isEmbeddingSdk: false,
onUpdateVisualizationSettings: () => {},
// prefer passing in a function that doesn't cause the application to reload
onChangeLocation: location => {
Expand All @@ -65,6 +67,7 @@ const defaultProps = {
const mapStateToProps = state => ({
fontFamily: getFont(state),
isRawTable: getIsShowingRawTable(state),
isEmbeddingSdk: getIsEmbeddingSdk(state),
});

const SMALL_CARD_WIDTH_THRESHOLD = 150;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export interface VisualizationProps {
isPlaceholder?: boolean;
isFullscreen: boolean;
isQueryBuilder: boolean;
isEmbeddingSdk: boolean;
showTitle: boolean;
isDashboard: boolean;
isEditing: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,27 @@ import styled from "@emotion/styled";
import { ResponsiveEChartsRenderer } from "metabase/visualizations/components/EChartsRenderer";
import LegendLayout from "metabase/visualizations/components/legend/LegendLayout";

export const CartesianChartRoot = styled.div<{ isQueryBuilder: boolean }>`
padding: ${({ isQueryBuilder }) =>
isQueryBuilder ? "1rem 1rem 1rem 2rem" : "0.5rem 1rem"};
type CartesianChartRootProps = {
isQueryBuilder?: boolean;
isEmbeddingSdk?: boolean;
};

const getChartPadding = ({
isEmbeddingSdk,
isQueryBuilder,
}: CartesianChartRootProps) => {
if (isEmbeddingSdk) {
return "0rem";
}
if (isQueryBuilder) {
return "1rem 1rem 1rem 2rem";
}

return "0.5rem 1rem";
};

export const CartesianChartRoot = styled.div<CartesianChartRootProps>`
padding: ${getChartPadding};
height: 100%;
display: flex;
flex-direction: column;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ function _CartesianChart(props: VisualizationProps) {
headerIcon,
actionButtons,
isQueryBuilder,
isEmbeddingSdk,
isFullscreen,
hovered,
onChangeCardAndRun,
Expand Down Expand Up @@ -88,7 +89,10 @@ function _CartesianChart(props: VisualizationProps) {
const canSelectTitle = !!onChangeCardAndRun;

return (
<CartesianChartRoot isQueryBuilder={isQueryBuilder}>
<CartesianChartRoot
isQueryBuilder={isQueryBuilder}
isEmbeddingSdk={isEmbeddingSdk}
>
{hasTitle && (
<LegendCaption
title={title}
Expand Down

0 comments on commit 06a682e

Please sign in to comment.