TypeScript project references for infra plugin (#90118)

Co-authored-by: Felix Stürmer <stuermer@weltenwort.de>
This commit is contained in:
Nathan L Smith 2021-02-08 08:59:45 -06:00 committed by GitHub
parent 5176aa6bc7
commit e4794af33c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 163 additions and 74 deletions

View file

@ -41,7 +41,21 @@ export type GetLogAlertsChartPreviewDataSuccessResponsePayload = rt.TypeOf<
typeof getLogAlertsChartPreviewDataSuccessResponsePayloadRT
>;
export const getLogAlertsChartPreviewDataAlertParamsSubsetRT = rt.intersection([
// This should not have an explicit `any` return type, but it's here because its
// inferred type includes `Comparator` which is a string enum exported from
// common/alerting/logs/log_threshold/types.ts.
//
// There's a bug that's fixed in TypeScript 4.2.0 that will allow us to remove
// the `:any` from this, so remove it when that update happens.
//
// If it's removed before then you get:
//
// x-pack/plugins/infra/common/http_api/log_alerts/chart_preview_data.ts:44:14 - error TS4023:
// Exported variable 'getLogAlertsChartPreviewDataAlertParamsSubsetRT' has or is using name 'Comparator'
// from external module "/Users/smith/Code/kibana/x-pack/plugins/infra/common/alerting/logs/log_threshold/types"
// but cannot be named.
//
export const getLogAlertsChartPreviewDataAlertParamsSubsetRT: any = rt.intersection([
rt.type({
criteria: countCriteriaRT,
timeUnit: timeUnitRT,

View file

@ -7,18 +7,35 @@
import * as rt from 'io-ts';
const createErrorRuntimeType = <Attributes extends rt.Mixed = rt.UndefinedType>(
statusCode: number,
errorCode: string,
attributes?: Attributes
) =>
export const badRequestErrorRT = rt.intersection([
rt.type({
statusCode: rt.literal(statusCode),
error: rt.literal(errorCode),
statusCode: rt.literal(400),
error: rt.literal('Bad Request'),
message: rt.string,
...(!!attributes ? { attributes } : {}),
});
}),
rt.partial({
attributes: rt.unknown,
}),
]);
export const badRequestErrorRT = createErrorRuntimeType(400, 'Bad Request');
export const forbiddenErrorRT = createErrorRuntimeType(403, 'Forbidden');
export const conflictErrorRT = createErrorRuntimeType(409, 'Conflict');
export const forbiddenErrorRT = rt.intersection([
rt.type({
statusCode: rt.literal(403),
error: rt.literal('Forbidden'),
message: rt.string,
}),
rt.partial({
attributes: rt.unknown,
}),
]);
export const conflictErrorRT = rt.intersection([
rt.type({
statusCode: rt.literal(409),
error: rt.literal('Conflict'),
message: rt.string,
}),
rt.partial({
attributes: rt.unknown,
}),
]);

View file

@ -286,7 +286,7 @@ export const ESTopHitsAggRT = rt.type({
top_hits: rt.object,
});
interface SnapshotTermsWithAggregation {
export interface SnapshotTermsWithAggregation {
terms: { field: string };
aggregations: MetricsUIAggregation;
}

View file

@ -9,7 +9,7 @@ import { isEqual } from 'lodash';
import { useState } from 'react';
import { MetricsExplorerMetric } from '../../../../common/http_api/metrics_explorer';
interface MetricThresholdPrefillOptions {
export interface MetricThresholdPrefillOptions {
groupBy: string | string[] | undefined;
filterQuery: string | undefined;
metrics: MetricsExplorerMetric[];

View file

@ -48,19 +48,19 @@ const wrapWithSharedState = () => {
return null;
}
private getTitle(title: TitleProp) {
public getTitle(title: TitleProp) {
return typeof title === 'function' ? title(titles[this.state.index - 1]) : title;
}
private pushTitle(title: string) {
public pushTitle(title: string) {
titles[this.state.index] = title;
}
private removeTitle() {
public removeTitle() {
titles.pop();
}
private updateDocumentTitle() {
public updateDocumentTitle() {
const title = (titles[titles.length - 1] || '') + TITLE_SUFFIX;
if (title !== document.title) {
document.title = title;

View file

@ -6,13 +6,19 @@
*/
import { EuiPanel } from '@elastic/eui';
import { FunctionComponent } from 'react';
import { StyledComponent } from 'styled-components';
import { euiStyled, EuiTheme } from '../../../../../../../src/plugins/kibana_react/common';
import { euiStyled } from '../../../../../../../src/plugins/kibana_react/common';
export const Toolbar = euiStyled(EuiPanel).attrs(() => ({
grow: false,
paddingSize: 'none',
}))`
// The return type of this component needs to be specified because the inferred
// return type depends on types that are not exported from EUI. You get a TS4023
// error if the return type is not specified.
export const Toolbar: StyledComponent<FunctionComponent, EuiTheme> = euiStyled(EuiPanel).attrs(
() => ({
grow: false,
paddingSize: 'none',
})
)`
border-top: none;
border-right: none;
border-left: none;

View file

@ -5,12 +5,18 @@
* 2.0.
*/
import React from 'react';
import { EuiDatePicker, EuiDatePickerProps } from '@elastic/eui';
import { euiStyled } from '../../../../../src/plugins/kibana_react/common';
import React, { FunctionComponent } from 'react';
import { StyledComponent } from 'styled-components';
import { euiStyled, EuiTheme } from '../../../../../src/plugins/kibana_react/common';
export const FixedDatePicker = euiStyled(
// The return type of this component needs to be specified because the inferred
// return type depends on types that are not exported from EUI. You get a TS4023
// error if the return type is not specified.
export const FixedDatePicker: StyledComponent<
FunctionComponent<EuiDatePickerProps>,
EuiTheme
> = euiStyled(
({
className,
inputClassName,

View file

@ -5,13 +5,20 @@
* 2.0.
*/
import { FunctionComponent } from 'react';
import { EuiPanel } from '@elastic/eui';
import { euiStyled } from '../../../../../src/plugins/kibana_react/common';
import { StyledComponent } from 'styled-components';
import { EuiTheme, euiStyled } from '../../../../../src/plugins/kibana_react/common';
export const ToolbarPanel = euiStyled(EuiPanel).attrs(() => ({
grow: false,
paddingSize: 'none',
}))`
// The return type of this component needs to be specified because the inferred
// return type depends on types that are not exported from EUI. You get a TS4023
// error if the return type is not specified.
export const ToolbarPanel: StyledComponent<FunctionComponent, EuiTheme> = euiStyled(EuiPanel).attrs(
() => ({
grow: false,
paddingSize: 'none',
})
)`
border-top: none;
border-right: none;
border-left: none;

View file

@ -27,7 +27,7 @@ const initialState = {
type State = Readonly<typeof initialState>;
export const CustomFieldPanel = class extends React.PureComponent<Props, State> {
export class CustomFieldPanel extends React.PureComponent<Props, State> {
public static displayName = 'CustomFieldPanel';
public readonly state: State = initialState;
public render() {
@ -86,4 +86,4 @@ export const CustomFieldPanel = class extends React.PureComponent<Props, State>
private handleFieldSelection = (selectedOptions: SelectedOption[]) => {
this.setState({ selectedOptions });
};
};
}

View file

@ -44,7 +44,7 @@ interface Props {
currentTime: number;
}
export const Node = class extends React.PureComponent<Props, State> {
export class Node extends React.PureComponent<Props, State> {
public readonly state: State = initialState;
public render() {
const { nodeType, node, options, squareSize, bounds, formatter, currentTime } = this.props;
@ -164,7 +164,7 @@ export const Node = class extends React.PureComponent<Props, State> {
this.setState({ isPopoverOpen: false });
}
};
};
}
const NodeContainer = euiStyled.div`
position: relative;

View file

@ -39,7 +39,7 @@ const initialState = {
type State = Readonly<typeof initialState>;
export const WaffleGroupByControls = class extends React.PureComponent<Props, State> {
export class WaffleGroupByControls extends React.PureComponent<Props, State> {
public static displayName = 'WaffleGroupByControls';
public readonly state: State = initialState;
@ -192,7 +192,7 @@ export const WaffleGroupByControls = class extends React.PureComponent<Props, St
}
this.handleClose();
};
};
}
const StyledContextMenu = euiStyled(EuiContextMenu)`
width: 320px;

View file

@ -235,22 +235,22 @@ export const useTrackedPromise = <Arguments extends any[], Result>(
return [promiseState, execute] as [typeof promiseState, typeof execute];
};
interface UninitializedPromiseState {
export interface UninitializedPromiseState {
state: 'uninitialized';
}
interface PendingPromiseState<ResolvedValue> {
export interface PendingPromiseState<ResolvedValue> {
state: 'pending';
promise: Promise<ResolvedValue>;
}
interface ResolvedPromiseState<ResolvedValue> {
export interface ResolvedPromiseState<ResolvedValue> {
state: 'resolved';
promise: Promise<ResolvedValue>;
value: ResolvedValue;
}
interface RejectedPromiseState<ResolvedValue, RejectedValue> {
export interface RejectedPromiseState<ResolvedValue, RejectedValue> {
state: 'rejected';
promise: Promise<ResolvedValue>;
value: RejectedValue;

View file

@ -0,0 +1,36 @@
{
"extends": "../../../tsconfig.base.json",
"compilerOptions": {
"composite": true,
"outDir": "./target/types",
"emitDeclarationOnly": true,
"declaration": true,
"declarationMap": true
},
"include": [
"../../typings/**/*",
"common/**/*",
"public/**/*",
"scripts/**/*",
"server/**/*",
"types/**/*"
],
"references": [
{ "path": "../../../src/core/tsconfig.json" },
{ "path": "../../../src/plugins/data/tsconfig.json" },
{ "path": "../../../src/plugins/embeddable/tsconfig.json" },
{ "path": "../../../src/plugins/home/tsconfig.json" },
{ "path": "../../../src/plugins/kibana_utils/tsconfig.json" },
{ "path": "../../../src/plugins/kibana_react/tsconfig.json" },
{ "path": "../../../src/plugins/usage_collection/tsconfig.json" },
{ "path": "../../../src/plugins/vis_type_timeseries/tsconfig.json" },
{ "path": "../data_enhanced/tsconfig.json" },
{ "path": "../alerts/tsconfig.json" },
{ "path": "../features/tsconfig.json" },
{ "path": "../license_management/tsconfig.json" },
{ "path": "../ml/tsconfig.json" },
{ "path": "../observability/tsconfig.json" },
{ "path": "../spaces/tsconfig.json" },
{ "path": "../triggers_actions_ui/tsconfig.json" }
]
}

View file

@ -9,73 +9,73 @@
"exclude": ["../typings/jest.d.ts"],
"references": [
{ "path": "../../src/core/tsconfig.json" },
{ "path": "../../src/plugins/telemetry_management_section/tsconfig.json" },
{ "path": "../../src/plugins/management/tsconfig.json" },
{ "path": "../../src/plugins/bfetch/tsconfig.json" },
{ "path": "../../src/plugins/charts/tsconfig.json" },
{ "path": "../../src/plugins/console/tsconfig.json" },
{ "path": "../../src/plugins/dashboard/tsconfig.json" },
{ "path": "../../src/plugins/discover/tsconfig.json" },
{ "path": "../../src/plugins/data/tsconfig.json" },
{ "path": "../../src/plugins/discover/tsconfig.json" },
{ "path": "../../src/plugins/embeddable/tsconfig.json" },
{ "path": "../../src/plugins/es_ui_shared/tsconfig.json" },
{ "path": "../../src/plugins/expressions/tsconfig.json" },
{ "path": "../../src/plugins/home/tsconfig.json" },
{ "path": "../../src/plugins/index_pattern_management/tsconfig.json" },
{ "path": "../../src/plugins/kibana_overview/tsconfig.json" },
{ "path": "../../src/plugins/kibana_react/tsconfig.json" },
{ "path": "../../src/plugins/kibana_usage_collection/tsconfig.json" },
{ "path": "../../src/plugins/kibana_utils/tsconfig.json" },
{ "path": "../../src/plugins/legacy_export/tsconfig.json" },
{ "path": "../../src/plugins/management/tsconfig.json" },
{ "path": "../../src/plugins/navigation/tsconfig.json" },
{ "path": "../../src/plugins/newsfeed/tsconfig.json" },
{ "path": "../../src/plugins/saved_objects/tsconfig.json" },
{ "path": "../../src/plugins/saved_objects_management/tsconfig.json" },
{ "path": "../../src/plugins/saved_objects_tagging_oss/tsconfig.json" },
{ "path": "../../src/plugins/saved_objects/tsconfig.json" },
{ "path": "../../src/plugins/share/tsconfig.json" },
{ "path": "../../src/plugins/telemetry_collection_manager/tsconfig.json" },
{ "path": "../../src/plugins/telemetry_management_section/tsconfig.json" },
{ "path": "../../src/plugins/telemetry/tsconfig.json" },
{ "path": "../../src/plugins/usage_collection/tsconfig.json" },
{ "path": "../../src/plugins/ui_actions/tsconfig.json" },
{ "path": "../../src/plugins/url_forwarding/tsconfig.json" },
{ "path": "../../src/plugins/index_pattern_management/tsconfig.json" },
{ "path": "../../src/plugins/usage_collection/tsconfig.json" },
{ "path": "../plugins/actions/tsconfig.json" },
{ "path": "../plugins/alerts/tsconfig.json" },
{ "path": "../plugins/beats_management/tsconfig.json" },
{ "path": "../plugins/cloud/tsconfig.json" },
{ "path": "../plugins/code/tsconfig.json" },
{ "path": "../plugins/console_extensions/tsconfig.json" },
{ "path": "../plugins/data_enhanced/tsconfig.json" },
{ "path": "../plugins/dashboard_mode/tsconfig.json" },
{ "path": "../plugins/enterprise_search/tsconfig.json" },
{ "path": "../plugins/global_search/tsconfig.json" },
{ "path": "../plugins/global_search_providers/tsconfig.json" },
{ "path": "../plugins/features/tsconfig.json" },
{ "path": "../plugins/data_enhanced/tsconfig.json" },
{ "path": "../plugins/embeddable_enhanced/tsconfig.json" },
{ "path": "../plugins/encrypted_saved_objects/tsconfig.json" },
{ "path": "../plugins/enterprise_search/tsconfig.json" },
{ "path": "../plugins/event_log/tsconfig.json" },
{ "path": "../plugins/licensing/tsconfig.json" },
{ "path": "../plugins/features/tsconfig.json" },
{ "path": "../plugins/global_search_bar/tsconfig.json" },
{ "path": "../plugins/global_search_providers/tsconfig.json" },
{ "path": "../plugins/global_search/tsconfig.json" },
{ "path": "../plugins/grokdebugger/tsconfig.json" },
{ "path": "../plugins/index_management/tsconfig.json" },
{ "path": "../plugins/infra/tsconfig.json" },
{ "path": "../plugins/ingest_pipelines/tsconfig.json" },
{ "path": "../plugins/lens/tsconfig.json" },
{ "path": "../plugins/license_management/tsconfig.json" },
{ "path": "../plugins/licensing/tsconfig.json" },
{ "path": "../plugins/ml/tsconfig.json" },
{ "path": "../plugins/observability/tsconfig.json" },
{ "path": "../plugins/painless_lab/tsconfig.json" },
{ "path": "../plugins/runtime_fields/tsconfig.json" },
{ "path": "../plugins/saved_objects_tagging/tsconfig.json" },
{ "path": "../plugins/security/tsconfig.json" },
{ "path": "../plugins/snapshot_restore/tsconfig.json" },
{ "path": "../plugins/spaces/tsconfig.json" },
{ "path": "../plugins/stack_alerts/tsconfig.json" },
{ "path": "../plugins/task_manager/tsconfig.json" },
{ "path": "../plugins/telemetry_collection_xpack/tsconfig.json" },
{ "path": "../plugins/transform/tsconfig.json" },
{ "path": "../plugins/triggers_actions_ui/tsconfig.json" },
{ "path": "../plugins/ui_actions_enhanced/tsconfig.json" },
{ "path": "../plugins/spaces/tsconfig.json" },
{ "path": "../plugins/security/tsconfig.json" },
{ "path": "../plugins/encrypted_saved_objects/tsconfig.json" },
{ "path": "../plugins/stack_alerts/tsconfig.json" },
{ "path": "../plugins/beats_management/tsconfig.json" },
{ "path": "../plugins/cloud/tsconfig.json" },
{ "path": "../plugins/saved_objects_tagging/tsconfig.json" },
{ "path": "../plugins/global_search_bar/tsconfig.json" },
{ "path": "../plugins/observability/tsconfig.json" },
{ "path": "../plugins/ingest_pipelines/tsconfig.json" },
{ "path": "../plugins/license_management/tsconfig.json" },
{ "path": "../plugins/snapshot_restore/tsconfig.json" },
{ "path": "../plugins/grokdebugger/tsconfig.json" },
{ "path": "../plugins/painless_lab/tsconfig.json" },
{ "path": "../plugins/upgrade_assistant/tsconfig.json" },
{ "path": "../plugins/watcher/tsconfig.json" },
{ "path": "../plugins/runtime_fields/tsconfig.json" },
{ "path": "../plugins/index_management/tsconfig.json" }
{ "path": "../plugins/watcher/tsconfig.json" }
]
}

View file

@ -22,6 +22,7 @@
"plugins/embeddable_enhanced/**/*",
"plugins/event_log/**/*",
"plugins/enterprise_search/**/*",
"plugins/infra/**/*",
"plugins/licensing/**/*",
"plugins/lens/**/*",
"plugins/maps/**/*",
@ -118,6 +119,7 @@
{ "path": "./plugins/global_search/tsconfig.json" },
{ "path": "./plugins/graph/tsconfig.json" },
{ "path": "./plugins/grokdebugger/tsconfig.json" },
{ "path": "./plugins/infra/tsconfig.json" },
{ "path": "./plugins/ingest_pipelines/tsconfig.json" },
{ "path": "./plugins/lens/tsconfig.json" },
{ "path": "./plugins/license_management/tsconfig.json" },

View file

@ -23,6 +23,7 @@
{ "path": "./plugins/global_search/tsconfig.json" },
{ "path": "./plugins/graph/tsconfig.json" },
{ "path": "./plugins/grokdebugger/tsconfig.json" },
{ "path": "./plugins/infra/tsconfig.json" },
{ "path": "./plugins/ingest_pipelines/tsconfig.json" },
{ "path": "./plugins/lens/tsconfig.json" },
{ "path": "./plugins/license_management/tsconfig.json" },