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 Mar 30, 2024
2 parents ed003b8 + 5ad9d18 commit 176fb8d
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 23 deletions.
20 changes: 20 additions & 0 deletions src/components/AntdStaticMethods.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Entry component
import { App } from 'antd';
import type { MessageInstance } from 'antd/es/message/interface';
import type { ModalStaticFunctions } from 'antd/es/modal/confirm';
import type { NotificationInstance } from 'antd/es/notification/interface';
import { memo } from 'react';

let message: MessageInstance;
let notification: NotificationInstance;
let modal: Omit<ModalStaticFunctions, 'warn'>;

export default memo(() => {
const staticFunction = App.useApp();
message = staticFunction.message;
modal = staticFunction.modal;
notification = staticFunction.notification;
return null;
});

export { message, modal, notification };
3 changes: 1 addition & 2 deletions src/config/modelProviders/google.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ const Google: ModelProviderCard = {
{
description: 'The most capable model for highly complex tasks',
displayName: 'Gemini 1.0 Ultra',
hidden: true,
id: 'gemini-ultra-latest',
id: 'gemini-ultra',
maxOutput: 2048,
tokens: 32_768,
},
Expand Down
2 changes: 2 additions & 0 deletions src/layout/GlobalProvider/AppTheme.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'antd/dist/reset.css';
import Image from 'next/image';
import { PropsWithChildren, ReactNode, memo, useEffect } from 'react';

import AntdStaticMethods from '@/components/AntdStaticMethods';
import {
LOBE_THEME_APPEARANCE,
LOBE_THEME_NEUTRAL_COLOR,
Expand Down Expand Up @@ -76,6 +77,7 @@ const AppTheme = memo<AppThemeProps>(
themeMode={themeMode}
>
<GlobalStyle />
<AntdStaticMethods />
<ConfigProvider config={{ imgAs: Image, imgUnoptimized: true }}>
<Container>{children}</Container>
</ConfigProvider>
Expand Down
16 changes: 8 additions & 8 deletions src/layout/GlobalProvider/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,17 @@ const GlobalLayout = async ({ children }: GlobalLayoutProps) => {

return (
<StyleRegistry>
<AppTheme
defaultAppearance={appearance?.value}
defaultNeutralColor={neutralColor?.value as any}
defaultPrimaryColor={primaryColor?.value as any}
>
<Locale antdLocale={antdLocale} defaultLang={defaultLang?.value}>
<Locale antdLocale={antdLocale} defaultLang={defaultLang?.value}>
<AppTheme
defaultAppearance={appearance?.value}
defaultNeutralColor={neutralColor?.value as any}
defaultPrimaryColor={primaryColor?.value as any}
>
<StoreHydration />
{children}
<DebugUI />
</Locale>
</AppTheme>
</AppTheme>
</Locale>
</StyleRegistry>
);
};
Expand Down
2 changes: 1 addition & 1 deletion src/store/session/slices/session/action.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { message } from 'antd';
import { t } from 'i18next';
import useSWR, { SWRResponse, mutate } from 'swr';
import { DeepPartial } from 'utility-types';
import { StateCreator } from 'zustand/vanilla';

import { message } from '@/components/AntdStaticMethods';
import { INBOX_SESSION_ID } from '@/const/session';
import { useClientDataSWR } from '@/libs/swr';
import { sessionService } from '@/services/session';
Expand Down
2 changes: 1 addition & 1 deletion src/store/tool/slices/customPlugin/action.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { notification } from 'antd';
import { t } from 'i18next';
import { merge } from 'lodash-es';
import { StateCreator } from 'zustand/vanilla';

import { notification } from '@/components/AntdStaticMethods';
import { pluginService } from '@/services/plugin';
import { pluginHelpers } from '@/store/tool/helpers';
import { LobeToolCustomPlugin, PluginInstallError } from '@/types/tool/plugin';
Expand Down
12 changes: 7 additions & 5 deletions src/store/tool/slices/store/action.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import { LobeChatPluginManifest, LobeChatPluginMeta } from '@lobehub/chat-plugin-sdk';
import { act, renderHook } from '@testing-library/react';
import { notification } from 'antd';
import useSWR from 'swr';
import { Mock, afterEach, beforeEach, describe, expect, it, vi } from 'vitest';

import { notification } from '@/components/AntdStaticMethods';
import { pluginService } from '@/services/plugin';
import { LobeToolCustomPlugin } from '@/types/tool/plugin';

import { useToolStore } from '../../store';

// Mock necessary modules and functions
vi.mock('@/components/AntdStaticMethods', () => ({
notification: {
error: vi.fn(),
},
}));
// Mock the pluginService.getPluginList method
vi.mock('@/services/plugin', () => ({
pluginService: {
Expand Down Expand Up @@ -173,8 +178,6 @@ describe('useToolStore:pluginStore', () => {

describe('installPlugin', () => {
it('should install a plugin with valid manifest', async () => {
vi.spyOn(notification, 'error');

const pluginIdentifier = 'plugin1';

const originalUpdateInstallLoadingState = useToolStore.getState().updateInstallLoadingState;
Expand Down Expand Up @@ -250,7 +253,6 @@ describe('useToolStore:pluginStore', () => {
const error = new TypeError('noManifest');

// Mock necessary modules and functions
vi.spyOn(notification, 'error');
(pluginService.getPluginManifest as Mock).mockRejectedValue(error);

useToolStore.setState({
Expand Down
8 changes: 4 additions & 4 deletions src/store/tool/slices/store/action.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { LobeChatPluginsMarketIndex } from '@lobehub/chat-plugin-sdk';
import { notification } from 'antd';
import { t } from 'i18next';
import { produce } from 'immer';
import useSWR, { SWRResponse, mutate } from 'swr';
import { StateCreator } from 'zustand/vanilla';

import { notification } from '@/components/AntdStaticMethods';
import { pluginService } from '@/services/plugin';
import { pluginStoreSelectors } from '@/store/tool/selectors';
import { LobeTool } from '@/types/tool';
Expand Down Expand Up @@ -40,9 +40,8 @@ export const createPluginStoreSlice: StateCreator<
const plugin = pluginStoreSelectors.getPluginById(name)(get());
if (!plugin) return;

const { updateInstallLoadingState, refreshPlugins } = get();
try {
const { updateInstallLoadingState, refreshPlugins } = get();

updateInstallLoadingState(name, true);
const data = await pluginService.getPluginManifest(plugin.manifest);
updateInstallLoadingState(name, undefined);
Expand All @@ -52,8 +51,9 @@ export const createPluginStoreSlice: StateCreator<
await refreshPlugins();
} catch (error) {
console.error(error);
const err = error as PluginInstallError;
updateInstallLoadingState(name, undefined);

const err = error as PluginInstallError;
notification.error({
description: t(`error.${err.message}`, { ns: 'plugin' }),
message: t('error.installError', { name: plugin.meta.title, ns: 'plugin' }),
Expand Down
3 changes: 1 addition & 2 deletions src/utils/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { notification } from 'antd';

import { notification } from '@/components/AntdStaticMethods';
import { CURRENT_CONFIG_VERSION, Migration } from '@/migrations';
import {
ConfigFile,
Expand Down

0 comments on commit 176fb8d

Please sign in to comment.