Skip to content

Commit

Permalink
Replace old source hook with new hook in link-to
Browse files Browse the repository at this point in the history
  • Loading branch information
weltenwort committed Aug 6, 2020
1 parent 13fd9e3 commit a541efe
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ export const logSourceConfigurationOriginRT = rt.keyof({
export type LogSourceConfigurationOrigin = rt.TypeOf<typeof logSourceConfigurationOriginRT>;

const logSourceFieldsConfigurationRT = rt.strict({
container: rt.string,
host: rt.string,
pod: rt.string,
timestamp: rt.string,
tiebreaker: rt.string,
});
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/infra/common/inventory_models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export const findInventoryModel = (type: InventoryItemType) => {
};

interface InventoryFields {
message: string[];
host: string;
pod: string;
container: string;
Expand Down
41 changes: 19 additions & 22 deletions x-pack/plugins/infra/public/pages/link_to/redirect_to_node_logs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,43 @@
*/

import { i18n } from '@kbn/i18n';

import { flowRight } from 'lodash';
import flowRight from 'lodash/flowRight';
import React from 'react';
import { Redirect, RouteComponentProps } from 'react-router-dom';

import { useMount } from 'react-use';
import { useKibana } from '../../../../../../src/plugins/kibana_react/public';
import { findInventoryFields } from '../../../common/inventory_models';
import { InventoryItemType } from '../../../common/inventory_models/types';
import { LoadingPage } from '../../components/loading_page';
import { replaceLogFilterInQueryString } from '../../containers/logs/log_filter';
import { replaceLogPositionInQueryString } from '../../containers/logs/log_position';
import { useLogSource } from '../../containers/logs/log_source';
import { replaceSourceIdInQueryString } from '../../containers/source_id';
import { SourceConfigurationFields } from '../../graphql/types';
import { getFilterFromLocation, getTimeFromLocation } from './query_params';
import { useSource } from '../../containers/source/source';
import { findInventoryFields } from '../../../common/inventory_models';
import { InventoryItemType } from '../../../common/inventory_models/types';
import { LinkDescriptor } from '../../hooks/use_link_props';
import { getFilterFromLocation, getTimeFromLocation } from './query_params';

type RedirectToNodeLogsType = RouteComponentProps<{
nodeId: string;
nodeType: InventoryItemType;
sourceId?: string;
}>;

const getFieldByNodeType = (
nodeType: InventoryItemType,
fields: SourceConfigurationFields.Fields
) => {
const inventoryFields = findInventoryFields(nodeType, fields);
return inventoryFields.id;
};

export const RedirectToNodeLogs = ({
match: {
params: { nodeId, nodeType, sourceId = 'default' },
},
location,
}: RedirectToNodeLogsType) => {
const { source, isLoading } = useSource({ sourceId });
const configuration = source && source.configuration;
const { services } = useKibana();
const { isLoading, loadSourceConfiguration, sourceConfiguration } = useLogSource({
fetch: services.http.fetch,
sourceId,
});
const fields = sourceConfiguration?.configuration.fields;

useMount(() => {
loadSourceConfiguration();
});

if (isLoading) {
return (
Expand All @@ -55,13 +54,11 @@ export const RedirectToNodeLogs = ({
})}
/>
);
}

if (!configuration) {
} else if (fields == null) {
return null;
}

const nodeFilter = `${getFieldByNodeType(nodeType, configuration.fields)}: ${nodeId}`;
const nodeFilter = `${findInventoryFields(nodeType, fields).id}: ${nodeId}`;
const userFilter = getFilterFromLocation(location);
const filter = userFilter ? `(${nodeFilter}) and (${userFilter})` : nodeFilter;

Expand Down

0 comments on commit a541efe

Please sign in to comment.