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: filter formula value component adaptive by cell value type #1161

Merged
merged 1 commit into from
Dec 12, 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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { IDateFilter, IFilterItem } from '@teable/core';
import { CellValueType, FieldType } from '@teable/core';
import { assertNever, CellValueType, FieldType } from '@teable/core';
import { useMemo } from 'react';
import { useTranslation } from '../../../../context/app/i18n';
import type { DateField, IFieldInstance } from '../../../../model';
Expand Down Expand Up @@ -50,6 +50,35 @@ export function BaseFieldValue(props: IBaseFieldValue) {
/>
);

const getFormulaValueComponent = (cType: CellValueType) => {
switch (cType) {
case CellValueType.Boolean:
return <FilterCheckbox value={value as boolean} onChange={onSelect} className="w-10" />;
case CellValueType.DateTime:
return (
<FilterDatePicker
field={field as unknown as DateField}
value={value as IDateFilter}
onSelect={onSelect}
operator={operator}
/>
);
case CellValueType.Number:
return (
<NumberEditor
value={value as number}
onChange={onSelect as (value?: number | null) => void}
className="min-w-28 max-w-40 placeholder:text-xs"
placeholder={t('filter.default.placeholder')}
/>
);
case CellValueType.String:
return InputComponent;
default:
assertNever(cType);
}
};

switch (field?.type) {
case FieldType.Number:
return (
Expand Down Expand Up @@ -146,10 +175,7 @@ export function BaseFieldValue(props: IBaseFieldValue) {
return <FilterUserSelect {...props} />;
}
case FieldType.Formula: {
if (field.cellValueType === CellValueType.Boolean) {
return <FilterCheckbox value={value as boolean} onChange={onSelect} className="w-10" />;
}
return InputComponent;
return getFormulaValueComponent(field.cellValueType);
}
default:
return InputComponent;
Expand Down
Loading