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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
57 changes: 31 additions & 26 deletions src/features/AgentSetting/AgentMeta/AutoGenerateInput.tsx
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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