Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix doc links/loading #10621

Merged
merged 1 commit into from
Feb 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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