-
Notifications
You must be signed in to change notification settings - Fork 461
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
fix(ui): improve endpoints ordering #3041
Conversation
(b.endpoint.method === 'PUT' || b.endpoint.method === 'PATCH' || b.endpoint.method === 'DELETE') | ||
) | ||
return -1; | ||
else if (a.endpoint.method === 'PUT' && (b.endpoint.method === 'PATCH' || b.endpoint.method === 'DELETE')) return -1; |
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.
can we do?
const METHOD_PRIORITY = {
'GET': 1,
'POST': 2,
'PUT': 3,
'PATCH': 4,
'DELETE': 5
};
return METHOD_PRIORITY[a.endpoint.method] - METHOD_PRIORITY[b.endpoint.method];
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.
unrelated to this PR but I am not sure why we have 2 .sort
chained one after each other.
Also this sorting logic is becoming quite complex and I feel could be refactored like:
groups.push({ name: group[0],
flows: group[1].sort((a, b) => {
const comparePaths = (pathA, pathB) => {
const countPathSegments = (path) => (path.match(/\//g) || []).length;
const lenA = countPathSegments(pathA);
const lenB = countPathSegments(pathB);
if (lenA !== lenB) {
return lenA - lenB;
}
return pathA.localeCompare(pathB);
};
const compareMethods = (methodA, methodB) => { ... };
const pathComparison = comparePaths(a.endpoint.path, b.endpoint.path);
if (pathComparison !== 0) {
return pathComparison;
}
return compareMethods(a.endpoint.method, b.endpoint.method);
})
});
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.
Changed with your first suggestion 👌🏻
It split in two because I had issues containing the logic of grouping and sorting in the same sort
(grouping by paths, then sorting alphabetically, then sorting by method)
Changes
We were only pushing items up if the comparison was directly different, so when we compared POST to DELETE, POST was not pushed up.