-
Notifications
You must be signed in to change notification settings - Fork 3.1k
fix: Modify the license sorting method #8935
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -216,11 +216,20 @@ const search = async () => { | |
| .then((res) => { | ||
| loading.value = false; | ||
| data.value = res.data.items || []; | ||
| console.log(data.value); | ||
| for (const item of data.value) { | ||
| item.productName = 'product-1panel-pro'; | ||
| item.expiresAt = item.productPro === '0' ? '' : timestampToDate(Number(item.productPro)); | ||
| } | ||
| data.value.sort((a, b) => { | ||
| const masterLabel = i18n.global.t('xpack.node.master'); | ||
| const nodeA = loadBindNode(a); | ||
| const nodeB = loadBindNode(b); | ||
|
|
||
| if (nodeA === masterLabel || nodeB === masterLabel) { | ||
| return Number(nodeB === masterLabel) - Number(nodeA === masterLabel); | ||
| } | ||
| return a.status.localeCompare(b.status); | ||
| }); | ||
| paginationConfig.total = res.data.total; | ||
| }) | ||
| .catch(() => { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code you provided has a few minor issues that can be addressed:
Here's the revised code with these improvements: const search = async () => {
loading.value = false;
data.value = res.data.items || [];
for (const item of data.value) {
item.productName = 'product-1panel-pro';
item.expiresAt = item.productPro === '0' ? '' : timestampToDate(Number(item.productPro));
}
// Remove the unnecessary console log
// console.log(data.value);
// Optimize sorting by first handling special cases
const masterLabel = i18n.global.t('xpack.node.master');
// Use Array.prototype.map for efficiency
const sortedData = data.value
.map(item => loadBindNode(item));
// Custom comparison logic considering masterLabel
sortedData.sort((a, b) => {
if (a === masterLabel || b === masterLabel) {
return Number(b === masterLabel) - Number(a === masterLabel);
}
return a.status.localeCompare(b.status);
});
paginationConfig.total = res.data.total;
// Optionally replace original data with sortedData
/*
data.value = sortedData;
*/
};These changes should help clean up the code, make it more readable, and potentially optimize performance depending on the specific use case. |
||
|
|
||
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.
There are several areas that could be optimized or addressed:
Sorting Logic: The sorting logic can be simplified to avoid nested function calls inside the
localeComparemethod.Variable Naming: Consider renaming variables like
timestampToDate,loadBindNode, and other similar functions for clarity.Handling Empty Data Conditionally: Ensure that the code handles empty data gracefully to prevent potential errors.
Comments for Clarity: Add comments for better understanding of the code flow.
Here is an improved version of your code snippet:
Key Improvements:
localeComparewithout additional checks.