diff --git a/packages/manager/.changeset/pr-13234-changed-1767172149210.md b/packages/manager/.changeset/pr-13234-changed-1767172149210.md new file mode 100644 index 00000000000..770e04ff88d --- /dev/null +++ b/packages/manager/.changeset/pr-13234-changed-1767172149210.md @@ -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)) diff --git a/packages/manager/src/features/components/PlansPanel/utils/planFilters.test.ts b/packages/manager/src/features/components/PlansPanel/utils/planFilters.test.ts index 1c4e99cf5c5..7dddf55b744 100644 --- a/packages/manager/src/features/components/PlansPanel/utils/planFilters.test.ts +++ b/packages/manager/src/features/components/PlansPanel/utils/planFilters.test.ts @@ -11,6 +11,7 @@ import { filterPlansByGpuType, filterPlansByType, getAvailableTypes, + getGenerationRank, supportsTypeFiltering, } from './planFilters'; @@ -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); + }); + }); }); diff --git a/packages/manager/src/features/components/PlansPanel/utils/planFilters.ts b/packages/manager/src/features/components/PlansPanel/utils/planFilters.ts index 9dd66d55a8d..9cec18a885e 100644 --- a/packages/manager/src/features/components/PlansPanel/utils/planFilters.ts +++ b/packages/manager/src/features/components/PlansPanel/utils/planFilters.ts @@ -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 => { + 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 * @@ -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)