Skip to content

Commit 245aa0c

Browse files
committed
Fixed types
1 parent b1ff00d commit 245aa0c

5 files changed

Lines changed: 55 additions & 44 deletions

File tree

‎superset-frontend/plugins/plugin-chart-ag-grid-table/src/buildQuery.ts‎

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -253,13 +253,21 @@ const buildQuery: BuildQuery<TableChartFormData> = (
253253
};
254254

255255
sortByFromOwnState = sortSource
256-
.map((sortItem: any) => {
257-
const colId = sortItem?.colId || sortItem?.key;
258-
const sortKey = mapColIdToIdentifier(colId);
259-
if (!sortKey) return null;
260-
const isDesc = sortItem?.sort === 'desc' || sortItem?.desc;
261-
return [sortKey, !isDesc] as QueryFormOrderBy;
262-
})
256+
.map(
257+
(sortItem: {
258+
colId?: string;
259+
key?: string;
260+
sort?: string;
261+
desc?: boolean;
262+
}) => {
263+
const colId = sortItem?.colId || sortItem?.key;
264+
if (!colId) return null;
265+
const sortKey = mapColIdToIdentifier(colId);
266+
if (!sortKey) return null;
267+
const isDesc = sortItem?.sort === 'desc' || sortItem?.desc;
268+
return [sortKey, !isDesc] as QueryFormOrderBy;
269+
},
270+
)
263271
.filter((item): item is QueryFormOrderBy => item !== null);
264272

265273
// Add secondary sort for stable ordering (matches AG Grid's stable sort behavior)
@@ -439,25 +447,25 @@ const buildQuery: BuildQuery<TableChartFormData> = (
439447
) {
440448
// Get columns that have AG Grid filters
441449
const agGridFilterColumns = new Set(
442-
ownState.agGridSimpleFilters.map((filter: any) => filter.col),
450+
ownState.agGridSimpleFilters.map(
451+
(filter: { col: string }) => filter.col,
452+
),
443453
);
444454

445455
// Remove existing TEMPORAL_RANGE filters for columns that have new AG Grid filters
446456
// This prevents duplicate filters like "No filter" and actual date ranges
447-
const existingFilters = (queryObject.filters || []).filter(
448-
(filter: any) => {
449-
// Keep filter if it doesn't have the expected structure
450-
if (!filter || typeof filter !== 'object' || !filter.col) {
451-
return true;
452-
}
453-
// Keep filter if it's not a temporal range filter
454-
if (filter.op !== 'TEMPORAL_RANGE') {
455-
return true;
456-
}
457-
// Remove if this column has an AG Grid filter
458-
return !agGridFilterColumns.has(filter.col);
459-
},
460-
);
457+
const existingFilters = (queryObject.filters || []).filter(filter => {
458+
// Keep filter if it doesn't have the expected structure
459+
if (!filter || typeof filter !== 'object' || !filter.col) {
460+
return true;
461+
}
462+
// Keep filter if it's not a temporal range filter
463+
if (filter.op !== 'TEMPORAL_RANGE') {
464+
return true;
465+
}
466+
// Remove if this column has an AG Grid filter
467+
return !agGridFilterColumns.has(filter.col);
468+
});
461469

462470
queryObject = {
463471
...queryObject,
@@ -605,8 +613,8 @@ const buildQuery: BuildQuery<TableChartFormData> = (
605613
// Use this closure to cache changing of external filters, if we have server pagination we need reset page to 0, after
606614
// external filter changed
607615
export const cachedBuildQuery = (): BuildQuery<TableChartFormData> => {
608-
let cachedChanges: any = {};
609-
const setCachedChanges = (newChanges: any) => {
616+
let cachedChanges: Record<string, unknown> = {};
617+
const setCachedChanges = (newChanges: Record<string, unknown>) => {
610618
cachedChanges = { ...cachedChanges, ...newChanges };
611619
};
612620

‎superset-frontend/plugins/plugin-chart-ag-grid-table/src/renderers/NumericCellRenderer.tsx‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
* specific language governing permissions and limitations
1717
* under the License.
1818
*/
19-
import { styled, useTheme } from '@apache-superset/core/ui';
19+
import { styled, useTheme, type SupersetTheme } from '@apache-superset/core/ui';
2020
import { CustomCellRendererProps } from '@superset-ui/core/components/ThemedAgGridReact';
21-
import { BasicColorFormatterType, InputColumn } from '../types';
21+
import { BasicColorFormatterType, InputColumn, ValueRange } from '../types';
2222
import { useIsDark } from '../utils/useTableTheme';
2323

2424
const StyledTotalCell = styled.div`
@@ -53,8 +53,6 @@ const Bar = styled.div<{
5353
z-index: 1;
5454
`;
5555

56-
type ValueRange = [number, number];
57-
5856
/**
5957
* Cell background width calculation for horizontal bar chart
6058
*/
@@ -64,7 +62,7 @@ function cellWidth({
6462
alignPositiveNegative,
6563
}: {
6664
value: number;
67-
valueRange: ValueRange;
65+
valueRange: [number, number];
6866
alignPositiveNegative: boolean;
6967
}) {
7068
const [minValue, maxValue] = valueRange;
@@ -89,7 +87,7 @@ function cellOffset({
8987
alignPositiveNegative,
9088
}: {
9189
value: number;
92-
valueRange: ValueRange;
90+
valueRange: [number, number];
9391
alignPositiveNegative: boolean;
9492
}) {
9593
if (alignPositiveNegative) {
@@ -114,7 +112,7 @@ function cellBackground({
114112
value: number;
115113
colorPositiveNegative: boolean;
116114
isDarkTheme: boolean;
117-
theme: any;
115+
theme: SupersetTheme | null;
118116
}) {
119117
if (!colorPositiveNegative) {
120118
return 'transparent'; // Use transparent background when colorPositiveNegative is false
@@ -134,7 +132,7 @@ export const NumericCellRenderer = (
134132
basicColorFormatters: {
135133
[Key: string]: BasicColorFormatterType;
136134
}[];
137-
valueRange: any;
135+
valueRange: ValueRange;
138136
alignPositiveNegative: boolean;
139137
colorPositiveNegative: boolean;
140138
},

‎superset-frontend/plugins/plugin-chart-ag-grid-table/src/types.ts‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,19 +237,25 @@ export interface InputColumn {
237237
isNumeric: boolean;
238238
isMetric: boolean;
239239
isPercentMetric: boolean;
240-
config: Record<string, any>;
241-
formatter?: Function;
240+
config: TableColumnConfig;
241+
formatter?:
242+
| TimeFormatter
243+
| NumberFormatter
244+
| CustomFormatter
245+
| CurrencyFormatter;
242246
originalLabel?: string;
243247
metricName?: string;
244248
}
245249

250+
export type ValueRange = [number, number] | null;
251+
246252
export type CellRendererProps = CustomCellRendererProps & {
247253
hasBasicColorFormatters: boolean | undefined;
248254
col: InputColumn;
249255
basicColorFormatters: {
250256
[Key: string]: BasicColorFormatterType;
251257
}[];
252-
valueRange: any;
258+
valueRange: ValueRange;
253259
alignPositiveNegative: boolean;
254260
colorPositiveNegative: boolean;
255261
allowRenderHtml: boolean;

‎superset-frontend/plugins/plugin-chart-ag-grid-table/src/utils/getInitialFilterModel.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,22 @@ import type { AgGridChartState } from '@superset-ui/core';
2121

2222
const getInitialFilterModel = (
2323
chartState?: Partial<AgGridChartState>,
24-
serverPaginationData?: Record<string, any>,
24+
serverPaginationData?: Record<string, unknown>,
2525
serverPagination?: boolean,
26-
): Record<string, any> | undefined => {
26+
): Record<string, unknown> | undefined => {
2727
const chartStateFilterModel =
2828
chartState?.filterModel && !isEmpty(chartState.filterModel)
29-
? chartState.filterModel
29+
? (chartState.filterModel as Record<string, unknown>)
3030
: undefined;
3131

3232
const serverFilterModel =
3333
serverPagination &&
3434
serverPaginationData?.agGridFilterModel &&
3535
!isEmpty(serverPaginationData.agGridFilterModel)
36-
? serverPaginationData.agGridFilterModel
36+
? (serverPaginationData.agGridFilterModel as Record<string, unknown>)
3737
: undefined;
3838

39-
return chartStateFilterModel || serverFilterModel;
39+
return chartStateFilterModel ?? serverFilterModel;
4040
};
4141

4242
export default getInitialFilterModel;

‎superset-frontend/plugins/plugin-chart-ag-grid-table/src/utils/useColDefs.ts‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@
1919
*/
2020
import { ColDef } from '@superset-ui/core/components/ThemedAgGridReact';
2121
import { useCallback, useMemo } from 'react';
22-
import { DataRecord } from '@superset-ui/core';
22+
import { DataRecord, DataRecordValue } from '@superset-ui/core';
2323
import { GenericDataType } from '@apache-superset/core/api/core';
2424
import { ColorFormatters } from '@superset-ui/chart-controls';
2525
import { extent as d3Extent, max as d3Max } from 'd3-array';
2626
import {
2727
BasicColorFormatterType,
2828
CellRendererProps,
2929
InputColumn,
30+
ValueRange,
3031
} from '../types';
3132
import getCellClass from './getCellClass';
3233
import filterValueGetter from './filterValueGetter';
@@ -41,7 +42,7 @@ import { valueFormatter, valueGetter } from './formatValue';
4142
import getCellStyle from './getCellStyle';
4243

4344
interface InputData {
44-
[key: string]: any;
45+
[key: string]: DataRecordValue;
4546
}
4647

4748
type UseColDefsProps = {
@@ -62,8 +63,6 @@ type UseColDefsProps = {
6263
slice_id: number;
6364
};
6465

65-
type ValueRange = [number, number];
66-
6766
function getValueRange(
6867
key: string,
6968
alignPositiveNegative: boolean,

0 commit comments

Comments
 (0)