Skip to content

Commit

Permalink
ui: sort items in the sql activity dropdown menu
Browse files Browse the repository at this point in the history
Fixes cockroachdb#78081.

Previously, app names in the dropdown menu for the stmts, txns, and
sessions pages were unsorted. This change sorts these app names.

Release note (ui change): app names and database names in the dropdown
menu are sorted.
  • Loading branch information
Gerardo Torres committed Mar 21, 2022
1 parent 464a1d4 commit a6ea113
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pkg/ui/workspaces/cluster-ui/src/sessions/sessionsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ function getSessionAppFilterOptions(sessions: SessionInfo[]): string[] {
),
);

return Array.from(uniqueAppNames);
return Array.from(uniqueAppNames).sort();
}

export class SessionsPage extends React.Component<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ export const selectApps = createSelector(sqlStatsSelector, sqlStatsState => {
}
},
);
return [].concat(sawBlank ? ["(unset)"] : []).concat(Object.keys(apps));
return []
.concat(sawBlank ? ["(unset)"] : [])
.concat(Object.keys(apps).sort());
});

// selectDatabases returns the array of all databases with statement statistics present
Expand All @@ -99,7 +101,9 @@ export const selectDatabases = createSelector(
s.key.key_data.database ? s.key.key_data.database : "(unset)",
),
),
).filter((dbName: string) => dbName !== null && dbName.length > 0);
)
.filter((dbName: string) => dbName !== null && dbName.length > 0)
.sort();
},
);

Expand Down
2 changes: 1 addition & 1 deletion pkg/ui/workspaces/cluster-ui/src/transactionsPage/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const getTrxAppFilterOptions = (
.map(t => (t.stats_data.app ? t.stats_data.app : "(unset)")),
);

return Array.from(uniqueAppNames);
return Array.from(uniqueAppNames).sort();
};

export const collectStatementsText = (statements: Statement[]): string =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ describe("selectApps", () => {

const result = selectApps(state);

assert.deepEqual(result, ["(unset)", "foobar", "cockroach sql"]);
assert.deepEqual(result, ["(unset)", "cockroach sql", "foobar"]);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,10 @@ export const selectApps = createSelector(
}
},
);
return [].concat(sawBlank ? ["(unset)"] : []).concat(Object.keys(apps));
return []
.concat(sawBlank ? ["(unset)"] : [])
.concat(Object.keys(apps))
.sort();
},
);

Expand All @@ -206,7 +209,9 @@ export const selectDatabases = createSelector(
s.key.key_data.database ? s.key.key_data.database : "(unset)",
),
),
).filter((dbName: string) => dbName !== null && dbName.length > 0);
)
.filter((dbName: string) => dbName !== null && dbName.length > 0)
.sort();
},
);

Expand Down

0 comments on commit a6ea113

Please sign in to comment.