-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f98571d
commit 22b2dfb
Showing
9 changed files
with
214 additions
and
194 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import React from "react"; | ||
import styled from "styled-components"; | ||
import clsx from "classnames"; | ||
|
||
import { Flex, Icon } from "design-system"; | ||
|
||
interface FileTabProps { | ||
isActive: boolean; | ||
title: string; | ||
onClick: () => void; | ||
onClose: (e: React.MouseEvent) => void; | ||
icon?: React.ReactNode; | ||
} | ||
|
||
export const StyledTab = styled(Flex)` | ||
position: relative; | ||
height: 100%; | ||
font-size: 12px; | ||
color: var(--ads-v2-colors-text-default); | ||
cursor: pointer; | ||
gap: var(--ads-v2-spaces-2); | ||
border-top: 1px solid transparent; | ||
border-top-left-radius: var(--ads-v2-border-radius); | ||
border-top-right-radius: var(--ads-v2-border-radius); | ||
align-items: center; | ||
justify-content: center; | ||
padding: var(--ads-v2-spaces-3); | ||
border-left: 1px solid transparent; | ||
border-right: 1px solid transparent; | ||
border-top: 2px solid transparent; | ||
&.active { | ||
background: var(--ads-v2-colors-control-field-default-bg); | ||
border-top-color: var(--ads-v2-color-bg-brand); | ||
border-left-color: var(--ads-v2-color-border-muted); | ||
border-right-color: var(--ads-v2-color-border-muted); | ||
} | ||
& > .tab-close { | ||
position: relative; | ||
right: -2px; | ||
visibility: hidden; | ||
} | ||
&:hover > .tab-close { | ||
visibility: visible; | ||
} | ||
&.active > .tab-close { | ||
visibility: visible; | ||
} | ||
`; | ||
|
||
export const TabTextContainer = styled.span` | ||
width: 100%; | ||
text-overflow: ellipsis; | ||
white-space: nowrap; | ||
overflow: hidden; | ||
`; | ||
|
||
export const TabIconContainer = styled.div` | ||
height: 12px; | ||
width: 12px; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
flex-shrink: 0; | ||
img { | ||
width: 12px; | ||
} | ||
`; | ||
|
||
export const FileTab = ({ | ||
icon, | ||
isActive, | ||
onClick, | ||
onClose, | ||
title, | ||
}: FileTabProps) => { | ||
return ( | ||
<StyledTab | ||
className={clsx("editor-tab", isActive && "active")} | ||
data-testid={`t--ide-tab-${title}`} | ||
onClick={onClick} | ||
> | ||
{icon ? <TabIconContainer>{icon}</TabIconContainer> : null} | ||
<TabTextContainer>{title}</TabTextContainer> | ||
{/* not using button component because of the size not matching design */} | ||
<Icon | ||
className="tab-close rounded-[4px] hover:bg-[var(--ads-v2-colors-action-tertiary-surface-hover-bg)] cursor-pointer p-[2px]" | ||
data-testid="t--tab-close-btn" | ||
name="close-line" | ||
onClick={onClose} | ||
/> | ||
</StyledTab> | ||
); | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,67 @@ | ||
import React from "react"; | ||
import type { Ref } from "react"; | ||
import React, { forwardRef } from "react"; | ||
import { Flex, Spinner, Button } from "design-system"; | ||
import { useCurrentEditorState, useIDETabClickHandlers } from "../hooks"; | ||
import { useIsJSAddLoading } from "@appsmith/pages/Editor/IDE/EditorPane/JS/hooks"; | ||
import { EditorEntityTabState } from "@appsmith/entities/IDE/constants"; | ||
import { | ||
EditorEntityTab, | ||
EditorEntityTabState, | ||
} from "@appsmith/entities/IDE/constants"; | ||
import { FileTab } from "IDE/Components/FileTab"; | ||
|
||
const AddButton = () => { | ||
const { addClickHandler } = useIDETabClickHandlers(); | ||
const isJSLoading = useIsJSAddLoading(); | ||
const { segmentMode } = useCurrentEditorState(); | ||
const AddButton = forwardRef( | ||
( | ||
{ | ||
newTabClickCallback, | ||
onClose, | ||
}: { | ||
newTabClickCallback: () => void; | ||
onClose: (actionId?: string) => void; | ||
}, | ||
ref: Ref<HTMLDivElement>, | ||
) => { | ||
const { addClickHandler } = useIDETabClickHandlers(); | ||
const isJSLoading = useIsJSAddLoading(); | ||
const { segment, segmentMode } = useCurrentEditorState(); | ||
|
||
if (segmentMode === EditorEntityTabState.Add) { | ||
return null; | ||
} | ||
if (isJSLoading) { | ||
return ( | ||
<Flex px="spaces-2"> | ||
<Spinner size="md" /> | ||
</Flex> | ||
if (isJSLoading) { | ||
return ( | ||
<Flex px="spaces-2"> | ||
<Spinner size="md" /> | ||
</Flex> | ||
); | ||
} | ||
|
||
const onCloseClick = (e: React.MouseEvent) => { | ||
e.stopPropagation(); | ||
onClose(); | ||
}; | ||
|
||
return segmentMode === EditorEntityTabState.Add ? ( | ||
<FileTab | ||
isActive={segmentMode === EditorEntityTabState.Add} | ||
onClick={newTabClickCallback} | ||
onClose={(e) => onCloseClick(e)} | ||
title={`New ${segment === EditorEntityTab.JS ? "JS" : "Query"}`} | ||
/> | ||
) : ( | ||
<div | ||
className="bg-white sticky right-0 flex items-center h-[32px] border-b border-b-[var(--ads-v2-color-border-muted)] pl-[var(--ads-v2-spaces-2)]" | ||
ref={ref} | ||
> | ||
<Button | ||
className="!min-w-[24px]" | ||
data-testid="t--ide-tabs-add-button" | ||
id="tabs-add-toggle" | ||
isIconButton | ||
kind="tertiary" | ||
onClick={addClickHandler} | ||
size="sm" | ||
startIcon="add-line" | ||
/> | ||
</div> | ||
); | ||
} | ||
return ( | ||
<Button | ||
className="!min-w-[24px]" | ||
data-testid="t--ide-tabs-add-button" | ||
id="tabs-add-toggle" | ||
isIconButton | ||
kind="tertiary" | ||
onClick={addClickHandler} | ||
size="sm" | ||
startIcon="add-line" | ||
/> | ||
); | ||
}; | ||
}, | ||
); | ||
|
||
export { AddButton }; |
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
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
Oops, something went wrong.