Skip to content

Commit

Permalink
perf: filter field convert sync (#857)
Browse files Browse the repository at this point in the history
* perf: optimize select field type convert sync logic

* fix: forbid trigger upload when resolve import file

* fix: type error
  • Loading branch information
caoxing9 authored Aug 25, 2024
1 parent c170769 commit 9c69d8d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import type {
ISelectFieldOptions,
IFilterItem,
IFilter,
IFilterValue,
} from '@teable/core';
import { PrismaService } from '@teable/db-main-prisma';
import { isEqual, differenceBy, find } from 'lodash';
import { isEqual, differenceBy, find, isEmpty } from 'lodash';
import { ViewService } from '../../view/view.service';
import type { IFieldInstance } from '../model/factory';

Expand Down Expand Up @@ -154,54 +155,23 @@ export class FieldViewSyncService {

const transformFilter = (filter: IFilterSet | IFilterItem): IFilterSet | IFilterItem => {
if ('filterSet' in filter) {
const newFilterSet = filter.filterSet.map(transformFilter);
return {
conjunction: filter.conjunction,
filterSet: filter.filterSet.map(transformFilter),
filterSet: newFilterSet.filter((item) => !isEmpty(item)),
};
} else {
// target item
if (filter.fieldId === fieldId) {
const newValue = transformValue(filter.value);
return {
...filter,
value: filter.value !== null ? newValue : null,
shouldDelete: newValue === null,
} as IFilterItem & {
shouldDelete: boolean;
};
if (filter.fieldId === fieldId && filter.value !== null) {
const newValue = transformValue(filter.value) as IFilterValue;
return (newValue ? { ...filter, value: newValue } : {}) as IFilterItem;
}
return {
...filter,
};
}
};

const deleteConvertEmptyFilterItem = (
filter: IFilterSet | IFilterItem
): IFilterSet | IFilterItem => {
if ('filterSet' in filter) {
return {
conjunction: filter.conjunction,
filterSet: filter.filterSet
.filter((item) => {
if (!Array.isArray(item)) {
return !(
item as IFilterItem & {
shouldDelete: boolean;
}
).shouldDelete;
}
return true;
})
.filter(transformFilter),
};
} else {
return {
...filter,
};
}
};

return deleteConvertEmptyFilterItem(transformFilter(data)) as IFilterSet;
return transformFilter(data) as IFilterSet;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { generateAttachmentId } from '@teable/core';
import type { SUPPORTEDTYPE, INotifyVo } from '@teable/openapi';
import { UploadType } from '@teable/openapi';
import { AttachmentManager } from '@teable/sdk/components';
import { Spin, Button } from '@teable/ui-lib';
import { Spin, Button, cn } from '@teable/ui-lib';
import { useState } from 'react';
import { useTranslation } from 'react-i18next';
import { Process } from './Process';
Expand All @@ -25,7 +25,11 @@ const UploadPanel = (props: IUploadPanelProps) => {
const [isImporting, setIsImporting] = useState(false);

return (
<div className="relative flex h-96 items-center justify-center">
<div
className={cn('relative flex h-96 items-center justify-center', {
'pointer-events-none': isImporting,
})}
>
{!file ? (
<Trigger
onBeforeUpload={() => {
Expand All @@ -51,7 +55,7 @@ const UploadPanel = (props: IUploadPanelProps) => {
onChange(file);
}}
>
<div className="flex h-full cursor-pointer items-center justify-center rounded-sm border-2 border-dashed hover:border-secondary">
<div className="flex h-full items-center justify-center rounded-sm border-2 border-dashed hover:border-secondary">
{!isImporting ? (
<Button variant="ghost">{t('table:import.tips.importWayTip')}</Button>
) : (
Expand Down

0 comments on commit 9c69d8d

Please sign in to comment.