From c1380e397cf91d0e0701b5c11d54ec37d88a017f Mon Sep 17 00:00:00 2001 From: sumit_chaturvedi Date: Wed, 21 May 2025 21:56:32 +0530 Subject: [PATCH] srn Helper method correction --- ui/lib/helper-filters.ts | 27 +++++++++++++++++++++++++++ ui/lib/helper.ts | 20 -------------------- 2 files changed, 27 insertions(+), 20 deletions(-) diff --git a/ui/lib/helper-filters.ts b/ui/lib/helper-filters.ts index fe17185746..3eeaa84ea3 100644 --- a/ui/lib/helper-filters.ts +++ b/ui/lib/helper-filters.ts @@ -44,3 +44,30 @@ export const extractSortAndKey = (searchParams: Record) => { return { searchParamsKey, rawSort, encodedSort }; }; + +/** + * Replaces a specific field name inside a filter-style key of an object. + * @param obj - The input object with filter-style keys (e.g., { 'filter[inserted_at]': '2025-05-21' }). + * @param oldField - The field name to be replaced (e.g., 'inserted_at'). + * @param newField - The field name to replace with (e.g., 'updated_at'). + * @returns A new object with the updated filter key if a match is found. + */ +export function replaceFilterFieldKey( + obj: Record, + oldField: string, + newField: string, +): Record { + const fieldObj: Record = {}; + + for (const key in obj) { + const match = key.match(/^filter\[(.+)\]$/); + if (match && match[1] === oldField) { + const newKey = `filter[${newField}]`; + fieldObj[newKey] = obj[key]; + } else { + fieldObj[key] = obj[key]; + } + } + + return fieldObj; +} diff --git a/ui/lib/helper.ts b/ui/lib/helper.ts index 229ec34cbb..db664e2a18 100644 --- a/ui/lib/helper.ts +++ b/ui/lib/helper.ts @@ -269,23 +269,3 @@ export const permissionFormFields: PermissionInfo[] = [ description: "Provides access to billing settings and invoices", }, ]; - -export function replaceFilterFieldKey( - obj: Record, - oldField: string, - newField: string, -): Record { - const fieldObj: Record = {}; - - for (const key in obj) { - const match = key.match(/^filter\[(.+)\]$/); - if (match && match[1] === oldField) { - const newKey = `filter[${newField}]`; - fieldObj[newKey] = obj[key]; - } else { - fieldObj[key] = obj[key]; - } - } - - return fieldObj; -}