From f1ecc97ffb5dc6cef276f78450ab1ad8c2d95e4d Mon Sep 17 00:00:00 2001 From: Shamin Date: Tue, 1 Sep 2020 18:55:14 +0530 Subject: [PATCH 01/11] Converted maps_router and store operations files --- .../{maps_router.js => maps_router.tsx} | 22 +++++++++++++------ ...tore_operations.js => store_operations.ts} | 0 2 files changed, 15 insertions(+), 7 deletions(-) rename x-pack/plugins/maps/public/routing/{maps_router.js => maps_router.tsx} (81%) rename x-pack/plugins/maps/public/routing/{store_operations.js => store_operations.ts} (100%) diff --git a/x-pack/plugins/maps/public/routing/maps_router.js b/x-pack/plugins/maps/public/routing/maps_router.tsx similarity index 81% rename from x-pack/plugins/maps/public/routing/maps_router.js rename to x-pack/plugins/maps/public/routing/maps_router.tsx index f0f5234e3f989..3112b06916156 100644 --- a/x-pack/plugins/maps/public/routing/maps_router.js +++ b/x-pack/plugins/maps/public/routing/maps_router.tsx @@ -6,7 +6,7 @@ import React from 'react'; import { render, unmountComponentAtNode } from 'react-dom'; -import { Router, Switch, Route, Redirect } from 'react-router-dom'; +import { Router, Switch, Route, Redirect, RouteComponentProps } from 'react-router-dom'; import { i18n } from '@kbn/i18n'; import { getCoreChrome, @@ -18,16 +18,18 @@ import { import { createKbnUrlStateStorage, withNotifyOnErrors, + IKbnUrlStateStorage, } from '../../../../../src/plugins/kibana_utils/public'; import { getStore } from './store_operations'; import { Provider } from 'react-redux'; import { LoadListAndRender } from './routes/list/load_list_and_render'; import { LoadMapAndRender } from './routes/maps_app/load_map_and_render'; +import { AppMountContext, AppMountParameters } from 'kibana/public'; -export let goToSpecifiedPath; -export let kbnUrlStateStorage; +export let goToSpecifiedPath: (path: string) => void; +export let kbnUrlStateStorage: IKbnUrlStateStorage; -export async function renderApp(context, { appBasePath, element, history, onAppLeave }) { +export async function renderApp(context: AppMountContext, { appBasePath, element, history, onAppLeave }: AppMountParameters) { goToSpecifiedPath = (path) => history.push(path); kbnUrlStateStorage = createKbnUrlStateStorage({ useHash: false, @@ -42,11 +44,17 @@ export async function renderApp(context, { appBasePath, element, history, onAppL }; } -const App = ({ history, appBasePath, onAppLeave }) => { +interface AppProps { + history: AppMountParameters['history'] | RouteComponentProps['history']; + appBasePath: AppMountParameters['appBasePath']; + onAppLeave: AppMountParameters['onAppLeave']; +} + +const App: React.FC = ({ history, appBasePath, onAppLeave }) => { const store = getStore(); const I18nContext = getCoreI18n().Context; - const stateTransfer = getEmbeddableService()?.getStateTransfer(history); + const stateTransfer = getEmbeddableService()?.getStateTransfer(history as AppMountParameters['history']); const { originatingApp } = stateTransfer?.getIncomingEditorState({ keysToRemoveAfterFetch: ['originatingApp'] }) || {}; @@ -66,7 +74,7 @@ const App = ({ history, appBasePath, onAppLeave }) => { return ( - + Date: Tue, 1 Sep 2020 20:11:40 +0530 Subject: [PATCH 02/11] Converted files in map routes to typescript --- .../map_container/map_container.tsx | 2 +- .../routing/bootstrap/get_initial_layers.d.ts | 12 -- ...nitial_layers.js => get_initial_layers.ts} | 12 +- ..._initial_query.js => get_initial_query.ts} | 0 ...onfig.js => get_initial_refresh_config.ts} | 6 +- ...filters.js => get_initial_time_filters.ts} | 0 ...ader.js => gis_map_saved_object_loader.ts} | 0 .../bootstrap/services/saved_gis_map.ts | 1 - ...and_render.js => load_list_and_render.tsx} | 1 + .../{maps_list_view.js => maps_list_view.tsx} | 84 ++++++++---- .../routes/maps_app/get_breadcrumbs.tsx | 3 +- .../routes/maps_app/{index.js => index.ts} | 35 +++-- ..._and_render.js => load_map_and_render.tsx} | 12 +- .../{maps_app_view.js => maps_app_view.tsx} | 122 +++++++++++++++--- .../routes/maps_app/top_nav_config.tsx | 1 - ..._state_manager.js => app_state_manager.ts} | 13 +- .../{app_sync.js => app_sync.ts} | 8 +- .../routing/state_syncing/global_sync.ts | 11 +- 18 files changed, 233 insertions(+), 90 deletions(-) delete mode 100644 x-pack/plugins/maps/public/routing/bootstrap/get_initial_layers.d.ts rename x-pack/plugins/maps/public/routing/bootstrap/{get_initial_layers.js => get_initial_layers.ts} (86%) rename x-pack/plugins/maps/public/routing/bootstrap/{get_initial_query.js => get_initial_query.ts} (100%) rename x-pack/plugins/maps/public/routing/bootstrap/{get_initial_refresh_config.js => get_initial_refresh_config.ts} (88%) rename x-pack/plugins/maps/public/routing/bootstrap/{get_initial_time_filters.js => get_initial_time_filters.ts} (100%) rename x-pack/plugins/maps/public/routing/bootstrap/services/{gis_map_saved_object_loader.js => gis_map_saved_object_loader.ts} (100%) rename x-pack/plugins/maps/public/routing/routes/list/{load_list_and_render.js => load_list_and_render.tsx} (98%) rename x-pack/plugins/maps/public/routing/routes/list/{maps_list_view.js => maps_list_view.tsx} (87%) rename x-pack/plugins/maps/public/routing/routes/maps_app/{index.js => index.ts} (64%) rename x-pack/plugins/maps/public/routing/routes/maps_app/{load_map_and_render.js => load_map_and_render.tsx} (81%) rename x-pack/plugins/maps/public/routing/routes/maps_app/{maps_app_view.js => maps_app_view.tsx} (76%) rename x-pack/plugins/maps/public/routing/state_syncing/{app_state_manager.js => app_state_manager.ts} (72%) rename x-pack/plugins/maps/public/routing/state_syncing/{app_sync.js => app_sync.ts} (88%) diff --git a/x-pack/plugins/maps/public/connected_components/map_container/map_container.tsx b/x-pack/plugins/maps/public/connected_components/map_container/map_container.tsx index bf75c86ac249d..fe00e3704493e 100644 --- a/x-pack/plugins/maps/public/connected_components/map_container/map_container.tsx +++ b/x-pack/plugins/maps/public/connected_components/map_container/map_container.tsx @@ -36,7 +36,7 @@ import 'mapbox-gl/dist/mapbox-gl.css'; const RENDER_COMPLETE_EVENT = 'renderComplete'; interface Props { - addFilters: ((filters: Filter[]) => Promise) | null; + addFilters: ((filters: Filter[]) => void) | null; getFilterActions?: () => Promise; getActionContext?: () => ActionExecutionContext; areLayersLoaded: boolean; diff --git a/x-pack/plugins/maps/public/routing/bootstrap/get_initial_layers.d.ts b/x-pack/plugins/maps/public/routing/bootstrap/get_initial_layers.d.ts deleted file mode 100644 index a23e715a08295..0000000000000 --- a/x-pack/plugins/maps/public/routing/bootstrap/get_initial_layers.d.ts +++ /dev/null @@ -1,12 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import { LayerDescriptor } from '../../../common/descriptor_types'; - -export function getInitialLayers( - layerListJSON?: string, - initialLayers?: LayerDescriptor[] -): LayerDescriptor[]; diff --git a/x-pack/plugins/maps/public/routing/bootstrap/get_initial_layers.js b/x-pack/plugins/maps/public/routing/bootstrap/get_initial_layers.ts similarity index 86% rename from x-pack/plugins/maps/public/routing/bootstrap/get_initial_layers.js rename to x-pack/plugins/maps/public/routing/bootstrap/get_initial_layers.ts index b47f83d5a6664..75c48c55da03b 100644 --- a/x-pack/plugins/maps/public/routing/bootstrap/get_initial_layers.js +++ b/x-pack/plugins/maps/public/routing/bootstrap/get_initial_layers.ts @@ -15,15 +15,20 @@ 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'; +// @ts-expect-error import { KibanaTilemapSource } from '../../classes/sources/kibana_tilemap_source'; +// @ts-expect-error 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'; +import { LayerDescriptor } from 'x-pack/plugins/maps/common/descriptor_types'; -export function getInitialLayers(layerListJSON, initialLayers = []) { +export function getInitialLayers(layerListJSON?: string, initialLayers: LayerDescriptor[] = []) { if (layerListJSON) { return JSON.parse(layerListJSON); } @@ -58,9 +63,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({ diff --git a/x-pack/plugins/maps/public/routing/bootstrap/get_initial_query.js b/x-pack/plugins/maps/public/routing/bootstrap/get_initial_query.ts similarity index 100% rename from x-pack/plugins/maps/public/routing/bootstrap/get_initial_query.js rename to x-pack/plugins/maps/public/routing/bootstrap/get_initial_query.ts diff --git a/x-pack/plugins/maps/public/routing/bootstrap/get_initial_refresh_config.js b/x-pack/plugins/maps/public/routing/bootstrap/get_initial_refresh_config.ts similarity index 88% rename from x-pack/plugins/maps/public/routing/bootstrap/get_initial_refresh_config.js rename to x-pack/plugins/maps/public/routing/bootstrap/get_initial_refresh_config.ts index d7b3bbf5b4ab2..a7934de334df2 100644 --- a/x-pack/plugins/maps/public/routing/bootstrap/get_initial_refresh_config.js +++ b/x-pack/plugins/maps/public/routing/bootstrap/get_initial_refresh_config.ts @@ -6,8 +6,12 @@ import { getUiSettings } from '../../kibana_services'; import { UI_SETTINGS } from '../../../../../../src/plugins/data/public'; +import { QueryState } from 'src/plugins/data/public'; -export function getInitialRefreshConfig({ mapStateJSON, globalState = {} }) { +export function getInitialRefreshConfig({ mapStateJSON, globalState = {} }: { + mapStateJSON: any; + globalState: QueryState; +}) { const uiSettings = getUiSettings(); if (mapStateJSON) { diff --git a/x-pack/plugins/maps/public/routing/bootstrap/get_initial_time_filters.js b/x-pack/plugins/maps/public/routing/bootstrap/get_initial_time_filters.ts similarity index 100% rename from x-pack/plugins/maps/public/routing/bootstrap/get_initial_time_filters.js rename to x-pack/plugins/maps/public/routing/bootstrap/get_initial_time_filters.ts diff --git a/x-pack/plugins/maps/public/routing/bootstrap/services/gis_map_saved_object_loader.js b/x-pack/plugins/maps/public/routing/bootstrap/services/gis_map_saved_object_loader.ts similarity index 100% rename from x-pack/plugins/maps/public/routing/bootstrap/services/gis_map_saved_object_loader.js rename to x-pack/plugins/maps/public/routing/bootstrap/services/gis_map_saved_object_loader.ts diff --git a/x-pack/plugins/maps/public/routing/bootstrap/services/saved_gis_map.ts b/x-pack/plugins/maps/public/routing/bootstrap/services/saved_gis_map.ts index 6f8e7777f671b..511f015b0ff80 100644 --- a/x-pack/plugins/maps/public/routing/bootstrap/services/saved_gis_map.ts +++ b/x-pack/plugins/maps/public/routing/bootstrap/services/saved_gis_map.ts @@ -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'; diff --git a/x-pack/plugins/maps/public/routing/routes/list/load_list_and_render.js b/x-pack/plugins/maps/public/routing/routes/list/load_list_and_render.tsx similarity index 98% rename from x-pack/plugins/maps/public/routing/routes/list/load_list_and_render.js rename to x-pack/plugins/maps/public/routing/routes/list/load_list_and_render.tsx index ee1307956071a..d831a78edb42f 100644 --- a/x-pack/plugins/maps/public/routing/routes/list/load_list_and_render.js +++ b/x-pack/plugins/maps/public/routing/routes/list/load_list_and_render.tsx @@ -12,6 +12,7 @@ import { MapsListView } from './maps_list_view'; import { Redirect } from 'react-router-dom'; export class LoadListAndRender extends React.Component { + _isMounted?: boolean; state = { mapsLoaded: false, hasSavedMaps: null, diff --git a/x-pack/plugins/maps/public/routing/routes/list/maps_list_view.js b/x-pack/plugins/maps/public/routing/routes/list/maps_list_view.tsx similarity index 87% rename from x-pack/plugins/maps/public/routing/routes/list/maps_list_view.js rename to x-pack/plugins/maps/public/routing/routes/list/maps_list_view.tsx index 8fe6866cd7834..72c1721b5b032 100644 --- a/x-pack/plugins/maps/public/routing/routes/list/maps_list_view.js +++ b/x-pack/plugins/maps/public/routing/routes/list/maps_list_view.tsx @@ -4,16 +4,8 @@ * you may not use this file except in compliance with the Elastic License. */ -import React from 'react'; +import React, { MouseEvent } from 'react'; import _ from 'lodash'; -import { getMapsSavedObjectLoader } from '../../bootstrap/services/gis_map_saved_object_loader'; -import { - getMapsCapabilities, - getUiSettings, - getToasts, - getCoreChrome, - getNavigateToApp, -} from '../../../kibana_services'; import { EuiTitle, EuiFieldSearch, @@ -32,10 +24,26 @@ import { } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n/react'; +import { Direction } from '@elastic/eui'; +import { + Criteria, + CriteriaWithPagination, + EuiBasicTableColumn, +} from '@elastic/eui/src/components/basic_table/basic_table'; +import { EuiTableSortingType } from '@elastic/eui'; import { addHelpMenuToAppChrome } from '../../../help_menu_util'; import { goToSpecifiedPath } from '../../maps_router'; import { APP_ID, MAP_PATH } from '../../../../common/constants'; +import { + getMapsCapabilities, + getUiSettings, + getToasts, + getCoreChrome, + getNavigateToApp, +} from '../../../kibana_services'; +import { getMapsSavedObjectLoader } from '../../bootstrap/services/gis_map_saved_object_loader'; + export const EMPTY_FILTER = ''; function navigateToNewMap() { @@ -44,9 +52,30 @@ function navigateToNewMap() { path: MAP_PATH, }); } +interface MapsListViewState { + sortField?: string | number | symbol; + sortDirection?: Direction; + hasInitialFetchReturned: boolean; + isFetchingItems: boolean; + showDeleteModal: boolean; + showLimitError: boolean; + filter: string; + items: []; + selectedIds: []; + page: number; + perPage: number; + readOnly: any; + listingLimit: any; + totalItems?: number; +} + +interface SelectionItem { + id: string; +} export class MapsListView extends React.Component { - state = { + _isMounted?: boolean; + state: MapsListViewState = { hasInitialFetchReturned: false, isFetchingItems: false, showDeleteModal: false, @@ -76,9 +105,9 @@ export class MapsListView extends React.Component { getCoreChrome().docTitle.change('Maps'); } - _find = (search) => getMapsSavedObjectLoader().find(search, this.state.listingLimit); + _find = (search: string) => getMapsSavedObjectLoader().find(search, this.state.listingLimit); - _delete = (ids) => getMapsSavedObjectLoader().delete(ids); + _delete = (ids: string | string[]) => getMapsSavedObjectLoader().delete(ids); debouncedFetch = _.debounce(async (filter) => { const response = await this._find(filter); @@ -135,10 +164,13 @@ export class MapsListView extends React.Component { this.setState({ showDeleteModal: true }); }; - onTableChange = ({ page, sort = {} }) => { - const { index: pageIndex, size: pageSize } = page; + onTableChange = ({ + page, + sort, + }: Criteria | CriteriaWithPagination) => { + const { index: pageIndex, size: pageSize } = page!; - let { field: sortField, direction: sortDirection } = sort; + let { field: sortField, direction: sortDirection } = sort || {}; // 3rd sorting state that is not captured by sort - native order (no sort) // when switching from desc to asc for the same field - use native order @@ -147,8 +179,8 @@ export class MapsListView extends React.Component { this.state.sortDirection === 'desc' && sortDirection === 'asc' ) { - sortField = null; - sortDirection = null; + sortField = undefined; + sortDirection = undefined; } this.setState({ @@ -165,8 +197,8 @@ export class MapsListView extends React.Component { if (this.state.sortField) { itemsCopy.sort((a, b) => { - const fieldA = _.get(a, this.state.sortField, ''); - const fieldB = _.get(b, this.state.sortField, ''); + const fieldA = _.get(a, this.state.sortField!, ''); + const fieldB = _.get(b, this.state.sortField!, ''); let order = 1; if (this.state.sortDirection === 'desc') { order = -1; @@ -320,7 +352,7 @@ export class MapsListView extends React.Component { } renderTable() { - const tableColumns = [ + const tableColumns: Array> = [ { field: 'title', name: i18n.translate('xpack.maps.mapListing.titleFieldTitle', { @@ -329,7 +361,7 @@ export class MapsListView extends React.Component { sortable: true, render: (field, record) => ( { + onClick={(e: MouseEvent) => { e.preventDefault(); goToSpecifiedPath(`/map/${record.id}`); }} @@ -355,12 +387,12 @@ export class MapsListView extends React.Component { pageSizeOptions: [10, 20, 50], }; - let selection = false; + let selection; if (!this.state.readOnly) { selection = { - onSelectionChange: (selection) => { + onSelectionChange: (s: SelectionItem[]) => { this.setState({ - selectedIds: selection.map((item) => { + selectedIds: s.map((item) => { return item.id; }), }); @@ -368,11 +400,11 @@ export class MapsListView extends React.Component { }; } - const sorting = {}; + const sorting: EuiTableSortingType = {}; if (this.state.sortField) { sorting.sort = { field: this.state.sortField, - direction: this.state.sortDirection, + direction: this.state.sortDirection!, }; } const items = this.state.items.length === 0 ? [] : this.getPageOfItems(); diff --git a/x-pack/plugins/maps/public/routing/routes/maps_app/get_breadcrumbs.tsx b/x-pack/plugins/maps/public/routing/routes/maps_app/get_breadcrumbs.tsx index 1ccf890597edc..149c04b414c18 100644 --- a/x-pack/plugins/maps/public/routing/routes/maps_app/get_breadcrumbs.tsx +++ b/x-pack/plugins/maps/public/routing/routes/maps_app/get_breadcrumbs.tsx @@ -6,7 +6,6 @@ import { i18n } from '@kbn/i18n'; import { getNavigateToApp } from '../../../kibana_services'; -// @ts-expect-error import { goToSpecifiedPath } from '../../maps_router'; export const unsavedChangesWarning = i18n.translate( @@ -25,7 +24,7 @@ export function getBreadcrumbs({ title: string; getHasUnsavedChanges: () => boolean; originatingApp?: string; - getAppNameFromId?: (id: string) => string; + getAppNameFromId?: (id: string) => string | undefined; }) { const breadcrumbs = []; if (originatingApp && getAppNameFromId) { diff --git a/x-pack/plugins/maps/public/routing/routes/maps_app/index.js b/x-pack/plugins/maps/public/routing/routes/maps_app/index.ts similarity index 64% rename from x-pack/plugins/maps/public/routing/routes/maps_app/index.js rename to x-pack/plugins/maps/public/routing/routes/maps_app/index.ts index 326db7289e60d..05ac2600f5957 100644 --- a/x-pack/plugins/maps/public/routing/routes/maps_app/index.js +++ b/x-pack/plugins/maps/public/routing/routes/maps_app/index.ts @@ -33,8 +33,17 @@ import { import { FLYOUT_STATE } from '../../../reducers/ui'; import { getMapsCapabilities } from '../../../kibana_services'; import { getInspectorAdapters } from '../../../reducers/non_serializable_instances'; +import { MapStoreState } from '../../../reducers/store'; +import { ThunkDispatch } from 'redux-thunk'; +import { Filter, Query, TimeRange } from 'src/plugins/data/public'; +import { + MapRefreshConfig, + MapCenterAndZoom, + LayerDescriptor, +} from 'x-pack/plugins/maps/common/descriptor_types'; +import { MapSettings } from '../../../reducers/map'; -function mapStateToProps(state = {}) { +function mapStateToProps(state: MapStoreState) { return { isFullScreen: getIsFullScreen(state), isOpenSettingsDisabled: getFlyoutDisplay(state) !== FLYOUT_STATE.NONE, @@ -50,9 +59,16 @@ function mapStateToProps(state = {}) { }; } -function mapDispatchToProps(dispatch) { +interface DispatchSetQueryArgs { + filters?: Filter[]; + query?: Query; + timeFilters?: TimeRange; + forceRefresh?: boolean; +} + +function mapDispatchToProps(dispatch: ThunkDispatch, MapStoreState, any>) { return { - dispatchSetQuery: ({ forceRefresh, filters, query, timeFilters }) => { + dispatchSetQuery: ({ forceRefresh, filters, query, timeFilters }: DispatchSetQueryArgs) => { dispatch( setQuery({ filters, @@ -62,12 +78,13 @@ function mapDispatchToProps(dispatch) { }) ); }, - setRefreshConfig: (refreshConfig) => dispatch(setRefreshConfig(refreshConfig)), - replaceLayerList: (layerList) => dispatch(replaceLayerList(layerList)), - setGotoWithCenter: (latLonZoom) => dispatch(setGotoWithCenter(latLonZoom)), - setMapSettings: (mapSettings) => dispatch(setMapSettings(mapSettings)), - setIsLayerTOCOpen: (isLayerTOCOpen) => dispatch(setIsLayerTOCOpen(isLayerTOCOpen)), - setOpenTOCDetails: (openTOCDetails) => dispatch(setOpenTOCDetails(openTOCDetails)), + setRefreshConfig: (refreshConfig: MapRefreshConfig) => + dispatch(setRefreshConfig(refreshConfig)), + replaceLayerList: (layerList: LayerDescriptor[]) => dispatch(replaceLayerList(layerList)), + setGotoWithCenter: (latLonZoom: MapCenterAndZoom) => dispatch(setGotoWithCenter(latLonZoom)), + setMapSettings: (mapSettings: MapSettings) => dispatch(setMapSettings(mapSettings)), + setIsLayerTOCOpen: (isLayerTOCOpen: boolean) => dispatch(setIsLayerTOCOpen(isLayerTOCOpen)), + setOpenTOCDetails: (openTOCDetails: string[]) => dispatch(setOpenTOCDetails(openTOCDetails)), clearUi: () => { dispatch(setSelectedLayer(null)); dispatch(updateFlyout(FLYOUT_STATE.NONE)); diff --git a/x-pack/plugins/maps/public/routing/routes/maps_app/load_map_and_render.js b/x-pack/plugins/maps/public/routing/routes/maps_app/load_map_and_render.tsx similarity index 81% rename from x-pack/plugins/maps/public/routing/routes/maps_app/load_map_and_render.js rename to x-pack/plugins/maps/public/routing/routes/maps_app/load_map_and_render.tsx index eebbb17582821..41be93490c31b 100644 --- a/x-pack/plugins/maps/public/routing/routes/maps_app/load_map_and_render.js +++ b/x-pack/plugins/maps/public/routing/routes/maps_app/load_map_and_render.tsx @@ -10,8 +10,18 @@ import { getMapsSavedObjectLoader } from '../../bootstrap/services/gis_map_saved import { getCoreChrome, getToasts } from '../../../kibana_services'; import { i18n } from '@kbn/i18n'; import { Redirect } from 'react-router-dom'; +import { AppMountParameters } from 'kibana/public'; +import { EmbeddableStateTransfer } from 'src/plugins/embeddable/public'; -export const LoadMapAndRender = class extends React.Component { +interface LoadMapAndRenderProps { + savedMapId?: Record; + onAppLeave: AppMountParameters['onAppLeave']; + stateTransfer: EmbeddableStateTransfer; + originatingApp?: string; +} + +export const LoadMapAndRender = class extends React.Component { + _isMounted!: boolean; state = { savedMap: null, failedToLoad: false, diff --git a/x-pack/plugins/maps/public/routing/routes/maps_app/maps_app_view.js b/x-pack/plugins/maps/public/routing/routes/maps_app/maps_app_view.tsx similarity index 76% rename from x-pack/plugins/maps/public/routing/routes/maps_app/maps_app_view.js rename to x-pack/plugins/maps/public/routing/routes/maps_app/maps_app_view.tsx index 485b0ed7682fa..21277b1584e8e 100644 --- a/x-pack/plugins/maps/public/routing/routes/maps_app/maps_app_view.js +++ b/x-pack/plugins/maps/public/routing/routes/maps_app/maps_app_view.tsx @@ -26,20 +26,84 @@ import { } from '../../state_syncing/global_sync'; import { AppStateManager } from '../../state_syncing/app_state_manager'; import { startAppStateSyncing } from '../../state_syncing/app_sync'; -import { esFilters } from '../../../../../../../src/plugins/data/public'; +import { + esFilters, + Filter, + Query, + TimeRange, + IndexPattern, + SavedQuery, +} from '../../../../../../../src/plugins/data/public'; import { MapContainer } from '../../../connected_components/map_container'; import { getIndexPatternsFromIds } from '../../../index_pattern_util'; import { getTopNavConfig } from './top_nav_config'; import { getBreadcrumbs, unsavedChangesWarning } from './get_breadcrumbs'; +import { AppLeaveAction } from 'kibana/public'; +import { EmbeddableStateTransfer, Adapters } from 'src/plugins/embeddable/public'; +import { + LayerDescriptor, + MapRefreshConfig, + MapCenterAndZoom, +} from 'x-pack/plugins/maps/common/descriptor_types'; +import { MapSettings } from '../../../reducers/map'; +import { Subscription } from 'rxjs'; +import { QueryStateChange, QueryState } from 'src/plugins/data/public/query'; +import { AppLeaveActionFactory } from 'src/core/public/application/types'; + +interface MapsAppViewProps { + savedMap: any; + onAppLeave: (handler: (factory: AppLeaveActionFactory) => AppLeaveAction | undefined) => void; + stateTransfer: EmbeddableStateTransfer; + originatingApp?: string; + layerListConfigOnly: unknown; + replaceLayerList: (layerList: LayerDescriptor[]) => any; + filters: Filter[]; + isFullScreen: boolean; + isOpenSettingsDisabled: boolean; + enableFullScreen: () => any; + openMapSettings: () => any; + inspectorAdapters: Adapters; + nextIndexPatternIds: string[]; + dispatchSetQuery: ({ + forceRefresh, + filters, + query, + timeFilters, + }: { + filters?: Filter[]; + query?: Query; + timeFilters?: TimeRange; + forceRefresh?: boolean; + }) => void; + timeFilters: TimeRange; + refreshConfig: MapRefreshConfig; + setRefreshConfig: (refreshConfig: MapRefreshConfig) => any; + isSaveDisabled: boolean; + clearUi: () => {}; + setGotoWithCenter: (latLonZoom: MapCenterAndZoom) => any; + setMapSettings: (mapSettings: MapSettings) => any; + setIsLayerTOCOpen: (isLayerTOCOpen: boolean) => any; + setOpenTOCDetails: (openTOCDetails: string[]) => any; + query: Query; +} + +interface MapsAppViewState { + initialized: boolean; + initialLayerListConfig: any; + indexPatterns: IndexPattern[]; + savedQuery: SavedQuery | string; + originatingApp?: string; +} -export class MapsAppView extends React.Component { - _globalSyncUnsubscribe = null; - _globalSyncChangeMonitorSubscription = null; - _appSyncUnsubscribe = null; +export class MapsAppView extends React.Component { + _globalSyncUnsubscribe: (() => void) | null = null; + _globalSyncChangeMonitorSubscription: Subscription | null = null; + _appSyncUnsubscribe: (() => void) | null = null; _appStateManager = new AppStateManager(); - _prevIndexPatternIds = null; + _prevIndexPatternIds: string[] | null = null; + _isMounted?: boolean; - constructor(props) { + constructor(props: MapsAppViewProps) { super(props); this.state = { indexPatterns: [], @@ -62,7 +126,7 @@ export class MapsAppView extends React.Component { const initialSavedQuery = this._appStateManager.getAppState().savedQuery; if (initialSavedQuery) { - this._updateStateFromSavedQuery(initialSavedQuery); + this._updateStateFromSavedQuery(initialSavedQuery as SavedQuery); } this._initMap(); @@ -75,7 +139,7 @@ export class MapsAppView extends React.Component { return; } } - return actions.default(); + return actions.default() as AppLeaveAction; }); } @@ -121,7 +185,13 @@ export class MapsAppView extends React.Component { getCoreChrome().setBreadcrumbs(breadcrumbs); }; - _updateFromGlobalState = ({ changes, state: globalState }) => { + _updateFromGlobalState = ({ + changes, + state: globalState, + }: { + changes: QueryStateChange; + state: QueryState; + }) => { if (!this.state.initialized || !changes || !globalState) { return; } @@ -144,7 +214,17 @@ export class MapsAppView extends React.Component { } } - _onQueryChange = ({ filters, query, time, forceRefresh = false }) => { + _onQueryChange = ({ + filters, + query, + time, + forceRefresh = false, + }: { + filters?: Filter[]; + query?: Query; + time?: TimeRange; + forceRefresh?: boolean; + }) => { const { filterManager } = getData().query; if (filters) { @@ -165,7 +245,7 @@ export class MapsAppView extends React.Component { }); // sync globalState - const updatedGlobalState = { filters: filterManager.getGlobalFilters() }; + const updatedGlobalState: { filters: Filter[]; time?: TimeRange } = { filters: filterManager.getGlobalFilters() }; if (time) { updatedGlobalState.time = time; } @@ -173,7 +253,7 @@ export class MapsAppView extends React.Component { }; _initMapAndLayerSettings() { - const globalState = getGlobalState(); + const globalState: QueryState = getGlobalState(); const mapStateJSON = this.props.savedMap.mapStateJSON; let savedObjectFilters = []; @@ -219,14 +299,14 @@ export class MapsAppView extends React.Component { }); } - _onFiltersChange = (filters) => { + _onFiltersChange = (filters: Filter[]) => { this._onQueryChange({ filters, }); }; // mapRefreshConfig: MapRefreshConfig - _onRefreshConfigChange(mapRefreshConfig) { + _onRefreshConfigChange(mapRefreshConfig: MapRefreshConfig) { this.props.setRefreshConfig(mapRefreshConfig); updateGlobalState( { @@ -239,7 +319,7 @@ export class MapsAppView extends React.Component { ); } - _updateStateFromSavedQuery = (savedQuery) => { + _updateStateFromSavedQuery = (savedQuery: SavedQuery) => { this.setState({ savedQuery: { ...savedQuery } }); this._appStateManager.setQueryAndFilters({ savedQuery }); @@ -328,7 +408,10 @@ export class MapsAppView extends React.Component { dateRangeTo={this.props.timeFilters.to} isRefreshPaused={this.props.refreshConfig.isPaused} refreshInterval={this.props.refreshConfig.interval} - onRefreshChange={({ isPaused, refreshInterval }) => { + onRefreshChange={({ isPaused, refreshInterval }: { + isPaused: boolean; + refreshInterval: number; + }) => { this._onRefreshConfigChange({ isPaused, interval: refreshInterval, @@ -337,8 +420,9 @@ export class MapsAppView extends React.Component { showSearchBar={true} showFilterBar={true} showDatePicker={true} + // @ts-ignore showSaveQuery={getMapsCapabilities().saveQuery} - savedQuery={this.state.savedQuery} + savedQuery={this.state.savedQuery as SavedQuery} onSaved={this._updateStateFromSavedQuery} onSavedQueryUpdated={this._updateStateFromSavedQuery} onClearSavedQuery={() => { @@ -354,7 +438,7 @@ export class MapsAppView extends React.Component { ); } - _addFilter = (newFilters) => { + _addFilter = (newFilters: Filter[]) => { newFilters.forEach((filter) => { filter.$state = { store: esFilters.FilterStateStore.APP_STATE }; }); diff --git a/x-pack/plugins/maps/public/routing/routes/maps_app/top_nav_config.tsx b/x-pack/plugins/maps/public/routing/routes/maps_app/top_nav_config.tsx index 497c87ad533a6..47f41f2b76f3e 100644 --- a/x-pack/plugins/maps/public/routing/routes/maps_app/top_nav_config.tsx +++ b/x-pack/plugins/maps/public/routing/routes/maps_app/top_nav_config.tsx @@ -21,7 +21,6 @@ import { showSaveModal, } from '../../../../../../../src/plugins/saved_objects/public'; import { MAP_SAVED_OBJECT_TYPE } from '../../../../common/constants'; -// @ts-expect-error import { goToSpecifiedPath } from '../../maps_router'; import { ISavedGisMap } from '../../bootstrap/services/saved_gis_map'; import { EmbeddableStateTransfer } from '../../../../../../../src/plugins/embeddable/public'; diff --git a/x-pack/plugins/maps/public/routing/state_syncing/app_state_manager.js b/x-pack/plugins/maps/public/routing/state_syncing/app_state_manager.ts similarity index 72% rename from x-pack/plugins/maps/public/routing/state_syncing/app_state_manager.js rename to x-pack/plugins/maps/public/routing/state_syncing/app_state_manager.ts index 4cdba13bd85d2..786df41cd2194 100644 --- a/x-pack/plugins/maps/public/routing/state_syncing/app_state_manager.js +++ b/x-pack/plugins/maps/public/routing/state_syncing/app_state_manager.ts @@ -5,15 +5,20 @@ */ import { Subject } from 'rxjs'; +import { Filter, SavedQuery, Query } from 'src/plugins/data/public'; export class AppStateManager { - _query = ''; - _savedQuery = ''; - _filters = []; + _query: string | { [key: string]: any } = ''; + _savedQuery: SavedQuery | string = ''; + _filters: Filter[] = []; _updated$ = new Subject(); - setQueryAndFilters({ query, savedQuery, filters }) { + setQueryAndFilters({ query, savedQuery, filters }: { + query?: Query; + filters?: Filter[]; + savedQuery?: SavedQuery | string; + }) { if (query && this._query !== query) { this._query = query; } diff --git a/x-pack/plugins/maps/public/routing/state_syncing/app_sync.js b/x-pack/plugins/maps/public/routing/state_syncing/app_sync.ts similarity index 88% rename from x-pack/plugins/maps/public/routing/state_syncing/app_sync.js rename to x-pack/plugins/maps/public/routing/state_syncing/app_sync.ts index 60e8dc9cd574c..6f477362ab39f 100644 --- a/x-pack/plugins/maps/public/routing/state_syncing/app_sync.js +++ b/x-pack/plugins/maps/public/routing/state_syncing/app_sync.ts @@ -5,12 +5,13 @@ */ import { connectToQueryState, esFilters } from '../../../../../../src/plugins/data/public'; -import { syncState } from '../../../../../../src/plugins/kibana_utils/public'; +import { syncState, BaseStateContainer } from '../../../../../../src/plugins/kibana_utils/public'; import { map } from 'rxjs/operators'; import { getData } from '../../kibana_services'; import { kbnUrlStateStorage } from '../maps_router'; +import { AppStateManager } from './app_state_manager'; -export function startAppStateSyncing(appStateManager) { +export function startAppStateSyncing(appStateManager: AppStateManager) { // get appStateContainer // sync app filters with app state container from data.query to state container const { query } = getData(); @@ -19,7 +20,7 @@ export function startAppStateSyncing(appStateManager) { // clear app state filters to prevent application filters from other applications being transfered to maps query.filterManager.setAppFilters([]); - const stateContainer = { + const stateContainer: BaseStateContainer = { get: () => ({ query: appStateManager.getQuery(), filters: appStateManager.getFilters(), @@ -48,6 +49,7 @@ export function startAppStateSyncing(appStateManager) { // merge initial state from app state container and current state in url const initialAppState = { ...stateContainer.get(), + // @ts-ignore ...kbnUrlStateStorage.get('_a'), }; // trigger state update. actually needed in case some data was in url diff --git a/x-pack/plugins/maps/public/routing/state_syncing/global_sync.ts b/x-pack/plugins/maps/public/routing/state_syncing/global_sync.ts index 4e17241752f53..ed6090afca3cd 100644 --- a/x-pack/plugins/maps/public/routing/state_syncing/global_sync.ts +++ b/x-pack/plugins/maps/public/routing/state_syncing/global_sync.ts @@ -3,10 +3,9 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ - +import { QueryState } from 'src/plugins/data/public'; import { syncQueryStateWithUrl } from '../../../../../../src/plugins/data/public'; import { getData } from '../../kibana_services'; -// @ts-ignore import { kbnUrlStateStorage } from '../maps_router'; export function startGlobalStateSyncing() { @@ -14,16 +13,14 @@ export function startGlobalStateSyncing() { return stop; } -export function getGlobalState() { - return kbnUrlStateStorage.get('_g'); +export function getGlobalState(): QueryState { + return kbnUrlStateStorage.get('_g') as QueryState; } -export function updateGlobalState(newState: unknown, flushUrlState = false) { +export function updateGlobalState(newState: QueryState, flushUrlState = false) { const globalState = getGlobalState(); kbnUrlStateStorage.set('_g', { - // @ts-ignore ...globalState, - // @ts-ignore ...newState, }); if (flushUrlState) { From 7ef4d894ec6eb0144954488c55a1b6a4128fafc1 Mon Sep 17 00:00:00 2001 From: Shamin Date: Tue, 1 Sep 2020 20:29:48 +0530 Subject: [PATCH 03/11] Removed an unwanted ts-expect-error --- .../plugins/maps/public/routing/bootstrap/get_initial_layers.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/x-pack/plugins/maps/public/routing/bootstrap/get_initial_layers.ts b/x-pack/plugins/maps/public/routing/bootstrap/get_initial_layers.ts index 75c48c55da03b..f548a4d59f8ce 100644 --- a/x-pack/plugins/maps/public/routing/bootstrap/get_initial_layers.ts +++ b/x-pack/plugins/maps/public/routing/bootstrap/get_initial_layers.ts @@ -17,7 +17,6 @@ import '../../classes/sources/es_geo_grid_source'; import '../../classes/sources/xyz_tms_source'; // @ts-expect-error import { KibanaTilemapSource } from '../../classes/sources/kibana_tilemap_source'; -// @ts-expect-error import { TileLayer } from '../../classes/layers/tile_layer/tile_layer'; // @ts-expect-error import { EMSTMSSource } from '../../classes/sources/ems_tms_source'; From f06a0d1b394e5d2ea09e613f920aa2ef0e87d28c Mon Sep 17 00:00:00 2001 From: Shamin Date: Tue, 1 Sep 2020 23:48:16 +0530 Subject: [PATCH 04/11] Fixed the lint errors from jenkins --- src/plugins/data/public/index.ts | 1 + .../map_container/map_container.tsx | 2 +- .../maps/public/lazy_load_bundle/index.ts | 6 ++-- .../public/lazy_load_bundle/lazy/index.ts | 2 -- x-pack/plugins/maps/public/plugin.ts | 1 - .../routing/bootstrap/get_initial_layers.ts | 2 +- .../routing/bootstrap/get_initial_query.ts | 10 +++++- .../bootstrap/get_initial_refresh_config.ts | 7 ++-- .../bootstrap/get_initial_time_filters.ts | 9 +++++- .../maps/public/routing/maps_router.tsx | 13 +++++--- .../routes/list/load_list_and_render.tsx | 4 +-- .../routing/routes/list/maps_list_view.tsx | 4 +-- .../public/routing/routes/maps_app/index.ts | 6 ++-- .../routes/maps_app/load_map_and_render.tsx | 6 ++-- .../routing/routes/maps_app/maps_app_view.tsx | 32 +++++++++++-------- .../state_syncing/app_state_manager.ts | 6 +++- .../public/routing/state_syncing/app_sync.ts | 2 +- 17 files changed, 71 insertions(+), 42 deletions(-) diff --git a/src/plugins/data/public/index.ts b/src/plugins/data/public/index.ts index 27b16c57ffecf..19ffc6d32800b 100644 --- a/src/plugins/data/public/index.ts +++ b/src/plugins/data/public/index.ts @@ -429,6 +429,7 @@ export { TimeHistory, TimefilterContract, TimeHistoryContract, + QueryStateChange, } from './query'; export { diff --git a/x-pack/plugins/maps/public/connected_components/map_container/map_container.tsx b/x-pack/plugins/maps/public/connected_components/map_container/map_container.tsx index fe00e3704493e..bf75c86ac249d 100644 --- a/x-pack/plugins/maps/public/connected_components/map_container/map_container.tsx +++ b/x-pack/plugins/maps/public/connected_components/map_container/map_container.tsx @@ -36,7 +36,7 @@ import 'mapbox-gl/dist/mapbox-gl.css'; const RENDER_COMPLETE_EVENT = 'renderComplete'; interface Props { - addFilters: ((filters: Filter[]) => void) | null; + addFilters: ((filters: Filter[]) => Promise) | null; getFilterActions?: () => Promise; getActionContext?: () => ActionExecutionContext; areLayersLoaded: boolean; diff --git a/x-pack/plugins/maps/public/lazy_load_bundle/index.ts b/x-pack/plugins/maps/public/lazy_load_bundle/index.ts index 5f2a640aa9d0f..03752a1c3e11e 100644 --- a/x-pack/plugins/maps/public/lazy_load_bundle/index.ts +++ b/x-pack/plugins/maps/public/lazy_load_bundle/index.ts @@ -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'; @@ -40,7 +40,7 @@ interface LazyLoadedMapModules { initialLayers?: LayerDescriptor[] ) => LayerDescriptor[]; mergeInputWithSavedMap: any; - renderApp: (context: unknown, params: unknown) => ReactElement; + renderApp: (context: AppMountContext, params: AppMountParameters) => Promise<() => void>; createSecurityLayerDescriptors: ( indexPatternId: string, indexPatternTitle: string @@ -57,7 +57,6 @@ export async function lazyLoadMapModules(): Promise { loadModulesPromise = new Promise(async (resolve) => { const { - // @ts-expect-error getMapsSavedObjectLoader, getQueryableUniqueIndexPatternIds, MapEmbeddable, @@ -68,7 +67,6 @@ export async function lazyLoadMapModules(): Promise { addLayerWithoutDataSync, getInitialLayers, mergeInputWithSavedMap, - // @ts-expect-error renderApp, createSecurityLayerDescriptors, registerLayerWizard, diff --git a/x-pack/plugins/maps/public/lazy_load_bundle/lazy/index.ts b/x-pack/plugins/maps/public/lazy_load_bundle/lazy/index.ts index e55160383a8f3..28f5acdc17656 100644 --- a/x-pack/plugins/maps/public/lazy_load_bundle/lazy/index.ts +++ b/x-pack/plugins/maps/public/lazy_load_bundle/lazy/index.ts @@ -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'; @@ -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'; diff --git a/x-pack/plugins/maps/public/plugin.ts b/x-pack/plugins/maps/public/plugin.ts index b08135b4e486c..00ee7f376efc6 100644 --- a/x-pack/plugins/maps/public/plugin.ts +++ b/x-pack/plugins/maps/public/plugin.ts @@ -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); diff --git a/x-pack/plugins/maps/public/routing/bootstrap/get_initial_layers.ts b/x-pack/plugins/maps/public/routing/bootstrap/get_initial_layers.ts index f548a4d59f8ce..e828dc88409cb 100644 --- a/x-pack/plugins/maps/public/routing/bootstrap/get_initial_layers.ts +++ b/x-pack/plugins/maps/public/routing/bootstrap/get_initial_layers.ts @@ -15,6 +15,7 @@ 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'; @@ -25,7 +26,6 @@ import { VectorTileLayer } from '../../classes/layers/vector_tile_layer/vector_t import { getIsEmsEnabled, getToasts } from '../../kibana_services'; import { INITIAL_LAYERS_KEY } from '../../../common/constants'; import { getKibanaTileMap } from '../../meta'; -import { LayerDescriptor } from 'x-pack/plugins/maps/common/descriptor_types'; export function getInitialLayers(layerListJSON?: string, initialLayers: LayerDescriptor[] = []) { if (layerListJSON) { diff --git a/x-pack/plugins/maps/public/routing/bootstrap/get_initial_query.ts b/x-pack/plugins/maps/public/routing/bootstrap/get_initial_query.ts index 1f2cf27077623..2df4dbffe7f22 100644 --- a/x-pack/plugins/maps/public/routing/bootstrap/get_initial_query.ts +++ b/x-pack/plugins/maps/public/routing/bootstrap/get_initial_query.ts @@ -6,7 +6,15 @@ import { getData } from '../../kibana_services'; -export function getInitialQuery({ mapStateJSON, appState = {} }) { +export function getInitialQuery({ + mapStateJSON, + appState = {}, +}: { + mapStateJSON: any; + appState: { + query?: string | { [key: string]: any }; + }; +}) { if (appState.query) { return appState.query; } diff --git a/x-pack/plugins/maps/public/routing/bootstrap/get_initial_refresh_config.ts b/x-pack/plugins/maps/public/routing/bootstrap/get_initial_refresh_config.ts index a7934de334df2..6e2525dadf98c 100644 --- a/x-pack/plugins/maps/public/routing/bootstrap/get_initial_refresh_config.ts +++ b/x-pack/plugins/maps/public/routing/bootstrap/get_initial_refresh_config.ts @@ -4,11 +4,14 @@ * 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'; -import { QueryState } from 'src/plugins/data/public'; -export function getInitialRefreshConfig({ mapStateJSON, globalState = {} }: { +export function getInitialRefreshConfig({ + mapStateJSON, + globalState = {}, +}: { mapStateJSON: any; globalState: QueryState; }) { diff --git a/x-pack/plugins/maps/public/routing/bootstrap/get_initial_time_filters.ts b/x-pack/plugins/maps/public/routing/bootstrap/get_initial_time_filters.ts index 9c11dabe03923..abbd381d05b79 100644 --- a/x-pack/plugins/maps/public/routing/bootstrap/get_initial_time_filters.ts +++ b/x-pack/plugins/maps/public/routing/bootstrap/get_initial_time_filters.ts @@ -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: any; + globalState: QueryState; +}) { if (mapStateJSON) { const mapState = JSON.parse(mapStateJSON); if (mapState.timeFilters) { diff --git a/x-pack/plugins/maps/public/routing/maps_router.tsx b/x-pack/plugins/maps/public/routing/maps_router.tsx index 3112b06916156..3d7d19eae9928 100644 --- a/x-pack/plugins/maps/public/routing/maps_router.tsx +++ b/x-pack/plugins/maps/public/routing/maps_router.tsx @@ -8,6 +8,8 @@ import React from 'react'; import { render, unmountComponentAtNode } from 'react-dom'; import { Router, Switch, Route, Redirect, RouteComponentProps } from 'react-router-dom'; import { i18n } from '@kbn/i18n'; +import { Provider } from 'react-redux'; +import { AppMountContext, AppMountParameters } from 'kibana/public'; import { getCoreChrome, getCoreI18n, @@ -21,15 +23,16 @@ import { IKbnUrlStateStorage, } from '../../../../../src/plugins/kibana_utils/public'; import { getStore } from './store_operations'; -import { Provider } from 'react-redux'; import { LoadListAndRender } from './routes/list/load_list_and_render'; import { LoadMapAndRender } from './routes/maps_app/load_map_and_render'; -import { AppMountContext, AppMountParameters } from 'kibana/public'; export let goToSpecifiedPath: (path: string) => void; export let kbnUrlStateStorage: IKbnUrlStateStorage; -export async function renderApp(context: AppMountContext, { appBasePath, element, history, onAppLeave }: AppMountParameters) { +export async function renderApp( + context: AppMountContext, + { appBasePath, element, history, onAppLeave }: AppMountParameters +) { goToSpecifiedPath = (path) => history.push(path); kbnUrlStateStorage = createKbnUrlStateStorage({ useHash: false, @@ -54,7 +57,9 @@ const App: React.FC = ({ history, appBasePath, onAppLeave }) => { const store = getStore(); const I18nContext = getCoreI18n().Context; - const stateTransfer = getEmbeddableService()?.getStateTransfer(history as AppMountParameters['history']); + const stateTransfer = getEmbeddableService()?.getStateTransfer( + history as AppMountParameters['history'] + ); const { originatingApp } = stateTransfer?.getIncomingEditorState({ keysToRemoveAfterFetch: ['originatingApp'] }) || {}; diff --git a/x-pack/plugins/maps/public/routing/routes/list/load_list_and_render.tsx b/x-pack/plugins/maps/public/routing/routes/list/load_list_and_render.tsx index d831a78edb42f..e97484caf2087 100644 --- a/x-pack/plugins/maps/public/routing/routes/list/load_list_and_render.tsx +++ b/x-pack/plugins/maps/public/routing/routes/list/load_list_and_render.tsx @@ -5,11 +5,11 @@ */ import React from 'react'; +import { i18n } from '@kbn/i18n'; +import { Redirect } from 'react-router-dom'; import { getMapsSavedObjectLoader } from '../../bootstrap/services/gis_map_saved_object_loader'; import { getToasts } from '../../../kibana_services'; -import { i18n } from '@kbn/i18n'; import { MapsListView } from './maps_list_view'; -import { Redirect } from 'react-router-dom'; export class LoadListAndRender extends React.Component { _isMounted?: boolean; diff --git a/x-pack/plugins/maps/public/routing/routes/list/maps_list_view.tsx b/x-pack/plugins/maps/public/routing/routes/list/maps_list_view.tsx index 72c1721b5b032..f6c3149c04c67 100644 --- a/x-pack/plugins/maps/public/routing/routes/list/maps_list_view.tsx +++ b/x-pack/plugins/maps/public/routing/routes/list/maps_list_view.tsx @@ -31,10 +31,10 @@ import { EuiBasicTableColumn, } from '@elastic/eui/src/components/basic_table/basic_table'; import { EuiTableSortingType } from '@elastic/eui'; -import { addHelpMenuToAppChrome } from '../../../help_menu_util'; import { goToSpecifiedPath } from '../../maps_router'; +// @ts-expect-error +import { addHelpMenuToAppChrome } from '../../../help_menu_util'; import { APP_ID, MAP_PATH } from '../../../../common/constants'; - import { getMapsCapabilities, getUiSettings, diff --git a/x-pack/plugins/maps/public/routing/routes/maps_app/index.ts b/x-pack/plugins/maps/public/routing/routes/maps_app/index.ts index 05ac2600f5957..3aed506225d8b 100644 --- a/x-pack/plugins/maps/public/routing/routes/maps_app/index.ts +++ b/x-pack/plugins/maps/public/routing/routes/maps_app/index.ts @@ -5,6 +5,8 @@ */ import { connect } from 'react-redux'; +import { ThunkDispatch } from 'redux-thunk'; +import { Filter, Query, TimeRange } from 'src/plugins/data/public'; import { MapsAppView } from './maps_app_view'; import { getFlyoutDisplay, getIsFullScreen } from '../../../selectors/ui_selectors'; import { @@ -34,13 +36,11 @@ import { FLYOUT_STATE } from '../../../reducers/ui'; import { getMapsCapabilities } from '../../../kibana_services'; import { getInspectorAdapters } from '../../../reducers/non_serializable_instances'; import { MapStoreState } from '../../../reducers/store'; -import { ThunkDispatch } from 'redux-thunk'; -import { Filter, Query, TimeRange } from 'src/plugins/data/public'; import { MapRefreshConfig, MapCenterAndZoom, LayerDescriptor, -} from 'x-pack/plugins/maps/common/descriptor_types'; +} from '../../../../common/descriptor_types'; import { MapSettings } from '../../../reducers/map'; function mapStateToProps(state: MapStoreState) { diff --git a/x-pack/plugins/maps/public/routing/routes/maps_app/load_map_and_render.tsx b/x-pack/plugins/maps/public/routing/routes/maps_app/load_map_and_render.tsx index 41be93490c31b..66012587a299f 100644 --- a/x-pack/plugins/maps/public/routing/routes/maps_app/load_map_and_render.tsx +++ b/x-pack/plugins/maps/public/routing/routes/maps_app/load_map_and_render.tsx @@ -5,13 +5,13 @@ */ import React from 'react'; -import { MapsAppView } from '.'; -import { getMapsSavedObjectLoader } from '../../bootstrap/services/gis_map_saved_object_loader'; -import { getCoreChrome, getToasts } from '../../../kibana_services'; import { i18n } from '@kbn/i18n'; import { Redirect } from 'react-router-dom'; import { AppMountParameters } from 'kibana/public'; import { EmbeddableStateTransfer } from 'src/plugins/embeddable/public'; +import { getCoreChrome, getToasts } from '../../../kibana_services'; +import { getMapsSavedObjectLoader } from '../../bootstrap/services/gis_map_saved_object_loader'; +import { MapsAppView } from '.'; interface LoadMapAndRenderProps { savedMapId?: Record; diff --git a/x-pack/plugins/maps/public/routing/routes/maps_app/maps_app_view.tsx b/x-pack/plugins/maps/public/routing/routes/maps_app/maps_app_view.tsx index 21277b1584e8e..aec2c44e3fe7e 100644 --- a/x-pack/plugins/maps/public/routing/routes/maps_app/maps_app_view.tsx +++ b/x-pack/plugins/maps/public/routing/routes/maps_app/maps_app_view.tsx @@ -7,6 +7,9 @@ import React from 'react'; import 'mapbox-gl/dist/mapbox-gl.css'; import _ from 'lodash'; +import { AppLeaveAction, AppMountParameters } from 'kibana/public'; +import { EmbeddableStateTransfer, Adapters } from 'src/plugins/embeddable/public'; +import { Subscription } from 'rxjs'; import { DEFAULT_IS_LAYER_TOC_OPEN } from '../../../reducers/ui'; import { getData, @@ -33,26 +36,24 @@ import { TimeRange, IndexPattern, SavedQuery, + QueryStateChange, + QueryState, } from '../../../../../../../src/plugins/data/public'; import { MapContainer } from '../../../connected_components/map_container'; import { getIndexPatternsFromIds } from '../../../index_pattern_util'; import { getTopNavConfig } from './top_nav_config'; import { getBreadcrumbs, unsavedChangesWarning } from './get_breadcrumbs'; -import { AppLeaveAction } from 'kibana/public'; -import { EmbeddableStateTransfer, Adapters } from 'src/plugins/embeddable/public'; import { LayerDescriptor, MapRefreshConfig, MapCenterAndZoom, -} from 'x-pack/plugins/maps/common/descriptor_types'; + MapQuery, +} from '../../../../common/descriptor_types'; import { MapSettings } from '../../../reducers/map'; -import { Subscription } from 'rxjs'; -import { QueryStateChange, QueryState } from 'src/plugins/data/public/query'; -import { AppLeaveActionFactory } from 'src/core/public/application/types'; interface MapsAppViewProps { savedMap: any; - onAppLeave: (handler: (factory: AppLeaveActionFactory) => AppLeaveAction | undefined) => void; + onAppLeave: AppMountParameters['onAppLeave']; stateTransfer: EmbeddableStateTransfer; originatingApp?: string; layerListConfigOnly: unknown; @@ -79,12 +80,12 @@ interface MapsAppViewProps { refreshConfig: MapRefreshConfig; setRefreshConfig: (refreshConfig: MapRefreshConfig) => any; isSaveDisabled: boolean; - clearUi: () => {}; + clearUi: () => void; setGotoWithCenter: (latLonZoom: MapCenterAndZoom) => any; setMapSettings: (mapSettings: MapSettings) => any; setIsLayerTOCOpen: (isLayerTOCOpen: boolean) => any; setOpenTOCDetails: (openTOCDetails: string[]) => any; - query: Query; + query: MapQuery | undefined; } interface MapsAppViewState { @@ -136,7 +137,7 @@ export class MapsAppView extends React.Component { if (this._hasUnsavedChanges()) { if (!window.confirm(unsavedChangesWarning)) { - return; + return {} as AppLeaveAction; } } return actions.default() as AppLeaveAction; @@ -245,7 +246,9 @@ export class MapsAppView extends React.Component { @@ -438,7 +444,7 @@ export class MapsAppView extends React.Component { + _addFilter = async (newFilters: Filter[]) => { newFilters.forEach((filter) => { filter.$state = { store: esFilters.FilterStateStore.APP_STATE }; }); diff --git a/x-pack/plugins/maps/public/routing/state_syncing/app_state_manager.ts b/x-pack/plugins/maps/public/routing/state_syncing/app_state_manager.ts index 786df41cd2194..78f2ecc7941ee 100644 --- a/x-pack/plugins/maps/public/routing/state_syncing/app_state_manager.ts +++ b/x-pack/plugins/maps/public/routing/state_syncing/app_state_manager.ts @@ -14,7 +14,11 @@ export class AppStateManager { _updated$ = new Subject(); - setQueryAndFilters({ query, savedQuery, filters }: { + setQueryAndFilters({ + query, + savedQuery, + filters, + }: { query?: Query; filters?: Filter[]; savedQuery?: SavedQuery | string; diff --git a/x-pack/plugins/maps/public/routing/state_syncing/app_sync.ts b/x-pack/plugins/maps/public/routing/state_syncing/app_sync.ts index 6f477362ab39f..b346822913bec 100644 --- a/x-pack/plugins/maps/public/routing/state_syncing/app_sync.ts +++ b/x-pack/plugins/maps/public/routing/state_syncing/app_sync.ts @@ -4,9 +4,9 @@ * you may not use this file except in compliance with the Elastic License. */ +import { map } from 'rxjs/operators'; import { connectToQueryState, esFilters } from '../../../../../../src/plugins/data/public'; import { syncState, BaseStateContainer } from '../../../../../../src/plugins/kibana_utils/public'; -import { map } from 'rxjs/operators'; import { getData } from '../../kibana_services'; import { kbnUrlStateStorage } from '../maps_router'; import { AppStateManager } from './app_state_manager'; From 765f772c4ea358eb9fff43f2ea2558239d507a17 Mon Sep 17 00:00:00 2001 From: Shamin Date: Wed, 2 Sep 2020 21:45:43 +0530 Subject: [PATCH 05/11] Naming changes, type for mapStateJSON etc. --- .../routing/bootstrap/get_initial_query.ts | 2 +- .../bootstrap/get_initial_refresh_config.ts | 2 +- .../bootstrap/get_initial_time_filters.ts | 2 +- .../maps/public/routing/maps_router.tsx | 4 ++-- .../public/routing/routes/maps_app/index.ts | 22 +++++++++++-------- .../routes/maps_app/load_map_and_render.tsx | 4 ++-- .../routing/routes/maps_app/maps_app_view.tsx | 8 +++---- 7 files changed, 24 insertions(+), 20 deletions(-) diff --git a/x-pack/plugins/maps/public/routing/bootstrap/get_initial_query.ts b/x-pack/plugins/maps/public/routing/bootstrap/get_initial_query.ts index 2df4dbffe7f22..1f9395426aded 100644 --- a/x-pack/plugins/maps/public/routing/bootstrap/get_initial_query.ts +++ b/x-pack/plugins/maps/public/routing/bootstrap/get_initial_query.ts @@ -10,7 +10,7 @@ export function getInitialQuery({ mapStateJSON, appState = {}, }: { - mapStateJSON: any; + mapStateJSON: string; appState: { query?: string | { [key: string]: any }; }; diff --git a/x-pack/plugins/maps/public/routing/bootstrap/get_initial_refresh_config.ts b/x-pack/plugins/maps/public/routing/bootstrap/get_initial_refresh_config.ts index 6e2525dadf98c..dcacf9f5601d3 100644 --- a/x-pack/plugins/maps/public/routing/bootstrap/get_initial_refresh_config.ts +++ b/x-pack/plugins/maps/public/routing/bootstrap/get_initial_refresh_config.ts @@ -12,7 +12,7 @@ export function getInitialRefreshConfig({ mapStateJSON, globalState = {}, }: { - mapStateJSON: any; + mapStateJSON: string; globalState: QueryState; }) { const uiSettings = getUiSettings(); diff --git a/x-pack/plugins/maps/public/routing/bootstrap/get_initial_time_filters.ts b/x-pack/plugins/maps/public/routing/bootstrap/get_initial_time_filters.ts index abbd381d05b79..c4941b604ce34 100644 --- a/x-pack/plugins/maps/public/routing/bootstrap/get_initial_time_filters.ts +++ b/x-pack/plugins/maps/public/routing/bootstrap/get_initial_time_filters.ts @@ -11,7 +11,7 @@ export function getInitialTimeFilters({ mapStateJSON, globalState, }: { - mapStateJSON: any; + mapStateJSON: string; globalState: QueryState; }) { if (mapStateJSON) { diff --git a/x-pack/plugins/maps/public/routing/maps_router.tsx b/x-pack/plugins/maps/public/routing/maps_router.tsx index 3d7d19eae9928..5291d9c361161 100644 --- a/x-pack/plugins/maps/public/routing/maps_router.tsx +++ b/x-pack/plugins/maps/public/routing/maps_router.tsx @@ -47,13 +47,13 @@ export async function renderApp( }; } -interface AppProps { +interface Props { history: AppMountParameters['history'] | RouteComponentProps['history']; appBasePath: AppMountParameters['appBasePath']; onAppLeave: AppMountParameters['onAppLeave']; } -const App: React.FC = ({ history, appBasePath, onAppLeave }) => { +const App: React.FC = ({ history, appBasePath, onAppLeave }) => { const store = getStore(); const I18nContext = getCoreI18n().Context; diff --git a/x-pack/plugins/maps/public/routing/routes/maps_app/index.ts b/x-pack/plugins/maps/public/routing/routes/maps_app/index.ts index 3aed506225d8b..812d7fcf30981 100644 --- a/x-pack/plugins/maps/public/routing/routes/maps_app/index.ts +++ b/x-pack/plugins/maps/public/routing/routes/maps_app/index.ts @@ -6,6 +6,7 @@ import { connect } from 'react-redux'; import { ThunkDispatch } from 'redux-thunk'; +import { AnyAction } from 'redux'; import { Filter, Query, TimeRange } from 'src/plugins/data/public'; import { MapsAppView } from './maps_app_view'; import { getFlyoutDisplay, getIsFullScreen } from '../../../selectors/ui_selectors'; @@ -59,16 +60,19 @@ function mapStateToProps(state: MapStoreState) { }; } -interface DispatchSetQueryArgs { - filters?: Filter[]; - query?: Query; - timeFilters?: TimeRange; - forceRefresh?: boolean; -} - -function mapDispatchToProps(dispatch: ThunkDispatch, MapStoreState, any>) { +function mapDispatchToProps(dispatch: ThunkDispatch) { return { - dispatchSetQuery: ({ forceRefresh, filters, query, timeFilters }: DispatchSetQueryArgs) => { + dispatchSetQuery: ({ + forceRefresh, + filters, + query, + timeFilters, + }: { + filters?: Filter[]; + query?: Query; + timeFilters?: TimeRange; + forceRefresh?: boolean; + }) => { dispatch( setQuery({ filters, diff --git a/x-pack/plugins/maps/public/routing/routes/maps_app/load_map_and_render.tsx b/x-pack/plugins/maps/public/routing/routes/maps_app/load_map_and_render.tsx index 66012587a299f..4475873949d7c 100644 --- a/x-pack/plugins/maps/public/routing/routes/maps_app/load_map_and_render.tsx +++ b/x-pack/plugins/maps/public/routing/routes/maps_app/load_map_and_render.tsx @@ -13,14 +13,14 @@ import { getCoreChrome, getToasts } from '../../../kibana_services'; import { getMapsSavedObjectLoader } from '../../bootstrap/services/gis_map_saved_object_loader'; import { MapsAppView } from '.'; -interface LoadMapAndRenderProps { +interface Props { savedMapId?: Record; onAppLeave: AppMountParameters['onAppLeave']; stateTransfer: EmbeddableStateTransfer; originatingApp?: string; } -export const LoadMapAndRender = class extends React.Component { +export const LoadMapAndRender = class extends React.Component { _isMounted!: boolean; state = { savedMap: null, diff --git a/x-pack/plugins/maps/public/routing/routes/maps_app/maps_app_view.tsx b/x-pack/plugins/maps/public/routing/routes/maps_app/maps_app_view.tsx index aec2c44e3fe7e..8abfa37f27c6a 100644 --- a/x-pack/plugins/maps/public/routing/routes/maps_app/maps_app_view.tsx +++ b/x-pack/plugins/maps/public/routing/routes/maps_app/maps_app_view.tsx @@ -51,7 +51,7 @@ import { } from '../../../../common/descriptor_types'; import { MapSettings } from '../../../reducers/map'; -interface MapsAppViewProps { +interface Props { savedMap: any; onAppLeave: AppMountParameters['onAppLeave']; stateTransfer: EmbeddableStateTransfer; @@ -88,7 +88,7 @@ interface MapsAppViewProps { query: MapQuery | undefined; } -interface MapsAppViewState { +interface State { initialized: boolean; initialLayerListConfig: any; indexPatterns: IndexPattern[]; @@ -96,7 +96,7 @@ interface MapsAppViewState { originatingApp?: string; } -export class MapsAppView extends React.Component { +export class MapsAppView extends React.Component { _globalSyncUnsubscribe: (() => void) | null = null; _globalSyncChangeMonitorSubscription: Subscription | null = null; _appSyncUnsubscribe: (() => void) | null = null; @@ -104,7 +104,7 @@ export class MapsAppView extends React.Component Date: Thu, 3 Sep 2020 23:22:56 +0530 Subject: [PATCH 06/11] More type fixes in map routes --- .../routing/bootstrap/get_initial_query.ts | 2 +- .../bootstrap/get_initial_refresh_config.ts | 2 +- .../bootstrap/get_initial_time_filters.ts | 2 +- .../routes/maps_app/load_map_and_render.tsx | 14 +++++-- .../routing/routes/maps_app/maps_app_view.tsx | 42 +++++++++---------- .../state_syncing/app_state_manager.ts | 14 +++---- 6 files changed, 41 insertions(+), 35 deletions(-) diff --git a/x-pack/plugins/maps/public/routing/bootstrap/get_initial_query.ts b/x-pack/plugins/maps/public/routing/bootstrap/get_initial_query.ts index 1f9395426aded..c7143b0fa7010 100644 --- a/x-pack/plugins/maps/public/routing/bootstrap/get_initial_query.ts +++ b/x-pack/plugins/maps/public/routing/bootstrap/get_initial_query.ts @@ -10,7 +10,7 @@ export function getInitialQuery({ mapStateJSON, appState = {}, }: { - mapStateJSON: string; + mapStateJSON?: string; appState: { query?: string | { [key: string]: any }; }; diff --git a/x-pack/plugins/maps/public/routing/bootstrap/get_initial_refresh_config.ts b/x-pack/plugins/maps/public/routing/bootstrap/get_initial_refresh_config.ts index dcacf9f5601d3..7d759cb25052f 100644 --- a/x-pack/plugins/maps/public/routing/bootstrap/get_initial_refresh_config.ts +++ b/x-pack/plugins/maps/public/routing/bootstrap/get_initial_refresh_config.ts @@ -12,7 +12,7 @@ export function getInitialRefreshConfig({ mapStateJSON, globalState = {}, }: { - mapStateJSON: string; + mapStateJSON?: string; globalState: QueryState; }) { const uiSettings = getUiSettings(); diff --git a/x-pack/plugins/maps/public/routing/bootstrap/get_initial_time_filters.ts b/x-pack/plugins/maps/public/routing/bootstrap/get_initial_time_filters.ts index c4941b604ce34..549cc154fe487 100644 --- a/x-pack/plugins/maps/public/routing/bootstrap/get_initial_time_filters.ts +++ b/x-pack/plugins/maps/public/routing/bootstrap/get_initial_time_filters.ts @@ -11,7 +11,7 @@ export function getInitialTimeFilters({ mapStateJSON, globalState, }: { - mapStateJSON: string; + mapStateJSON?: string; globalState: QueryState; }) { if (mapStateJSON) { diff --git a/x-pack/plugins/maps/public/routing/routes/maps_app/load_map_and_render.tsx b/x-pack/plugins/maps/public/routing/routes/maps_app/load_map_and_render.tsx index 4475873949d7c..78d12b65bd302 100644 --- a/x-pack/plugins/maps/public/routing/routes/maps_app/load_map_and_render.tsx +++ b/x-pack/plugins/maps/public/routing/routes/maps_app/load_map_and_render.tsx @@ -12,18 +12,24 @@ import { EmbeddableStateTransfer } from 'src/plugins/embeddable/public'; import { getCoreChrome, getToasts } from '../../../kibana_services'; import { getMapsSavedObjectLoader } from '../../bootstrap/services/gis_map_saved_object_loader'; import { MapsAppView } from '.'; +import { ISavedGisMap } from '../../bootstrap/services/saved_gis_map'; interface Props { - savedMapId?: Record; + savedMapId?: string; onAppLeave: AppMountParameters['onAppLeave']; stateTransfer: EmbeddableStateTransfer; originatingApp?: string; } -export const LoadMapAndRender = class extends React.Component { +interface State { + savedMap?: ISavedGisMap; + failedToLoad: boolean; +} + +export const LoadMapAndRender = class extends React.Component { _isMounted!: boolean; state = { - savedMap: null, + savedMap: undefined, failedToLoad: false, }; @@ -68,7 +74,7 @@ export const LoadMapAndRender = class extends React.Component { return savedMap ? ( any; + layerListConfigOnly: LayerDescriptor[]; + replaceLayerList: (layerList: LayerDescriptor[]) => void; filters: Filter[]; isFullScreen: boolean; isOpenSettingsDisabled: boolean; - enableFullScreen: () => any; - openMapSettings: () => any; + enableFullScreen: () => void; + openMapSettings: () => void; inspectorAdapters: Adapters; nextIndexPatternIds: string[]; dispatchSetQuery: ({ @@ -78,21 +79,21 @@ interface Props { }) => void; timeFilters: TimeRange; refreshConfig: MapRefreshConfig; - setRefreshConfig: (refreshConfig: MapRefreshConfig) => any; + setRefreshConfig: (refreshConfig: MapRefreshConfig) => void; isSaveDisabled: boolean; clearUi: () => void; - setGotoWithCenter: (latLonZoom: MapCenterAndZoom) => any; - setMapSettings: (mapSettings: MapSettings) => any; - setIsLayerTOCOpen: (isLayerTOCOpen: boolean) => any; - setOpenTOCDetails: (openTOCDetails: string[]) => any; + setGotoWithCenter: (latLonZoom: MapCenterAndZoom) => void; + setMapSettings: (mapSettings: MapSettings) => void; + setIsLayerTOCOpen: (isLayerTOCOpen: boolean) => void; + setOpenTOCDetails: (openTOCDetails: string[]) => void; query: MapQuery | undefined; } interface State { initialized: boolean; - initialLayerListConfig: any; + initialLayerListConfig?: LayerDescriptor[]; indexPatterns: IndexPattern[]; - savedQuery: SavedQuery | string; + savedQuery?: SavedQuery; originatingApp?: string; } @@ -109,8 +110,6 @@ export class MapsAppView extends React.Component { this.state = { indexPatterns: [], initialized: false, - savedQuery: '', - initialLayerListConfig: null, // tracking originatingApp in state so the connection can be broken by users originatingApp: props.originatingApp, }; @@ -125,10 +124,11 @@ export class MapsAppView extends React.Component { this._updateFromGlobalState ); - const initialSavedQuery = this._appStateManager.getAppState().savedQuery; - if (initialSavedQuery) { - this._updateStateFromSavedQuery(initialSavedQuery as SavedQuery); - } + // savedQuery must be fetched from savedQueryId + // const initialSavedQuery = this._appStateManager.getAppState().savedQuery; + // if (initialSavedQuery) { + // this._updateStateFromSavedQuery(initialSavedQuery as SavedQuery); + // } this._initMap(); @@ -324,7 +324,7 @@ export class MapsAppView extends React.Component { _updateStateFromSavedQuery = (savedQuery: SavedQuery) => { this.setState({ savedQuery: { ...savedQuery } }); - this._appStateManager.setQueryAndFilters({ savedQuery }); + this._appStateManager.setQueryAndFilters({ savedQueryId: savedQuery.id }); const { filterManager } = getData().query; const savedQueryFilters = savedQuery.attributes.filters || []; @@ -433,8 +433,8 @@ export class MapsAppView extends React.Component { onSavedQueryUpdated={this._updateStateFromSavedQuery} onClearSavedQuery={() => { const { filterManager, queryString } = getData().query; - this.setState({ savedQuery: '' }); - this._appStateManager.setQueryAndFilters({ savedQuery: '' }); + this.setState({ savedQuery: undefined }); + this._appStateManager.setQueryAndFilters({ savedQueryId: '' }); this._onQueryChange({ filters: filterManager.getGlobalFilters(), query: queryString.getDefaultQuery(), diff --git a/x-pack/plugins/maps/public/routing/state_syncing/app_state_manager.ts b/x-pack/plugins/maps/public/routing/state_syncing/app_state_manager.ts index 78f2ecc7941ee..e5e7e28330cbc 100644 --- a/x-pack/plugins/maps/public/routing/state_syncing/app_state_manager.ts +++ b/x-pack/plugins/maps/public/routing/state_syncing/app_state_manager.ts @@ -5,29 +5,29 @@ */ import { Subject } from 'rxjs'; -import { Filter, SavedQuery, Query } from 'src/plugins/data/public'; +import { Filter, Query } from 'src/plugins/data/public'; export class AppStateManager { _query: string | { [key: string]: any } = ''; - _savedQuery: SavedQuery | string = ''; + _savedQueryId: string = ''; _filters: Filter[] = []; _updated$ = new Subject(); setQueryAndFilters({ query, - savedQuery, + savedQueryId, filters, }: { query?: Query; filters?: Filter[]; - savedQuery?: SavedQuery | string; + savedQueryId?: string; }) { if (query && this._query !== query) { this._query = query; } - if (savedQuery && this._savedQuery !== savedQuery) { - this._savedQuery = savedQuery; + if (savedQueryId && this._savedQueryId !== savedQueryId) { + this._savedQueryId = savedQueryId; } if (filters && this._filters !== filters) { this._filters = filters; @@ -46,7 +46,7 @@ export class AppStateManager { getAppState() { return { query: this._query, - savedQuery: this._savedQuery, + savedQuery: this._savedQueryId, filters: this._filters, }; } From 46f09800fc71b25475a89086900a6ca749818e7c Mon Sep 17 00:00:00 2001 From: Shamin Date: Fri, 4 Sep 2020 21:47:42 +0530 Subject: [PATCH 07/11] More type fixes in map routes --- .../routes/list/load_list_and_render.tsx | 2 +- .../routing/routes/list/maps_list_view.tsx | 22 ++++++++---------- .../routes/maps_app/load_map_and_render.tsx | 2 +- .../routing/routes/maps_app/maps_app_view.tsx | 23 ++++--------------- .../state_syncing/app_state_manager.ts | 2 +- .../routing/state_syncing/global_sync.ts | 14 +++++++---- 6 files changed, 27 insertions(+), 38 deletions(-) diff --git a/x-pack/plugins/maps/public/routing/routes/list/load_list_and_render.tsx b/x-pack/plugins/maps/public/routing/routes/list/load_list_and_render.tsx index e97484caf2087..e85afb470dbe6 100644 --- a/x-pack/plugins/maps/public/routing/routes/list/load_list_and_render.tsx +++ b/x-pack/plugins/maps/public/routing/routes/list/load_list_and_render.tsx @@ -12,7 +12,7 @@ import { getToasts } from '../../../kibana_services'; import { MapsListView } from './maps_list_view'; export class LoadListAndRender extends React.Component { - _isMounted?: boolean; + _isMounted: boolean = false; state = { mapsLoaded: false, hasSavedMaps: null, diff --git a/x-pack/plugins/maps/public/routing/routes/list/maps_list_view.tsx b/x-pack/plugins/maps/public/routing/routes/list/maps_list_view.tsx index f6c3149c04c67..2db686d89ead0 100644 --- a/x-pack/plugins/maps/public/routing/routes/list/maps_list_view.tsx +++ b/x-pack/plugins/maps/public/routing/routes/list/maps_list_view.tsx @@ -26,7 +26,6 @@ import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n/react'; import { Direction } from '@elastic/eui'; import { - Criteria, CriteriaWithPagination, EuiBasicTableColumn, } from '@elastic/eui/src/components/basic_table/basic_table'; @@ -52,7 +51,7 @@ function navigateToNewMap() { path: MAP_PATH, }); } -interface MapsListViewState { +interface State { sortField?: string | number | symbol; sortDirection?: Direction; hasInitialFetchReturned: boolean; @@ -60,12 +59,12 @@ interface MapsListViewState { showDeleteModal: boolean; showLimitError: boolean; filter: string; - items: []; - selectedIds: []; + items: SelectionItem[]; + selectedIds: string[]; page: number; perPage: number; - readOnly: any; - listingLimit: any; + readOnly: boolean; + listingLimit: number; totalItems?: number; } @@ -74,8 +73,8 @@ interface SelectionItem { } export class MapsListView extends React.Component { - _isMounted?: boolean; - state: MapsListViewState = { + _isMounted: boolean = false; + state: State = { hasInitialFetchReturned: false, isFetchingItems: false, showDeleteModal: false, @@ -107,7 +106,7 @@ export class MapsListView extends React.Component { _find = (search: string) => getMapsSavedObjectLoader().find(search, this.state.listingLimit); - _delete = (ids: string | string[]) => getMapsSavedObjectLoader().delete(ids); + _delete = (ids: string[]) => getMapsSavedObjectLoader().delete(ids); debouncedFetch = _.debounce(async (filter) => { const response = await this._find(filter); @@ -164,10 +163,7 @@ export class MapsListView extends React.Component { this.setState({ showDeleteModal: true }); }; - onTableChange = ({ - page, - sort, - }: Criteria | CriteriaWithPagination) => { + onTableChange = ({ page, sort }: CriteriaWithPagination) => { const { index: pageIndex, size: pageSize } = page!; let { field: sortField, direction: sortDirection } = sort || {}; diff --git a/x-pack/plugins/maps/public/routing/routes/maps_app/load_map_and_render.tsx b/x-pack/plugins/maps/public/routing/routes/maps_app/load_map_and_render.tsx index 78d12b65bd302..2f663c8c2d725 100644 --- a/x-pack/plugins/maps/public/routing/routes/maps_app/load_map_and_render.tsx +++ b/x-pack/plugins/maps/public/routing/routes/maps_app/load_map_and_render.tsx @@ -27,7 +27,7 @@ interface State { } export const LoadMapAndRender = class extends React.Component { - _isMounted!: boolean; + _isMounted: boolean = false; state = { savedMap: undefined, failedToLoad: false, diff --git a/x-pack/plugins/maps/public/routing/routes/maps_app/maps_app_view.tsx b/x-pack/plugins/maps/public/routing/routes/maps_app/maps_app_view.tsx index 58f4bf7d076d1..1c803123a00ba 100644 --- a/x-pack/plugins/maps/public/routing/routes/maps_app/maps_app_view.tsx +++ b/x-pack/plugins/maps/public/routing/routes/maps_app/maps_app_view.tsx @@ -26,6 +26,7 @@ import { getGlobalState, updateGlobalState, startGlobalStateSyncing, + MapsGlobalState, } from '../../state_syncing/global_sync'; import { AppStateManager } from '../../state_syncing/app_state_manager'; import { startAppStateSyncing } from '../../state_syncing/app_sync'; @@ -103,7 +104,7 @@ export class MapsAppView extends React.Component { _appSyncUnsubscribe: (() => void) | null = null; _appStateManager = new AppStateManager(); _prevIndexPatternIds: string[] | null = null; - _isMounted?: boolean; + _isMounted: boolean = false; constructor(props: Props) { super(props); @@ -246,7 +247,7 @@ export class MapsAppView extends React.Component { }); // sync globalState - const updatedGlobalState: { filters: Filter[]; time?: TimeRange } = { + const updatedGlobalState: MapsGlobalState = { filters: filterManager.getGlobalFilters(), }; if (time) { @@ -406,29 +407,15 @@ export class MapsAppView extends React.Component { forceRefresh: true, }); }} - onFiltersUpdated={this._onFiltersChange} dateRangeFrom={this.props.timeFilters.from} dateRangeTo={this.props.timeFilters.to} isRefreshPaused={this.props.refreshConfig.isPaused} refreshInterval={this.props.refreshConfig.interval} - onRefreshChange={({ - isPaused, - refreshInterval, - }: { - isPaused: boolean; - refreshInterval: number; - }) => { - this._onRefreshConfigChange({ - isPaused, - interval: refreshInterval, - }); - }} showSearchBar={true} showFilterBar={true} showDatePicker={true} - // @ts-ignore - showSaveQuery={getMapsCapabilities().saveQuery} - savedQuery={this.state.savedQuery as SavedQuery} + showSaveQuery={!!getMapsCapabilities().saveQuery} + savedQuery={this.state.savedQuery} onSaved={this._updateStateFromSavedQuery} onSavedQueryUpdated={this._updateStateFromSavedQuery} onClearSavedQuery={() => { diff --git a/x-pack/plugins/maps/public/routing/state_syncing/app_state_manager.ts b/x-pack/plugins/maps/public/routing/state_syncing/app_state_manager.ts index e5e7e28330cbc..0c37a824255c7 100644 --- a/x-pack/plugins/maps/public/routing/state_syncing/app_state_manager.ts +++ b/x-pack/plugins/maps/public/routing/state_syncing/app_state_manager.ts @@ -46,7 +46,7 @@ export class AppStateManager { getAppState() { return { query: this._query, - savedQuery: this._savedQueryId, + savedQueryId: this._savedQueryId, filters: this._filters, }; } diff --git a/x-pack/plugins/maps/public/routing/state_syncing/global_sync.ts b/x-pack/plugins/maps/public/routing/state_syncing/global_sync.ts index ed6090afca3cd..1e779831c5e0c 100644 --- a/x-pack/plugins/maps/public/routing/state_syncing/global_sync.ts +++ b/x-pack/plugins/maps/public/routing/state_syncing/global_sync.ts @@ -3,21 +3,27 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -import { QueryState } from 'src/plugins/data/public'; +import { TimeRange, RefreshInterval, Filter } from 'src/plugins/data/public'; import { syncQueryStateWithUrl } from '../../../../../../src/plugins/data/public'; import { getData } from '../../kibana_services'; import { kbnUrlStateStorage } from '../maps_router'; +export interface MapsGlobalState { + time?: TimeRange; + refreshInterval?: RefreshInterval; + filters?: Filter[]; +} + export function startGlobalStateSyncing() { const { stop } = syncQueryStateWithUrl(getData().query, kbnUrlStateStorage); return stop; } -export function getGlobalState(): QueryState { - return kbnUrlStateStorage.get('_g') as QueryState; +export function getGlobalState(): MapsGlobalState { + return kbnUrlStateStorage.get('_g') as MapsGlobalState; } -export function updateGlobalState(newState: QueryState, flushUrlState = false) { +export function updateGlobalState(newState: MapsGlobalState, flushUrlState = false) { const globalState = getGlobalState(); kbnUrlStateStorage.set('_g', { ...globalState, From 6836aecd173f4b121053ae9a9fafa8edcf27dc7e Mon Sep 17 00:00:00 2001 From: Shamin Date: Tue, 8 Sep 2020 18:55:42 +0530 Subject: [PATCH 08/11] Added back some removed props --- .../navigation/public/top_nav_menu/top_nav_menu.tsx | 4 +++- .../routing/routes/maps_app/maps_app_view.tsx | 13 +++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/plugins/navigation/public/top_nav_menu/top_nav_menu.tsx b/src/plugins/navigation/public/top_nav_menu/top_nav_menu.tsx index a1a40b49cc8f0..4107a61fca551 100644 --- a/src/plugins/navigation/public/top_nav_menu/top_nav_menu.tsx +++ b/src/plugins/navigation/public/top_nav_menu/top_nav_menu.tsx @@ -23,7 +23,7 @@ import classNames from 'classnames'; import { MountPoint } from '../../../../core/public'; import { MountPointPortal } from '../../../kibana_react/public'; -import { StatefulSearchBarProps, DataPublicPluginStart } from '../../../data/public'; +import { StatefulSearchBarProps, DataPublicPluginStart, Filter } from '../../../data/public'; import { TopNavMenuData } from './top_nav_menu_data'; import { TopNavMenuItem } from './top_nav_menu_item'; @@ -55,6 +55,8 @@ export type TopNavMenuProps = StatefulSearchBarProps & { * ``` */ setMenuMountPoint?: (menuMount: MountPoint | undefined) => void; + onFiltersUpdated?: (filters: Filter[]) => void; + onRefreshChange?: (options: { isPaused: boolean; refreshInterval: number }) => void; }; /* diff --git a/x-pack/plugins/maps/public/routing/routes/maps_app/maps_app_view.tsx b/x-pack/plugins/maps/public/routing/routes/maps_app/maps_app_view.tsx index 1c803123a00ba..677351017c204 100644 --- a/x-pack/plugins/maps/public/routing/routes/maps_app/maps_app_view.tsx +++ b/x-pack/plugins/maps/public/routing/routes/maps_app/maps_app_view.tsx @@ -407,10 +407,23 @@ export class MapsAppView extends React.Component { forceRefresh: true, }); }} + onFiltersUpdated={this._onFiltersChange} dateRangeFrom={this.props.timeFilters.from} dateRangeTo={this.props.timeFilters.to} isRefreshPaused={this.props.refreshConfig.isPaused} refreshInterval={this.props.refreshConfig.interval} + onRefreshChange={({ + isPaused, + refreshInterval, + }: { + isPaused: boolean; + refreshInterval: number; + }) => { + this._onRefreshConfigChange({ + isPaused, + interval: refreshInterval, + }); + }} showSearchBar={true} showFilterBar={true} showDatePicker={true} From 33fa7b3eea0eebba98ab27a50fca35a8626021fb Mon Sep 17 00:00:00 2001 From: Shamin Date: Tue, 8 Sep 2020 21:18:04 +0530 Subject: [PATCH 09/11] Added types to app state manager --- .../public/top_nav_menu/top_nav_menu.tsx | 67 ++++++++++--------- .../routing/bootstrap/get_initial_query.ts | 5 +- .../state_syncing/app_state_manager.ts | 20 +++--- 3 files changed, 46 insertions(+), 46 deletions(-) diff --git a/src/plugins/navigation/public/top_nav_menu/top_nav_menu.tsx b/src/plugins/navigation/public/top_nav_menu/top_nav_menu.tsx index 4107a61fca551..b284c60bac5de 100644 --- a/src/plugins/navigation/public/top_nav_menu/top_nav_menu.tsx +++ b/src/plugins/navigation/public/top_nav_menu/top_nav_menu.tsx @@ -23,41 +23,44 @@ import classNames from 'classnames'; import { MountPoint } from '../../../../core/public'; import { MountPointPortal } from '../../../kibana_react/public'; -import { StatefulSearchBarProps, DataPublicPluginStart, Filter } 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 ( - * - * - * - * - * ) - * } - * ``` - */ - setMenuMountPoint?: (menuMount: MountPoint | undefined) => void; - onFiltersUpdated?: (filters: Filter[]) => void; - onRefreshChange?: (options: { isPaused: boolean; refreshInterval: number }) => void; -}; +export type TopNavMenuProps = StatefulSearchBarProps & + Omit & { + 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 ( + * + * + * + * + * ) + * } + * ``` + */ + setMenuMountPoint?: (menuMount: MountPoint | undefined) => void; + }; /* * Top Nav Menu is a convenience wrapper component for: diff --git a/x-pack/plugins/maps/public/routing/bootstrap/get_initial_query.ts b/x-pack/plugins/maps/public/routing/bootstrap/get_initial_query.ts index c7143b0fa7010..43293d152dbff 100644 --- a/x-pack/plugins/maps/public/routing/bootstrap/get_initial_query.ts +++ b/x-pack/plugins/maps/public/routing/bootstrap/get_initial_query.ts @@ -5,15 +5,14 @@ */ import { getData } from '../../kibana_services'; +import { MapsAppState } from '../state_syncing/app_state_manager'; export function getInitialQuery({ mapStateJSON, appState = {}, }: { mapStateJSON?: string; - appState: { - query?: string | { [key: string]: any }; - }; + appState: MapsAppState; }) { if (appState.query) { return appState.query; diff --git a/x-pack/plugins/maps/public/routing/state_syncing/app_state_manager.ts b/x-pack/plugins/maps/public/routing/state_syncing/app_state_manager.ts index 0c37a824255c7..122b50f823a95 100644 --- a/x-pack/plugins/maps/public/routing/state_syncing/app_state_manager.ts +++ b/x-pack/plugins/maps/public/routing/state_syncing/app_state_manager.ts @@ -7,22 +7,20 @@ import { Subject } from 'rxjs'; import { Filter, Query } from 'src/plugins/data/public'; +export interface MapsAppState { + query?: Query | null; + savedQueryId?: string; + filters?: Filter[]; +} + export class AppStateManager { - _query: string | { [key: string]: any } = ''; + _query: Query | null = null; _savedQueryId: string = ''; _filters: Filter[] = []; _updated$ = new Subject(); - setQueryAndFilters({ - query, - savedQueryId, - filters, - }: { - query?: Query; - filters?: Filter[]; - savedQueryId?: string; - }) { + setQueryAndFilters({ query, savedQueryId, filters }: MapsAppState) { if (query && this._query !== query) { this._query = query; } @@ -43,7 +41,7 @@ export class AppStateManager { return this._filters; } - getAppState() { + getAppState(): MapsAppState { return { query: this._query, savedQueryId: this._savedQueryId, From c027668e9fd6e5bc62a8fc3a72ca517d3785bddf Mon Sep 17 00:00:00 2001 From: Shamin Date: Wed, 9 Sep 2020 00:55:50 +0530 Subject: [PATCH 10/11] Autogenerated api documentation --- .../kibana-plugin-plugins-data-public.md | 1 + ...data-public.querystatechange.appfilters.md | 11 +++++++++++ ...a-public.querystatechange.globalfilters.md | 11 +++++++++++ ...in-plugins-data-public.querystatechange.md | 19 +++++++++++++++++++ ...in-plugins-data-public.querystringinput.md | 2 +- ...na-plugin-plugins-data-public.searchbar.md | 4 ++-- src/plugins/data/public/public.api.md | 15 +++++++++++++-- 7 files changed, 58 insertions(+), 5 deletions(-) create mode 100644 docs/development/plugins/data/public/kibana-plugin-plugins-data-public.querystatechange.appfilters.md create mode 100644 docs/development/plugins/data/public/kibana-plugin-plugins-data-public.querystatechange.globalfilters.md create mode 100644 docs/development/plugins/data/public/kibana-plugin-plugins-data-public.querystatechange.md diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.md index b651480a85899..0c493ca492953 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.md @@ -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) | \* | diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.querystatechange.appfilters.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.querystatechange.appfilters.md new file mode 100644 index 0000000000000..b358e9477e515 --- /dev/null +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.querystatechange.appfilters.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [QueryStateChange](./kibana-plugin-plugins-data-public.querystatechange.md) > [appFilters](./kibana-plugin-plugins-data-public.querystatechange.appfilters.md) + +## QueryStateChange.appFilters property + +Signature: + +```typescript +appFilters?: boolean; +``` diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.querystatechange.globalfilters.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.querystatechange.globalfilters.md new file mode 100644 index 0000000000000..c395f169c35a5 --- /dev/null +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.querystatechange.globalfilters.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [QueryStateChange](./kibana-plugin-plugins-data-public.querystatechange.md) > [globalFilters](./kibana-plugin-plugins-data-public.querystatechange.globalfilters.md) + +## QueryStateChange.globalFilters property + +Signature: + +```typescript +globalFilters?: boolean; +``` diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.querystatechange.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.querystatechange.md new file mode 100644 index 0000000000000..71fb211da11d2 --- /dev/null +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.querystatechange.md @@ -0,0 +1,19 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [QueryStateChange](./kibana-plugin-plugins-data-public.querystatechange.md) + +## QueryStateChange interface + +Signature: + +```typescript +export interface QueryStateChange extends QueryStateChangePartial +``` + +## Properties + +| Property | Type | Description | +| --- | --- | --- | +| [appFilters](./kibana-plugin-plugins-data-public.querystatechange.appfilters.md) | boolean | | +| [globalFilters](./kibana-plugin-plugins-data-public.querystatechange.globalfilters.md) | boolean | | + diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.querystringinput.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.querystringinput.md index 9f3ed8c1263ba..3dbfd9430e913 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.querystringinput.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.querystringinput.md @@ -7,5 +7,5 @@ Signature: ```typescript -QueryStringInput: React.FC> +QueryStringInput: React.FC> ``` diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.searchbar.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.searchbar.md index 498691c06285d..d1d20291a6799 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.searchbar.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.searchbar.md @@ -7,7 +7,7 @@ Signature: ```typescript -SearchBar: React.ComponentClass, "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 & ReactIntl.InjectedIntlProps>; +SearchBar: React.ComponentClass, "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 & ReactIntl.InjectedIntlProps>; } ``` diff --git a/src/plugins/data/public/public.api.md b/src/plugins/data/public/public.api.md index c2cc2fdc3c134..be86d64ba34ff 100644 --- a/src/plugins/data/public/public.api.md +++ b/src/plugins/data/public/public.api.md @@ -1461,6 +1461,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) // @@ -1678,8 +1689,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, "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 & ReactIntl.InjectedIntlProps>; +export const SearchBar: React.ComponentClass, "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 & ReactIntl.InjectedIntlProps>; }; // Warning: (ae-forgotten-export) The symbol "SearchBarOwnProps" needs to be exported by the entry point index.d.ts From 5e31e4ce9e867dadd7906bd1c6f71efe5cb5bb87 Mon Sep 17 00:00:00 2001 From: Shamin Date: Wed, 9 Sep 2020 01:04:22 +0530 Subject: [PATCH 11/11] Type fixes --- .../maps/public/routing/routes/list/maps_list_view.tsx | 2 +- .../public/routing/routes/maps_app/load_map_and_render.tsx | 4 ++-- .../maps/public/routing/routes/maps_app/maps_app_view.tsx | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/x-pack/plugins/maps/public/routing/routes/list/maps_list_view.tsx b/x-pack/plugins/maps/public/routing/routes/list/maps_list_view.tsx index 2db686d89ead0..d66a0d1b7d0da 100644 --- a/x-pack/plugins/maps/public/routing/routes/list/maps_list_view.tsx +++ b/x-pack/plugins/maps/public/routing/routes/list/maps_list_view.tsx @@ -164,7 +164,7 @@ export class MapsListView extends React.Component { }; onTableChange = ({ page, sort }: CriteriaWithPagination) => { - const { index: pageIndex, size: pageSize } = page!; + const { index: pageIndex, size: pageSize } = page; let { field: sortField, direction: sortDirection } = sort || {}; diff --git a/x-pack/plugins/maps/public/routing/routes/maps_app/load_map_and_render.tsx b/x-pack/plugins/maps/public/routing/routes/maps_app/load_map_and_render.tsx index 2f663c8c2d725..7ab138300dc4c 100644 --- a/x-pack/plugins/maps/public/routing/routes/maps_app/load_map_and_render.tsx +++ b/x-pack/plugins/maps/public/routing/routes/maps_app/load_map_and_render.tsx @@ -28,7 +28,7 @@ interface State { export const LoadMapAndRender = class extends React.Component { _isMounted: boolean = false; - state = { + state: State = { savedMap: undefined, failedToLoad: false, }; @@ -74,7 +74,7 @@ export const LoadMapAndRender = class extends React.Component { return savedMap ? ( { }; _initMapAndLayerSettings() { - const globalState: QueryState = getGlobalState(); + const globalState: MapsGlobalState = getGlobalState(); const mapStateJSON = this.props.savedMap.mapStateJSON; let savedObjectFilters = [];