Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions frontend/src/components/App/Home/RecentClusters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,17 @@ export default function RecentClusters(props: RecentClustersProps) {

let recentClusters: Cluster[] = [];

// If we have more than the maximum number of recent clusters allowed, we show the most
// recent ones. Otherwise, just show the clusters in the order they are received.
const clustersByName = React.useMemo(() => {
if (clusters.length <= maxRecentClusters) {
return new Map<string, Cluster>();
}
return new Map<string, Cluster>(clusters.map(cluster => [cluster.name, cluster] as const));
}, [clusters]);

if (clusters.length > maxRecentClusters) {
// Get clusters matching the recent cluster names, if they exist still.
recentClusters = recentClusterNames
.map(name => clusters.find(cluster => cluster.name === name))
.map(name => clustersByName.get(name))
.filter(item => !!item) as Cluster[];
// See whether we need to fill with new clusters (when the recent clusters were less than the
// maximum/wanted).
Expand Down
11 changes: 8 additions & 3 deletions frontend/src/components/cluster/Chooser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,17 @@ function ClusterList(props: ClusterListProps) {

let recentClusters: Cluster[] = [];

// If we have more than the maximum number of recent clusters allowed, we show the most
// recent ones. Otherwise, just show the clusters in the order they are received.
const clustersByName = React.useMemo(() => {
if (clusters.length <= maxRecentClusters) {
return new Map<string, Cluster>();
}
return new Map<string, Cluster>(clusters.map(cluster => [cluster.name, cluster] as const));
}, [clusters]);

if (clusters.length > maxRecentClusters) {
// Get clusters matching the recent cluster names, if they exist still.
recentClusters = recentClusterNames
.map(name => clusters.find(cluster => cluster.name === name))
.map(name => clustersByName.get(name))
.filter(item => !!item) as Cluster[];
// See whether we need to fill with new clusters (when the recent clusters were less than the
// maximum/wanted).
Expand Down
Loading