From d312d380aee338594484e9ec6a67695df5b08d6d Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Fri, 12 Jul 2019 22:35:09 +0000 Subject: [PATCH] [CORL-436] Embed Code (#2398) * feat: initial implementation * fix: moved embed configuration to advanced * feat: added copy button to embed code * fix: removing unused line --- package-lock.json | 9 ++- package.json | 2 + .../sections/Advanced/AdvancedConfig.tsx | 5 +- .../Advanced/AdvancedConfigContainer.tsx | 1 + .../Configure/sections/Advanced/EmbedCode.css | 10 +++ .../Configure/sections/Advanced/EmbedCode.tsx | 80 +++++++++++++++++++ .../sections/Advanced/EmbedCodeContainer.tsx | 25 ++++++ .../__snapshots__/advanced.spec.tsx.snap | 60 ++++++++++++++ src/core/client/embed/Coral.ts | 11 +-- src/core/common/utils/getLocationOrigin.ts | 5 ++ src/core/common/utils/index.ts | 1 + src/core/server/config.ts | 2 +- .../server/graph/tenant/resolvers/Settings.ts | 6 ++ .../server/graph/tenant/schema/schema.graphql | 5 ++ src/locales/en-US/admin.ftl | 6 ++ 15 files changed, 214 insertions(+), 14 deletions(-) create mode 100644 src/core/client/admin/routes/Configure/sections/Advanced/EmbedCode.css create mode 100644 src/core/client/admin/routes/Configure/sections/Advanced/EmbedCode.tsx create mode 100644 src/core/client/admin/routes/Configure/sections/Advanced/EmbedCodeContainer.tsx create mode 100644 src/core/common/utils/getLocationOrigin.ts create mode 100644 src/core/server/graph/tenant/resolvers/Settings.ts diff --git a/package-lock.json b/package-lock.json index 29eb9f24b..b775a8cbd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3541,6 +3541,12 @@ "commander": "*" } }, + "@types/common-tags": { + "version": "1.8.0", + "resolved": "https://registry.npmjs.org/@types/common-tags/-/common-tags-1.8.0.tgz", + "integrity": "sha512-htRqZr5qn8EzMelhX/Xmx142z218lLyGaeZ3YR8jlze4TATRU9huKKvuBmAJEW4LCC4pnY1N6JAm6p85fMHjhg==", + "dev": true + }, "@types/compression-webpack-plugin": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/@types/compression-webpack-plugin/-/compression-webpack-plugin-2.0.0.tgz", @@ -7992,8 +7998,7 @@ "common-tags": { "version": "1.8.0", "resolved": "https://registry.npmjs.org/common-tags/-/common-tags-1.8.0.tgz", - "integrity": "sha512-6P6g0uetGpW/sdyUy/iQQCbFF0kWVMSIVSyYz7Zgjcgh8mgw8PQzDNZeyZ5DQ2gM7LBoZPHmnjz8rUthkBG5tw==", - "dev": true + "integrity": "sha512-6P6g0uetGpW/sdyUy/iQQCbFF0kWVMSIVSyYz7Zgjcgh8mgw8PQzDNZeyZ5DQ2gM7LBoZPHmnjz8rUthkBG5tw==" }, "commondir": { "version": "1.0.1", diff --git a/package.json b/package.json index a79e45bfb..58191d518 100644 --- a/package.json +++ b/package.json @@ -60,6 +60,7 @@ "bull": "^3.8.1", "bunyan": "^1.8.12", "cheerio": "^1.0.0-rc.2", + "common-tags": "^1.8.0", "consolidate": "0.14.0", "content-security-policy-builder": "^2.0.0", "convict": "^4.3.1", @@ -152,6 +153,7 @@ "@types/cheerio": "^0.22.8", "@types/classnames": "^2.2.7", "@types/commander": "^2.12.2", + "@types/common-tags": "^1.8.0", "@types/compression-webpack-plugin": "^2.0.0", "@types/consolidate": "0.0.34", "@types/convict": "^4.2.0", diff --git a/src/core/client/admin/routes/Configure/sections/Advanced/AdvancedConfig.tsx b/src/core/client/admin/routes/Configure/sections/Advanced/AdvancedConfig.tsx index 6e77f3916..2a65b3487 100644 --- a/src/core/client/admin/routes/Configure/sections/Advanced/AdvancedConfig.tsx +++ b/src/core/client/admin/routes/Configure/sections/Advanced/AdvancedConfig.tsx @@ -5,6 +5,7 @@ import { HorizontalGutter } from "coral-ui/components"; import CommentStreamLiveUpdatesContainer from "./CommentStreamLiveUpdatesContainer"; import CustomCSSConfigContainer from "./CustomCSSConfigContainer"; +import EmbedCodeContainer from "./EmbedCodeContainer"; import PermittedDomainsConfigContainer from "./PermittedDomainsConfigContainer"; interface Props { @@ -12,7 +13,8 @@ interface Props { settings: PropTypesOf["settings"] & PropTypesOf["settings"] & PropTypesOf["settings"] & - PropTypesOf["settingsReadOnly"]; + PropTypesOf["settingsReadOnly"] & + PropTypesOf["settings"]; onInitValues: (values: any) => void; } @@ -22,6 +24,7 @@ const AdvancedConfig: FunctionComponent = ({ onInitValues, }) => ( + { const enhanced = withFragmentContainer({ settings: graphql` fragment AdvancedConfigContainer_settings on Settings { + ...EmbedCodeContainer_settings ...CustomCSSConfigContainer_settings ...PermittedDomainsConfigContainer_settings ...CommentStreamLiveUpdatesContainer_settings diff --git a/src/core/client/admin/routes/Configure/sections/Advanced/EmbedCode.css b/src/core/client/admin/routes/Configure/sections/Advanced/EmbedCode.css new file mode 100644 index 000000000..7d58b1830 --- /dev/null +++ b/src/core/client/admin/routes/Configure/sections/Advanced/EmbedCode.css @@ -0,0 +1,10 @@ +.textArea { + width: 100%; + box-sizing: border-box; + padding: calc(0.5 * var(--mini-unit)); + resize: none; +} + +.copyArea { + text-align: right; +} diff --git a/src/core/client/admin/routes/Configure/sections/Advanced/EmbedCode.tsx b/src/core/client/admin/routes/Configure/sections/Advanced/EmbedCode.tsx new file mode 100644 index 000000000..67ae78e75 --- /dev/null +++ b/src/core/client/admin/routes/Configure/sections/Advanced/EmbedCode.tsx @@ -0,0 +1,80 @@ +import { stripIndent } from "common-tags"; +import { Localized } from "fluent-react/compat"; +import React, { FunctionComponent, useMemo } from "react"; + +import { getLocationOrigin } from "coral-common/utils"; +import { CopyButton } from "coral-framework/components"; +import { HorizontalGutter, Typography } from "coral-ui/components"; + +import Header from "../../Header"; + +import styles from "./EmbedCode.css"; + +interface Props { + staticURI: string | null; +} + +const EmbedCode: FunctionComponent = ({ staticURI }) => { + const embed = useMemo(() => { + // Get the origin of the current page. + const origin = getLocationOrigin(); + + // Optionally use the staticURI for configuration. + const script = staticURI || origin; + + // Return the HTML template. + const text = stripIndent` +
+ `; + + // Count the number of rows in the embed code. + const rows = text.split(/\r\n|\r|\n/).length; + + return { text, rows }; + }, [staticURI]); + + return ( + + +
Embed Code
+
+ + + Copy and paste the code below into your CMS to embed Coral comment + streams in each of your site’s stories. + + +