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

fix: routerSetter #112

Merged
merged 1 commit into from
Mar 15, 2024
Merged
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
29 changes: 18 additions & 11 deletions packages/designer/src/setters/router-setter.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from 'react';
import React, { useEffect, useState } from 'react';
import { Box } from 'coral-system';
import { Input, Radio } from 'antd';
import { isValidUrl } from '@music163/tango-helpers';
Expand All @@ -12,25 +12,32 @@ export function RouterSetter(props: FormItemComponentProps) {
});
const [input, setInput] = useState<string>(props.value);
const { routeOptions } = useWorkspaceData();

const displayType = props.type || 'both';
useEffect(() => {
displayType === 'router' ? setType('select') : setType('input');
}, [displayType]);
return (
<Box>
<Box mb="m">
<Radio.Group
value={type}
optionType="button"
buttonStyle="solid"
onChange={(e) => setType(e.target.value)}
>
<Radio value="select">选择路由</Radio>
<Radio value="input">自定义输入</Radio>
</Radio.Group>
{['both', 'router'].includes(displayType) && (
<Radio.Group
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果是 both 模式的话,就无法变回 input,select 模式了

value={type}
optionType="button"
buttonStyle="solid"
onChange={(e) => setType(e.target.value)}
>
<Radio value="select">选择路由</Radio>
<Radio value="input">自定义输入</Radio>
</Radio.Group>
)}
</Box>
{type === 'select' && (
<PickerSetter placeholder="请选择本地路由" options={routeOptions} {...props} />
)}
{type === 'input' && (
<Input
placeholder="输入任意的路由或链接地址"
placeholder={`请输入任意${{ link: '链接', router: '路由', both: '' }[displayType]}地址`}
{...props}
value={input}
onChange={(e) => setInput(e.target.value)}
Expand Down
Loading