From 420751c4b900af6cf05fe1dcf8e24811ddea1365 Mon Sep 17 00:00:00 2001
From: Drew Powers
Date: Sat, 20 Apr 2019 18:17:17 -0600
Subject: [PATCH] Add hide-cta attribute to manifold-product (#83)
* Add hide-cta attribute to manifold-product
* Add test
* Update docs, Prettier cleanup
YOLO
---
src/components.d.ts | 10 +++++
.../manifold-icon/manifold-icon.tsx | 10 ++---
.../manifold-plan-details.tsx | 9 +++--
.../manifold-plan-menu/manifold-plan-menu.tsx | 2 +-
.../manifold-product-details.tsx | 1 -
.../manifold-product-page.e2e.ts | 40 +++++++++++++++++++
.../manifold-product-page.tsx | 34 +++++++++-------
.../manifold-product-page/readme.md | 1 +
.../manifold-product/manifold-product.tsx | 17 ++++++--
src/components/manifold-product/readme.md | 19 ++++++---
.../manifold-service-card.tsx | 7 ++--
src/index.html | 13 ++++++
12 files changed, 127 insertions(+), 36 deletions(-)
diff --git a/src/components.d.ts b/src/components.d.ts
index 363d4a602..b68b7ac99 100644
--- a/src/components.d.ts
+++ b/src/components.d.ts
@@ -356,11 +356,13 @@ export namespace Components {
}
interface ManifoldProductPage {
+ 'hideCta'?: boolean;
'linkFormat'?: string;
'product'?: Catalog.ExpandedProduct;
'provider'?: Catalog.Provider;
}
interface ManifoldProductPageAttributes extends StencilHTMLAttributes {
+ 'hideCta'?: boolean;
'linkFormat'?: string;
'onManifold-productCTA-click'?: (event: CustomEvent) => void;
'product'?: Catalog.ExpandedProduct;
@@ -373,6 +375,10 @@ export namespace Components {
*/
'connection': Connection;
/**
+ * _(optional)_ Hide the CTA on the left?
+ */
+ 'hideCta'?: boolean;
+ /**
* _(optional)_ Link format structure, with `:product` placeholder
*/
'linkFormat'?: string;
@@ -387,6 +393,10 @@ export namespace Components {
*/
'connection'?: Connection;
/**
+ * _(optional)_ Hide the CTA on the left?
+ */
+ 'hideCta'?: boolean;
+ /**
* _(optional)_ Link format structure, with `:product` placeholder
*/
'linkFormat'?: string;
diff --git a/src/components/manifold-icon/manifold-icon.tsx b/src/components/manifold-icon/manifold-icon.tsx
index 2f9027764..8dfb12c7b 100644
--- a/src/components/manifold-icon/manifold-icon.tsx
+++ b/src/components/manifold-icon/manifold-icon.tsx
@@ -60,11 +60,11 @@ export class ManifoldIcon {
,
]
) : (
-
- )}
+
+ )}
);
}
diff --git a/src/components/manifold-plan-details/manifold-plan-details.tsx b/src/components/manifold-plan-details/manifold-plan-details.tsx
index c46c70a81..c2ca038dc 100644
--- a/src/components/manifold-plan-details/manifold-plan-details.tsx
+++ b/src/components/manifold-plan-details/manifold-plan-details.tsx
@@ -30,7 +30,8 @@ export class ManifoldPlanDetails {
@Event({
eventName: 'manifold-planCTA-click',
bubbles: true,
- }) ctaClicked: EventEmitter;
+ })
+ ctaClicked: EventEmitter;
componentWillLoad() {
const features = this.initialFeatures();
@@ -73,9 +74,9 @@ export class ManifoldPlanDetails {
});
}
return this.linkFormat
- .replace(/:product/ig, this.product.body.label)
- .replace(/:plan/ig, this.plan.body.label)
- .replace(/:features/ig, params.toString())
+ .replace(/:product/gi, this.product.body.label)
+ .replace(/:plan/gi, this.plan.body.label)
+ .replace(/:features/gi, params.toString());
}
get header() {
diff --git a/src/components/manifold-plan-menu/manifold-plan-menu.tsx b/src/components/manifold-plan-menu/manifold-plan-menu.tsx
index f442d570e..921361ea3 100644
--- a/src/components/manifold-plan-menu/manifold-plan-menu.tsx
+++ b/src/components/manifold-plan-menu/manifold-plan-menu.tsx
@@ -29,7 +29,7 @@ const PlanButton: FunctionalComponent<{
export class ManifoldPlanMenu {
@Prop() plans: Catalog.ExpandedPlan[] = [];
@Prop() selectedPlanId: string;
- @Prop() selectPlan: Function = () => { };
+ @Prop() selectPlan: Function = () => {};
get customPlans() {
return Array.isArray(this.plans)
diff --git a/src/components/manifold-product-details/manifold-product-details.tsx b/src/components/manifold-product-details/manifold-product-details.tsx
index 552896940..43a2ff2ef 100644
--- a/src/components/manifold-product-details/manifold-product-details.tsx
+++ b/src/components/manifold-product-details/manifold-product-details.tsx
@@ -17,7 +17,6 @@ export class ManifoldProductDetails {
{tagline}
-
{value_props.map(({ body, header }) => (
diff --git a/src/components/manifold-product-page/manifold-product-page.e2e.ts b/src/components/manifold-product-page/manifold-product-page.e2e.ts
index eb747028e..5b0f1a301 100644
--- a/src/components/manifold-product-page/manifold-product-page.e2e.ts
+++ b/src/components/manifold-product-page/manifold-product-page.e2e.ts
@@ -1,4 +1,5 @@
import { newE2EPage } from '@stencil/core/testing';
+import { Product } from '../../spec/mock/catalog';
/* eslint-disable no-param-reassign, @typescript-eslint/no-explicit-any */
@@ -17,4 +18,43 @@ describe('', () => {
const el = await page.find('manifold-product-page >>> manifold-link-button');
expect(await el.getProperty('href')).toBe('/product/iron_cache');
});
+
+ it('CTA is shown by default', async () => {
+ const page = await newE2EPage({ html: `` });
+
+ const props = { product: Product };
+ await page.$eval(
+ 'manifold-product-page',
+ (elm: any, { product }: any) => {
+ elm.product = product;
+ },
+ props
+ );
+
+ await page.waitForChanges();
+
+ const button = await page.find('manifold-product-page >>> manifold-link-button');
+ expect(button).toBeDefined();
+ });
+
+ it('CTA button hides with prop', async () => {
+ const page = await newE2EPage({
+ html: ``,
+ });
+
+ const props = { product: Product };
+ await page.$eval(
+ 'manifold-product-page',
+ (elm: any, { product }: any) => {
+ elm.product = product;
+ elm.hideCta = true;
+ },
+ props
+ );
+
+ await page.waitForChanges();
+
+ const button = await page.find('manifold-product-page >>> manifold-link-button');
+ expect(button).toBeNull();
+ });
});
diff --git a/src/components/manifold-product-page/manifold-product-page.tsx b/src/components/manifold-product-page/manifold-product-page.tsx
index 2e69ac042..654899802 100644
--- a/src/components/manifold-product-page/manifold-product-page.tsx
+++ b/src/components/manifold-product-page/manifold-product-page.tsx
@@ -9,23 +9,27 @@ import { themeIcons } from '../../assets/icons';
shadow: true,
})
export class ManifoldProductPage {
+ @Prop() hideCta?: boolean = false;
@Prop() linkFormat?: string;
@Prop() product?: Catalog.ExpandedProduct;
@Prop() provider?: Catalog.Provider;
@Event({
eventName: 'manifold-productCTA-click',
bubbles: true,
- }) ctaClicked: EventEmitter;
+ })
+ ctaClicked: EventEmitter;
get ctaLink() {
if (!this.product) return undefined;
if (typeof this.linkFormat !== 'string') return undefined;
- return this.linkFormat.replace(/:product/ig, this.product.body.label);
+ return this.linkFormat.replace(/:product/gi, this.product.body.label);
}
get providerName() {
if (!this.product || !this.provider) return undefined;
- return (this.provider.body.name !== this.product.body.name && this.provider.body.name) || undefined;
+ return (
+ (this.provider.body.name !== this.product.body.name && this.provider.body.name) || undefined
+ );
}
onClick = (e: Event): void => {
@@ -53,17 +57,19 @@ export class ManifoldProductPage {
>
{this.providerName && `from ${this.providerName}`}
-
+ {this.hideCta !== true && (
+
+ )}
{tags && (
) : (
-
- )}
+
+ )}
{this.name}
diff --git a/src/index.html b/src/index.html
index 5d02c0758..3279294be 100644
--- a/src/index.html
+++ b/src/index.html
@@ -384,6 +384,12 @@ Navigation
<manifold-product product-label="aiven-redis" link-format="/product/:product" />
<!-- <a href="/product/aiven-redis"> -->
+
+ Hide CTA
+
+ You can alternately hide the CTA on the left altogether with hide-cta
:
+
+ <manifold-product product-label="aiven-cassandra" hide-cta />
Properties
@@ -405,6 +411,13 @@ Properties
Connection |
connections.prod |
+
+ hideCta |
+ hide-cta |
+ (optional) Hide the CTA on the left? |
+ boolean | undefined |
+ false |
+
linkFormat |
link-format |