perf: improve notification and feed channel filter logic

support label filter
This commit is contained in:
moonrailgun 2024-09-10 00:03:59 +08:00
parent 2e609452b5
commit e770e42893
2 changed files with 32 additions and 17 deletions

View File

@ -1,5 +1,5 @@
import { Button, Empty, Select, SelectProps } from 'antd'; import { Button, Empty, Select, SelectProps } from 'antd';
import React from 'react'; import React, { useMemo } from 'react';
import { trpc } from '../../api/trpc'; import { trpc } from '../../api/trpc';
import { useCurrentWorkspaceId } from '../../store/user'; import { useCurrentWorkspaceId } from '../../store/user';
import { PlusOutlined } from '@ant-design/icons'; import { PlusOutlined } from '@ant-design/icons';
@ -16,6 +16,15 @@ export const FeedChannelPicker: React.FC<FeedChannelPickerProps> = React.memo(
workspaceId, workspaceId,
}); });
const options = useMemo(
() =>
allChannels.map((m) => ({
label: m.name,
value: m.id,
})),
[allChannels]
);
return ( return (
<Select <Select
notFoundContent={ notFoundContent={
@ -38,13 +47,9 @@ export const FeedChannelPicker: React.FC<FeedChannelPickerProps> = React.memo(
/> />
} }
{...props} {...props}
> options={options}
{allChannels.map((m) => ( optionFilterProp="label"
<Select.Option key={m.id} value={m.id}> />
{m.name}
</Select.Option>
))}
</Select>
); );
} }
); );

View File

@ -1,5 +1,5 @@
import { Button, Empty, Select, SelectProps } from 'antd'; import { Button, Empty, Select, SelectProps } from 'antd';
import React from 'react'; import React, { useMemo } from 'react';
import { trpc } from '../../api/trpc'; import { trpc } from '../../api/trpc';
import { useCurrentWorkspaceId } from '../../store/user'; import { useCurrentWorkspaceId } from '../../store/user';
import { ColorTag } from '../ColorTag'; import { ColorTag } from '../ColorTag';
@ -17,6 +17,21 @@ export const NotificationPicker: React.FC<NotificationPickerProps> = React.memo(
workspaceId, workspaceId,
}); });
const options = useMemo(
() =>
allNotification.map((notification) => ({
label: (
<div>
<ColorTag label={notification.type} />
{notification.name}
</div>
),
value: notification.id,
desc: notification.name,
})),
[allNotification]
);
return ( return (
<Select <Select
notFoundContent={ notFoundContent={
@ -39,14 +54,9 @@ export const NotificationPicker: React.FC<NotificationPickerProps> = React.memo(
/> />
} }
{...props} {...props}
> options={options}
{allNotification.map((m) => ( optionFilterProp="desc"
<Select.Option key={m.id} value={m.id}> />
<ColorTag label={m.type} />
{m.name}
</Select.Option>
))}
</Select>
); );
} }
); );