-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(chore): reduce re-render cycles in EndpointContent (#1268)
- Loading branch information
1 parent
ff8e48d
commit 1d30276
Showing
5 changed files
with
103 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
packages/ui/app/src/api-page/endpoints/EndpointContentHeader.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { useAtomValue } from "jotai"; | ||
import { memo } from "react"; | ||
import { FERN_STREAM_ATOM } from "../../atoms"; | ||
import { useSelectedEnvironmentId } from "../../atoms/environment"; | ||
import { Breadcrumbs } from "../../components/Breadcrumbs"; | ||
import { ResolvedEndpointDefinition, resolveEnvironment } from "../../resolver/types"; | ||
import { EndpointAvailabilityTag } from "./EndpointAvailabilityTag"; | ||
import { EndpointStreamingEnabledToggle } from "./EndpointStreamingEnabledToggle"; | ||
import { EndpointUrlWithOverflow } from "./EndpointUrlWithOverflow"; | ||
|
||
interface EndpointContentHeaderProps { | ||
endpoint: ResolvedEndpointDefinition; | ||
breadcrumbs: readonly string[]; | ||
container: React.MutableRefObject<HTMLElement | null>; | ||
} | ||
|
||
export const EndpointContentHeader = memo<EndpointContentHeaderProps>(({ endpoint, breadcrumbs, container }) => { | ||
const isStream = useAtomValue(FERN_STREAM_ATOM); | ||
const endpointProp = endpoint.stream != null && isStream ? endpoint.stream : endpoint; | ||
const selectedEnvironmentId = useSelectedEnvironmentId(); | ||
return ( | ||
<header className="space-y-1 pb-2 pt-8"> | ||
<Breadcrumbs breadcrumbs={breadcrumbs} /> | ||
<div className="flex items-center justify-between"> | ||
<span> | ||
<h1 className="fern-page-heading"> | ||
{/* <AnimatedTitle>{endpoint.title}</AnimatedTitle> */} | ||
{endpoint.title} | ||
</h1> | ||
{endpoint.availability != null && ( | ||
<span className="inline-block ml-2 align-text-bottom"> | ||
<EndpointAvailabilityTag availability={endpoint.availability} minimal={true} /> | ||
</span> | ||
)} | ||
</span> | ||
|
||
{endpointProp.stream != null && ( | ||
<EndpointStreamingEnabledToggle endpointProp={endpointProp} container={container} /> | ||
)} | ||
</div> | ||
<EndpointUrlWithOverflow | ||
path={endpoint.path} | ||
method={endpoint.method} | ||
selectedEnvironment={resolveEnvironment(endpoint, selectedEnvironmentId)} | ||
showEnvironment | ||
large | ||
/> | ||
</header> | ||
); | ||
}); | ||
|
||
EndpointContentHeader.displayName = "EndpointContentHeader"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 5 additions & 8 deletions
13
packages/ui/app/src/api-page/endpoints/EndpointStreamingEnabledToggle.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters