Skip to content

Commit

Permalink
Convert map client routing files to TS (#76387)
Browse files Browse the repository at this point in the history
* Converted maps_router and store operations files

* Converted files in map routes to typescript

* Removed an unwanted ts-expect-error

* Fixed the lint errors from jenkins

* Naming changes, type for mapStateJSON etc.

* More type fixes in map routes

* More type fixes in map routes

* Added back some removed props

* Added types to app state manager

* Autogenerated api documentation

* Type fixes

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
  • Loading branch information
shamin and elasticmachine authored Sep 8, 2020
1 parent cb5979a commit 194d0b0
Show file tree
Hide file tree
Showing 30 changed files with 407 additions and 161 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
| [OptionedValueProp](./kibana-plugin-plugins-data-public.optionedvalueprop.md) | |
| [Query](./kibana-plugin-plugins-data-public.query.md) | |
| [QueryState](./kibana-plugin-plugins-data-public.querystate.md) | All query state service state |
| [QueryStateChange](./kibana-plugin-plugins-data-public.querystatechange.md) | |
| [QuerySuggestionBasic](./kibana-plugin-plugins-data-public.querysuggestionbasic.md) | \* |
| [QuerySuggestionField](./kibana-plugin-plugins-data-public.querysuggestionfield.md) | \* |
| [QuerySuggestionGetFnArgs](./kibana-plugin-plugins-data-public.querysuggestiongetfnargs.md) | \* |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) &gt; [QueryStateChange](./kibana-plugin-plugins-data-public.querystatechange.md) &gt; [appFilters](./kibana-plugin-plugins-data-public.querystatechange.appfilters.md)

## QueryStateChange.appFilters property

<b>Signature:</b>

```typescript
appFilters?: boolean;
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) &gt; [QueryStateChange](./kibana-plugin-plugins-data-public.querystatechange.md) &gt; [globalFilters](./kibana-plugin-plugins-data-public.querystatechange.globalfilters.md)

## QueryStateChange.globalFilters property

<b>Signature:</b>

```typescript
globalFilters?: boolean;
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) &gt; [QueryStateChange](./kibana-plugin-plugins-data-public.querystatechange.md)

## QueryStateChange interface

<b>Signature:</b>

```typescript
export interface QueryStateChange extends QueryStateChangePartial
```
## Properties
| Property | Type | Description |
| --- | --- | --- |
| [appFilters](./kibana-plugin-plugins-data-public.querystatechange.appfilters.md) | <code>boolean</code> | |
| [globalFilters](./kibana-plugin-plugins-data-public.querystatechange.globalfilters.md) | <code>boolean</code> | |
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<b>Signature:</b>

```typescript
SearchBar: React.ComponentClass<Pick<Pick<SearchBarProps, "query" | "isLoading" | "filters" | "onRefresh" | "onRefreshChange" | "refreshInterval" | "intl" | "indexPatterns" | "dataTestSubj" | "customSubmitButton" | "screenTitle" | "showQueryBar" | "showQueryInput" | "showFilterBar" | "showDatePicker" | "showAutoRefreshOnly" | "isRefreshPaused" | "dateRangeFrom" | "dateRangeTo" | "showSaveQuery" | "savedQuery" | "onQueryChange" | "onQuerySubmit" | "onSaved" | "onSavedQueryUpdated" | "onClearSavedQuery" | "indicateNoData" | "timeHistory" | "onFiltersUpdated">, "query" | "isLoading" | "filters" | "onRefresh" | "onRefreshChange" | "refreshInterval" | "indexPatterns" | "dataTestSubj" | "customSubmitButton" | "screenTitle" | "showQueryBar" | "showQueryInput" | "showFilterBar" | "showDatePicker" | "showAutoRefreshOnly" | "isRefreshPaused" | "dateRangeFrom" | "dateRangeTo" | "showSaveQuery" | "savedQuery" | "onQueryChange" | "onQuerySubmit" | "onSaved" | "onSavedQueryUpdated" | "onClearSavedQuery" | "indicateNoData" | "timeHistory" | "onFiltersUpdated">, any> & {
WrappedComponent: React.ComponentType<Pick<SearchBarProps, "query" | "isLoading" | "filters" | "onRefresh" | "onRefreshChange" | "refreshInterval" | "intl" | "indexPatterns" | "dataTestSubj" | "customSubmitButton" | "screenTitle" | "showQueryBar" | "showQueryInput" | "showFilterBar" | "showDatePicker" | "showAutoRefreshOnly" | "isRefreshPaused" | "dateRangeFrom" | "dateRangeTo" | "showSaveQuery" | "savedQuery" | "onQueryChange" | "onQuerySubmit" | "onSaved" | "onSavedQueryUpdated" | "onClearSavedQuery" | "indicateNoData" | "timeHistory" | "onFiltersUpdated"> & ReactIntl.InjectedIntlProps>;
SearchBar: React.ComponentClass<Pick<Pick<SearchBarProps, "query" | "isLoading" | "filters" | "onRefresh" | "onRefreshChange" | "refreshInterval" | "intl" | "indexPatterns" | "dataTestSubj" | "timeHistory" | "customSubmitButton" | "screenTitle" | "showQueryBar" | "showQueryInput" | "showFilterBar" | "showDatePicker" | "showAutoRefreshOnly" | "isRefreshPaused" | "dateRangeFrom" | "dateRangeTo" | "showSaveQuery" | "savedQuery" | "onQueryChange" | "onQuerySubmit" | "onSaved" | "onSavedQueryUpdated" | "onClearSavedQuery" | "indicateNoData" | "onFiltersUpdated">, "query" | "isLoading" | "filters" | "onRefresh" | "onRefreshChange" | "refreshInterval" | "indexPatterns" | "dataTestSubj" | "timeHistory" | "customSubmitButton" | "screenTitle" | "showQueryBar" | "showQueryInput" | "showFilterBar" | "showDatePicker" | "showAutoRefreshOnly" | "isRefreshPaused" | "dateRangeFrom" | "dateRangeTo" | "showSaveQuery" | "savedQuery" | "onQueryChange" | "onQuerySubmit" | "onSaved" | "onSavedQueryUpdated" | "onClearSavedQuery" | "indicateNoData" | "onFiltersUpdated">, any> & {
WrappedComponent: React.ComponentType<Pick<SearchBarProps, "query" | "isLoading" | "filters" | "onRefresh" | "onRefreshChange" | "refreshInterval" | "intl" | "indexPatterns" | "dataTestSubj" | "timeHistory" | "customSubmitButton" | "screenTitle" | "showQueryBar" | "showQueryInput" | "showFilterBar" | "showDatePicker" | "showAutoRefreshOnly" | "isRefreshPaused" | "dateRangeFrom" | "dateRangeTo" | "showSaveQuery" | "savedQuery" | "onQueryChange" | "onQuerySubmit" | "onSaved" | "onSavedQueryUpdated" | "onClearSavedQuery" | "indicateNoData" | "onFiltersUpdated"> & ReactIntl.InjectedIntlProps>;
}
```
1 change: 1 addition & 0 deletions src/plugins/data/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@ export {
TimeHistory,
TimefilterContract,
TimeHistoryContract,
QueryStateChange,
} from './query';

export {
Expand Down
15 changes: 13 additions & 2 deletions src/plugins/data/public/public.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1465,6 +1465,17 @@ export interface QueryState {
time?: TimeRange;
}

// Warning: (ae-forgotten-export) The symbol "QueryStateChangePartial" needs to be exported by the entry point index.d.ts
// Warning: (ae-missing-release-tag) "QueryStateChange" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
export interface QueryStateChange extends QueryStateChangePartial {
// (undocumented)
appFilters?: boolean;
// (undocumented)
globalFilters?: boolean;
}

// Warning: (ae-forgotten-export) The symbol "Props" needs to be exported by the entry point index.d.ts
// Warning: (ae-missing-release-tag) "QueryStringInput" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
Expand Down Expand Up @@ -1682,8 +1693,8 @@ export const search: {
// Warning: (ae-missing-release-tag) "SearchBar" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
export const SearchBar: React.ComponentClass<Pick<Pick<SearchBarProps, "query" | "isLoading" | "filters" | "onRefresh" | "onRefreshChange" | "refreshInterval" | "intl" | "indexPatterns" | "dataTestSubj" | "customSubmitButton" | "screenTitle" | "showQueryBar" | "showQueryInput" | "showFilterBar" | "showDatePicker" | "showAutoRefreshOnly" | "isRefreshPaused" | "dateRangeFrom" | "dateRangeTo" | "showSaveQuery" | "savedQuery" | "onQueryChange" | "onQuerySubmit" | "onSaved" | "onSavedQueryUpdated" | "onClearSavedQuery" | "indicateNoData" | "timeHistory" | "onFiltersUpdated">, "query" | "isLoading" | "filters" | "onRefresh" | "onRefreshChange" | "refreshInterval" | "indexPatterns" | "dataTestSubj" | "customSubmitButton" | "screenTitle" | "showQueryBar" | "showQueryInput" | "showFilterBar" | "showDatePicker" | "showAutoRefreshOnly" | "isRefreshPaused" | "dateRangeFrom" | "dateRangeTo" | "showSaveQuery" | "savedQuery" | "onQueryChange" | "onQuerySubmit" | "onSaved" | "onSavedQueryUpdated" | "onClearSavedQuery" | "indicateNoData" | "timeHistory" | "onFiltersUpdated">, any> & {
WrappedComponent: React.ComponentType<Pick<SearchBarProps, "query" | "isLoading" | "filters" | "onRefresh" | "onRefreshChange" | "refreshInterval" | "intl" | "indexPatterns" | "dataTestSubj" | "customSubmitButton" | "screenTitle" | "showQueryBar" | "showQueryInput" | "showFilterBar" | "showDatePicker" | "showAutoRefreshOnly" | "isRefreshPaused" | "dateRangeFrom" | "dateRangeTo" | "showSaveQuery" | "savedQuery" | "onQueryChange" | "onQuerySubmit" | "onSaved" | "onSavedQueryUpdated" | "onClearSavedQuery" | "indicateNoData" | "timeHistory" | "onFiltersUpdated"> & ReactIntl.InjectedIntlProps>;
export const SearchBar: React.ComponentClass<Pick<Pick<SearchBarProps, "query" | "isLoading" | "filters" | "onRefresh" | "onRefreshChange" | "refreshInterval" | "intl" | "indexPatterns" | "dataTestSubj" | "timeHistory" | "customSubmitButton" | "screenTitle" | "showQueryBar" | "showQueryInput" | "showFilterBar" | "showDatePicker" | "showAutoRefreshOnly" | "isRefreshPaused" | "dateRangeFrom" | "dateRangeTo" | "showSaveQuery" | "savedQuery" | "onQueryChange" | "onQuerySubmit" | "onSaved" | "onSavedQueryUpdated" | "onClearSavedQuery" | "indicateNoData" | "onFiltersUpdated">, "query" | "isLoading" | "filters" | "onRefresh" | "onRefreshChange" | "refreshInterval" | "indexPatterns" | "dataTestSubj" | "timeHistory" | "customSubmitButton" | "screenTitle" | "showQueryBar" | "showQueryInput" | "showFilterBar" | "showDatePicker" | "showAutoRefreshOnly" | "isRefreshPaused" | "dateRangeFrom" | "dateRangeTo" | "showSaveQuery" | "savedQuery" | "onQueryChange" | "onQuerySubmit" | "onSaved" | "onSavedQueryUpdated" | "onClearSavedQuery" | "indicateNoData" | "onFiltersUpdated">, any> & {
WrappedComponent: React.ComponentType<Pick<SearchBarProps, "query" | "isLoading" | "filters" | "onRefresh" | "onRefreshChange" | "refreshInterval" | "intl" | "indexPatterns" | "dataTestSubj" | "timeHistory" | "customSubmitButton" | "screenTitle" | "showQueryBar" | "showQueryInput" | "showFilterBar" | "showDatePicker" | "showAutoRefreshOnly" | "isRefreshPaused" | "dateRangeFrom" | "dateRangeTo" | "showSaveQuery" | "savedQuery" | "onQueryChange" | "onQuerySubmit" | "onSaved" | "onSavedQueryUpdated" | "onClearSavedQuery" | "indicateNoData" | "onFiltersUpdated"> & ReactIntl.InjectedIntlProps>;
};

// Warning: (ae-forgotten-export) The symbol "SearchBarOwnProps" needs to be exported by the entry point index.d.ts
Expand Down
65 changes: 35 additions & 30 deletions src/plugins/navigation/public/top_nav_menu/top_nav_menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,39 +23,44 @@ import classNames from 'classnames';

import { MountPoint } from '../../../../core/public';
import { MountPointPortal } from '../../../kibana_react/public';
import { StatefulSearchBarProps, DataPublicPluginStart } from '../../../data/public';
import {
StatefulSearchBarProps,
DataPublicPluginStart,
SearchBarProps,
} from '../../../data/public';
import { TopNavMenuData } from './top_nav_menu_data';
import { TopNavMenuItem } from './top_nav_menu_item';

export type TopNavMenuProps = StatefulSearchBarProps & {
config?: TopNavMenuData[];
showSearchBar?: boolean;
showQueryBar?: boolean;
showQueryInput?: boolean;
showDatePicker?: boolean;
showFilterBar?: boolean;
data?: DataPublicPluginStart;
className?: string;
/**
* If provided, the menu part of the component will be rendered as a portal inside the given mount point.
*
* This is meant to be used with the `setHeaderActionMenu` core API.
*
* @example
* ```ts
* export renderApp = ({ element, history, setHeaderActionMenu }: AppMountParameters) => {
* const topNavConfig = ...; // TopNavMenuProps
* return (
* <Router history=history>
* <TopNavMenu {...topNavConfig} setMenuMountPoint={setHeaderActionMenu}>
* <MyRoutes />
* </Router>
* )
* }
* ```
*/
setMenuMountPoint?: (menuMount: MountPoint | undefined) => void;
};
export type TopNavMenuProps = StatefulSearchBarProps &
Omit<SearchBarProps, 'kibana' | 'intl' | 'timeHistory'> & {
config?: TopNavMenuData[];
showSearchBar?: boolean;
showQueryBar?: boolean;
showQueryInput?: boolean;
showDatePicker?: boolean;
showFilterBar?: boolean;
data?: DataPublicPluginStart;
className?: string;
/**
* If provided, the menu part of the component will be rendered as a portal inside the given mount point.
*
* This is meant to be used with the `setHeaderActionMenu` core API.
*
* @example
* ```ts
* export renderApp = ({ element, history, setHeaderActionMenu }: AppMountParameters) => {
* const topNavConfig = ...; // TopNavMenuProps
* return (
* <Router history=history>
* <TopNavMenu {...topNavConfig} setMenuMountPoint={setHeaderActionMenu}>
* <MyRoutes />
* </Router>
* )
* }
* ```
*/
setMenuMountPoint?: (menuMount: MountPoint | undefined) => void;
};

/*
* Top Nav Menu is a convenience wrapper component for:
Expand Down
6 changes: 2 additions & 4 deletions x-pack/plugins/maps/public/lazy_load_bundle/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { AnyAction } from 'redux';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { IndexPatternsContract } from 'src/plugins/data/public/index_patterns';
import { ReactElement } from 'react';
import { AppMountContext, AppMountParameters } from 'kibana/public';
import { IndexPattern } from 'src/plugins/data/public';
import { Embeddable, IContainer } from '../../../../../src/plugins/embeddable/public';
import { LayerDescriptor } from '../../common/descriptor_types';
Expand Down Expand Up @@ -40,7 +40,7 @@ interface LazyLoadedMapModules {
initialLayers?: LayerDescriptor[]
) => LayerDescriptor[];
mergeInputWithSavedMap: any;
renderApp: (context: unknown, params: unknown) => ReactElement<any>;
renderApp: (context: AppMountContext, params: AppMountParameters) => Promise<() => void>;
createSecurityLayerDescriptors: (
indexPatternId: string,
indexPatternTitle: string
Expand All @@ -57,7 +57,6 @@ export async function lazyLoadMapModules(): Promise<LazyLoadedMapModules> {

loadModulesPromise = new Promise(async (resolve) => {
const {
// @ts-expect-error
getMapsSavedObjectLoader,
getQueryableUniqueIndexPatternIds,
MapEmbeddable,
Expand All @@ -68,7 +67,6 @@ export async function lazyLoadMapModules(): Promise<LazyLoadedMapModules> {
addLayerWithoutDataSync,
getInitialLayers,
mergeInputWithSavedMap,
// @ts-expect-error
renderApp,
createSecurityLayerDescriptors,
registerLayerWizard,
Expand Down
2 changes: 0 additions & 2 deletions x-pack/plugins/maps/public/lazy_load_bundle/lazy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
// These are map-dependencies of the embeddable.
// By lazy-loading these, the Maps-app can register the embeddable when the plugin mounts, without actually pulling all the code.

// @ts-expect-error
export * from '../../routing/bootstrap/services/gis_map_saved_object_loader';
export * from '../../embeddable/map_embeddable';
export * from '../../kibana_services';
Expand All @@ -16,7 +15,6 @@ export * from '../../actions';
export * from '../../selectors/map_selectors';
export * from '../../routing/bootstrap/get_initial_layers';
export * from '../../embeddable/merge_input_with_saved_map';
// @ts-expect-error
export * from '../../routing/maps_router';
export * from '../../classes/layers/solution_layers/security';
export { registerLayerWizard } from '../../classes/layers/layer_wizard_registry';
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/maps/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ export class MapsPlugin
icon: `plugins/${APP_ID}/icon.svg`,
euiIconType: APP_ICON,
category: DEFAULT_APP_CATEGORIES.kibana,
// @ts-expect-error
async mount(context, params) {
const { renderApp } = await lazyLoadMapModules();
return renderApp(context, params);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,19 @@ import '../../classes/sources/es_pew_pew_source';
import '../../classes/sources/kibana_regionmap_source';
import '../../classes/sources/es_geo_grid_source';
import '../../classes/sources/xyz_tms_source';
import { LayerDescriptor } from '../../../common/descriptor_types';
// @ts-expect-error
import { KibanaTilemapSource } from '../../classes/sources/kibana_tilemap_source';
import { TileLayer } from '../../classes/layers/tile_layer/tile_layer';
// @ts-expect-error
import { EMSTMSSource } from '../../classes/sources/ems_tms_source';
// @ts-expect-error
import { VectorTileLayer } from '../../classes/layers/vector_tile_layer/vector_tile_layer';
import { getIsEmsEnabled, getToasts } from '../../kibana_services';
import { INITIAL_LAYERS_KEY } from '../../../common/constants';
import { getKibanaTileMap } from '../../meta';

export function getInitialLayers(layerListJSON, initialLayers = []) {
export function getInitialLayers(layerListJSON?: string, initialLayers: LayerDescriptor[] = []) {
if (layerListJSON) {
return JSON.parse(layerListJSON);
}
Expand Down Expand Up @@ -58,9 +62,10 @@ export function getInitialLayersFromUrlParam() {

try {
let mapInitLayers = mapAppParams.get(INITIAL_LAYERS_KEY);
if (mapInitLayers[mapInitLayers.length - 1] === '#') {
mapInitLayers = mapInitLayers.substr(0, mapInitLayers.length - 1);
if (mapInitLayers![mapInitLayers!.length - 1] === '#') {
mapInitLayers = mapInitLayers!.substr(0, mapInitLayers!.length - 1);
}
// @ts-ignore
return rison.decode_array(mapInitLayers);
} catch (e) {
getToasts().addWarning({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,15 @@
*/

import { getData } from '../../kibana_services';
import { MapsAppState } from '../state_syncing/app_state_manager';

export function getInitialQuery({ mapStateJSON, appState = {} }) {
export function getInitialQuery({
mapStateJSON,
appState = {},
}: {
mapStateJSON?: string;
appState: MapsAppState;
}) {
if (appState.query) {
return appState.query;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,17 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { QueryState } from 'src/plugins/data/public';
import { getUiSettings } from '../../kibana_services';
import { UI_SETTINGS } from '../../../../../../src/plugins/data/public';

export function getInitialRefreshConfig({ mapStateJSON, globalState = {} }) {
export function getInitialRefreshConfig({
mapStateJSON,
globalState = {},
}: {
mapStateJSON?: string;
globalState: QueryState;
}) {
const uiSettings = getUiSettings();

if (mapStateJSON) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,16 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { QueryState } from 'src/plugins/data/public';
import { getUiSettings } from '../../kibana_services';

export function getInitialTimeFilters({ mapStateJSON, globalState }) {
export function getInitialTimeFilters({
mapStateJSON,
globalState,
}: {
mapStateJSON?: string;
globalState: QueryState;
}) {
if (mapStateJSON) {
const mapState = JSON.parse(mapStateJSON);
if (mapState.timeFilters) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import { copyPersistentState } from '../../../reducers/util';
// @ts-expect-error
import { extractReferences, injectReferences } from '../../../../common/migrations/references';
import { getExistingMapPath, MAP_SAVED_OBJECT_TYPE } from '../../../../common/constants';
// @ts-expect-error
import { getStore } from '../../store_operations';
import { MapStoreState } from '../../../reducers/store';
import { LayerDescriptor } from '../../../../common/descriptor_types';
Expand Down
Loading

0 comments on commit 194d0b0

Please sign in to comment.