Skip to content

Commit

Permalink
Order connectors by stage before alphabetical (#11637)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Roes authored Mar 31, 2022
1 parent 526c5a0 commit f642864
Showing 1 changed file with 28 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,24 @@ type MenuWithRequestButtonProps = MenuListComponentProps<IDataItem, false>;
* A higher positive number will put the given connector to the top of the list
* a low negative number to the end of it.
*/
const ORDER_OVERWRITE: Record<string, number> = {
// Push Google Sheets connector to top
"71607ba1-c0ac-4799-8049-7f4b90dd50f7": 1,
};
const ORDER_OVERWRITE: Record<string, number> = {};

/**
* Returns the order for a specific release stage label. This will define
* in what order the different release stages are shown inside the select.
* They will be shown in an increasing order (i.e. 0 on top), unless not overwritten
* by ORDER_OVERWRITE above.
*/
function getOrderForReleaseStage(stage?: ReleaseStage): number {
switch (stage) {
case ReleaseStage.BETA:
return 1;
case ReleaseStage.ALPHA:
return 2;
default:
return 0;
}
}

const ConnectorList: React.FC<MenuWithRequestButtonProps> = ({
children,
Expand Down Expand Up @@ -214,9 +228,16 @@ const ConnectorServiceTypeControl: React.FC<{
const priorityA = ORDER_OVERWRITE[a.value] ?? 0;
const priorityB = ORDER_OVERWRITE[b.value] ?? 0;
// If they have different priority use the higher priority first, otherwise use the label
return priorityA !== priorityB
? priorityB - priorityA
: naturalComparator(a.label, b.label);
if (priorityA !== priorityB) {
return priorityB - priorityA;
} else if (a.releaseStage !== b.releaseStage) {
return (
getOrderForReleaseStage(a.releaseStage) -
getOrderForReleaseStage(b.releaseStage)
);
} else {
return naturalComparator(a.label, b.label);
}
}),
// eslint-disable-next-line react-hooks/exhaustive-deps
[availableServices]
Expand Down

0 comments on commit f642864

Please sign in to comment.