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

feat: modify ui of limit tool #391

Closed
wants to merge 4 commits into from
Closed
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
37 changes: 20 additions & 17 deletions packages/graphic-walker/src/components/limitSetting.tsx
Original file line number Diff line number Diff line change
@@ -1,35 +1,38 @@
import React, { useMemo } from 'react';
import React from 'react';
import { useTranslation } from 'react-i18next';
import { useDebounceValueBind } from '../hooks';
import { createStreamedValueBindHook } from '../hooks';
import { Checkbox } from './ui/checkbox';
import { Slider } from './ui/slider';
import { Input } from './ui/input';
import debounce from 'lodash-es/debounce';

const useDebounceValueBind = createStreamedValueBindHook((f) => debounce(f, 600));

export default function LimitSetting(props: { value: number; setValue: (v: number) => void }) {
const { t } = useTranslation('translation', { keyPrefix: 'main.tabpanel.settings' });
const [innerValue, setInnerValue] = useDebounceValueBind(props.value, (v) => props.setValue(v));
const sliderValue = useMemo(() => (innerValue > 0 ? [innerValue] : [0]), [innerValue]);
const [enable, setEnable] = React.useState(props.value > 0);
const [innerValue, setInnerValue] = useDebounceValueBind(props.value > 0 ? props.value : 100, (v) => enable && props.setValue(v));

return (
<div className="w-60 mt-2 p-2">
<Slider
min={1}
max={50}
step={1}
name="limit"
className="w-full"
disabled={innerValue < 0}
onValueChange={([v]) => setInnerValue(v)}
value={sliderValue}
<Input
className='h-8'
type='number'
min={0}
step={10}
value={innerValue}
disabled={!enable}
onChange={(e) => setInnerValue(parseInt(e.target.value))}
/>
<div className="ml-1 mt-3 flex items-center">
<Checkbox
className="mr-1"
checked={innerValue > 0}
checked={enable}
onCheckedChange={(v) => {
setInnerValue(v ? 30 : -1);
setEnable(!!v);
v ? props.setValue(innerValue) : props.setValue(0);
}}
></Checkbox>
{`${t('limit')}${innerValue > 0 ? `: ${innerValue}` : ''}`}
{ t('limit') }
</div>
</div>
);
Expand Down
2 changes: 1 addition & 1 deletion packages/graphic-walker/src/locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@
"cancel": "Cancel",
"delete_paint": "Delete Painting"
},
"limit": "Limit",
"limit": "enable query limit (rows)",
"size": "Resize",
"size_setting": {
"width": "Width",
Expand Down
2 changes: 1 addition & 1 deletion packages/graphic-walker/src/locales/ja-JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@
"cancel": "キャンセル",
"delete_paint": "キャンバスを削除"
},
"limit": "上限",
"limit": "クエリ制限 (行数) を有効にする",
"size": "サイズ変更",
"size_setting": {
"width": "幅",
Expand Down
2 changes: 1 addition & 1 deletion packages/graphic-walker/src/locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@
"cancel": "取消改动",
"delete_paint": "删除画板"
},
"limit": "上限",
"limit": "启用查询限制(行)",
"size": "调整尺寸",
"size_setting": {
"width": "宽度",
Expand Down
Loading