-
Notifications
You must be signed in to change notification settings - Fork 2.1k
fix: chat avatar display problem #2749
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
Conversation
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. 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. |
[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.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
@@ -359,6 +359,9 @@ function getDetail() { | |||
detail.value.tts_model_id = res.data.tts_model | |||
detail.value.tts_type = res.data.tts_type | |||
saveTime.value = res.data?.update_time | |||
application.asyncGetAccessToken(id, loading).then((res: any) => { | |||
detail.value = { ...detail.value, ...res.data } | |||
}) | |||
workflowRef.value?.clearGraphData() | |||
nextTick(() => { | |||
workflowRef.value?.render(detail.value.work_flow) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The provided code is mostly correct but has a few minor improvements that can be made:
-
Consistent Return Value Handling: The
application.asyncGetAccessToken
promise returns an object with properties likestatus
and possibly other attributes instead ofdata
. You may want to handle this more appropriately.application.asyncGetAccessToken(id, loading).then((res: any) => { if (res.status && res.data) { detail.value = { ...detail.value, ...res.data }; } else { console.error("Failed to retrieve access token data"); } }).catch((error) => { console.error("Error fetching access token:", error); });
-
Optimize Next Tick Execution: Since you're calling
nextTick()
synchronously after clearing the graph data, it might not improve performance much unless there's significant work being done in the template rendering phase. Consider moving this toworkflowRef.value?.render(detail.value.work_flow)
directly insidenextTick
. -
Type Annotations: While TypeScript annotations aren't necessary in modern JavaScript, they help catch potential errors related to type mismatches during development. Ensure all variables are properly typed.
Here’s the slightly optimized version:
function getDetail() {
detail.value.tts_model_id = res.data.tts_model
detail.value.tts_type = res.data.tts_type
saveTime.value = res.data?.update_time;
application.asyncGetAccessToken(id, loading).then((res: any) => {
if (res.status && res.data) {
detail.value = { ...detail.value, ...res.data };
} else {
console.error("Failed to retrieve access token data.");
}
}).catch((error) => {
console.error("Error fetching access token:", error);
});
// Move nextTick execution here directly for render logic.
nextTick(() => {
const updatedWorkflow = {
tts_model_id: res.data.tts_model,
tts_type: res.data.tts_type,
update_time: res.data?.update_time,
...(detail.value || {}),
...detail.value.newFieldFromTokenAccess,
// Add other fields needed from token access as needed
};
workflowRef.value?.clearGraphData();
workflowRef.value?.render(updatedWorkflow);
});
}
These changes enhance readability and consistency while addressing some common practices for handling asynchronous operations better.
@@ -693,6 +693,9 @@ function getDetail() { | |||
applicationForm.value.tts_type = res.data.tts_type | |||
applicationForm.value.model_setting.no_references_prompt = | |||
res.data.model_setting.no_references_prompt || '{question}' | |||
application.asyncGetAccessToken(id, loading).then((res: any) => { | |||
applicationForm.value = { ...applicationForm.value, ...res.data } | |||
}) | |||
}) | |||
} | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code looks generally fine but has a few areas that can be improved:
-
Async/Await: The use of
loading
inapplication.asyncGetAccessToken(id, loading)
is redundant because theasync/await
syntax inherently handles the promise's resolution status. -
Optional Chaining: Using optional chaining (
?.
) is recommended over null checks for accessing nested properties to avoid errors. -
Return Statement: The
return
statement after the.then()
handler is unnecessary and might hide errors if not handled properly. -
Code Splitting: Assuming
applicationForm
,id
, and other variables are defined elsewhere and used multiple times, consider splitting the function into smaller parts to improve readability and maintainability.
Here’s an optimized version of the code with these improvements:
function getDetail() {
applicationForm.value.tts_type = res.data.tts_type;
// Use ? for optional chaining to safely access object properties
const noReferencesPrompt = res.data.model_setting?.no_references_prompt || '{question}';
applicationForm.value.model_setting.no_references_prompt = noReferencesPrompt;
// Use async/await for cleaner error handling
try {
const accessTokenResponse = await application.asyncGetAccessToken(id);
// Merge the returned data into applicationForm using spread operator
Object.assign(applicationForm.value, accessTokenResponse.data);
} catch (error) {
console.error('Error fetching access token:', error);
}
}
Key Changes:
- Removed the
loading
parameter fromapplication.asyncGetAccessToken
. - Used optional chaining (
?.
) onres.data.model_setting.no_references_prompt
. - Swapped
.then().catch()
with atry...catch
block for cleaner error handling. - Merged the merged response data directly into
applicationForm.value
usingObject.assign
.
What this PR does / why we need it?
Summary of your change
Please indicate you've done the following: