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

Enhancement - only save keys to settings.providers if validated #597

Merged
merged 1 commit into from
Apr 18, 2024

Conversation

kliu57
Copy link
Collaborator

@kliu57 kliu57 commented Apr 17, 2024

Fixes #596

Summary: No longer saving providers or their api keys to settings.providers array unless the api key is validated. If an invalid or blank is entered, the provider is REMOVED from settings.providers.

Important coding points:

  • Removed the placeholder text in the api key field when you create a new custom provider row (placeholder text was showing up as asterix)
  • Removed the useDebounce code, it wasn't working and is not worth the trouble to fix. useDebounce is sort of like a useEffect, but which allows us to wait until the user stops typing to validate the key. However, we do not expect anyone to be typing out a 32 character api key anyways, so opted to remove.
  • The keys are stored in tableProviders and only when they are validated they are stored to settings.providers
  • In these scenarios, tableProviders is synced with settings.providers: (when "syncing" happens, those invalid and blank api keys will disappear)
    • When modal first opens
    • When modal closes
    • When current provider is set (need to sync to update the checkmark)
    • When a custom provider is deleted (need to sync to show the row deleted)
    • When a custom provider is added (need to sync to show the new row)
  • Note: If you create a custom provider and then later set the key to something invalid, when you close the modal the custom provider row will disappear since we only save it if it has a valid key.

@kliu57 kliu57 requested review from Rachit1313 and rjwignar April 17, 2024 01:33
@kliu57 kliu57 self-assigned this Apr 17, 2024
Copy link

cloudflare-workers-and-pages bot commented Apr 17, 2024

Deploying chatcraft-org with  Cloudflare Pages  Cloudflare Pages

Latest commit: a88885c
Status: ✅  Deploy successful!
Preview URL: https://0bd70c1a.console-overthinker-dev.pages.dev
Branch Preview URL: https://issue-596.console-overthinker-dev.pages.dev

View logs

@kliu57 kliu57 added this to the Release 2.0 milestone Apr 17, 2024
@kliu57
Copy link
Collaborator Author

kliu57 commented Apr 17, 2024

@rjwignar @Rachit1313 Sorry not yet ready for review. Will comment again when it is.

@kliu57
Copy link
Collaborator Author

kliu57 commented Apr 17, 2024

@rjwignar @Rachit1313 Now it is ready for review

@kliu57 kliu57 requested a review from WangGithub0 April 17, 2024 02:14
@WangGithub0
Copy link
Collaborator

I found the error color changed, is this the expected?
production:
image

priview
image

@kliu57
Copy link
Collaborator Author

kliu57 commented Apr 17, 2024

I found the error color changed, is this the expected? production: image

priview image

The color is different because the message is different. The orange one happens when you try to add a new custom provider, but you put an invalid key. So it says "Provider not added" I used a warning instead of error so it can automatically disappear, I feel it is more convenient. The red one is when you change your current provider key to an invalid one.

Copy link
Collaborator

@Rachit1313 Rachit1313 left a comment

Choose a reason for hiding this comment

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

Looks good to me.

@tarasglek
Copy link
Owner

I think Error was more correct here..as it's fairly fatal that you can't validate your key

@kliu57
Copy link
Collaborator Author

kliu57 commented Apr 18, 2024

I think Error was more correct here..as it's fairly fatal that you can't validate your key

@tarasglek Ok, I modified the code so that users trying to add a new custom provider but gave an invalid url or invalid key will get the "error" type alert instead of the warning

Copy link
Collaborator

@WangGithub0 WangGithub0 left a comment

Choose a reason for hiding this comment

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

It looks good to me.

@kliu57 kliu57 merged commit e24503b into main Apr 18, 2024
4 checks passed
@kliu57 kliu57 deleted the issue-596 branch April 18, 2024 17:29
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.

Only valid keys should be stored in settings.providers array
4 participants