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

Implemented Notification from the mantine functionality for Config.tsx and Urloader.tsx #121

Closed
wants to merge 0 commits into from

Conversation

auksesir
Copy link
Contributor

@auksesir auksesir commented Sep 4, 2023

I made the code to empty the text input box and uncheck the checkbox after submitting the URL. I also made selected values stay as placeholders in Config.tsx.

@vercel
Copy link

vercel bot commented Sep 4, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
aixplora ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 19, 2023 11:13pm

@@ -4,6 +4,8 @@ import './UrlLoader.css';
import { useEffect, useState } from 'react';
import { apiCall } from '../../../utils/api';
import { useForm } from '@mantine/form';
import { Notifications } from '@mantine/notifications';
import { check } from 'prettier';
Copy link
Owner

Choose a reason for hiding this comment

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

this seems not to be used?

Copy link
Owner

@grumpyp grumpyp left a comment

Choose a reason for hiding this comment

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

lgtm awesome work.

Can you also refresh the Uploaded.tsx component, if someone indexed a Website? Basically like you did with the callback function for the Dropzone component.

In the App.tsx there's also some logic which either shows the Config page or the Welcome to AIxplora.

This is currently not working I believe it has to do something with state change, please doublecheck here.

Again: Thanks a lot for working on this!

@grumpyp
Copy link
Owner

grumpyp commented Sep 7, 2023

I reviewed again, looks good to me but something with the localstorage doesn't work properly. If I refresh my config is gone again. Testing it via home <-> config page

@auksesir
Copy link
Contributor Author

auksesir commented Sep 7, 2023

Do you want the App to keep the same configuration after reloading it?
I can implement that.

@grumpyp
Copy link
Owner

grumpyp commented Sep 8, 2023

Do you want the App to keep the same configuration after reloading it? I can implement that.

Hi, yes, once a user has set a configuration it should always fallback on it.

In the backend it's implemented like this, so it references the last row of the table..

...
self.openai_api_key = Database().get_session().execute(text("SELECT openai_api_key FROM config")).fetchall()[-1]
...

Otherwise a user had to set a new config on every start-up.

Comment on lines 43 to 45
apiCall('/files/website', 'POST', payload)
.then((response) => {
console.log(response.data);
window.location.reload();

Notifications.show({
title: 'URL Upload Successful',
message: 'The URL was successfully uploaded.',
color: 'green'
});

// passing the website to the Upload.tsx component
onFilesUploaded([payload.website]);
})
Copy link
Owner

Choose a reason for hiding this comment

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

we should add a check here, if the status code f.e. is 500 it still will "upload successful".

@@ -37,10 +38,9 @@ function saveConfig(OPENAI_API_KEY: string, model: string, embeddingsmodel: stri
// console.log('Error fetching config:', error);
// return false;
// });
// }
// }console.log("saveconfig");
return apiCall('/config', 'POST', payload).then((response) => {
Copy link
Owner

Choose a reason for hiding this comment

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

Would you say we should extend the apiCall function with a boolean to deactivate the Notification? As of now a user gets the Endpoint error + the configerror.

Comment on lines 52 to 71
useEffect(() => {
// Attempt to retrieve the configuration data from localStorage
const savedConfig = JSON.parse(localStorage.getItem('config') || '{}');

if (Object.keys(savedConfig).length > 0) {
// Configuration data exists in localStorage, set it as valid
setConfigValid(true);
} else {
// Configuration data does not exist in localStorage, set it as invalid
setConfigValid(false);
}
}, []);

if (isConfigValid === undefined) {
return <div>Loading...</div>;
}


return isConfigValid ? <Start /> : <Config setConfigValid={setConfigValid} />;
}
Copy link
Owner

Choose a reason for hiding this comment

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

Hi there, it works like expected. Very good job!

I would like to have another oppinion on the behavior. So for now, if I delete the database, the API key is still stored.
I mentioned that in this case an API call would make sense every time the Home page is opened initally.

Would you be open to discussing whether to adapt this approach? Should we implement it additionally or go with that approach? So we have 1 single souce of truth basically -> which is the db.

Same for the Config page btw :)

Copy link
Owner

@grumpyp grumpyp left a comment

Choose a reason for hiding this comment

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

Great work, I left some comments with questions :)

@auksesir
Copy link
Contributor Author

Hi, that makes sense. I'll start working on it :)

@@ -14,7 +14,7 @@ const selectBaseUrl = () => {
}
};

export const apiCall = async (endpoint, method, data) => {
export const apiCall = async (endpoint, method, data, disableNotification = false) => {
Copy link
Owner

Choose a reason for hiding this comment

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

the default parameter should either be true or it should be if(disabledNotification), otherwise we won't have any Notifcation.

Comment on lines 92 to 113
// Make an API call to fetch the configuration data only on the first load
if (!dataLoaded) {
apiCall('/config', 'GET', null, true)
.then((response) => {
const fetchedConfig = response.data;
// Set the form values based on the retrieved data
form.setValues({
OPENAI_API_KEY: fetchedConfig.openai_api_key || '',
model: fetchedConfig.model || '',
embeddingsmodel: fetchedConfig.embeddings_model || '',
});
// Save to localStorage for future loads
localStorage.setItem('config', JSON.stringify(fetchedConfig));
// Set the dataLoaded flag to true to prevent future API calls
setDataLoaded(true);
})
.catch((error) => {
console.log('Error fetching config:', error);
// Handle the error as needed, maybe show a notification or take other actions
});
}

Copy link
Owner

Choose a reason for hiding this comment

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

this would make the first load everytime one goes back to Config component - is the if dataLoaded then even needed? as the state will be gone if we change the component.

@@ -41,12 +93,11 @@ export default function Hello() {
<Router>
<HeaderResponsive links={randomLinks}/>
<Routes>
<Route path="/" element={<Home />}/>
<Route path="/" element={isConfigValid ? <GettingStarted/> : <Config/>}/>
Copy link
Owner

Choose a reason for hiding this comment

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

I am not sure if this will work, if the API returns JSON instead of the true and false which is wanted in the JSX condition.

Copy link
Owner

@grumpyp grumpyp left a comment

Choose a reason for hiding this comment

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

I think I found some little mistakes, other than that nice work. I like the additional status code implementation you did even without questioning. Really awesome :)

@grumpyp
Copy link
Owner

grumpyp commented Sep 13, 2023

hi @auksesir please ping me if you checked my review and changed if possible so I'll have another look. thx

@auksesir
Copy link
Contributor Author

Hi @grumpyp, I've changed it. Let me know if it's working correctly.

@grumpyp
Copy link
Owner

grumpyp commented Sep 14, 2023

Hi, I am sorry but it's not working like expected:

So if there's no Config in the DB, it should render the Config component. If there's one GettingStarted. You can play around by deleting the database.db sqllite db.

@auksesir
Copy link
Contributor Author

Hi @grumpyp. It should work as expected now.

I tried testing it one last time but I started getting this error:

Access to XMLHttpRequest at 'http://localhost:8000/config/' (redirected from 'http://localhost:8000/config') from origin 'http://localhost:1212' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

It started occurring even though I had not changed anything. Do you have any idea what could it be? I was trying to figure it out but nothing worked.

@grumpyp
Copy link
Owner

grumpyp commented Sep 20, 2023

Hi, sorry, but it doesn't work.

Please make also sure to merge the current origin/main, I left a little comment which caught my attention when started the review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants