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

feat(widgets): fetch saved access token automatically #344

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

pagour98
Copy link

@pagour98 pagour98 commented Nov 30, 2024

Issue:

In every page refresh, developer has to provide access token for testing the demo app, which involves lot of context switching and time consuming.

Solution

** Provided a solution to fetch saved access token automatically from local storage**

Vidcast of testing:
Link:

Manual Tests Performed

  • Tested demo app with our without correct access token.
  • Checked meeting behaviour and ensured we can join the meeting.
  • I have tested mute/unmute and video on/video off and ensured it does not break any functionality in the Join Meeting button
  • After joining the meeting, I have also tested audio, video, share screen, settings & Leave meeting functionality.

Summary by CodeRabbit

  • New Features

    • Token management enhancements: pre-fill token input, clear token functionality, and dynamic "Save Token" button.
    • Users can now edit the token input field regardless of existing tokens.
  • Documentation

    • Added a new file documenting licenses and copyright notices for various JavaScript libraries used in the project.

Copy link

coderabbitai bot commented Nov 30, 2024

Walkthrough

The changes involve modifications to the App component in demo/App.jsx, focusing on token management features. A useEffect hook is introduced to retrieve a saved access token from localStorage, and the functionality for clearing, updating, and saving the token has been enhanced. Additionally, a new file, docs/demo.bundle.21d6dc76bb96ca9b5537.js.LICENSE.txt, has been added, containing licensing information for various JavaScript libraries used in the project.

Changes

File Change Summary
demo/App.jsx - Added useEffect to retrieve access token from localStorage on mount.
- Updated handleClearToken to remove token from localStorage.
- Enhanced handleUpdateInputToken to enable/disable "Save Token" button based on input field.
- Modified handleSaveToken to save input token to localStorage.
- Removed readOnly property from Input component for user editing.
docs/demo.bundle.21d6dc76bb96ca9b5537.js.LICENSE.txt - Introduced a new file with licensing information for various JavaScript libraries.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant App
    participant LocalStorage

    User->>App: Mount Component
    App->>LocalStorage: Retrieve Access Token
    LocalStorage-->>App: Return Token (if exists)
    App->>User: Pre-fill Token Input (if exists)
    User->>App: Update Token Input
    App->>App: Enable/Disable Save Token Button
    User->>App: Click Save Token
    App->>LocalStorage: Save Token
    User->>App: Click Clear Token
    App->>LocalStorage: Remove Token
Loading

🐰 "In the code where tokens play,
A rabbit hops and saves the day!
With localStorage, oh so bright,
It keeps our tokens safe and right.
Click to save, or clear with glee,
Our app is happy, just wait and see!" 🐇


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (2)
demo/App.jsx (2)

38-43: LGTM! Consider adding error handling for localStorage access.

The useEffect hook correctly retrieves the saved token on component mount. However, localStorage access can fail in certain scenarios (e.g., private browsing mode).

 useEffect(() => {
-  const savedUserAccessToken = localStorage.getItem('webexWidgetsDemoAccessToken');
-  if (savedUserAccessToken) {
-    setTokenInput(savedUserAccessToken);
-  }
+  try {
+    const savedUserAccessToken = localStorage.getItem('webexWidgetsDemoAccessToken');
+    if (savedUserAccessToken) {
+      setTokenInput(savedUserAccessToken);
+    }
+  } catch (error) {
+    console.warn('Failed to retrieve saved access token:', error);
+  }
 }, []);

27-31: Add error handling for localStorage operations.

Token saving should handle potential localStorage failures gracefully.

 const handleSaveToken = (event) => {
   event.preventDefault();
-  setToken(tokenInput);
-  localStorage.setItem('webexWidgetsDemoAccessToken', tokenInput);
+  try {
+    localStorage.setItem('webexWidgetsDemoAccessToken', tokenInput);
+    setToken(tokenInput);
+  } catch (error) {
+    console.error('Failed to save access token:', error);
+    // Optionally show user feedback about the failure
+  }
 };
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 1dd0ec7 and ebd4149.

⛔ Files ignored due to path filters (1)
  • docs/demo.bundle.21d6dc76bb96ca9b5537.js.map is excluded by !**/*.map
📒 Files selected for processing (2)
  • demo/App.jsx (2 hunks)
  • docs/demo.bundle.21d6dc76bb96ca9b5537.js.LICENSE.txt (1 hunks)
🧰 Additional context used
🪛 LanguageTool
docs/demo.bundle.21d6dc76bb96ca9b5537.js.LICENSE.txt

[style] ~381-~381: ‘WITH REGARD TO’ might be wordy. Consider a shorter alternative.
Context: ...AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WAR...

(EN_WORDINESS_PREMIUM_WITH_REGARD_TO)


[duplication] ~435-~435: Possible typo: you repeated a word
Context: ... this source tree. / /* * @license React * react.production.min.js * * Copyright (c) F...

(ENGLISH_WORD_REPEAT_RULE)


[style] ~512-~512: Using many exclamation marks might seem excessive (in this case: 69 exclamation marks for a text that’s 11998 characters long)
Context: ...See LICENSE file. */ //! moment.js //! moment.js locale configuration

(EN_EXCESSIVE_EXCLAMATION)

🔇 Additional comments (2)
demo/App.jsx (1)

Line range hint 14-19: LGTM! Token cleanup is properly implemented.

The function correctly clears both the state and localStorage.

docs/demo.bundle.21d6dc76bb96ca9b5537.js.LICENSE.txt (1)

1-512: LGTM! Comprehensive license documentation.

The file properly documents all third-party licenses, ensuring legal compliance.

🧰 Tools
🪛 LanguageTool

[style] ~381-~381: ‘WITH REGARD TO’ might be wordy. Consider a shorter alternative.
Context: ...AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WAR...

(EN_WORDINESS_PREMIUM_WITH_REGARD_TO)


[duplication] ~435-~435: Possible typo: you repeated a word
Context: ... this source tree. / /* * @license React * react.production.min.js * * Copyright (c) F...

(ENGLISH_WORD_REPEAT_RULE)


[style] ~512-~512: Using many exclamation marks might seem excessive (in this case: 69 exclamation marks for a text that’s 11998 characters long)
Context: ...See LICENSE file. */ //! moment.js //! moment.js locale configuration

(EN_EXCESSIVE_EXCLAMATION)

Comment on lines 22 to +25
setTokenInput(event.target.value);
const saveTokenButton = document.getElementById('saveTokenButtonId');
if (event.target.value.length === 0) saveTokenButton.disabled = true;
else saveTokenButton.disabled = false;
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Replace direct DOM manipulation with React state.

Direct DOM manipulation with getElementById is an anti-pattern in React. Use state to manage the button's disabled state.

+const [isSaveButtonDisabled, setIsSaveButtonDisabled] = useState(true);
+
 const handleUpdateInputToken = (event) => {
   setTokenInput(event.target.value);
-  const saveTokenButton = document.getElementById('saveTokenButtonId');
-  if (event.target.value.length === 0) saveTokenButton.disabled = true;
-  else saveTokenButton.disabled = false;
+  setIsSaveButtonDisabled(event.target.value.length === 0);
 };

Then update the button props:

-<Button color="blue" type="submit" onClick={handleSaveToken} disabled={!!token} ariaLabel="Save Token">
+<Button color="blue" type="submit" onClick={handleSaveToken} disabled={!!token || isSaveButtonDisabled} ariaLabel="Save Token">

Committable suggestion skipped: line range outside the PR's diff.

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.

1 participant