Skip to content

Commit

Permalink
Improve DiscoverIndexPattern code
Browse files Browse the repository at this point in the history
  • Loading branch information
kertal committed Jan 9, 2020
1 parent cf1fb60 commit 551f751
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,6 @@ export interface DiscoverIndexPatternProps {
setIndexPattern: (id: string) => void;
}

/**
* At initial rendering the angular directive the selectedIndexPattern prop is undefined
* this wrapper component should be removed once all is deangularized
*/
export function DiscoverIndexPatternWrapper(props: DiscoverIndexPatternProps) {
if (!props.selectedIndexPattern || !Array.isArray(props.indexPatternList)) {
return null;
}
return <DiscoverIndexPattern {...props} />;
}

/**
* Component allows you to select an index pattern in discovers side bar
*/
Expand All @@ -60,12 +49,15 @@ export function DiscoverIndexPattern({
id: entity.id,
title: entity.attributes!.title,
}));
const { id: selectedId, attributes } = selectedIndexPattern;
const { id: selectedId, attributes } = selectedIndexPattern || {};

const [selected, setSelected] = useState({
id: selectedId,
title: attributes ? attributes.title : '',
});
if (!selectedId) {
return null;
}

return (
<div className="indexPattern__container">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,20 @@
* specific language governing permissions and limitations
* under the License.
*/
import React from 'react';
import { wrapInI18nContext } from '../../../kibana_services';
import { DiscoverIndexPatternWrapper } from './discover_index_pattern';
import { DiscoverIndexPattern, DiscoverIndexPatternProps } from './discover_index_pattern';

/**
* At initial rendering the angular directive the selectedIndexPattern prop is undefined
* This wrapper catches this, had to be introduced to satisfy eslint
*/
export function DiscoverIndexPatternWrapper(props: DiscoverIndexPatternProps) {
if (!props.selectedIndexPattern || !Array.isArray(props.indexPatternList)) {
return null;
}
return <DiscoverIndexPattern {...props} />;
}

export function createIndexPatternSelectDirective(reactDirective: any) {
return reactDirective(wrapInI18nContext(DiscoverIndexPatternWrapper), [
Expand Down

0 comments on commit 551f751

Please sign in to comment.