Skip to content

Commit

Permalink
Added changeset: Migrate /volumes to Tanstack router
Browse files Browse the repository at this point in the history
  • Loading branch information
abailly-akamai committed Nov 1, 2024
1 parent f6e07c2 commit 2f88aae
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/manager": Tech Stories
---

Migrate `/volumes` to Tanstack router ([#11154](https://github.com/linode/manager/pull/11154))
3 changes: 3 additions & 0 deletions packages/manager/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ module.exports = {
],
rules: {
'no-restricted-imports': [
// This needs to remain a warning since trying to link to a feature that is not yet migrated will break the UI
// For those cases react-router-dom history.push is still needed
// That being said this can be turned into an error temporarily to catch all the cases while developing
'warn',
{
paths: [
Expand Down
16 changes: 8 additions & 8 deletions packages/manager/src/routes/utils/buildXFilters.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('buildXFilters', () => {

it('handles single additional filter with contains operator', () => {
const result = buildXFilters({
additionalFilters: {
nonPaginationFilters: {
label: { '+contains': 'test' },
},
pagination: {
Expand All @@ -35,7 +35,7 @@ describe('buildXFilters', () => {

it('handles additional filters with no pagination', () => {
const result = buildXFilters({
additionalFilters: {
nonPaginationFilters: {
label: { '+contains': 'test' },
},
});
Expand All @@ -47,7 +47,7 @@ describe('buildXFilters', () => {

it('handles multiple fields with different operators', () => {
const result = buildXFilters({
additionalFilters: {
nonPaginationFilters: {
created: { '+gt': 123456789 },
status: { '+neq': 'deleted' },
},
Expand All @@ -67,7 +67,7 @@ describe('buildXFilters', () => {

it('handles complex filters with AND operator', () => {
const result = buildXFilters({
additionalFilters: {
nonPaginationFilters: {
tags: {
'+and': [{ '+contains': 'production' }, { '+contains': 'database' }],
},
Expand All @@ -89,7 +89,7 @@ describe('buildXFilters', () => {

it('handles OR operator with array of strings', () => {
const result = buildXFilters({
additionalFilters: {
nonPaginationFilters: {
region: { '+or': ['us-east', 'us-west'] },
},
pagination: {
Expand All @@ -107,7 +107,7 @@ describe('buildXFilters', () => {

it('handles numeric comparison operators', () => {
const result = buildXFilters({
additionalFilters: {
nonPaginationFilters: {
memory: { '+lt': 1024 },
size: { '+gte': 50 },
},
Expand All @@ -127,7 +127,7 @@ describe('buildXFilters', () => {

it('handles multiple operators on the same field', () => {
const result = buildXFilters({
additionalFilters: {
nonPaginationFilters: {
created: {
'+gte': 1609459200, // 2021-01-01
'+lt': 1640995200, // 2022-01-01
Expand All @@ -151,7 +151,7 @@ describe('buildXFilters', () => {

it('can feature an operator as the first key', () => {
const result = buildXFilters({
additionalFilters: {
nonPaginationFilters: {
'+or': [{ id: 0 }, { id: 1 }, { id: 2 }, { id: 3 }],
},
pagination: {
Expand Down
16 changes: 11 additions & 5 deletions packages/manager/src/routes/utils/buildXFilters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,17 @@ type FieldFilter = {
};

type AdditionalFilters =
| Partial<FilterConditionTypes>
| Partial<Record<string, FieldFilter>>;
| Omit<Partial<FilterConditionTypes>, '+order' | '+order_by'>
| Omit<Partial<Record<string, FieldFilter>>, '+order' | '+order_by'>;

interface BuildXFilterParams {
additionalFilters?: AdditionalFilters;
/**
* Filters to be added to the xFilters object.
*/
nonPaginationFilters?: AdditionalFilters;
/**
* Pagination options. This can be undefined if the pagination is not needed.
*/
pagination?: {
order: OrderDirection;
orderBy: string;
Expand All @@ -37,12 +43,12 @@ interface BuildXFilterParams {
* It is usually meant for a landing page with a filterable table.
*/
export function buildXFilters({
additionalFilters,
nonPaginationFilters,
pagination,
}: BuildXFilterParams): Filter {
return {
'+order': pagination?.order,
'+order_by': pagination?.orderBy,
...additionalFilters,
...nonPaginationFilters,
};
}
2 changes: 1 addition & 1 deletion packages/manager/src/routes/volumes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const buildVolumeXFilters = ({
query,
}: BuildVolumeXFiltersParams) =>
buildXFilters({
additionalFilters: query
nonPaginationFilters: query
? {
label: { '+contains': query },
}
Expand Down

0 comments on commit 2f88aae

Please sign in to comment.