Skip to content

Commit

Permalink
fix: disabled autogenerate field icon when empty system role
Browse files Browse the repository at this point in the history
  • Loading branch information
techcontributor committed Apr 25, 2024
1 parent 40507dd commit cf7d640
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 39 deletions.
57 changes: 31 additions & 26 deletions src/features/AgentSetting/AgentMeta/AutoGenerateInput.tsx
Expand Up @@ -5,37 +5,42 @@ import { Wand2 } from 'lucide-react';
import { memo } from 'react';
import { useTranslation } from 'react-i18next';


export interface AutoGenerateInputProps extends InputProps {
canAutoGenerate?: boolean;
loading?: boolean;
onGenerate?: () => void;
}

const AutoGenerateInput = memo<AutoGenerateInputProps>(({ loading, onGenerate, ...props }) => {
const { t } = useTranslation('common');
const theme = useTheme();
const AutoGenerateInput = memo<AutoGenerateInputProps>(
({ loading, onGenerate, canAutoGenerate, ...props }) => {
const { t } = useTranslation('common');
const theme = useTheme();

return (
<Input
suffix={
onGenerate && (
<ActionIcon
active
icon={Wand2}
loading={loading}
onClick={onGenerate}
size={'small'}
style={{
color: theme.colorInfo,
marginRight: -4,
}}
title={t('autoGenerate')}
/>
)
}
type={'block'}
{...props}
/>
);
});
return (
<Input
suffix={
onGenerate && (
<ActionIcon
active
disable={!canAutoGenerate}
icon={Wand2}
loading={loading}
onClick={onGenerate}
size="small"
style={{
color: theme.colorInfo,
marginRight: -4,
}}
title={t('autoGenerate')}
/>
)
}
type="block"
{...props}
/>
);
},
);

export default AutoGenerateInput;
4 changes: 3 additions & 1 deletion src/features/AgentSetting/AgentMeta/AutoGenerateSelect.tsx
Expand Up @@ -7,12 +7,13 @@ import { memo } from 'react';
import { useTranslation } from 'react-i18next';

export interface AutoGenerateInputProps extends SelectProps {
canAutoGenerate?: boolean;
loading?: boolean;
onGenerate?: () => void;
}

const AutoGenerateSelect = memo<AutoGenerateInputProps>(
({ loading, onGenerate, value, ...props }) => {
({ loading, onGenerate, value, canAutoGenerate, ...props }) => {
const { t } = useTranslation('common');
const theme = useTheme();

Expand All @@ -25,6 +26,7 @@ const AutoGenerateSelect = memo<AutoGenerateInputProps>(
onGenerate && (
<ActionIcon
active
disable={!canAutoGenerate}
icon={Wand2}
loading={loading}
onClick={onGenerate}
Expand Down
2 changes: 2 additions & 0 deletions src/features/AgentSetting/AgentMeta/index.tsx
Expand Up @@ -61,6 +61,8 @@ const AgentMeta = memo(() => {
return {
children: (
<AutoGenerate
canAutoGenerate={hasSystemRole}
disabled={!hasSystemRole}
loading={loading[item.key as keyof SessionLoadingState]}
onChange={item.onChange}
onGenerate={() => {
Expand Down
13 changes: 1 addition & 12 deletions src/features/AgentSetting/store/action.ts
Expand Up @@ -9,9 +9,7 @@ import { chatService } from '@/services/chat';
import { LobeAgentConfig } from '@/types/agent';
import { MetaData } from '@/types/meta';
import { setNamespace } from '@/utils/storeDebug';

import { SessionLoadingState } from '../store/initialState';
import { State, initialState } from './initialState';
import { State, initialState, SessionLoadingState } from './initialState';
import { ConfigDispatch, configReducer } from './reducers/config';
import { MetaDataDispatch, metaDataReducer } from './reducers/meta';

Expand Down Expand Up @@ -91,9 +89,6 @@ export const store: StateCreator<Store, [['zustand/devtools', never]]> = (set, g
const { dispatchMeta, config, meta, updateLoadingState, streamUpdateMetaString } = get();

const systemRole = config.systemRole;

if (!systemRole) return;

const preValue = meta.description;

// 替换为 ...
Expand All @@ -115,9 +110,6 @@ export const store: StateCreator<Store, [['zustand/devtools', never]]> = (set, g
const { dispatchMeta, config, meta, updateLoadingState, streamUpdateMetaArray } = get();

const systemRole = config.systemRole;

if (!systemRole) return;

const preValue = meta.tags;

// 替换为 ...
Expand All @@ -141,9 +133,6 @@ export const store: StateCreator<Store, [['zustand/devtools', never]]> = (set, g
const { dispatchMeta, config, meta, updateLoadingState, streamUpdateMetaString } = get();

const systemRole = config.systemRole;

if (!systemRole) return;

const previousTitle = meta.title;

// 替换为 ...
Expand Down

0 comments on commit cf7d640

Please sign in to comment.