From 982ab2b48e7c1e12448df51dc0b5ace6c9616185 Mon Sep 17 00:00:00 2001 From: Apoorv Mishra Date: Sun, 7 Aug 2022 12:41:30 +0530 Subject: [PATCH] feat(editor): support google form embeds (#3930) Fixes #3129 and #3923 --- public/images/google-forms.png | Bin 0 -> 1131 bytes shared/editor/embeds/GoogleForms.test.ts | 48 +++++++++++++++++++++++ shared/editor/embeds/GoogleForms.tsx | 33 ++++++++++++++++ shared/editor/embeds/index.tsx | 8 ++++ 4 files changed, 89 insertions(+) create mode 100644 public/images/google-forms.png create mode 100644 shared/editor/embeds/GoogleForms.test.ts create mode 100644 shared/editor/embeds/GoogleForms.tsx diff --git a/public/images/google-forms.png b/public/images/google-forms.png new file mode 100644 index 0000000000000000000000000000000000000000..512422e00fcc7682dc2e8ee89e9ca115c6c34580 GIT binary patch literal 1131 zcmeAS@N?(olHy`uVBq!ia0vp^6(G#P1|%(0%q{^b#^NA%Cx&(BWL`2bu&8>vIEGX( zzMW&69pWg`mR=edX`r~E!%XPU0jDjSIWm${vr`kb|1q&vYwP~u?-KjhsIX+?Mp4m& zYAjA#yd8p9W@MaUS*OxI_v@N-ReASnm))Fmrl9QJ_nXD#&!44Oo2RFl3prnFwB2+{ zVB1rMhNJNu3~U>AFhBaVB7vdXT0yU$i*8&o_B*{-wr{`fDZXCLTm8KMvc;G8ZrQhO zqS(DPOVatpFCYKDdSdkC%6A3_-21*?`f9yAxbBYKGCg^}bUmM??&bHF{=BYzdwG}r z{n>Lh&uz_o^lhs6|5|Is=`Uh-{(WHfs+xWG%Uf%MGw(M}cx!rlLIqEuLHxAbr%~qW z{BQlIn_V~jceYXBz)#!j#>>w8RZQEM*1)XT@R?of{D*a)pGaLd1#*_BB5?vw7>nKe zb*-|f_w}p^$w79{pDhmfw z*&d$nFPndUNqm{zz4o?j^lO*8+c{9Ze}4O2dzNY$u2=ASPs6F}C#-(5r~Ul*Hhot0 zquo6GK1Wh6Hcs#^DKz&9DQ7rvRW~=>iD7%U``5b+J9aI7>&5Y)?Bj}k(hT9-x5RQf z_j{I<^!z(2z_ugJ{rHRATYJw7Fx|L)vGD(~(^K->{$yU*6kMk9#CAqspV5R{#)=Iu zU##feI7gpl!}j3AyVvRT&lEUt&yV-LmBBPw4n`k$cS(=8K%t$BAD@2ywK1ygv~ymG$?qkL7Z)a# z^eetUxOlR2+G~b}waQ6`4M!WIEE%@-bsS|7W6pZYaKlPTj5&g5#Z=)czGbP$AFYsY zXIz%L-0n=Bq_f_|d(&k1wJeq2^sr7m=-}ZkZz}#-_Rd>l^ko7UPz}$LZ$2Ce`PzNu zvAMxhKD9D@+xDp9x+dewwW=%zy4G6_r+sc^fU5(VV|J{_E~@O*J&!XjbDE`}XWY!3 zBXKwRglbhu(TN;ch7F}II&2#x0<_r=Toc?VaUjWItqeo7`;jDuZpN)e3^}rb-HbYH hS57ew28GYXZ^$rm9Jrb&04zNiJYD@<);T3K0RYH}1b_el literal 0 HcmV?d00001 diff --git a/shared/editor/embeds/GoogleForms.test.ts b/shared/editor/embeds/GoogleForms.test.ts new file mode 100644 index 000000000..24a8a3c0f --- /dev/null +++ b/shared/editor/embeds/GoogleForms.test.ts @@ -0,0 +1,48 @@ +import GoogleForms from "./GoogleForms"; + +describe("GoogleForms", () => { + const match = GoogleForms.ENABLED[0]; + + test("to be enabled on long-form share links", () => { + expect( + "https://docs.google.com/forms/d/e/1FAIpQLSetbCGiE8DhfVQZMtLE_CU2MwpSsrkXi690hkEDREOvMu8VYQ/viewform?usp=sf_link".match( + match + ) + ).toBeTruthy(); + expect( + "https://docs.google.com/forms/d/e/1FAIpQLSetbCGiE8DhfVQZMtLE_CU2MwpSsrkXi690hkEDREOvMu8VYQ/viewform".match( + match + ) + ).toBeTruthy(); + expect( + "https://docs.google.com/forms/d/e/1FAIpQLSetbCGiE8DhfVQZMtLE_CU2MwpSsrkXi690hkEDREOvMu8VYQ/viewform?embedded=true".match( + match + ) + ).toBeTruthy(); + }); + + test("to be enabled on edit links", () => { + expect( + "https://docs.google.com/forms/d/1zG75dmHQGpomQlWB6VtRhWajNer7mKMjtApM_aRAJV8/edit".match( + match + ) + ).toBeTruthy(); + }); + + test("to not be enabled elsewhere", () => { + expect("https://docs.google.com/forms".match(match)).toBe(null); + expect("https://docs.google.com/forms/d/".match(match)).toBe(null); + expect("https://docs.google.com".match(match)).toBe(null); + expect("https://www.google.com".match(match)).toBe(null); + expect( + "https://docssgoogle.com/forms/d/e/1FAIpQLSetbCGiE8DhfVQZMtLE_CU2MwpSsrkXi690hkEDREOvMu8VYQ/viewform?usp=sf_link".match( + match + ) + ).toBe(null); + expect( + "https://docs.googleecom/forms/d/e/1FAIpQLSetbCGiE8DhfVQZMtLE_CU2MwpSsrkXi690hkEDREOvMu8VYQ/viewform".match( + match + ) + ).toBe(null); + }); +}); diff --git a/shared/editor/embeds/GoogleForms.tsx b/shared/editor/embeds/GoogleForms.tsx new file mode 100644 index 000000000..9379836ca --- /dev/null +++ b/shared/editor/embeds/GoogleForms.tsx @@ -0,0 +1,33 @@ +import * as React from "react"; +import Frame from "../components/Frame"; +import Image from "../components/Image"; +import { EmbedProps as Props } from "."; + +function GoogleForms(props: Props) { + return ( + + } + canonicalUrl={props.attrs.href} + title="Google Forms" + border + /> + ); +} + +GoogleForms.ENABLED = [ + new RegExp("^https?://docs\\.google\\.com/forms/d/(.+)$"), +]; + +export default GoogleForms; diff --git a/shared/editor/embeds/index.tsx b/shared/editor/embeds/index.tsx index 329cc1216..e2e1ddc7f 100644 --- a/shared/editor/embeds/index.tsx +++ b/shared/editor/embeds/index.tsx @@ -21,6 +21,7 @@ import GoogleDataStudio from "./GoogleDataStudio"; import GoogleDocs from "./GoogleDocs"; import GoogleDrawings from "./GoogleDrawings"; import GoogleDrive from "./GoogleDrive"; +import GoogleForms from "./GoogleForms"; import GoogleSheets from "./GoogleSheets"; import GoogleSlides from "./GoogleSlides"; import InVision from "./InVision"; @@ -233,6 +234,13 @@ const embeds: EmbedDescriptor[] = [ component: GoogleDataStudio, matcher: matcher(GoogleDataStudio), }, + { + title: "Google Forms", + keywords: "form survey", + icon: () => Google Forms, + component: GoogleForms, + matcher: matcher(GoogleForms), + }, { title: "InVision", keywords: "design prototype",