Skip to content

Commit

Permalink
fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
walterra committed Apr 18, 2023
1 parent 01458a8 commit 6fee2b8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
9 changes: 8 additions & 1 deletion x-pack/plugins/aiops/public/application/utils/url_state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';

import type { Filter, Query } from '@kbn/es-query';
import { isPopulatedObject } from '@kbn/ml-is-populated-object';

import { SEARCH_QUERY_LANGUAGE, SearchQueryLanguage } from './search_utils';

Expand All @@ -27,12 +28,18 @@ export interface AiOpsIndexBasedAppState {
filters?: Filter[];
}

export type AiOpsFullIndexBasedAppState = Required<AiOpsIndexBasedAppState>;

export const getDefaultAiOpsListState = (
overrides?: Partial<AiOpsIndexBasedAppState>
): Required<AiOpsIndexBasedAppState> => ({
): AiOpsFullIndexBasedAppState => ({
searchString: '',
searchQuery: defaultSearchQuery,
searchQueryLanguage: SEARCH_QUERY_LANGUAGE.KUERY,
filters: [],
...overrides,
});

export const isFullAiOpsListState = (arg: unknown): arg is AiOpsFullIndexBasedAppState => {
return isPopulatedObject(arg, Object.keys(getDefaultAiOpsListState()));
};
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
import { useDiscoverLinks } from '../use_discover_links';
import { MiniHistogram } from '../../mini_histogram';
import { useEuiTheme } from '../../../hooks/use_eui_theme';
import type { AiOpsIndexBasedAppState } from '../../../application/utils/url_state';
import type { AiOpsFullIndexBasedAppState } from '../../../application/utils/url_state';
import type { EventRate, Category, SparkLinesPerCategory } from '../use_categorize_request';
import { useTableState } from './use_table_state';

Expand All @@ -42,7 +42,7 @@ interface Props {
dataViewId: string;
selectedField: string | undefined;
timefilter: TimefilterContract;
aiopsListState: Required<AiOpsIndexBasedAppState>;
aiopsListState: AiOpsFullIndexBasedAppState;
pinnedCategory: Category | null;
setPinnedCategory: (category: Category | null) => void;
selectedCategory: Category | null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import type { SearchQueryLanguage } from '../../application/utils/search_utils';
import { useAiopsAppContext } from '../../hooks/use_aiops_app_context';
import {
getDefaultAiOpsListState,
isFullAiOpsListState,
type AiOpsPageUrlState,
} from '../../application/utils/url_state';

Expand Down Expand Up @@ -296,7 +297,10 @@ export const LogCategorizationPage: FC = () => {
fieldSelected={selectedField !== null}
/>

{selectedField !== undefined && categories !== null && categories.length > 0 ? (
{selectedField !== undefined &&
categories !== null &&
categories.length > 0 &&
isFullAiOpsListState(aiopsListState) ? (
<CategoryTable
categories={categories}
aiopsListState={aiopsListState}
Expand Down

0 comments on commit 6fee2b8

Please sign in to comment.