feat: 增加插件面板操作的注册方法

pull/81/head
moonrailgun 3 years ago
parent 48351fea68
commit 46899f2148

@ -6,6 +6,11 @@ import { CommonPanelWrapper } from '../common/Wrapper';
import { usePanelWindow } from '@/hooks/usePanelWindow';
import { OpenedPanelTip } from '@/components/OpenedPanelTip';
import { IconBtn } from '@/components/IconBtn';
import {
DMPluginPanelActionProps,
GroupPluginPanelActionProps,
pluginPanelActions,
} from '@/plugin/common';
/**
*
@ -41,6 +46,26 @@ export const GroupPanelWrapper: React.FC<GroupPanelWrapperProps> = React.memo(
<CommonPanelWrapper
header={panelInfo.name}
actions={(setRightPanel) => [
...pluginPanelActions
.filter(
(action): action is GroupPluginPanelActionProps =>
action.position === 'group'
)
.map((action) => (
<IconBtn
key={action.name}
title={action.label}
shape="square"
icon={action.icon}
iconClassName="text-2xl"
onClick={() =>
action.onClick({
groupId: props.groupId,
panelId: props.panelId,
})
}
/>
)),
<IconBtn
key="open"
title={t('在新窗口打开')}

@ -14,6 +14,7 @@ import { AppendDMConverseMembers } from '@/components/modals/AppendDMConverseMem
import { usePanelWindow } from '@/hooks/usePanelWindow';
import { OpenedPanelTip } from '@/components/OpenedPanelTip';
import { IconBtn } from '@/components/IconBtn';
import { DMPluginPanelActionProps, pluginPanelActions } from '@/plugin/common';
const ConversePanelTitle: React.FC<{ converse: ChatConverseState }> =
React.memo(({ converse }) => {
@ -60,6 +61,21 @@ export const ConversePanel: React.FC<ConversePanelProps> = React.memo(
}
return _compact([
...pluginPanelActions
.filter(
(action): action is DMPluginPanelActionProps =>
action.position === 'dm'
)
.map((action) => (
<IconBtn
key={action.name}
title={action.label}
shape="square"
icon={action.icon}
iconClassName="text-2xl"
onClick={() => action.onClick({ converseId })}
/>
)),
<IconBtn
key="open"
title={t('在新窗口打开')}

@ -161,3 +161,36 @@ export const [pluginRootRoute, regPluginRootRoute] = buildRegList<{
path: string;
component: React.ComponentType;
}>();
export interface BasePluginPanelActionProps {
/**
*
*/
name: string;
/**
*
*/
label: string;
/**
* iconify
*/
icon: string;
}
export interface GroupPluginPanelActionProps
extends BasePluginPanelActionProps {
position: 'group';
onClick: (ctx: { groupId: string; panelId: string }) => void;
}
export interface DMPluginPanelActionProps extends BasePluginPanelActionProps {
position: 'dm';
onClick: (ctx: { converseId: string }) => void;
}
/**
*
*/
export const [pluginPanelActions, regPluginPanelAction] = buildRegList<
GroupPluginPanelActionProps | DMPluginPanelActionProps
>();

Loading…
Cancel
Save