Skip to content
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

SettingForm 优化 #125

Merged
merged 6 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/designer/src/setters/event-setter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { ExpressionModal, getWrappedExpressionCode } from './expression-setter';

enum EventAction {
NoAction = 'noAction',
ConsoleLog = 'consoleLog',
BindExpression = 'bindExpression',
OpenModal = 'openModal',
CloseModal = 'closeModal',
Expand All @@ -24,6 +25,7 @@ const wrapperStyle = css`

const options = [
{ label: '无动作', value: EventAction.NoAction },
{ label: '打印事件', value: EventAction.ConsoleLog },
{ label: '绑定 JS 表达式', value: EventAction.BindExpression },
{ label: '打开页面', value: EventAction.NavigateTo },
{ label: '打开弹窗', value: EventAction.OpenModal },
Expand Down Expand Up @@ -63,6 +65,9 @@ export function EventSetter(props: EventSetterProps) {
case EventAction.BindExpression:
setExpModalVisible(true);
break;
case EventAction.ConsoleLog:
handleChange('(...args) => console.log(...args)');
break;
case EventAction.NoAction:
handleChange(undefined);
break;
Expand Down
37 changes: 34 additions & 3 deletions packages/designer/src/setters/expression-setter.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useState, useEffect, useCallback } from 'react';
import { Box, Text, css } from 'coral-system';
import { Modal } from 'antd';
import { Dropdown, Modal } from 'antd';
import {
isValidExpressionCode,
isWrappedByExpressionContainer,
Expand All @@ -13,8 +13,14 @@ import {
getValue,
IVariableTreeNode,
} from '@music163/tango-helpers';
import { CloseCircleFilled, ExpandAltOutlined } from '@ant-design/icons';
import { Panel, InputCode, Action } from '@music163/tango-ui';
import {
CloseCircleFilled,
ExpandAltOutlined,
InfoOutlined,
KeyOutlined,
MenuOutlined,
} from '@ant-design/icons';
import { Panel, InputCode, Action, CodeOutlined } from '@music163/tango-ui';
import { FormItemComponentProps } from '@music163/tango-setting-form';
import { useWorkspace, useWorkspaceData } from '@music163/tango-context';
import { VariableTree } from '../components';
Expand Down Expand Up @@ -60,6 +66,8 @@ export function getWrappedExpressionCode(code: string) {
}

const suffixStyle = css`
display: flex;
align-items: center;
.anticon-close-circle {
color: rgba(0, 0, 0, 0.25);
&:hover {
Expand All @@ -73,6 +81,7 @@ export interface ExpressionSetterProps extends FormItemComponentProps<string> {
modalTip?: string;
autoCompleteOptions?: string[];
allowClear?: boolean;
showOptionsDropDown?: boolean;
}

export function ExpressionSetter(props: ExpressionSetterProps) {
Expand All @@ -86,6 +95,7 @@ export function ExpressionSetter(props: ExpressionSetterProps) {
status,
allowClear = true,
newStoreTemplate,
showOptionsDropDown = true,
} = props;
const [visible, { on, off }] = useBoolean();
const [inputValue, setInputValue] = useState(() => {
Expand Down Expand Up @@ -118,6 +128,7 @@ export function ExpressionSetter(props: ExpressionSetterProps) {

return (
<Box className="ExpressionSetter">
{/* 同时支持下拉框展示 */}
<InputCode
placeholder={placeholder}
suffix={
Expand All @@ -130,6 +141,26 @@ export function ExpressionSetter(props: ExpressionSetterProps) {
}}
/>
)}
{showOptionsDropDown && autoCompleteOptions?.length && (
<Dropdown
menu={{
items: autoCompleteOptions.map((option) => ({
key: option,
label: (
<Text
onClick={() => {
change(option);
}}
>
{option}
</Text>
),
})),
}}
>
<Action tooltip="使用预设代码片段" icon={<MenuOutlined />} size="small" />
</Dropdown>
)}
<Action
tooltip="打开表达式变量选择面板"
icon={<ExpandAltOutlined />}
Expand Down
3 changes: 3 additions & 0 deletions packages/designer/src/setting-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ export const SettingPanel = observer((props: SettingPanelProps) => {
borderLeftColor="line2"
bg="white"
headerProps={headerProps}
bodyProps={{
overflowY: 'hidden',
}}
className="SettingPanel"
>
{prototype ? (
Expand Down
2 changes: 2 additions & 0 deletions packages/setting-form/src/form-ui.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export function FormControlGroup({
collapsed={collapsed}
onCollapse={setCollapsed}
className="FormControlGroup"
stickyHeader
title={
<Box display="flex" columnGap="s">
<Checkbox
Expand All @@ -109,6 +110,7 @@ export function FormControlGroup({
borderColor="line.normal"
headerProps={{
bg: 'fill1',
zIndex: 2,
}}
>
<Box
Expand Down
15 changes: 12 additions & 3 deletions packages/setting-form/src/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@

const formStyle = css`
position: relative;

height: 100%;
display: flex;
flex-direction: column;
> .SettingFormMain > :first-child:is(.FormControl) {
margin-top: var(--tango-space-m);
}
Expand Down Expand Up @@ -197,9 +199,9 @@

return (
<FormVariableProvider value={{ disableSwitchExpressionSetter, showItemSubtitle }}>
<FormModelProvider value={model}>

Check warning on line 202 in packages/setting-form/src/form.tsx

View workflow job for this annotation

GitHub Actions / CI

React Hook useEffect has a missing dependency: 'model'. Either include it or remove the dependency array
<Box className="SettingForm" mb="xl" css={formStyle}>
<Box className="SettingFormHeader" position="sticky" top="0" bg="white" zIndex="2">
<Box className="SettingFormHeader" bg="white">
<Box px="l" py="m">
{showIdentifier && (
<FormHeader
Expand Down Expand Up @@ -247,7 +249,14 @@
</Box>
)}
</Box>
<Box className="SettingFormMain" display="flex" flexDirection="column" rowGap="m">
<Box
className="SettingFormMain"
display="flex"
flexDirection="column"
paddingBottom="m"
rowGap="m"
overflow="auto"
>
{renderProps(filterProps)}
{filterProps.length === 0 && (
<Empty image={Empty.PRESENTED_IMAGE_SIMPLE} description="未找到配置项" />
Expand Down
Loading