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: prefer the first description when multiple are detected #1650

Merged
merged 4 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import * as FernNavigation from "@fern-api/fdr-sdk/navigation";
import { EMPTY_ARRAY } from "@fern-api/ui-core-utils";
import cn from "clsx";
import { compact } from "lodash-es";
import { FC, PropsWithChildren, ReactNode, memo, useRef, useState } from "react";
import { FC, PropsWithChildren, ReactNode, memo, useEffect, useRef, useState } from "react";
import { capturePosthogEvent } from "../../analytics/posthog";
import { useIsApiReferencePaginated, useRouteListener } from "../../atoms";
import { FernAnchor } from "../../components/FernAnchor";
import { useHref } from "../../hooks/useHref";
Expand Down Expand Up @@ -98,6 +99,21 @@ export const EndpointParameterContent: FC<PropsWithChildren<EndpointParameter.Co
});

const href = useHref(slug, anchorId);
const descriptions = compact([description, ...additionalDescriptions]);

useEffect(() => {
if (descriptions.length > 0) {
capturePosthogEvent("api_reference_multiple_descriptions", {
name,
slug,
anchorIdParts,
count: descriptions.length,
descriptions,
});
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [descriptions]);

return (
<div
ref={ref}
Expand All @@ -113,7 +129,7 @@ export const EndpointParameterContent: FC<PropsWithChildren<EndpointParameter.Co
{availability != null && <EndpointAvailabilityTag availability={availability} minimal={true} />}
</span>
</FernAnchor>
<Markdown mdx={compact([description, ...additionalDescriptions])} className="!t-muted" size="sm" />
<Markdown mdx={descriptions[0]} className="!t-muted" size="sm" />
{children}
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import type * as FernNavigation from "@fern-api/fdr-sdk/navigation";
import titleCase from "@fern-api/ui-core-utils/titleCase";
import cn from "clsx";
import { compact } from "lodash-es";
import { useCallback, useMemo } from "react";
import { useCallback, useEffect, useMemo } from "react";
import { capturePosthogEvent } from "../../../analytics/posthog";
import { Markdown } from "../../../mdx/Markdown";
import { EndpointAvailabilityTag } from "../../endpoints/EndpointAvailabilityTag";
import {
Expand Down Expand Up @@ -33,7 +34,7 @@ export const DiscriminatedUnionVariant: React.FC<DiscriminatedUnionVariant.Props
}) => {
const { isRootTypeDefinition } = useTypeDefinitionContext();

const [shape, descriptions] = useMemo((): [ApiDefinition.TypeShape.Object_, FernDocs.MarkdownText[]] => {
const [shape, additionalDescriptions] = useMemo((): [ApiDefinition.TypeShape.Object_, FernDocs.MarkdownText[]] => {
const unwrapped = ApiDefinition.unwrapDiscriminatedUnionVariant({ discriminant }, unionVariant, types);
return [
{
Expand Down Expand Up @@ -62,6 +63,22 @@ export const DiscriminatedUnionVariant: React.FC<DiscriminatedUnionVariant.Props
[contextValue, discriminant, unionVariant.discriminantValue],
);

const descriptions = compact([unionVariant.description, ...additionalDescriptions]);

useEffect(() => {
if (descriptions.length > 0) {
capturePosthogEvent("api_reference_multiple_descriptions", {
slug,
anchorIdParts,
discriminant,
discriminantValue: unionVariant.discriminantValue,
count: descriptions.length,
descriptions,
});
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [descriptions]);

return (
<div
className={cn("flex flex-col py-3 gap-2", {
Expand All @@ -75,7 +92,7 @@ export const DiscriminatedUnionVariant: React.FC<DiscriminatedUnionVariant.Props
<EndpointAvailabilityTag availability={unionVariant.availability} minimal={true} />
)}
<div className="flex flex-col">
<Markdown mdx={compact([unionVariant.description, ...descriptions])} size="sm" />
<Markdown mdx={descriptions[0]} size="sm" />
<TypeDefinitionContext.Provider value={newContextValue}>
<InternalTypeDefinition
shape={shape}
Expand Down
3 changes: 2 additions & 1 deletion packages/ui/app/src/mdx/Markdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ export declare namespace Markdown {
export interface Props {
title?: ReactNode;

mdx: FernDocs.MarkdownText | FernDocs.MarkdownText[] | undefined;
// mdx: FernDocs.MarkdownText | FernDocs.MarkdownText[] | undefined;
mdx: FernDocs.MarkdownText | undefined;
className?: string;
size?: "xs" | "sm" | "lg";

Expand Down
Loading