Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

πŸ› fix: disabled autogenerate field icon when empty system role #2076

Merged
merged 7 commits into from May 4, 2024
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 @@ -63,6 +63,8 @@ const AgentMeta = memo(() => {
return {
children: (
<AutoGenerate
canAutoGenerate={hasSystemRole}
disabled={!hasSystemRole}
loading={loading[item.key as keyof SessionLoadingState]}
onChange={item.onChange}
onGenerate={() => {
Expand Down
15 changes: 5 additions & 10 deletions src/features/AgentSetting/store/action.ts
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why remove the systemRole condition?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arvinxx

it was for extra guard check condition but i hope this is not require any more since it is already been disabled in code using canAutoGenerate. (please find attachment)

but if you think this is required then i will put it back.
Screenshot 2024-04-29 at 12 17 43 PM

Copy link
Contributor

@arvinxx arvinxx May 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's required, because we have another place to call these functions like autocompleteMeta. And maybe in the future we will call it automatically when user just set system role in the chat page. so the guard is necessary

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay i made update as per feedback please check PR once.

@arvinxx

Copy link
Contributor

@arvinxx arvinxx May 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why update the const preValue = meta.description; line? I think this file don't need to change.

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,11 +89,10 @@ export const store: StateCreator<Store, [['zustand/devtools', never]]> = (set, g
const { dispatchMeta, config, meta, updateLoadingState, streamUpdateMetaString } = get();

const systemRole = config.systemRole;
const preValue = meta.description;

if (!systemRole) return;

const preValue = meta.description;

// 替捒为 ...
dispatchMeta({ type: 'update', value: { description: '...' } });

Expand All @@ -115,11 +112,10 @@ export const store: StateCreator<Store, [['zustand/devtools', never]]> = (set, g
const { dispatchMeta, config, meta, updateLoadingState, streamUpdateMetaArray } = get();

const systemRole = config.systemRole;
const preValue = meta.tags;

if (!systemRole) return;

const preValue = meta.tags;

// 替捒为 ...
dispatchMeta({ type: 'update', value: { tags: ['...'] } });

Expand All @@ -141,11 +137,10 @@ 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;

if (!systemRole) return;

// 替捒为 ...
dispatchMeta({ type: 'update', value: { title: '...' } });

Expand Down