Skip to content

Commit

Permalink
[editor][ez] Only Render SidePanel Tab Content When Active Tab
Browse files Browse the repository at this point in the history
# [editor][ez] Only Render SidePanel Tab Content When Active Tab

I noticed each of the tab components was being rendered even when they're not shown. We can improve render perf by only rendering them when their tab is selected.

## Testing:
- Just ensure tabs still work
- Use console.log to ensure the components are only rendered when shown
  • Loading branch information
Ryan Holinshead committed Feb 15, 2024
1 parent 2398cca commit 933df94
Showing 1 changed file with 42 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export default memo(function PromptActionBar({
onUpdatePromptMetadata,
}: Props) {
const [isExpanded, setIsExpanded] = useState(false);
const [selectedTab, setSelectedTab] = useState<string | null>("settings");
// TODO: Handle drag-to-resize
const modelSettingsSchema = promptSchema?.model_settings;
const promptMetadataSchema = promptSchema?.prompt_metadata;
Expand All @@ -85,49 +86,57 @@ export default memo(function PromptActionBar({
<ActionIcon size="sm" onClick={() => setIsExpanded(false)} mt="0.5em">
<IconClearAll />
</ActionIcon>
<Tabs defaultValue="settings" mb="1em">
<Tabs
defaultValue="settings"
value={selectedTab}
mb="1em"
onTabChange={setSelectedTab}
>
<Tabs.List>
<Tabs.Tab value="settings">Settings</Tabs.Tab>
{checkParametersSupported(prompt) && (
<Tabs.Tab value="parameters">Local Parameters</Tabs.Tab>
)}
</Tabs.List>

<Tabs.Panel value="settings" className="actionTabsPanel">
<ScrollArea
h={maxContentHeightPx}
type="auto"
style={{ overflowY: "auto" }}
>
<ModelSettingsRenderer
settings={getModelSettings(prompt)}
schema={modelSettingsSchema}
onUpdateModelSettings={onUpdateModelSettings}
/>
{/* For now, just render metadata if a schema is explicitly provided */}
{promptMetadataSchema && (
<PromptMetadataRenderer
metadata={getMetadata(prompt)}
onUpdatePromptMetadata={onUpdatePromptMetadata}
schema={promptMetadataSchema}
{selectedTab === "settings" && (
<Tabs.Panel value="settings" className="actionTabsPanel">
<ScrollArea
h={maxContentHeightPx}
type="auto"
style={{ overflowY: "auto" }}
>
<ModelSettingsRenderer
settings={getModelSettings(prompt)}
schema={modelSettingsSchema}
onUpdateModelSettings={onUpdateModelSettings}
/>
)}
</ScrollArea>
</Tabs.Panel>

{checkParametersSupported(prompt) && (
<Tabs.Panel value="parameters" className="actionTabsPanel">
<ParametersRenderer
initialValue={getPromptParameters(prompt)}
onUpdateParameters={onUpdateParameters}
maxHeight={
maxContentHeightPx
? maxContentHeightPx - ADD_PARAMETER_BOTTOM_HEIGHT
: undefined
}
/>
{/* For now, just render metadata if a schema is explicitly provided */}
{promptMetadataSchema && (
<PromptMetadataRenderer
metadata={getMetadata(prompt)}
onUpdatePromptMetadata={onUpdatePromptMetadata}
schema={promptMetadataSchema}
/>
)}
</ScrollArea>
</Tabs.Panel>
)}

{selectedTab === "parameters" &&
checkParametersSupported(prompt) && (
<Tabs.Panel value="parameters" className="actionTabsPanel">
<ParametersRenderer
initialValue={getPromptParameters(prompt)}
onUpdateParameters={onUpdateParameters}
maxHeight={
maxContentHeightPx
? maxContentHeightPx - ADD_PARAMETER_BOTTOM_HEIGHT
: undefined
}
/>
</Tabs.Panel>
)}
</Tabs>
</Container>
) : (
Expand Down

0 comments on commit 933df94

Please sign in to comment.