Skip to content

Commit

Permalink
Merge pull request #140 from ajthinking/node-search-sorting
Browse files Browse the repository at this point in the history
Input and Output are sorted on top when searching
  • Loading branch information
ajthinking authored Feb 25, 2024
2 parents 89fd72e + f2b29b8 commit aed6081
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion packages/ui/src/components/DataStory/modals/addNodeModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,24 @@ export const AddNodeModalContentProps = (props: AddNodeModalContentProps) => {

const matchingNodes = availableNodes
.sort((a: NodeDescription, b: NodeDescription) => {
// Prioritize sorting by type if either is "Input" or "Output"
const typePriority = {Input: 1, Output: 2}; // Define priority for types
const aTypePriority = typePriority[a.name] || Number.MAX_SAFE_INTEGER; // Default to a very high number if not "Input" or "Output"
const bTypePriority = typePriority[b.name] || Number.MAX_SAFE_INTEGER; // Same here

if (aTypePriority < bTypePriority) return -1; // Move "Input" or "Output" to the front
if (aTypePriority > bTypePriority) return 1;

// If neither is "Input" or "Output", or if they are the same, then sort by category
if ((a.category || '') < (b.category || '')) return -1;
if ((a.category || '') > (b.category || '')) return 1;

return 0;
})
.filter((nodeDescription: NodeDescription) => {
return JSON.stringify(nodeDescription).toLowerCase().includes(search.toLowerCase());
});


return (
<Modal setShowModal={setShowModal}>
<div data-cy="add-node-modal">
Expand Down

0 comments on commit aed6081

Please sign in to comment.