Skip to content

Commit

Permalink
fix most vis type errors due to ts 4.9.5 upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
nickofthyme committed Feb 1, 2024
1 parent 7e6e66f commit 89cf00e
Show file tree
Hide file tree
Showing 15 changed files with 47 additions and 119 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@ x-pack/plugins/lens/public/datatable_visualization/expression.tsx kibana-app
x-pack/plugins/lens/public/datatable_visualization/index.ts kibana-app
x-pack/plugins/lens/public/datatable_visualization/visualization.test.tsx kibana-app
x-pack/plugins/lens/public/datatable_visualization/visualization.tsx kibana-app
x-pack/plugins/lens/public/debounced_component/debounced_component.test.tsx kibana-app
x-pack/plugins/lens/public/debounced_component/debounced_component.tsx kibana-app
x-pack/plugins/lens/public/debounced_component/index.ts kibana-app
x-pack/plugins/lens/public/drag_drop/drag_drop.test.tsx kibana-app
x-pack/plugins/lens/public/drag_drop/drag_drop.tsx kibana-app
x-pack/plugins/lens/public/drag_drop/index.ts kibana-app
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import React from 'react';
import { storiesOf } from '@storybook/react';
import { from } from 'rxjs';
import { ExpressionValueVisDimension } from '@kbn/visualizations-plugin/common';
import { Datatable, DatatableColumn } from '@kbn/expressions-plugin/common';
import { Datatable, DatatableColumn, TextAlignment } from '@kbn/expressions-plugin/common';
import { Render } from '@kbn/presentation-util-plugin/public/__stories__';
import { ColorMode, CustomPaletteState } from '@kbn/charts-plugin/common';
import { getFormatService } from '../__mocks__/format_service';
Expand Down Expand Up @@ -209,8 +209,11 @@ storiesOf('renderers/visMetric', module)
},
labels: {
show: false,
// @ts-expect-error upgrade typescript v4.9.5
style: { spec: { fontSize: '60px', align: 'left' }, type: 'style', css: '' },
style: {
spec: { fontSize: '60px', textAlign: TextAlignment.LEFT },
type: 'style',
css: '',
},
position: LabelPosition.TOP,
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,13 @@ function hasAutoscaleProps<T>(props: T): props is T & AutoScaleProps {
return false;
}

function getWrappedComponentProps<T>(props: T) {
function getWrappedComponentProps<T>(props: T): T {
if (hasAutoscaleProps(props)) {
const { autoScaleParams, renderComplete, ...rest } = props;
return rest;
return {
...props,
autoScaleParams: undefined,
renderComplete: undefined,
};
}

return props;
Expand Down Expand Up @@ -132,8 +135,7 @@ export function withAutoScale<T>(WrappedComponent: ComponentType<T>) {
: {}),
}}
>
{/* @ts-expect-error upgrade typescript v4.9.5*/}
<WrappedComponent {...(restProps as T)} />
<WrappedComponent {...restProps} />
</div>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,19 @@ import { ExpressionAstExpression } from '../ast';
* `ExecutionContract` is a wrapper around `Execution` class. It provides the
* same functionality but does not expose Expressions plugin internals.
*/
export class ExecutionContract<Input = unknown, Output = unknown, InspectorAdapters = unknown> {
export class ExecutionContract<
Input = unknown,
Output = unknown,
InspectorAdapters extends Adapters = object
> {
public get isPending(): boolean {
const { state, result } = this.execution.state.get();
const finished = state === 'error' || (state === 'result' && !result?.partial);
return !finished;
}

// @ts-expect-error upgrade typescript v4.9.5
protected readonly execution: Execution<Input, Output, InspectorAdapters>;

// @ts-expect-error upgrade typescript v4.9.5
constructor(execution: Execution<Input, Output, InspectorAdapters>) {
this.execution = execution;
}
Expand Down Expand Up @@ -82,6 +84,5 @@ export class ExecutionContract<Input = unknown, Output = unknown, InspectorAdapt
* Get Inspector adapters provided to all functions of expression through
* execution context.
*/
// @ts-expect-error upgrade typescript v4.9.5
inspect = (): Adapters => this.execution.inspectorAdapters;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { FormattedColumn, TableVisConfig, TableVisUiState } from '../types';
import { DatatableColumn } from '@kbn/expressions-plugin/common';
import { createTableVisCell } from './table_vis_cell';
import { createGridColumns } from './table_vis_columns';
import { EuiDataGridProps } from '@elastic/eui';

jest.mock('./table_vis_columns', () => ({
createGridColumns: jest.fn(() => []),
Expand Down Expand Up @@ -107,8 +108,8 @@ describe('TableVisBasic', () => {
undefined
);

// @ts-expect-error upgrade typescript v4.9.5
const { onSort } = comp.find('EuiDataGrid').prop('sorting');
const { onSort } = comp.find('EuiDataGrid').prop<EuiDataGridProps['sorting']>('sorting')!;

// sort the first column
onSort([{ id: 'first', direction: 'asc' }]);
expect(uiStateProps.setSort).toHaveBeenCalledWith({ columnIndex: 0, direction: 'asc' });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,20 @@ export const convertToPercentileColumn = (
return null;
}
const commonColumnParams = createColumn(series, metric, field, { reducedTimeRange, timeShift });
const meta: PercentileColumn['meta'] =
index !== undefined
? {
reference: `${metric.id}.${index}`,
...commonColumnParams.meta,
}
: commonColumnParams.meta;

return {
operationType: 'percentile',
sourceField: field.name,
...commonColumnParams,
params: { ...params, ...getFormat(series) },
// @ts-expect-error upgrade typescript v4.9.5
meta:
index !== undefined
? {
reference: `${metric.id}.${index}`,
...commonColumnParams.meta,
}
: commonColumnParams.meta,
meta,
};
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
Column,
PercentileRanksColumnWithExtendedMeta,
CommonColumnConverterArgs,
PercentileColumn,
} from './types';

export const isPercentileRanksColumnWithMeta = (
Expand Down Expand Up @@ -56,19 +57,19 @@ export const convertToPercentileRankColumn = (
}

const commonColumnParams = createColumn(series, metric, field, { reducedTimeRange, timeShift });
const meta: PercentileColumn['meta'] =
index !== undefined
? {
reference: `${metric.id}.${index}`,
...commonColumnParams.meta,
}
: commonColumnParams.meta;
return {
operationType: 'percentile_rank',
sourceField: field.name,
...commonColumnParams,
params: { ...params, ...getFormat(series) },
// @ts-expect-error upgrade typescript v4.9.5
meta:
index !== undefined
? {
reference: `${metric.id}.${index}`,
...commonColumnParams.meta,
}
: commonColumnParams.meta,
meta,
};
};

Expand Down
4 changes: 1 addition & 3 deletions src/plugins/visualizations/public/vis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const getSearchSource = async (inputSearchSource: ISearchSource, savedSearchId?:

type PartialVisState = Assign<SerializedVis, { data: Partial<SerializedVisData> }>;

export class Vis<TVisParams = VisParams> {
export class Vis<TVisParams extends VisParams = VisParams> {
public readonly type: BaseVisType<TVisParams>;
public readonly id?: string;
public title: string = '';
Expand All @@ -69,7 +69,6 @@ export class Vis<TVisParams = VisParams> {

constructor(visType: string, visState: SerializedVis<TVisParams> = {} as any) {
this.type = this.getType(visType);
// @ts-expect-error upgrade typescript v4.9.5
this.params = this.getParams(visState.params);
this.uiState = new PersistedState(visState.uiState);
this.id = visState.id;
Expand Down Expand Up @@ -192,7 +191,6 @@ export class Vis<TVisParams = VisParams> {
title: this.title,
description: this.description,
type: this.type.name,
// @ts-expect-error upgrade typescript v4.9.5
params: cloneDeep(this.params),
uiState: this.uiState.toJSON(),
data: {
Expand Down
3 changes: 1 addition & 2 deletions src/plugins/visualizations/public/vis_async.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import type { SerializedVis } from './vis';
import type { VisParams } from '../common';

export const createVisAsync = async <TVisParams = VisParams>(
export const createVisAsync = async <TVisParams extends VisParams = VisParams>(
visType: string,
visState: SerializedVis<TVisParams> = {} as any
) => {
Expand All @@ -20,7 +20,6 @@ export const createVisAsync = async <TVisParams = VisParams>(
const { Vis } = await import('./vis');
const vis = new Vis(visType, visState);

// @ts-expect-error upgrade typescript v4.9.5
await vis.setState(visState);
return vis;
};

This file was deleted.

This file was deleted.

8 changes: 0 additions & 8 deletions x-pack/plugins/lens/public/debounced_component/index.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ import {
} from '../../../mocks';

import { mockDataPlugin, mountWithProvider } from '../../../mocks';
jest.mock('../../../debounced_component', () => {
return {
debouncedComponent: (fn: unknown) => fn,
};
});

import { WorkspacePanel } from './workspace_panel';
import { ReactWrapper } from 'enzyme';
Expand Down
4 changes: 1 addition & 3 deletions x-pack/plugins/lens/public/state_management/lens_slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1005,15 +1005,13 @@ export const makeLensReducer = (storeDeps: LensStoreDeps) => {
activeVisualization.removeLayer &&
state.visualization.state
) {
const updater = layerIds.reduce(
const updater = layerIds.reduce<unknown>(
(acc, layerId) =>
// @ts-expect-error upgrade typescript v4.9.5
activeVisualization.removeLayer ? activeVisualization.removeLayer(acc, layerId) : acc,
state.visualization.state
);

state.visualization.state =
// @ts-expect-error upgrade typescript v4.9.5
typeof updater === 'function' ? updater(current(state.visualization.state)) : updater;
}

Expand Down
7 changes: 5 additions & 2 deletions x-pack/plugins/lens/server/migrations/common_migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,11 @@ export const commonMigratePartitionChartGroups = (
}>
): LensDocShape850<{
shape: string;
layers: Array<{ primaryGroups?: string[]; secondaryGroups?: string[] }>;
layers: Array<{
primaryGroups?: string[];
secondaryGroups?: string[];
[key: string]: unknown; // unknown carryover key/values
}>;
}> => {
if (
attributes.state.visualization?.layers &&
Expand All @@ -514,7 +518,6 @@ export const commonMigratePartitionChartGroups = (
...attributes.state,
visualization: {
...attributes.state.visualization,
// @ts-expect-error upgrade typescript v4.9.5
layers: attributes.state.visualization.layers.map((l) => {
const groups = l.groups;

Expand Down

0 comments on commit 89cf00e

Please sign in to comment.