The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
fix: only show trial warning banner when 7 or fewer days remain (#74971)
github-automation-metabase2ecf81327832
diff --git a/frontend/src/metabase/common/components/AppBanner/AppBanner.unit.spec.tsx b/frontend/src/metabase/common/components/AppBanner/AppBanner.unit.spec.tsxindex 319137ff3e3..ae8ff34e521 100644--- a/frontend/src/metabase/common/components/AppBanner/AppBanner.unit.spec.tsx+++ b/frontend/src/metabase/common/components/AppBanner/AppBanner.unit.spec.tsx@@ -238,9 +238,9 @@ describe("AppBanner", () => {expect(screen.queryByTestId("app-banner")).not.toBeInTheDocument();});- it("should render if it is a valid instance in a trial period", () => {+ it("should render if it is a valid instance in a trial period with 7 or fewer days remaining", () => {jest.useFakeTimers();- jest.setSystemTime(new Date("2024-12-15"));+ jest.setSystemTime(new Date("2024-12-25"));setup({isAdmin: true,@@ -254,5 +254,22 @@ describe("AppBanner", () => {expect(screen.getByTestId("app-banner")).toBeInTheDocument();jest.useRealTimers();});++ it("should not render if there are more than 7 days remaining in the trial", () => {+ jest.useFakeTimers();+ jest.setSystemTime(new Date("2024-12-15"));++ setup({+ isAdmin: true,+ isHosted: true,+ tokenStatus: {+ ...token,+ "valid-thru": "2024-12-31T23:00:00.000Z",+ },+ });++ expect(screen.queryByTestId("app-banner")).not.toBeInTheDocument();+ jest.useRealTimers();+ });});});diff --git a/frontend/src/metabase/common/components/AppBanner/utils.ts b/frontend/src/metabase/common/components/AppBanner/utils.tsindex 51d34e18849..dc1db9cb2f7 100644--- a/frontend/src/metabase/common/components/AppBanner/utils.ts+++ b/frontend/src/metabase/common/components/AppBanner/utils.ts@@ -17,14 +17,13 @@ type Props = {* The banner will not be shown if:* - Inside an iframe* - The token has expired.- * - The banner was never dismissed (i.e., `lastDismissed` is null) or- * - The banner dismissal information is not available (i.e., `lastDismissed` is undefined).+ * - There are more than 7 days remaining in the trial.** If the trial is within the last 3 days, the function checks if the banner* was dismissed on the current day. Unless it was dismissed on that day,* the banner will be shown to the user.*- * If the trial has more than 3 days remaining, the banner will be shown only if+ * If the trial has between 4 and 7 days remaining, the banner will be shown only if* the user has never dismissed it.*/export function shouldShowTrialBanner({@@ -43,6 +42,11 @@ export function shouldShowTrialBanner({return false;}+ // No banner if more than 7 days remaining+ if (daysRemaining > 7) {+ return false;+ }+// Show banner if it was never dismissedif (!lastDismissed) {return true;diff --git a/frontend/src/metabase/common/components/AppBanner/utils.unit.spec.ts b/frontend/src/metabase/common/components/AppBanner/utils.unit.spec.tsindex c762a4619ec..a4a974f77a7 100644--- a/frontend/src/metabase/common/components/AppBanner/utils.unit.spec.ts+++ b/frontend/src/metabase/common/components/AppBanner/utils.unit.spec.ts@@ -14,7 +14,7 @@ describe("app banner utils", () => {).toBe(false);});- it.each([3, 2, 1, 0])(+ it.each([7, 3, 2, 1, 0])("should return true if daysRemaining is %s but the banner was never dismissed",(daysRemaining) => {expect(@@ -64,7 +64,7 @@ describe("app banner utils", () => {},);- it.each([42, 180, 14])(+ it.each([7, 6, 4])("should return false if daysRemaining is %s and the banner was dismissed at any point in the past",(daysRemaining) => {expect(@@ -78,7 +78,7 @@ describe("app banner utils", () => {},);- it.each([42, 180, 14])(+ it.each([7, 6, 4])("should return true if daysRemaining is %s but the banner was never dismissed",(daysRemaining) => {expect(@@ -92,7 +92,7 @@ describe("app banner utils", () => {},);- it.each([42, 180, 14])(+ it.each([7, 6, 4])("should return true if daysRemaining is %s but the banner dismissal information is not available",(daysRemaining) => {expect(@@ -106,6 +106,20 @@ describe("app banner utils", () => {},);+ it.each([8, 14, 42, 180])(+ "should return false if daysRemaining is %s (more than 7 days left)",+ (daysRemaining) => {+ expect(+ shouldShowTrialBanner({+ isWithinIframe: false,+ tokenExpiryTimestamp: "2021-11-27",+ daysRemaining,+ lastDismissed: null,+ }),+ ).toBe(false);+ },+ );+it("should return false if isWithinIframe is true", () => {expect(shouldShowTrialBanner({