-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
chore: Add redesign for JS Editor Form #36948
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,89 @@ | ||||||
import React from "react"; | ||||||
import { FEATURE_FLAG } from "ee/entities/FeatureFlag"; | ||||||
import type { JSEditorTab } from "reducers/uiReducers/jsPaneReducer"; | ||||||
import { useFeatureFlag } from "utils/hooks/useFeatureFlag"; | ||||||
import { | ||||||
type BlockCompletion, | ||||||
CodeEditorBorder, | ||||||
EditorModes, | ||||||
EditorSize, | ||||||
type EditorTheme, | ||||||
TabBehaviour, | ||||||
} from "components/editorComponents/CodeEditor/EditorConfig"; | ||||||
import type { CodeEditorGutter } from "components/editorComponents/CodeEditor"; | ||||||
import type { JSAction, JSCollection } from "entities/JSCollection"; | ||||||
import { OldJSEditorForm } from "./old/JSEditorForm"; | ||||||
import type { OnUpdateSettingsProps } from "../JSFunctionSettings"; | ||||||
import LazyCodeEditor from "components/editorComponents/LazyCodeEditor"; | ||||||
import { Flex } from "@appsmith/ads"; | ||||||
|
||||||
interface Props { | ||||||
executing: boolean; | ||||||
onValueChange: (value: string) => void; | ||||||
value: JSEditorTab; | ||||||
showSettings: undefined | boolean; | ||||||
blockCompletions: Array<BlockCompletion>; | ||||||
customGutter: CodeEditorGutter; | ||||||
currentJSCollection: JSCollection; | ||||||
changePermitted: boolean; | ||||||
onChange: (valueOrEvent: React.ChangeEvent | string) => void; | ||||||
theme: EditorTheme.LIGHT; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct the 'theme' prop type in 'Props' interface The Apply this diff to fix the issue: - theme: EditorTheme.LIGHT;
+ theme: EditorTheme; 📝 Committable suggestion
Suggested change
|
||||||
actions: JSAction[]; | ||||||
onUpdateSettings?: (props: OnUpdateSettingsProps) => void; | ||||||
} | ||||||
|
||||||
export const JSEditorForm = (props: Props) => { | ||||||
const isActionRedesignEnabled = useFeatureFlag( | ||||||
FEATURE_FLAG.release_actions_redesign_enabled, | ||||||
); | ||||||
|
||||||
if (!isActionRedesignEnabled) { | ||||||
return ( | ||||||
<OldJSEditorForm | ||||||
actions={props.actions} | ||||||
blockCompletions={props.blockCompletions} | ||||||
changePermitted={props.changePermitted} | ||||||
currentJSCollection={props.currentJSCollection} | ||||||
customGutter={props.customGutter} | ||||||
executing={props.executing} | ||||||
onChange={props.onChange} | ||||||
onUpdateSettings={props.onUpdateSettings} | ||||||
onValueChange={props.onValueChange} | ||||||
showSettings={props.showSettings} | ||||||
theme={props.theme} | ||||||
value={props.value} | ||||||
/> | ||||||
); | ||||||
} | ||||||
|
||||||
return ( | ||||||
<Flex flex="1" overflow="scroll"> | ||||||
<LazyCodeEditor | ||||||
AIAssisted | ||||||
blockCompletions={props.blockCompletions} | ||||||
border={CodeEditorBorder.NONE} | ||||||
borderLess | ||||||
className={"js-editor"} | ||||||
customGutter={props.customGutter} | ||||||
dataTreePath={`${props.currentJSCollection.name}.body`} | ||||||
disabled={!props.changePermitted} | ||||||
folding | ||||||
height={"100%"} | ||||||
hideEvaluatedValue | ||||||
input={{ | ||||||
value: props.currentJSCollection.body, | ||||||
onChange: props.onChange, | ||||||
}} | ||||||
isJSObject | ||||||
jsObjectName={props.currentJSCollection.name} | ||||||
mode={EditorModes.JAVASCRIPT} | ||||||
placeholder="Let's write some code!" | ||||||
showLightningMenu={false} | ||||||
showLineNumbers | ||||||
size={EditorSize.EXTENDED} | ||||||
tabBehaviour={TabBehaviour.INDENT} | ||||||
theme={props.theme} | ||||||
/> | ||||||
</Flex> | ||||||
); | ||||||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { JSEditorForm } from "./JSEditorForm"; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import { JSEditorTab } from "reducers/uiReducers/jsPaneReducer"; | ||
import React from "react"; | ||
import type { | ||
BlockCompletion, | ||
EditorTheme, | ||
} from "components/editorComponents/CodeEditor/EditorConfig"; | ||
import { | ||
CodeEditorBorder, | ||
EditorModes, | ||
EditorSize, | ||
TabBehaviour, | ||
} from "components/editorComponents/CodeEditor/EditorConfig"; | ||
import { TabbedViewContainer } from "../../styledComponents"; | ||
import { Tab, TabPanel, Tabs, TabsList } from "@appsmith/ads"; | ||
import LazyCodeEditor from "components/editorComponents/LazyCodeEditor"; | ||
import JSFunctionSettingsView, { | ||
type OnUpdateSettingsProps, | ||
} from "../../JSFunctionSettings"; | ||
import type { CodeEditorGutter } from "components/editorComponents/CodeEditor"; | ||
import type { JSAction, JSCollection } from "entities/JSCollection"; | ||
|
||
interface Props { | ||
executing: boolean; | ||
onValueChange: (value: string) => void; | ||
value: JSEditorTab; | ||
showSettings: undefined | boolean; | ||
blockCompletions: Array<BlockCompletion>; | ||
customGutter: CodeEditorGutter; | ||
currentJSCollection: JSCollection; | ||
changePermitted: boolean; | ||
onChange: (valueOrEvent: React.ChangeEvent | string) => void; | ||
theme: EditorTheme.LIGHT; | ||
actions: JSAction[]; | ||
onUpdateSettings?: (props: OnUpdateSettingsProps) => void; | ||
} | ||
|
||
export function OldJSEditorForm(props: Props) { | ||
return ( | ||
<TabbedViewContainer isExecuting={props.executing}> | ||
<Tabs | ||
defaultValue={JSEditorTab.CODE} | ||
onValueChange={props.onValueChange} | ||
value={props.value} | ||
> | ||
<TabsList> | ||
<Tab | ||
data-testid={`t--js-editor-` + JSEditorTab.CODE} | ||
value={JSEditorTab.CODE} | ||
> | ||
Code | ||
</Tab> | ||
{props.showSettings && ( | ||
<Tab | ||
data-testid={`t--js-editor-` + JSEditorTab.SETTINGS} | ||
value={JSEditorTab.SETTINGS} | ||
> | ||
Settings | ||
</Tab> | ||
)} | ||
</TabsList> | ||
<TabPanel value={JSEditorTab.CODE}> | ||
<div className="js-editor-tab"> | ||
<LazyCodeEditor | ||
AIAssisted | ||
blockCompletions={props.blockCompletions} | ||
border={CodeEditorBorder.NONE} | ||
borderLess | ||
className={"js-editor"} | ||
customGutter={props.customGutter} | ||
dataTreePath={`${props.currentJSCollection.name}.body`} | ||
disabled={!props.changePermitted} | ||
folding | ||
height={"100%"} | ||
hideEvaluatedValue | ||
input={{ | ||
value: props.currentJSCollection.body, | ||
onChange: props.onChange, | ||
}} | ||
isJSObject | ||
jsObjectName={props.currentJSCollection.name} | ||
mode={EditorModes.JAVASCRIPT} | ||
placeholder="Let's write some code!" | ||
showLightningMenu={false} | ||
showLineNumbers | ||
size={EditorSize.EXTENDED} | ||
tabBehaviour={TabBehaviour.INDENT} | ||
theme={props.theme} | ||
/> | ||
</div> | ||
</TabPanel> | ||
{props.showSettings && ( | ||
<TabPanel value={JSEditorTab.SETTINGS}> | ||
<div className="js-editor-tab"> | ||
<JSFunctionSettingsView | ||
actions={props.actions} | ||
disabled={!props.changePermitted} | ||
onUpdateSettings={props.onUpdateSettings} | ||
/> | ||
</div> | ||
</TabPanel> | ||
)} | ||
</Tabs> | ||
</TabbedViewContainer> | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Refactor
onValueChange
to improve clarity and type safety.Avoid using
string
as a parameter name and unnecessary type assertions.Consider updating the function as follows:
📝 Committable suggestion