-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'release' into feat/32440-editable-ide-tabs
- Loading branch information
Showing
15 changed files
with
388 additions
and
44 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
18 changes: 18 additions & 0 deletions
18
...widgets/src/components/AIChat/src/AssistantSuggestionButton/AssistantSuggestionButton.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,18 @@ | ||
import { Text } from "@appsmith/wds"; | ||
import { clsx } from "clsx"; | ||
import React from "react"; | ||
import { Button as HeadlessButton } from "react-aria-components"; | ||
import styles from "./styles.module.css"; | ||
import type { AssistantSuggestionButtonProps } from "./types"; | ||
|
||
export const AssistantSuggestionButton = ({ | ||
children, | ||
className, | ||
...rest | ||
}: AssistantSuggestionButtonProps) => { | ||
return ( | ||
<HeadlessButton className={clsx(styles.root, className)} {...rest}> | ||
<Text>{children}</Text> | ||
</HeadlessButton> | ||
); | ||
}; |
2 changes: 2 additions & 0 deletions
2
...ckages/design-system/widgets/src/components/AIChat/src/AssistantSuggestionButton/index.ts
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,2 @@ | ||
export * from "./AssistantSuggestionButton"; | ||
export * from "./types"; |
20 changes: 20 additions & 0 deletions
20
...sign-system/widgets/src/components/AIChat/src/AssistantSuggestionButton/styles.module.css
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,20 @@ | ||
.root { | ||
height: 30px; | ||
padding: 0 var(--inner-spacing-4); | ||
background-color: var(--bg-neutral-subtle-alt, #e7e8e8); | ||
border-radius: var(--radius-inner-button, 1.8px); | ||
|
||
&:hover { | ||
background-color: var(--bg-neutral-subtle-alt-hover, #f0f1f1); | ||
} | ||
|
||
&:focus-visible { | ||
box-shadow: | ||
0 0 0 2px var(--color-bg), | ||
0 0 0 4px var(--color-bd-focus); | ||
} | ||
|
||
&:active { | ||
background-color: var(--bg-neutral-subtle-alt-active, #e1e2e2); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
...ckages/design-system/widgets/src/components/AIChat/src/AssistantSuggestionButton/types.ts
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,5 @@ | ||
import type { PropsWithChildren } from "react"; | ||
import type { ButtonProps as HeadlessButtonProps } from "react-aria-components"; | ||
|
||
export interface AssistantSuggestionButtonProps | ||
extends PropsWithChildren<HeadlessButtonProps> {} |
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
152 changes: 152 additions & 0 deletions
152
app/client/src/components/propertyControls/ArrayComponent.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,152 @@ | ||
import { Button } from "@appsmith/ads"; | ||
import { debounce } from "lodash"; | ||
import React, { useCallback, useEffect, useState } from "react"; | ||
import styled from "styled-components"; | ||
import { ControlWrapper, InputGroup } from "./StyledControls"; | ||
|
||
function updateOptionLabel<T>( | ||
items: Array<T>, | ||
index: number, | ||
updatedLabel: string, | ||
) { | ||
return items.map((option: T, optionIndex) => { | ||
if (index !== optionIndex) { | ||
return option; | ||
} | ||
|
||
return updatedLabel; | ||
}); | ||
} | ||
|
||
const StyledBox = styled.div` | ||
width: 10px; | ||
`; | ||
|
||
type UpdateItemsFunction = ( | ||
items: string[], | ||
isUpdatedViaKeyboard?: boolean, | ||
) => void; | ||
|
||
interface ArrayComponentProps { | ||
items: string[]; | ||
updateItems: UpdateItemsFunction; | ||
addLabel?: string; | ||
} | ||
|
||
const StyledInputGroup = styled(InputGroup)` | ||
> .ads-v2-input__input-section > div { | ||
flex: 1; | ||
min-width: 0px; | ||
} | ||
`; | ||
|
||
export function ArrayComponent(props: ArrayComponentProps) { | ||
const [renderItems, setRenderItems] = useState<string[]>([]); | ||
const [typing, setTyping] = useState<boolean>(false); | ||
const { items } = props; | ||
|
||
useEffect(() => { | ||
let { items } = props; | ||
|
||
items = Array.isArray(items) ? items.slice() : []; | ||
|
||
items.length !== 0 && !typing && setRenderItems(items); | ||
}, [props, items.length, renderItems.length, typing]); | ||
|
||
const debouncedUpdateItems = useCallback( | ||
debounce((updatedItems: string[]) => { | ||
props.updateItems(updatedItems, true); | ||
}, 200), | ||
[props.updateItems], | ||
); | ||
|
||
function updateKey(index: number, updatedKey: string) { | ||
let { items } = props; | ||
|
||
items = Array.isArray(items) ? items : []; | ||
const updatedItems = updateOptionLabel(items, index, updatedKey); | ||
const updatedRenderItems = updateOptionLabel( | ||
renderItems, | ||
index, | ||
updatedKey, | ||
); | ||
|
||
setRenderItems(updatedRenderItems); | ||
debouncedUpdateItems(updatedItems); | ||
} | ||
|
||
function deleteItem(index: number, isUpdatedViaKeyboard = false) { | ||
let { items } = props; | ||
|
||
items = Array.isArray(items) ? items : []; | ||
|
||
const newItems = items.filter((o, i) => i !== index); | ||
const newRenderItems = renderItems.filter((o, i) => i !== index); | ||
|
||
setRenderItems(newRenderItems); | ||
props.updateItems(newItems, isUpdatedViaKeyboard); | ||
} | ||
|
||
function addItem(e: React.MouseEvent) { | ||
let { items } = props; | ||
|
||
items = Array.isArray(items) ? items.slice() : []; | ||
|
||
items.push(""); | ||
|
||
const updatedRenderItems = renderItems.slice(); | ||
|
||
updatedRenderItems.push(""); | ||
|
||
setRenderItems(updatedRenderItems); | ||
props.updateItems(items, e.detail === 0); | ||
} | ||
|
||
function onInputFocus() { | ||
setTyping(true); | ||
} | ||
|
||
function onInputBlur() { | ||
setTyping(false); | ||
} | ||
|
||
return ( | ||
<> | ||
{renderItems.map((item: string, index) => { | ||
return ( | ||
<ControlWrapper key={index} orientation={"HORIZONTAL"}> | ||
<StyledInputGroup | ||
dataType={"text"} | ||
onBlur={onInputBlur} | ||
onChange={(value: string) => updateKey(index, value)} | ||
onFocus={onInputFocus} | ||
value={item} | ||
/> | ||
<StyledBox /> | ||
<Button | ||
isIconButton | ||
kind="tertiary" | ||
onClick={(e: React.MouseEvent) => | ||
deleteItem(index, e.detail === 0) | ||
} | ||
size="sm" | ||
startIcon="delete-bin-line" | ||
/> | ||
</ControlWrapper> | ||
); | ||
})} | ||
|
||
<div className="flex flex-row-reverse mt-1"> | ||
<Button | ||
className="t--property-control-options-add" | ||
kind="tertiary" | ||
onClick={addItem} | ||
size="sm" | ||
startIcon="plus" | ||
> | ||
{props.addLabel || "Add suggestion"} | ||
</Button> | ||
</div> | ||
</> | ||
); | ||
} |
48 changes: 48 additions & 0 deletions
48
app/client/src/components/propertyControls/ArrayControl.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,48 @@ | ||
import { objectKeys } from "@appsmith/utils"; | ||
import type { DropdownOption } from "components/constants"; | ||
import React from "react"; | ||
import { isDynamicValue } from "utils/DynamicBindingUtils"; | ||
import { ArrayComponent } from "./ArrayComponent"; | ||
import type { ControlData, ControlProps } from "./BaseControl"; | ||
import BaseControl from "./BaseControl"; | ||
|
||
class ArrayControl extends BaseControl<ControlProps> { | ||
render() { | ||
return ( | ||
<ArrayComponent | ||
items={this.props.propertyValue} | ||
updateItems={this.updateItems} | ||
/> | ||
); | ||
} | ||
|
||
updateItems = (items: string[], isUpdatedViaKeyboard = false) => { | ||
this.updateProperty(this.props.propertyName, items, isUpdatedViaKeyboard); | ||
}; | ||
|
||
static getControlType() { | ||
return "ARRAY_INPUT"; | ||
} | ||
|
||
static canDisplayValueInUI(_config: ControlData, value: string): boolean { | ||
if (isDynamicValue(value)) return false; | ||
|
||
try { | ||
const items: DropdownOption[] = JSON.parse(value); | ||
|
||
for (const x of items) { | ||
const keys = objectKeys(x); | ||
|
||
if (!keys.includes("label") || !keys.includes("value")) { | ||
return false; | ||
} | ||
} | ||
} catch { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
} | ||
|
||
export default ArrayControl; |
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.