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 <noreply@anthropic.com>
This commit is contained in:
Hugh A Miles II
2026-05-07 00:12:59 -04:00
parent 3cb8b17337
commit 4d001c7d9c
3 changed files with 71 additions and 66 deletions

View File

@@ -211,9 +211,9 @@ export const DashboardPage: FC<PageProps> = ({ 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<Record<string, unknown> & { id: string }>) ||
[];
(dashboard?.metadata?.native_filter_configuration as Array<
Record<string, unknown> & { id: string }
>) || [];
const nativeFilters: PartialFilters = {};
filterConfigArray.forEach(filter => {
nativeFilters[filter.id] = filter as PartialFilters[string];

View File

@@ -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<string, unknown>;
// Handle OR operator: OR:!(condition1,condition2)
if (parsedObj.OR && Array.isArray(parsedObj.OR)) {
(parsedObj.OR as Record<string, unknown>[]).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<string, unknown>).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<string, unknown>;
// Handle OR operator: OR:!(condition1,condition2)
if (parsedObj.OR && Array.isArray(parsedObj.OR)) {
(parsedObj.OR as Record<string, unknown>[]).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<string, unknown>).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,
);

View File

@@ -16,7 +16,6 @@
# under the License.
"""Unit tests for Rison filter parser."""
from superset.utils.rison_filters import RisonFilterParser