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

fix(ui): improve endpoints ordering #3041

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

bodinsamuel
Copy link
Collaborator

Changes

  • Improve endpoints ordering
    We were only pushing items up if the comparison was directly different, so when we compared POST to DELETE, POST was not pushed up.

@bodinsamuel bodinsamuel self-assigned this Nov 22, 2024
(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;
Copy link
Collaborator

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];

Copy link
Collaborator

@TBonnin TBonnin Nov 22, 2024

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);
                })
            });

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.

2 participants