Skip to content

Commit

Permalink
Merge pull request #516 from mastra-ai/joshua/futr-567-fix-edit-bug-w…
Browse files Browse the repository at this point in the history
…ith-creating-an-index

fix edit bug with vectorProvider in create rag page
  • Loading branch information
Taofeeq-deru authored Oct 17, 2024
2 parents 9ee3585 + d72c209 commit 7943b9b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
5 changes: 4 additions & 1 deletion packages/admin/src/domains/rag/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,13 @@ export const checkVectorProviderExistsAction = async (

try {
const exists = await configWriterService.checkIfVectorProviderExists(providerName.toUpperCase());

const envFilePath = path.join(process.cwd(), '.env');
const fileEnvService = new FileEnvService(envFilePath);

const apiKey = await fileEnvService.getEnvValue(`${providerName.toUpperCase()}_API_KEY`);
return { exists, apiKey: apiKey! };

return { exists: exists && Boolean(apiKey), apiKey: apiKey! };
} catch (error) {
console.error(`Error checking if vector provider exists: ${error}`);
return { exists: false, apiKey: '' };
Expand Down
23 changes: 14 additions & 9 deletions packages/admin/src/domains/rag/components/vector-provider-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const lock = (
export const VectorProviderForm = () => {
const { apiKey, setApiKey, vectorProvider, setVectorProvider, entities } = useVectorFormContext();
const [show, setShow] = useState(true);
const [isSaved, setIsSaved] = useState(true);
const [isSaved, setIsSaved] = useState(false);
const [open, setOpen] = useState(false);
const [loading, setLoading] = useState(false);

Expand All @@ -66,7 +66,13 @@ export const VectorProviderForm = () => {
providerName: 'PINECONE',
});

const filled = vectorProvider && apiKey;
const isFilled = Boolean(vectorProvider) && Boolean(apiKey);
console.log({ isFilled });
useEffect(() => {
if (envApiKey) {
setApiKey(envApiKey);
}
}, [envApiKey]);

const updateLocalProvider = async () => {
if (!isSaved) {
Expand Down Expand Up @@ -98,11 +104,10 @@ export const VectorProviderForm = () => {
useEffect(() => {
if (exists) {
setIsSaved(true);
setVectorProvider('PINECONE');
}
}, [exists]);

console.log({ exists });

return (
<section className={cn('space-y-2 max-w-[36rem]')}>
<div className={cn('space-y-8', { 'opacity-50': isSaved })}>
Expand All @@ -113,11 +118,11 @@ export const VectorProviderForm = () => {
</h2>

<Button
className={cn('!opacity-100', { '!cursor-not-allowed opacity-50': !filled })}
className={cn('opacity-100', { ' !cursor-not-allowed opacity-50': !isFilled })}
variant="outline"
size="xs"
type="button"
disabled={isSaved}
disabled={apiKey === ''}
onClick={updateLocalProvider}
>
{isSaved ? 'Edit' : 'Save'}
Expand Down Expand Up @@ -148,7 +153,7 @@ export const VectorProviderForm = () => {
variant={'ghost'}
className="w-full py-5 mt-1 flex items-center justify-start cursor-default rounded bg-mastra-bg-6 gap-2 border-[0.5px] border-mastra-border-1 px-2 text-xs"
>
{exists ? 'PINECONE' : vectorProvider || 'Select vector provider'}
{vectorProvider || 'Select vector provider'}

<Icon name="down-caret" className="ml-auto" />
</Button>
Expand All @@ -164,14 +169,14 @@ export const VectorProviderForm = () => {
autoComplete="false"
autoCorrect="false"
onChange={e => setApiKey(e.target.value)}
value={exists ? envApiKey : ''}
value={exists ? envApiKey : apiKey}
disabled={!vectorProvider || isSaved}
/>

<Button
type="button"
variant="outline"
disabled={!vectorProvider}
disabled={!vectorProvider || isSaved}
className="w-[68px] font-mono text-sm self-end"
onClick={() => setShow(prev => !prev)}
>
Expand Down

0 comments on commit 7943b9b

Please sign in to comment.