From 4d001c7d9cb3a637e435e3376a3b8315eaad1ba6 Mon Sep 17 00:00:00 2001 From: Hugh A Miles II Date: Thu, 7 May 2026 00:12:59 -0400 Subject: [PATCH] fix(dashboard): satisfy lint/format on Rison filter files - Move parseFilterCondition above parseRisonFilters to fix oxlint no-use-before-define - Apply prettier to risonFilters.ts and DashboardPage.tsx - Apply ruff-format to test_rison_filters.py Co-Authored-By: Claude Opus 4.7 --- .../dashboard/containers/DashboardPage.tsx | 6 +- .../src/dashboard/util/risonFilters.ts | 130 +++++++++--------- tests/unit_tests/utils/test_rison_filters.py | 1 - 3 files changed, 71 insertions(+), 66 deletions(-) diff --git a/superset-frontend/src/dashboard/containers/DashboardPage.tsx b/superset-frontend/src/dashboard/containers/DashboardPage.tsx index c1f0c925cdd..30b2e25aae7 100644 --- a/superset-frontend/src/dashboard/containers/DashboardPage.tsx +++ b/superset-frontend/src/dashboard/containers/DashboardPage.tsx @@ -211,9 +211,9 @@ export const DashboardPage: FC = ({ idOrSlug }: PageProps) => { if (risonFilters.length > 0) { // Convert native filter config array to keyed object for lookup const filterConfigArray = - (dashboard?.metadata - ?.native_filter_configuration as Array & { id: string }>) || - []; + (dashboard?.metadata?.native_filter_configuration as Array< + Record & { id: string } + >) || []; const nativeFilters: PartialFilters = {}; filterConfigArray.forEach(filter => { nativeFilters[filter.id] = filter as PartialFilters[string]; diff --git a/superset-frontend/src/dashboard/util/risonFilters.ts b/superset-frontend/src/dashboard/util/risonFilters.ts index 2214dd80e6a..475b8bfdc7b 100644 --- a/superset-frontend/src/dashboard/util/risonFilters.ts +++ b/superset-frontend/src/dashboard/util/risonFilters.ts @@ -35,63 +35,6 @@ export interface IntelligentRisonInjectionResult { unmatchedFilters: RisonFilter[]; } -/** - * Parse Rison filter syntax from URL parameter. - * Supports formats like: (country:USA,year:2024) - */ -export function parseRisonFilters(risonString: string): RisonFilter[] { - try { - const parsed = rison.decode(risonString); - const filters: RisonFilter[] = []; - - if (!parsed || typeof parsed !== 'object') { - return filters; - } - - const parsedObj = parsed as Record; - - // Handle OR operator: OR:!(condition1,condition2) - if (parsedObj.OR && Array.isArray(parsedObj.OR)) { - (parsedObj.OR as Record[]).forEach(condition => { - if (typeof condition === 'object') { - Object.entries(condition).forEach(([key, value]) => { - filters.push(parseFilterCondition(key, value)); - }); - } - }); - return filters; - } - - // Handle NOT operator: NOT:(condition) - if (parsedObj.NOT && typeof parsedObj.NOT === 'object') { - Object.entries(parsedObj.NOT as Record).forEach( - ([key, value]) => { - const filter = parseFilterCondition(key, value); - if (filter.operator === '==') { - filter.operator = '!='; - } else if (filter.operator === 'IN') { - filter.operator = 'NOT IN'; - } - filters.push(filter); - }, - ); - return filters; - } - - // Handle regular filters - Object.entries(parsedObj).forEach(([key, value]) => { - if (key !== 'OR' && key !== 'NOT') { - filters.push(parseFilterCondition(key, value)); - } - }); - - return filters; - } catch (error) { - console.warn('Failed to parse Rison filters:', error); - return []; - } -} - /** * Parse individual filter condition */ @@ -165,6 +108,63 @@ function parseFilterCondition(key: string, value: unknown): RisonFilter { }; } +/** + * Parse Rison filter syntax from URL parameter. + * Supports formats like: (country:USA,year:2024) + */ +export function parseRisonFilters(risonString: string): RisonFilter[] { + try { + const parsed = rison.decode(risonString); + const filters: RisonFilter[] = []; + + if (!parsed || typeof parsed !== 'object') { + return filters; + } + + const parsedObj = parsed as Record; + + // Handle OR operator: OR:!(condition1,condition2) + if (parsedObj.OR && Array.isArray(parsedObj.OR)) { + (parsedObj.OR as Record[]).forEach(condition => { + if (typeof condition === 'object') { + Object.entries(condition).forEach(([key, value]) => { + filters.push(parseFilterCondition(key, value)); + }); + } + }); + return filters; + } + + // Handle NOT operator: NOT:(condition) + if (parsedObj.NOT && typeof parsedObj.NOT === 'object') { + Object.entries(parsedObj.NOT as Record).forEach( + ([key, value]) => { + const filter = parseFilterCondition(key, value); + if (filter.operator === '==') { + filter.operator = '!='; + } else if (filter.operator === 'IN') { + filter.operator = 'NOT IN'; + } + filters.push(filter); + }, + ); + return filters; + } + + // Handle regular filters + Object.entries(parsedObj).forEach(([key, value]) => { + if (key !== 'OR' && key !== 'NOT') { + filters.push(parseFilterCondition(key, value)); + } + }); + + return filters; + } catch (error) { + console.warn('Failed to parse Rison filters:', error); + return []; + } +} + /** * Convert Rison filters to Superset adhoc filter format */ @@ -330,9 +330,7 @@ function findMatchingNativeFilter( const hasMatchingTarget = nativeFilter.targets.some(target => { if (typeof target === 'object' && target && 'column' in target) { - return ( - target.column?.name?.trim().toLowerCase() === normalizedSubject - ); + return target.column?.name?.trim().toLowerCase() === normalizedSubject; } return false; }); @@ -425,7 +423,11 @@ function convertRisonToNativeValue( */ function buildDataMaskForFilter( risonFilter: RisonFilter, - nativeFilter: { id: string; filterType?: string; targets?: { column?: { name?: string } }[] }, + nativeFilter: { + id: string; + filterType?: string; + targets?: { column?: { name?: string } }[]; + }, columnName: string, ) { const convertedValue = convertRisonToNativeValue(risonFilter, nativeFilter); @@ -468,7 +470,11 @@ export function injectRisonFiltersIntelligently( const dataMaskEntry = buildDataMaskForFilter( risonFilter, - matchedFilter as { id: string; filterType?: string; targets?: { column?: { name?: string } }[] }, + matchedFilter as { + id: string; + filterType?: string; + targets?: { column?: { name?: string } }[]; + }, columnName, ); diff --git a/tests/unit_tests/utils/test_rison_filters.py b/tests/unit_tests/utils/test_rison_filters.py index ab30bd6ff60..4b3d6735d82 100644 --- a/tests/unit_tests/utils/test_rison_filters.py +++ b/tests/unit_tests/utils/test_rison_filters.py @@ -16,7 +16,6 @@ # under the License. """Unit tests for Rison filter parser.""" - from superset.utils.rison_filters import RisonFilterParser