Skip to content

Commit

Permalink
perf: filter relative (#1169)
Browse files Browse the repository at this point in the history
* perf: do not trigger input filter when blur

* fix: date filter e2e
  • Loading branch information
caoxing9 authored Dec 17, 2024
1 parent b2020fe commit f31332f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import { DEFAULT_LINK_VALUE_INDEXS } from '../../../20x-link';
export const getDates = () => {
const tz = 'Asia/Singapore';
const dateFieldName = x_20.fields[3].name;
dayjs.locale(dayjs.locale(), {
weekStart: 1,
});
const dates = x_20.records
.filter((r) => r.fields?.[dateFieldName])
.map((r) => {
Expand Down
19 changes: 15 additions & 4 deletions packages/sdk/src/components/editor/number/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,18 @@ import type { ICellEditor, IEditorRef } from '../type';

export const NumberEditorBase: ForwardRefRenderFunction<
IEditorRef<number>,
ICellEditor<number | null> & { placeholder?: string }
ICellEditor<number | null> & { placeholder?: string; saveOnChange?: boolean }
> = (props, ref) => {
const { value, onChange, className, readonly, style, saveOnBlur = true, placeholder } = props;
const {
value,
onChange,
className,
readonly,
style,
saveOnBlur = true,
saveOnChange = false,
placeholder,
} = props;
const inputRef = useRef<HTMLInputElement | null>(null);
const [str, setStr] = useState<string | null>(value ? value.toString() : '');

Expand All @@ -27,7 +36,9 @@ export const NumberEditorBase: ForwardRefRenderFunction<
};

const onChangeHandler = (e: React.ChangeEvent<HTMLInputElement>) => {
setStr(e.target.value);
const newValue = e.target.value;
setStr(newValue);
saveOnChange && onChange?.(parseStringToNumber(newValue));
};

return (
Expand All @@ -37,7 +48,7 @@ export const NumberEditorBase: ForwardRefRenderFunction<
className={cn('h-10 sm:h-8', className)}
value={str || ''}
onChange={onChangeHandler}
onBlur={() => saveOnBlur && saveValue()}
onBlur={() => saveOnBlur && !saveOnChange && saveValue()}
readOnly={readonly}
placeholder={placeholder}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ function FilterDatePicker(props: IFilerDatePickerProps) {
<Input
placeholder={t('filter.default.placeholder')}
defaultValue={innerValue?.numberOfDays ?? ''}
className="h-8 w-24 placeholder:text-[13px]"
className="h-8 w-24 placeholder:text-xs"
onInput={(e) => {
// limit the number positive
e.currentTarget.value = e.currentTarget.value?.replace(/\D/g, '');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export function BaseFieldValue(props: IBaseFieldValue) {
return (
<NumberEditor
value={value as number}
saveOnChange={true}
onChange={onSelect as (value?: number | null) => void}
className="min-w-28 max-w-40 placeholder:text-xs"
placeholder={t('filter.default.placeholder')}
Expand All @@ -84,6 +85,7 @@ export function BaseFieldValue(props: IBaseFieldValue) {
return (
<NumberEditor
value={value as number}
saveOnChange={true}
onChange={onSelect as (value?: number | null) => void}
className="min-w-28 max-w-40 placeholder:text-xs"
placeholder={t('filter.default.placeholder')}
Expand Down

0 comments on commit f31332f

Please sign in to comment.