Skip to content

Commit 55123c7

Browse files
author
Roman Snapko
committed
Add AiConfigIndicator component and integrate it into AI settings page
1 parent 086bfd0 commit 55123c7

3 files changed

Lines changed: 82 additions & 45 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { t } from 'i18next';
2+
import { CircleCheck, CircleMinus } from 'lucide-react';
3+
4+
type AiConfigIndicatorProps = {
5+
enabled: boolean;
6+
};
7+
8+
const AiConfigIndicator = ({ enabled }: AiConfigIndicatorProps) => {
9+
return (
10+
<div className="flex items-center gap-[6px] text-primary-900 font-medium">
11+
{enabled ? (
12+
<>
13+
<CircleCheck className="text-success-300" size={24} />
14+
<span>{t('OpenOps AI is enabled')}</span>
15+
</>
16+
) : (
17+
<>
18+
<CircleMinus className="text-muted-foreground" size={24} />
19+
<span>
20+
{t('OpenOps AI is disabled - Configure a connection to enable it')}
21+
</span>
22+
</>
23+
)}
24+
</div>
25+
);
26+
};
27+
28+
export { AiConfigIndicator };

packages/react-ui/src/app/features/ai/ai-settings-form.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ import {
44
BlockMetadataModelSummary,
55
} from '@openops/blocks-framework';
66
import { Form } from '@openops/components/ui';
7-
import { removeConnectionBrackets } from '@openops/shared';
87
import equal from 'fast-deep-equal';
98
import debounce from 'lodash.debounce';
10-
import React, { useEffect, useMemo, useRef, useState } from 'react';
9+
import React, { useEffect, useMemo, useState } from 'react';
1110
import { useForm } from 'react-hook-form';
1211

1312
type AiSettingsFormProps = {
@@ -78,7 +77,7 @@ const AiSettingsForm = ({
7877

7978
return (
8079
<Form {...form}>
81-
<form className="max-w-[516px]">
80+
<form>
8281
<ConnectionSelect
8382
disabled={disabled}
8483
allowDynamicValues={false}

packages/react-ui/src/app/routes/settings/ai/index.tsx

Lines changed: 52 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { QueryKeys } from '@/app/constants/query-keys';
2+
import { AiConfigIndicator } from '@/app/features/ai/ai-config-indicator';
23
import { AiSettingsForm } from '@/app/features/ai/ai-settings-form';
34
import {
45
AI_SETTINGS_SAVED_SUCCESSFULLY_TOAST,
@@ -9,7 +10,7 @@ import { aiSettingsApi } from '@/app/features/ai/lib/ai-settings-api';
910
import { aiSettingsHooks } from '@/app/features/ai/lib/ai-settings-hooks';
1011
import { mcpSettingsHooks } from '@/app/features/ai/lib/mcp-settings-hooks';
1112
import { blocksHooks } from '@/app/features/blocks/lib/blocks-hook';
12-
import { INTERNAL_ERROR_TOAST, toast } from '@openops/components/ui';
13+
import { INTERNAL_ERROR_TOAST, Skeleton, toast } from '@openops/components/ui';
1314
import {
1415
ApplicationErrorParams,
1516
ErrorCode,
@@ -85,7 +86,7 @@ const AiSettingsPage = () => {
8586

8687
return (
8788
<div className="flex w-full flex-col items-center justify-center gap-4">
88-
<div className="mx-auto w-full flex-col">
89+
<div className="mx-auto w-full flex flex-col gap-4">
8990
<h1 className="text-[24px] font-bold text-primary-900">
9091
{t('OpenOps AI')}
9192
</h1>
@@ -94,47 +95,56 @@ const AiSettingsPage = () => {
9495
'Enable OpenOps Assistant and other AI-powered features such as the CLI command generation.',
9596
)}
9697
</p>
97-
<div className="flex flex-col gap-8 p-6 border rounded-[11px]">
98-
{aiBlockModel && (
99-
<AiSettingsForm
100-
block={aiBlockModel}
101-
providerKey={'AI'}
102-
initialConnection={aiSettings?.[0]?.connection}
103-
onSave={(connectionName) =>
104-
onSaveAiSettings({
105-
...aiSettings?.[0],
106-
enabled: !!connectionName,
107-
connection: connectionName,
108-
})
109-
}
110-
disabled={isSavingAiSettings}
111-
displayName={t('Select Connection')}
112-
/>
113-
)}
114-
115-
{awsBlockModel && (
116-
<AiSettingsForm
117-
block={awsBlockModel}
118-
providerKey={'AWS'}
119-
initialConnection={mcpSettings?.awsCost?.connectionName}
120-
onSave={(connectionName: string) =>
121-
onSaveMcpSettings({
122-
...mcpSettings,
123-
awsCost: {
98+
<AiConfigIndicator enabled={!!aiSettings?.[0]?.connection} />
99+
<div className="p-6 border rounded-[11px]">
100+
<div className="max-w-[648px] flex flex-col gap-4">
101+
<h3 className="text-base font-bold">{t('AI connection')}</h3>
102+
{aiBlockModel ? (
103+
<AiSettingsForm
104+
block={aiBlockModel}
105+
providerKey={'AI'}
106+
initialConnection={aiSettings?.[0]?.connection}
107+
onSave={(connectionName) =>
108+
onSaveAiSettings({
109+
...aiSettings?.[0],
124110
enabled: !!connectionName,
125-
connectionName:
126-
removeConnectionBrackets(connectionName) ?? '',
127-
},
128-
})
129-
}
130-
disabled={
131-
isSavingMcpSettings ||
132-
!aiSettings?.[0]?.connection ||
133-
isSavingAiSettings
134-
}
135-
displayName={t('AWS Cost')}
136-
/>
137-
)}
111+
connection: connectionName,
112+
})
113+
}
114+
disabled={isSavingAiSettings}
115+
displayName={t('Select Connection')}
116+
/>
117+
) : (
118+
<Skeleton className="h-[78px]" />
119+
)}
120+
121+
<h3 className="text-sm font-normal">{t('MCP')}</h3>
122+
{awsBlockModel ? (
123+
<AiSettingsForm
124+
block={awsBlockModel}
125+
providerKey={'AWS'}
126+
initialConnection={mcpSettings?.awsCost?.connectionName}
127+
onSave={(connectionName: string) =>
128+
onSaveMcpSettings({
129+
...mcpSettings,
130+
awsCost: {
131+
enabled: !!connectionName,
132+
connectionName:
133+
removeConnectionBrackets(connectionName) ?? '',
134+
},
135+
})
136+
}
137+
disabled={
138+
isSavingMcpSettings ||
139+
!aiSettings?.[0]?.connection ||
140+
isSavingAiSettings
141+
}
142+
displayName={t('AWS Cost')}
143+
/>
144+
) : (
145+
<Skeleton className="h-[78px]" />
146+
)}
147+
</div>
138148
</div>
139149
</div>
140150
</div>

0 commit comments

Comments
 (0)