Skip to content

Commit

Permalink
Fix doc links/loading (#10621)
Browse files Browse the repository at this point in the history
  • Loading branch information
timroes authored Feb 24, 2022
1 parent 98bbda1 commit 996031e
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 32 deletions.
17 changes: 13 additions & 4 deletions airbyte-webapp/src/hooks/services/useDocumentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -27,5 +38,3 @@ const useDocumentation = (documentationUrl: string): UseDocumentationResult => {
}
);
};

export default useDocumentation;
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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;
Expand Down Expand Up @@ -45,11 +63,11 @@ const HeaderLink = styled.a`
}
`;

const Instruction: React.FC<IProps> = ({
const DocumentationPanel: React.FC<{ onClose: () => void } & IProps> = ({
selectedService,
documentationUrl,
onClose,
}) => {
const [isSideViewOpen, setIsSideViewOpen] = useToggle(false);
const config = useConfig();
const { data: docs, isLoading } = useDocumentation(documentationUrl);

Expand All @@ -61,37 +79,60 @@ const Instruction: React.FC<IProps> = ({
};

const urlReplacerPlugin: PluggableList = [[urls, removeBaseUrl]];
return (
<SideView
onClose={onClose}
headerLink={
<HeaderLink href={documentationUrl} target="_blank" rel="noreferrer">
<FormattedMessage
id="onboarding.instructionsLink"
values={{ name: selectedService.name }}
/>
</HeaderLink>
}
>
{isLoading ? (
<LoadingPage />
) : docs ? (
<Markdown content={docs} rehypePlugins={urlReplacerPlugin} />
) : (
<FormattedMessage id="docs.notFoundError" />
)}
</SideView>
);
};

const Instruction: React.FC<IProps> = ({
selectedService,
documentationUrl,
}) => {
const [isSideViewOpen, setIsSideViewOpen] = useToggle(false);
const docType = getDocumentationType(documentationUrl);

return (
<>
{isSideViewOpen && (
<SideView
<DocumentationPanel
onClose={() => setIsSideViewOpen(false)}
headerLink={
<HeaderLink
href={documentationUrl}
target="_blank"
rel="noreferrer"
>
<FormattedMessage
id="onboarding.instructionsLink"
values={{ name: selectedService.name }}
/>
</HeaderLink>
}
selectedService={selectedService}
documentationUrl={documentationUrl}
/>
)}

{docType === "internal" && (
<SideViewButton onClick={() => setIsSideViewOpen(true)}>
<FormattedMessage id="form.setupGuide" />
</SideViewButton>
)}
{docType === "external" && (
<DocumentationLink
href={documentationUrl}
target="_blank"
rel="noopener noreferrer"
>
{isLoading ? (
<LoadingPage />
) : docs ? (
<Markdown content={docs} rehypePlugins={urlReplacerPlugin} />
) : (
<FormattedMessage id="docs.notFoundError" />
)}
</SideView>
<FormattedMessage id="form.setupGuide" />
</DocumentationLink>
)}
<LinkToInstruction onClick={() => setIsSideViewOpen(true)}>
{documentationUrl && <FormattedMessage id="form.setupGuide" />}
</LinkToInstruction>
</>
);
};
Expand Down

0 comments on commit 996031e

Please sign in to comment.