Skip to content

Commit

Permalink
TypeScriptify visualize loader (#21025)
Browse files Browse the repository at this point in the history
* TypeScriptify Vis loaders

* Fix issue with undefined timeRange

* Fix chrome typing

* Fix unit tests

* Fix this issue

* Add missing uiState to request handler

* Implement Felix's suggestions

* Add timefilter listener
  • Loading branch information
timroes committed Jul 25, 2018
1 parent 716d6e2 commit 967cb4e
Show file tree
Hide file tree
Showing 37 changed files with 1,150 additions and 502 deletions.
Expand Up @@ -571,7 +571,7 @@ function discoverController(
.then(resp => {
$scope.visData = resp;
const visEl = $element.find('#discoverHistogram')[0];
visualizationLoader(visEl, $scope.vis, $scope.visData, $scope.uiState, { listenOnChange: true });
visualizationLoader.render(visEl, $scope.vis, $scope.visData, $scope.uiState, { listenOnChange: true });
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/ui/public/agg_types/buckets/date_histogram.js
Expand Up @@ -42,7 +42,7 @@ function getInterval(agg) {
}

function getBounds(vis) {
if (vis.API.timeFilter.isTimeRangeSelectorEnabled && vis.filters) {
if (vis.API.timeFilter.isTimeRangeSelectorEnabled && vis.filters && vis.filters.timeRange) {
return vis.API.timeFilter.calculateBounds(vis.filters.timeRange);
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/ui/public/chrome/index.d.ts
Expand Up @@ -17,8 +17,13 @@
* under the License.
*/

interface IInjector {
get<T>(injectable: string): T;
}

declare class Chrome {
public addBasePath<T = string>(path: T): T;
public dangerouslyGetActiveInjector(): Promise<IInjector>;
public getBasePath(): string;
public getXsrfToken(): string;
}
Expand Down
20 changes: 20 additions & 0 deletions src/ui/public/courier/index.d.ts
@@ -0,0 +1,20 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

export * from './search_source';
20 changes: 20 additions & 0 deletions src/ui/public/courier/search_source/index.d.ts
@@ -0,0 +1,20 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

export { SearchSource } from './search_source';
20 changes: 20 additions & 0 deletions src/ui/public/courier/search_source/search_source.d.ts
@@ -0,0 +1,20 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

export type SearchSource = any;
22 changes: 22 additions & 0 deletions src/ui/public/filter_bar/query_filter.d.ts
@@ -0,0 +1,22 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

export type QueryFilter = any;

export const FilterBarQueryFilterProvider: () => QueryFilter;
20 changes: 20 additions & 0 deletions src/ui/public/notify/index.d.ts
@@ -0,0 +1,20 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

export { toastNotifications, ToastNotifications } from './toasts';
20 changes: 20 additions & 0 deletions src/ui/public/notify/toasts/index.d.ts
@@ -0,0 +1,20 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

export { toastNotifications, ToastNotifications } from './toast_notifications';
41 changes: 41 additions & 0 deletions src/ui/public/notify/toasts/toast_notifications.d.ts
@@ -0,0 +1,41 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

interface Toast extends ToastDescription {
id: number;
}

interface ToastDescription {
title: string;
color?: string;
iconType?: string;
text?: string;
'data-test-subj'?: string;
}

export interface ToastNotifications {
onChange(changeCallback: () => void): void;
remove(toast: Toast): void;
add(toast: ToastDescription | string): Toast;
addSuccess(toast: ToastDescription | string): Toast;
addWarning(toast: ToastDescription | string): Toast;
addDanger(toast: ToastDescription | string): Toast;
}

export const toastNotifications: ToastNotifications;
20 changes: 20 additions & 0 deletions src/ui/public/private/index.d.ts
@@ -0,0 +1,20 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

export { IPrivate } from './private';
20 changes: 20 additions & 0 deletions src/ui/public/private/private.d.ts
@@ -0,0 +1,20 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

export type IPrivate = <T>(provider: (...injectable: any[]) => T) => T;
20 changes: 20 additions & 0 deletions src/ui/public/registry/vis_request_handlers.d.ts
@@ -0,0 +1,20 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

export const VisRequestHandlersRegistryProvider: () => any;
20 changes: 20 additions & 0 deletions src/ui/public/registry/vis_response_handlers.d.ts
@@ -0,0 +1,20 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

export const VisResponseHandlersRegistryProvider: () => any;
Expand Up @@ -17,4 +17,4 @@
* under the License.
*/

export * from './loader';
export type AppState = any;
20 changes: 20 additions & 0 deletions src/ui/public/timefilter/index.d.ts
@@ -0,0 +1,20 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

export { timefilter, Timefilter } from './timefilter';
21 changes: 21 additions & 0 deletions src/ui/public/timefilter/timefilter.d.ts
@@ -0,0 +1,21 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

export type Timefilter = any;
export const timefilter: Timefilter;
20 changes: 20 additions & 0 deletions src/ui/public/vis/agg_configs.d.ts
@@ -0,0 +1,20 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

export type AggConfigs = any;
2 changes: 2 additions & 0 deletions src/ui/public/vis/index.d.ts
Expand Up @@ -20,3 +20,5 @@
export { AggConfig } from './agg_config';
export { Vis, VisProvider } from './vis';
export { VisualizationController, VisType } from './vis_types/vis_type';
export * from './request_handlers';
export * from './response_handlers';
8 changes: 5 additions & 3 deletions src/ui/public/vis/request_handlers/courier.js
Expand Up @@ -104,9 +104,11 @@ const CourierRequestHandlerProvider = function () {
return aggs.onSearchRequestStart(searchSource, searchRequest);
});

timeFilterSearchSource.setField('filter', () => {
return getTime(searchSource.getField('index'), timeRange);
});
if (timeRange) {
timeFilterSearchSource.setField('filter', () => {
return getTime(searchSource.getField('index'), timeRange);
});
}

requestSearchSource.setField('filter', filters);
requestSearchSource.setField('query', query);
Expand Down

0 comments on commit 967cb4e

Please sign in to comment.