From 996031ee99525ee6cf3a469ab3c1661418a9e738 Mon Sep 17 00:00:00 2001 From: Tim Roes Date: Thu, 24 Feb 2022 15:22:23 +0100 Subject: [PATCH] Fix doc links/loading (#10621) --- .../src/hooks/services/useDocumentation.ts | 17 +++- .../components/Controls/Instruction.tsx | 97 +++++++++++++------ 2 files changed, 82 insertions(+), 32 deletions(-) diff --git a/airbyte-webapp/src/hooks/services/useDocumentation.ts b/airbyte-webapp/src/hooks/services/useDocumentation.ts index c1b5c8e63efc..8ec7c2633b46 100644 --- a/airbyte-webapp/src/hooks/services/useDocumentation.ts +++ b/airbyte-webapp/src/hooks/services/useDocumentation.ts @@ -9,9 +9,20 @@ export const documentationKeys = { text: (integrationUrl: string) => ["document", integrationUrl] as const, }; -const DOCS_URL = "https://docs.airbyte.io"; +const DOCS_URL = /^https:\/\/docs\.airbyte\.(io|com)/; -const useDocumentation = (documentationUrl: string): UseDocumentationResult => { +export const getDocumentationType = ( + documentationUrl: string +): "external" | "internal" | "none" => { + if (!documentationUrl) { + return "none"; + } + return DOCS_URL.test(documentationUrl) ? "internal" : "external"; +}; + +export const useDocumentation = ( + documentationUrl: string +): UseDocumentationResult => { const { integrationUrl } = useConfig(); const url = documentationUrl.replace(DOCS_URL, integrationUrl) + ".md"; @@ -27,5 +38,3 @@ const useDocumentation = (documentationUrl: string): UseDocumentationResult => { } ); }; - -export default useDocumentation; diff --git a/airbyte-webapp/src/views/Connector/ServiceForm/components/Controls/Instruction.tsx b/airbyte-webapp/src/views/Connector/ServiceForm/components/Controls/Instruction.tsx index e038127aef90..3f4c57724aaf 100644 --- a/airbyte-webapp/src/views/Connector/ServiceForm/components/Controls/Instruction.tsx +++ b/airbyte-webapp/src/views/Connector/ServiceForm/components/Controls/Instruction.tsx @@ -5,7 +5,10 @@ import { useToggle } from "react-use"; import urls from "rehype-urls"; import type { PluggableList } from "react-markdown/lib/react-markdown"; -import useDocumentation from "hooks/services/useDocumentation"; +import { + useDocumentation, + getDocumentationType, +} from "hooks/services/useDocumentation"; import { LoadingPage } from "components"; import { SideView } from "components/SideView"; import { Markdown } from "components/Markdown"; @@ -17,7 +20,22 @@ type IProps = { documentationUrl: string; }; -const LinkToInstruction = styled.span` +const SideViewButton = styled.button` + cursor: pointer; + margin-top: 5px; + font-weight: 500; + font-size: 14px; + line-height: 17px; + text-decoration: underline; + display: inline-block; + background: none; + border: none; + padding: 0; + + color: ${({ theme }) => theme.primaryColor}; +`; + +const DocumentationLink = styled.a` cursor: pointer; margin-top: 5px; font-weight: 500; @@ -45,11 +63,11 @@ const HeaderLink = styled.a` } `; -const Instruction: React.FC = ({ +const DocumentationPanel: React.FC<{ onClose: () => void } & IProps> = ({ selectedService, documentationUrl, + onClose, }) => { - const [isSideViewOpen, setIsSideViewOpen] = useToggle(false); const config = useConfig(); const { data: docs, isLoading } = useDocumentation(documentationUrl); @@ -61,37 +79,60 @@ const Instruction: React.FC = ({ }; const urlReplacerPlugin: PluggableList = [[urls, removeBaseUrl]]; + return ( + + + + } + > + {isLoading ? ( + + ) : docs ? ( + + ) : ( + + )} + + ); +}; + +const Instruction: React.FC = ({ + selectedService, + documentationUrl, +}) => { + const [isSideViewOpen, setIsSideViewOpen] = useToggle(false); + const docType = getDocumentationType(documentationUrl); return ( <> {isSideViewOpen && ( - setIsSideViewOpen(false)} - headerLink={ - - - - } + selectedService={selectedService} + documentationUrl={documentationUrl} + /> + )} + + {docType === "internal" && ( + setIsSideViewOpen(true)}> + + + )} + {docType === "external" && ( + - {isLoading ? ( - - ) : docs ? ( - - ) : ( - - )} - + + )} - setIsSideViewOpen(true)}> - {documentationUrl && } - ); };