refactor: improve conditional rendering on panel buttons (#5365)

add render condition on modal buttons
This commit is contained in:
Cristhian Zanforlin Lousa 2024-12-19 15:35:11 -03:00 • committed by GitHub
commit 435d86067c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 279 additions and 264 deletions

View file

@ -259,249 +259,253 @@ export default function IOModal({
<BaseModal.Trigger>{children}</BaseModal.Trigger> <BaseModal.Trigger>{children}</BaseModal.Trigger>
{/* TODO ADAPT TO ALL TYPES OF INPUTS AND OUTPUTS */} {/* TODO ADAPT TO ALL TYPES OF INPUTS AND OUTPUTS */}
<BaseModal.Content overflowHidden className="h-full"> <BaseModal.Content overflowHidden className="h-full">
<div className="flex-max-width h-full"> {open && (
<div <div className="flex-max-width h-full">
className={cn(
"flex h-full flex-shrink-0 flex-col justify-start transition-all duration-300",
sidebarOpen
? "absolute z-50 lg:relative lg:w-1/5 lg:max-w-[280px]"
: "w-0",
)}
>
<div className="flex h-full flex-col overflow-y-auto border-r border-border bg-muted p-4 text-center custom-scroll dark:bg-canvas">
<div className="flex items-center gap-2 pb-8">
<ShadTooltip
styleClasses="z-50"
side="right"
content="Hide sidebar"
>
<Button
variant="ghost"
className="flex h-8 w-8 items-center justify-center !p-0"
onClick={() => setSidebarOpen(!sidebarOpen)}
>
<IconComponent
name={sidebarOpen ? "PanelLeftClose" : "PanelLeftOpen"}
className="h-[18px] w-[18px] text-ring"
/>
</Button>
</ShadTooltip>
{sidebarOpen && <div className="font-semibold">Playground</div>}
</div>
{sidebarOpen && (
<div className="flex flex-col pl-3">
<div className="flex flex-col gap-2 pb-2">
<div className="flex items-center justify-between">
<div className="flex items-center gap-2">
<IconComponent
name="MessagesSquare"
className="h-[18px] w-[18px] text-ring"
/>
<div className="text-[13px] font-normal">Chat</div>
</div>
<ShadTooltip styleClasses="z-50" content="New Chat">
<div>
<Button
data-testid="new-chat"
variant="ghost"
className="flex h-8 w-8 items-center justify-center !p-0 hover:bg-secondary-hover"
onClick={(_) => {
setvisibleSession(undefined);
setSelectedViewField(undefined);
}}
>
<IconComponent
name="Plus"
className="h-[18px] w-[18px] text-ring"
/>
</Button>
</div>
</ShadTooltip>
</div>
</div>
<div className="flex flex-col">
{sessions.map((session, index) => (
<SessionSelector
setSelectedView={setSelectedViewField}
selectedView={selectedViewField}
key={index}
session={session}
deleteSession={(session) => {
handleDeleteSession(session);
if (selectedViewField?.id === session) {
setSelectedViewField(undefined);
}
}}
updateVisibleSession={(session) => {
setvisibleSession(session);
}}
toggleVisibility={() => {
setvisibleSession(session);
}}
isVisible={visibleSession === session}
inspectSession={(session) => {
setSelectedViewField({
id: session,
type: "Session",
});
}}
/>
))}
</div>
</div>
)}
</div>
</div>
<div className="flex h-full min-w-96 flex-grow bg-background">
{selectedViewField && (
<div
className={cn(
"flex h-full w-full flex-col items-start gap-4 p-4",
!selectedViewField ? "hidden" : "",
)}
>
<div className="font-xl flex items-center justify-center gap-3 font-semibold">
{haveChat && (
<button onClick={() => setSelectedViewField(undefined)}>
<IconComponent
name={"ArrowLeft"}
className="h-6 w-6"
></IconComponent>
</button>
)}
{
nodes.find((node) => node.id === selectedViewField.id)?.data
.node.display_name
}
</div>
<div className="h-full w-full">
{inputs.some(
(input) => input.id === selectedViewField.id,
) && (
<IOFieldView
type={InputOutput.INPUT}
left={false}
fieldType={selectedViewField.type!}
fieldId={selectedViewField.id!}
/>
)}
{outputs.some(
(output) => output.id === selectedViewField.id,
) && (
<IOFieldView
type={InputOutput.OUTPUT}
left={false}
fieldType={selectedViewField.type!}
fieldId={selectedViewField.id!}
/>
)}
{sessions.some(
(session) => session === selectedViewField.id,
) && (
<SessionView
session={selectedViewField.id}
id={currentFlowId}
/>
)}
</div>
</div>
)}
<div <div
className={cn( className={cn(
"flex h-full w-full flex-col justify-between p-4", "flex h-full flex-shrink-0 flex-col justify-start transition-all duration-300",
selectedViewField ? "hidden" : "", sidebarOpen
? "absolute z-50 lg:relative lg:w-1/5 lg:max-w-[280px]"
: "w-0",
)} )}
> >
<div className="mb-4 h-[5%] text-[16px] font-semibold"> <div className="flex h-full flex-col overflow-y-auto border-r border-border bg-muted p-4 text-center custom-scroll dark:bg-canvas">
{visibleSession && sessions.length > 0 && sidebarOpen && ( <div className="flex items-center gap-2 pb-8">
<div className="hidden lg:block"> <ShadTooltip
{visibleSession === currentFlowId styleClasses="z-50"
? "Default Session" side="right"
: `${visibleSession}`} content="Hide sidebar"
</div> >
)}
<div className={cn(sidebarOpen ? "lg:hidden" : "")}>
<div className="flex items-center gap-2">
<Button <Button
variant="ghost" variant="ghost"
size="icon" className="flex h-8 w-8 items-center justify-center !p-0"
onClick={() => setSidebarOpen(true)} onClick={() => setSidebarOpen(!sidebarOpen)}
className="h-8 w-8"
> >
<IconComponent <IconComponent
name={"PanelLeftOpen"} name={sidebarOpen ? "PanelLeftClose" : "PanelLeftOpen"}
className="h-[18px] w-[18px] text-ring" className="h-[18px] w-[18px] text-ring"
/> />
</Button> </Button>
</ShadTooltip>
{sidebarOpen && (
<div className="font-semibold">Playground</div> <div className="font-semibold">Playground</div>
)}
</div>
{sidebarOpen && (
<div className="flex flex-col pl-3">
<div className="flex flex-col gap-2 pb-2">
<div className="flex items-center justify-between">
<div className="flex items-center gap-2">
<IconComponent
name="MessagesSquare"
className="h-[18px] w-[18px] text-ring"
/>
<div className="text-[13px] font-normal">Chat</div>
</div>
<ShadTooltip styleClasses="z-50" content="New Chat">
<div>
<Button
data-testid="new-chat"
variant="ghost"
className="flex h-8 w-8 items-center justify-center !p-0 hover:bg-secondary-hover"
onClick={(_) => {
setvisibleSession(undefined);
setSelectedViewField(undefined);
}}
>
<IconComponent
name="Plus"
className="h-[18px] w-[18px] text-ring"
/>
</Button>
</div>
</ShadTooltip>
</div>
</div>
<div className="flex flex-col">
{sessions.map((session, index) => (
<SessionSelector
setSelectedView={setSelectedViewField}
selectedView={selectedViewField}
key={index}
session={session}
deleteSession={(session) => {
handleDeleteSession(session);
if (selectedViewField?.id === session) {
setSelectedViewField(undefined);
}
}}
updateVisibleSession={(session) => {
setvisibleSession(session);
}}
toggleVisibility={() => {
setvisibleSession(session);
}}
isVisible={visibleSession === session}
inspectSession={(session) => {
setSelectedViewField({
id: session,
type: "Session",
});
}}
/>
))}
</div>
</div>
)}
</div>
</div>
<div className="flex h-full min-w-96 flex-grow bg-background">
{selectedViewField && (
<div
className={cn(
"flex h-full w-full flex-col items-start gap-4 p-4",
!selectedViewField ? "hidden" : "",
)}
>
<div className="font-xl flex items-center justify-center gap-3 font-semibold">
{haveChat && (
<button onClick={() => setSelectedViewField(undefined)}>
<IconComponent
name={"ArrowLeft"}
className="h-6 w-6"
></IconComponent>
</button>
)}
{
nodes.find((node) => node.id === selectedViewField.id)
?.data.node.display_name
}
</div>
<div className="h-full w-full">
{inputs.some(
(input) => input.id === selectedViewField.id,
) && (
<IOFieldView
type={InputOutput.INPUT}
left={false}
fieldType={selectedViewField.type!}
fieldId={selectedViewField.id!}
/>
)}
{outputs.some(
(output) => output.id === selectedViewField.id,
) && (
<IOFieldView
type={InputOutput.OUTPUT}
left={false}
fieldType={selectedViewField.type!}
fieldId={selectedViewField.id!}
/>
)}
{sessions.some(
(session) => session === selectedViewField.id,
) && (
<SessionView
session={selectedViewField.id}
id={currentFlowId}
/>
)}
</div> </div>
</div> </div>
<div
className={cn(
sidebarOpen ? "pointer-events-none opacity-0" : "",
"absolute flex h-8 items-center justify-center rounded-sm ring-offset-background transition-opacity focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",
isPlayground ? "right-2 top-4" : "right-12 top-2",
)}
>
<ShadTooltip
side="bottom"
styleClasses="z-50"
content="New Chat"
>
<Button
className="mr-2 h-[32px] w-[32px] hover:bg-secondary-hover"
variant="ghost"
size="icon"
onClick={(_) => {
setvisibleSession(undefined);
setSelectedViewField(undefined);
}}
>
<IconComponent
name="Plus"
className="!h-[18px] !w-[18px] text-ring"
/>
</Button>
</ShadTooltip>
{!isPlayground && <Separator orientation="vertical" />}
</div>
</div>
{haveChat ? (
<div
className={cn(
visibleSession ? "h-[95%]" : "h-full",
sidebarOpen
? "pointer-events-none blur-sm lg:pointer-events-auto lg:blur-0"
: "",
)}
>
{messagesFetched && (
<ChatView
focusChat={sessionId}
sendMessage={sendMessage}
chatValue={chatValue}
setChatValue={setChatValue}
lockChat={lockChat}
setLockChat={setLockChat}
visibleSession={visibleSession}
closeChat={
!canvasOpen
? undefined
: () => {
setOpen(false);
}
}
/>
)}
</div>
) : (
<span className="flex h-full w-full items-center justify-center font-thin text-muted-foreground">
Select an IO component to view
</span>
)} )}
<div
className={cn(
"flex h-full w-full flex-col justify-between p-4",
selectedViewField ? "hidden" : "",
)}
>
<div className="mb-4 h-[5%] text-[16px] font-semibold">
{visibleSession && sessions.length > 0 && sidebarOpen && (
<div className="hidden lg:block">
{visibleSession === currentFlowId
? "Default Session"
: `${visibleSession}`}
</div>
)}
<div className={cn(sidebarOpen ? "lg:hidden" : "")}>
<div className="flex items-center gap-2">
<Button
variant="ghost"
size="icon"
onClick={() => setSidebarOpen(true)}
className="h-8 w-8"
>
<IconComponent
name={"PanelLeftOpen"}
className="h-[18px] w-[18px] text-ring"
/>
</Button>
<div className="font-semibold">Playground</div>
</div>
</div>
<div
className={cn(
sidebarOpen ? "pointer-events-none opacity-0" : "",
"absolute flex h-8 items-center justify-center rounded-sm ring-offset-background transition-opacity focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",
isPlayground ? "right-2 top-4" : "right-12 top-2",
)}
>
<ShadTooltip
side="bottom"
styleClasses="z-50"
content="New Chat"
>
<Button
className="mr-2 h-[32px] w-[32px] hover:bg-secondary-hover"
variant="ghost"
size="icon"
onClick={(_) => {
setvisibleSession(undefined);
setSelectedViewField(undefined);
}}
>
<IconComponent
name="Plus"
className="!h-[18px] !w-[18px] text-ring"
/>
</Button>
</ShadTooltip>
{!isPlayground && <Separator orientation="vertical" />}
</div>
</div>
{haveChat ? (
<div
className={cn(
visibleSession ? "h-[95%]" : "h-full",
sidebarOpen
? "pointer-events-none blur-sm lg:pointer-events-auto lg:blur-0"
: "",
)}
>
{messagesFetched && (
<ChatView
focusChat={sessionId}
sendMessage={sendMessage}
chatValue={chatValue}
setChatValue={setChatValue}
lockChat={lockChat}
setLockChat={setLockChat}
visibleSession={visibleSession}
closeChat={
!canvasOpen
? undefined
: () => {
setOpen(false);
}
}
/>
)}
</div>
) : (
<span className="flex h-full w-full items-center justify-center font-thin text-muted-foreground">
Select an IO component to view
</span>
)}
</div>
</div> </div>
</div> </div>
</div> )}
</BaseModal.Content> </BaseModal.Content>
</BaseModal> </BaseModal>
); );

View file

@ -54,15 +54,19 @@ export default function ApiModal({
/> />
</BaseModal.Header> </BaseModal.Header>
<BaseModal.Content overflowHidden> <BaseModal.Content overflowHidden>
<CustomAPIGenerator isOpen={open} /> {open && (
<CodeTabsComponent <>
open={open} <CustomAPIGenerator isOpen={open} />
tabs={tabs!} <CodeTabsComponent
activeTab={activeTab} open={open}
setActiveTab={setActiveTab} tabs={tabs!}
activeTweaks={activeTweaks} activeTab={activeTab}
setActiveTweaks={setActiveTweaks} setActiveTab={setActiveTab}
/> activeTweaks={activeTweaks}
setActiveTweaks={setActiveTweaks}
/>
</>
)}
</BaseModal.Content> </BaseModal.Content>
</BaseModal> </BaseModal>
); );

View file

@ -221,35 +221,42 @@ export default function ShareModal({
/> />
</BaseModal.Header> </BaseModal.Header>
<BaseModal.Content> <BaseModal.Content>
<div className="w-full rounded-lg border border-border p-4"> {open && (
<EditFlowSettings name={name} description={description} /> <>
</div> <div className="w-full rounded-lg border border-border p-4">
<div className="mt-3 flex h-8 w-full"> <EditFlowSettings name={name} description={description} />
<TagsSelector </div>
tags={tags ?? []} <div className="mt-3 flex h-8 w-full">
loadingTags={false} <TagsSelector
disabled={false} tags={tags ?? []}
selectedTags={selectedTags} loadingTags={false}
setSelectedTags={setSelectedTags} disabled={false}
/> selectedTags={selectedTags}
</div> setSelectedTags={setSelectedTags}
<div className="mb-2 mt-5 flex items-center space-x-2"> />
<Checkbox </div>
id="public" <div className="mb-2 mt-5 flex items-center space-x-2">
checked={sharePublic} <Checkbox
onCheckedChange={(event: boolean) => { id="public"
setSharePublic(event); checked={sharePublic}
}} onCheckedChange={(event: boolean) => {
data-testid="public-checkbox" setSharePublic(event);
/> }}
<label htmlFor="public" className="export-modal-save-api text-sm"> data-testid="public-checkbox"
Set {nameComponent} status to public />
</label> <label
</div> htmlFor="public"
<span className="text-xs text-destructive"> className="export-modal-save-api text-sm"
<b>Attention:</b> API keys in specified fields are automatically >
removed upon sharing. Set {nameComponent} status to public
</span> </label>
</div>
<span className="text-xs text-destructive">
<b>Attention:</b> API keys in specified fields are automatically
removed upon sharing.
</span>
</>
)}
</BaseModal.Content> </BaseModal.Content>
<BaseModal.Footer <BaseModal.Footer