Skip to content

Commit

Permalink
💄 style: improve settings display
Browse files Browse the repository at this point in the history
  • Loading branch information
arvinxx authored and canisminor1990 committed Dec 15, 2023
1 parent 605b3bf commit df57cde
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@ import { ActionIcon } from '@lobehub/ui';
import { LucideSettings } from 'lucide-react';
import { memo, useState } from 'react';
import { useTranslation } from 'react-i18next';

import PluginDetailModal from 'src/features/PluginDetailModal';
import { useToolStore } from '@/store/tool';

import { pluginHelpers, useToolStore } from '@/store/tool';
import { pluginSelectors } from '@/store/tool/selectors';

const Settings = memo<{ id: string }>(({ id }) => {
const item = useToolStore(pluginSelectors.getPluginManifestById(id));
const [open, setOpen] = useState(false);
const { t } = useTranslation('plugin');
const hasSettings = pluginHelpers.isSettingSchemaNonEmpty(item?.settings);

return (
item?.settings && (
hasSettings && (
<>
<ActionIcon
icon={LucideSettings}
Expand All @@ -27,7 +29,7 @@ const Settings = memo<{ id: string }>(({ id }) => {
setOpen(false);
}}
open={open}
schema={item.settings}
schema={item?.settings}
/>
</>
)
Expand Down
29 changes: 17 additions & 12 deletions src/features/PluginDetailModal/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { Modal, TabsNav } from '@lobehub/ui';
import { Divider } from 'antd';
import { Divider, TabsProps } from 'antd';
import { memo } from 'react';
import { useTranslation } from 'react-i18next';
import { Center } from 'react-layout-kit';
import useMergeState from 'use-merge-value';

import MobilePadding from '@/components/MobilePadding';
import PluginSettingsConfig from '@/features/PluginSettings';
import { pluginHelpers } from '@/store/tool';

import APIs from './APIs';
import Meta from './Meta';
Expand All @@ -28,6 +29,8 @@ const PluginDetailModal = memo<PluginDetailModalProps>(
});
const { t } = useTranslation('plugin');

const hasSettings = pluginHelpers.isSettingSchemaNonEmpty(schema);

return (
<Modal
cancelText={t('cancel', { ns: 'common' })}
Expand All @@ -46,20 +49,22 @@ const PluginDetailModal = memo<PluginDetailModalProps>(
<Divider style={{ marginBottom: 0, marginTop: 8 }} />
<TabsNav
activeKey={tabKey}
items={[
{
key: 'info',
label: t('detailModal.tabs.info'),
},
schema && {
key: 'settings',
label: t('detailModal.tabs.settings'),
},
]}
items={
[
{
key: 'info',
label: t('detailModal.tabs.info'),
},
hasSettings && {
key: 'settings',
label: t('detailModal.tabs.settings'),
},
].filter(Boolean) as TabsProps['items']
}
onChange={setTabKey}
/>
{tabKey === 'settings' ? (
schema && <PluginSettingsConfig id={id} schema={schema} />
hasSettings && <PluginSettingsConfig id={id} schema={schema} />
) : (
<APIs id={id} />
)}
Expand Down
6 changes: 4 additions & 2 deletions src/features/PluginStore/PluginItem/Action.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useTranslation } from 'react-i18next';
import { Flexbox } from 'react-layout-kit';

import PluginDetailModal from '@/features/PluginDetailModal';
import { useToolStore } from '@/store/tool';
import { pluginHelpers, useToolStore } from '@/store/tool';
import { pluginSelectors, pluginStoreSelectors } from '@/store/tool/selectors';
import { LobeToolType } from '@/types/tool/tool';

Expand All @@ -32,13 +32,15 @@ const Actions = memo<ActionsProps>(({ identifier, type }) => {
const plugin = useToolStore(pluginSelectors.getPluginManifestById(identifier));

const [tab, setTab] = useState('info');
const hasSettings = pluginHelpers.isSettingSchemaNonEmpty(plugin?.settings);

return (
<>
<Flexbox align={'center'} horizontal>
{installed ? (
<>
{isCustomPlugin && <EditCustomPlugin identifier={identifier} />}
{plugin?.settings && (
{hasSettings && (
<ActionIcon
icon={Settings2}
onClick={() => {
Expand Down
6 changes: 5 additions & 1 deletion src/store/tool/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LobeChatPluginManifest } from '@lobehub/chat-plugin-sdk';
import { LobeChatPluginManifest, PluginSchema } from '@lobehub/chat-plugin-sdk';

import { LobeTool } from '@/types/tool';

Expand All @@ -11,10 +11,14 @@ const getPluginAvatar = (meta?: LobeChatPluginManifest['meta']) => meta?.avatar
const isCustomPlugin = (id: string, pluginList: LobeTool[]) =>
pluginList.some((i) => i.identifier === id && i.type === 'customPlugin');

const isSettingSchemaNonEmpty = (schema?: PluginSchema) =>
schema?.properties && Object.keys(schema.properties).length > 0;

export const pluginHelpers = {
getPluginAvatar,
getPluginDesc,
getPluginFormList,
getPluginTitle,
isCustomPlugin,
isSettingSchemaNonEmpty,
};

0 comments on commit df57cde

Please sign in to comment.