Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
bentwnghk committed Jan 29, 2024
2 parents e588dd9 + feeb589 commit 9cdc928
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 22 deletions.
58 changes: 39 additions & 19 deletions src/app/chat/features/SessionListContent/CollapseGroup/Actions.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ActionIcon, Icon } from '@bentwnghk/ui';
import { App, Dropdown, DropdownProps, MenuProps } from 'antd';
import { createStyles } from 'antd-style';
import { MoreVertical, PencilLine, Settings2, Trash } from 'lucide-react';
import { MoreVertical, PencilLine, Plus, Settings2, Trash } from 'lucide-react';
import { memo, useMemo } from 'react';
import { useTranslation } from 'react-i18next';

Expand All @@ -15,19 +15,51 @@ const useStyles = createStyles(({ css }) => ({
interface ActionsProps extends Pick<DropdownProps, 'onOpenChange'> {
id?: string;
isCustomGroup?: boolean;
isPinned?: boolean;
openConfigModal: () => void;
openRenameModal?: () => void;
}

type ItemOfType<T> = T extends (infer Item)[] ? Item : never;
type MenuItemType = ItemOfType<MenuProps['items']>;

const Actions = memo<ActionsProps>(
({ id, openRenameModal, openConfigModal, onOpenChange, isCustomGroup }) => {
({ id, openRenameModal, openConfigModal, onOpenChange, isCustomGroup, isPinned }) => {
const { t } = useTranslation('chat');
const { styles } = useStyles();
const { modal } = App.useApp();

const [removeSessionGroup] = useSessionStore((s) => [s.removeSessionGroup]);
const [createSession, removeSessionGroup] = useSessionStore((s) => [
s.createSession,
s.removeSessionGroup,
]);

const sessionGroupConfigPublicItem: MenuItemType = {
icon: <Icon icon={Settings2} />,
key: 'config',
label: t('sessionGroup.config'),
onClick: ({ domEvent }) => {
domEvent.stopPropagation();
openConfigModal();
},
};

const newAgentPublicItem: MenuItemType = {
icon: <Icon icon={Plus} />,
key: 'newAgent',
label: t('newAgent'),
onClick: ({ domEvent }) => {
domEvent.stopPropagation();
createSession({ group: id, pinned: isPinned });
},
};

const customGroupItems: MenuProps['items'] = useMemo(
() => [
newAgentPublicItem,
{
type: 'divider',
},
{
icon: <Icon icon={PencilLine} />,
key: 'rename',
Expand All @@ -37,15 +69,7 @@ const Actions = memo<ActionsProps>(
openRenameModal?.();
},
},
{
icon: <Icon icon={Settings2} />,
key: 'config',
label: t('sessionGroup.config'),
onClick: ({ domEvent }) => {
domEvent.stopPropagation();
openConfigModal();
},
},
sessionGroupConfigPublicItem,
{
type: 'divider',
},
Expand Down Expand Up @@ -74,15 +98,11 @@ const Actions = memo<ActionsProps>(

const defaultItems: MenuProps['items'] = useMemo(
() => [
newAgentPublicItem,
{
icon: <Icon icon={Settings2} />,
key: 'config',
label: t('sessionGroup.config'),
onClick: ({ domEvent }) => {
domEvent.stopPropagation();
openConfigModal();
},
type: 'divider',
},
sessionGroupConfigPublicItem,
],
[],
);
Expand Down
2 changes: 1 addition & 1 deletion src/app/chat/features/SessionListContent/DefaultMode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const SessionListContent = memo(() => {
[
pinnedSessions.length > 0 && {
children: <SessionList dataSource={pinnedSessions} />,
extra: <Actions openConfigModal={() => setConfigGroupModalOpen(true)} />,
extra: <Actions isPinned openConfigModal={() => setConfigGroupModalOpen(true)} />,
key: SessionDefaultGroup.Pinned,
label: t('pin'),
},
Expand Down
3 changes: 2 additions & 1 deletion src/database/models/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ class _SessionModel extends BaseModel {

async create(type: 'agent' | 'group', defaultValue: Partial<LobeAgentSession>, id = uuid()) {
const data = merge(DEFAULT_AGENT_LOBE_SESSION, { type, ...defaultValue });
return this._add(data, id);
const dataDB = this.mapToDB_Session(data);
return this._add(dataDB, id);
}

async batchCreate(sessions: LobeAgentSession[]) {
Expand Down
2 changes: 1 addition & 1 deletion src/features/Conversation/Plugins/Inspector/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ const Inspector = memo<InspectorProps>(
label: t('debug.response'),
},
]}
style={{ display: 'grid', maxWidth: 800 }}
style={{ display: 'grid', maxWidth: 800, minWidth: 400 }}
/>
)}
</Flexbox>
Expand Down

0 comments on commit 9cdc928

Please sign in to comment.