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
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/manager": Changed
---

Update Generational Plans default sort to show newest (G8) -> oldest (G6) ([#13234](https://github.com/linode/manager/pull/13234))
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
filterPlansByGpuType,
filterPlansByType,
getAvailableTypes,
getGenerationRank,
supportsTypeFiltering,
} from './planFilters';

Expand Down Expand Up @@ -240,4 +241,19 @@ describe('planFilters utilities', () => {
expect(result).toEqual(gpuPlans);
});
});

describe('getGenerationRank', () => {
it('returns higher rank for newer generations', () => {
expect(getGenerationRank('g8-dedicated-4-2')).toBeGreaterThan(
getGenerationRank('g7-dedicated-4-2')
);
expect(getGenerationRank('g7-dedicated-4-2')).toBeGreaterThan(
getGenerationRank('g6-dedicated-2')
);
});

it('returns 0 for unknown generations', () => {
expect(getGenerationRank('legacy-plan')).toBe(0);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,19 @@ export const filterPlansByGeneration = (
// Type Filtering
// ============================================================================

/**
* Determines the relative generation order of a plan based on its ID.
*
* Used to sort plans from newest to oldest when the "All" type
* filter is selected (G8 -> G7 -> G6).
*/
export const getGenerationRank = (planId: string): number => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The returned values (3,2,1,0) are hardcoded. If more generations are introduced in future, changes will require code edits. We can use a mapping object for easier extensibility:

const generationMapping: Record<string, number> = {
  'g8-': 3,
  'g7-': 2,
  'g6-': 1,
};
for (const prefix in generationMapping) {
  if (planId.startsWith(prefix)) return generationMapping[prefix];
}
return 0;

if (planId.startsWith('g8-')) return 3;
if (planId.startsWith('g7-')) return 2;
if (planId.startsWith('g6-')) return 1;
return 0;
};

/**
* Filter plans by type within a generation
*
Expand All @@ -88,9 +101,11 @@ export const filterPlansByType = (
generation: PlanFilterGeneration,
type: PlanFilterType
): PlanWithAvailability[] => {
// "All" returns all plans unchanged
// "All" returns all plans, sorted from newest (G8) to oldest (G6)
if (type === PLAN_FILTER_ALL) {
return plans;
return [...plans].sort(
(a, b) => getGenerationRank(b.id) - getGenerationRank(a.id)
);
}

// G7, G6, and "All" generation only have "All" option (no sub-types)
Expand Down