Skip to content

fix: Historical user conversation data has been cleared#2840

Merged
shaohuzhang1 merged 1 commit intomainfrom
pr@main@fix_chat_session
Apr 9, 2025
Merged

fix: Historical user conversation data has been cleared#2840
shaohuzhang1 merged 1 commit intomainfrom
pr@main@fix_chat_session

Conversation

@shaohuzhang1
Copy link
Copy Markdown
Contributor

fix: Historical user conversation data has been cleared

@f2c-ci-robot
Copy link
Copy Markdown

f2c-ci-robot bot commented Apr 9, 2025

Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@f2c-ci-robot
Copy link
Copy Markdown

f2c-ci-robot bot commented Apr 9, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@shaohuzhang1 shaohuzhang1 merged commit 8dc793a into main Apr 9, 2025
4 checks passed
@shaohuzhang1 shaohuzhang1 deleted the pr@main@fix_chat_session branch April 9, 2025 11:16
return localStorage.getItem(`accessToken`)
},

getPermissions() {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The provided code snippet includes some minor issues that can be addressed:

Issues Identified:

  1. Redundancy: The function getToken fetches tokens from both localStorage items but uses different keys (${token}accessToken and ``accessToken```). This redundancy is unnecessary.
  2. Variable Naming: Using local_token as an alias for localStorage.getItem(...) does not improve readability; using access_token_from_storage would be more descriptive.

Optimization Suggestions:

  1. Remove the redundant logic and use consistency in fetching tokens:

    • Use only one key for accessing tokens, regardless of whether it's provided directly or stored in localStorage.
  2. Ensure clarity with variable names to make the code easier to understand:

@@ -65,14 +65,16 @@ const useUserStore = defineStore({
       let refreshTokenFromStorage

       if (refreshToken) {
         token = refreshToken
       }

-      // Fetch access token based on the provided token or 'accessToken' from storage
+      const tokenId = token || 'accessToken'
+      
       accessTokenFromStorage = localStorage.getItem(`${tokenId}AccessToken`)

       return accessTokenFromStorage ? accessTokenFromStorage : ''
+  } else {
+    // Fallback if no valid token is available
+    console.warn('No valid token found.')
+    return ''
   }
 }
 
 function getPermissions() {

By making these changes, the code becomes cleaner, reduces duplication, and improves its legibility and maintainability.

}
}
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The provided code function sendMessage can be optimized and enhanced as follows:

Functionality

The function currently handles sending messages with various parameters, including user input and optional loading status. However, there are some areas that could be improved:

  1. Loading Status Handling: The logic for deciding whether to call handleDebounceClick involves checking both the loading.value condition and props.applicationDetails?.name. This redundancy should be removed.

  2. Empty Message Validation: It might be beneficial to add a validation step to ensure that the message is not empty before attempting to send it.

  3. Conditional Logic Refinement: The conditional logic around showing user input can be simplified.

Optimization and Recommendations

  • Combine Conditions: Remove the redundant check for loading.value && props.applicationDetails?.name.
function sendMessage(val: string, other_params_data?: any, chat?: chatType) {
  if (val.trim() !== "") { // Add validation to prevent empty messages
    showUserInput.value = true
  } else {
    console.log("Message cannot be empty");
    return;
  }
}
  • Simplify Conditional Block: Combine the block handling when user input needs showing into one line.
if (val.trim() !== "" || !showUserInput.value) {
    showUserInput.value = val.trim() !== "";
  } else {
    console.log("Message cannot be empty.");
    return;
  }

Code Cleanup

Ensure the function is clean and easy to read by following PEP8 guidelines. Here’s an updated version of the function:

function sendMessage(val: string, other_params_data?: any, chat?: chatType) {
  if (val.trim() === "") {
    console.log("Message cannot be empty."); // Add explicit error logging
    return; // Optionally you could throw an exception if needed
  }

  const isValid = val.trim().length > 0;
  showUserInput.value = isValid;

  if (!isValid) {
    console.log("Failed to set showUserInput:", isValid);
  }
}

// Additional logic for handleDebounceClick remains unchanged
handleDebounceClick(val, other_params_data, chat);

In summary, these improvements reduce code duplication, make the logic clearer, and add basic value-validation checks to enhance maintainability and reliability of the function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant