Skip to content

Commit

Permalink
[7.x] [Logs UI] Remove apollo deps from log link-to routes (#74502) (#…
Browse files Browse the repository at this point in the history
…75071)

Backports the following commits to 7.x:
 - [Logs UI] Remove apollo deps from log link-to routes (#74502)
  • Loading branch information
weltenwort authored Aug 17, 2020
1 parent d35ffbb commit 3fcedaa
Show file tree
Hide file tree
Showing 11 changed files with 453 additions and 147 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
8 changes: 6 additions & 2 deletions x-pack/plugins/infra/public/components/loading_page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@ import { FlexPage } from './page';

interface LoadingPageProps {
message?: ReactNode;
'data-test-subj'?: string;
}

export const LoadingPage = ({ message }: LoadingPageProps) => (
<FlexPage>
export const LoadingPage = ({
message,
'data-test-subj': dataTestSubj = 'loadingPage',
}: LoadingPageProps) => (
<FlexPage data-test-subj={dataTestSubj}>
<EuiPageBody>
<EuiPageContent verticalPosition="center" horizontalPosition="center">
<EuiFlexGroup alignItems="center">
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/infra/public/components/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ export const PageContent = euiStyled.div`
`;

export const FlexPage = euiStyled(EuiPage)`
align-self: stretch;
flex: 1 0 0%;
`;
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { LoadingPage } from './loading_page';

export const SourceLoadingPage: React.FunctionComponent = () => (
<LoadingPage
data-test-subj="sourceLoadingPage"
message={
<FormattedMessage
id="xpack.infra.sourceLoadingPage.loadingDataSourcesMessage"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* 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 { LogSourceConfiguration, LogSourceStatus, useLogSource } from './log_source';

type CreateUseLogSource = (sourceConfiguration?: { sourceId?: string }) => typeof useLogSource;

const defaultSourceId = 'default';

export const createUninitializedUseLogSourceMock: CreateUseLogSource = ({
sourceId = defaultSourceId,
} = {}) => () => ({
derivedIndexPattern: {
fields: [],
title: 'unknown',
},
hasFailedLoadingSource: false,
hasFailedLoadingSourceStatus: false,
initialize: jest.fn(),
isLoading: false,
isLoadingSourceConfiguration: false,
isLoadingSourceStatus: false,
isUninitialized: true,
loadSource: jest.fn(),
loadSourceConfiguration: jest.fn(),
loadSourceFailureMessage: undefined,
loadSourceStatus: jest.fn(),
sourceConfiguration: undefined,
sourceId,
sourceStatus: undefined,
updateSourceConfiguration: jest.fn(),
});

export const createLoadingUseLogSourceMock: CreateUseLogSource = ({
sourceId = defaultSourceId,
} = {}) => (args) => ({
...createUninitializedUseLogSourceMock({ sourceId })(args),
isLoading: true,
isLoadingSourceConfiguration: true,
isLoadingSourceStatus: true,
});

export const createLoadedUseLogSourceMock: CreateUseLogSource = ({
sourceId = defaultSourceId,
} = {}) => (args) => ({
...createUninitializedUseLogSourceMock({ sourceId })(args),
sourceConfiguration: createBasicSourceConfiguration(sourceId),
sourceStatus: {
logIndexFields: [],
logIndexStatus: 'available',
},
});

export const createBasicSourceConfiguration = (sourceId: string): LogSourceConfiguration => ({
id: sourceId,
origin: 'stored',
configuration: {
description: `description for ${sourceId}`,
logAlias: 'LOG_INDICES',
logColumns: [],
fields: {
container: 'CONTAINER_FIELD',
host: 'HOST_FIELD',
pod: 'POD_FIELD',
tiebreaker: 'TIEBREAKER_FIELD',
timestamp: 'TIMESTAMP_FIELD',
},
name: sourceId,
},
});

export const createAvailableSourceStatus = (logIndexFields = []): LogSourceStatus => ({
logIndexFields,
logIndexStatus: 'available',
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
*/

import createContainer from 'constate';
import { useState, useMemo, useCallback } from 'react';
import { useCallback, useMemo, useState } from 'react';
import { useMountedState } from 'react-use';
import { HttpSetup } from 'src/core/public';
import {
LogSourceConfiguration,
LogSourceStatus,
LogSourceConfigurationPropertiesPatch,
LogSourceConfigurationProperties,
LogSourceConfigurationPropertiesPatch,
LogSourceStatus,
} from '../../../../common/http_api/log_sources';
import { useTrackedPromise } from '../../../utils/use_tracked_promise';
import { callFetchLogSourceConfigurationAPI } from './api/fetch_log_source_configuration';
Expand All @@ -32,6 +33,7 @@ export const useLogSource = ({
sourceId: string;
fetch: HttpSetup['fetch'];
}) => {
const getIsMounted = useMountedState();
const [sourceConfiguration, setSourceConfiguration] = useState<
LogSourceConfiguration | undefined
>(undefined);
Expand All @@ -45,6 +47,10 @@ export const useLogSource = ({
return await callFetchLogSourceConfigurationAPI(sourceId, fetch);
},
onResolve: ({ data }) => {
if (!getIsMounted()) {
return;
}

setSourceConfiguration(data);
},
},
Expand All @@ -58,6 +64,10 @@ export const useLogSource = ({
return await callPatchLogSourceConfigurationAPI(sourceId, patchedProperties, fetch);
},
onResolve: ({ data }) => {
if (!getIsMounted()) {
return;
}

setSourceConfiguration(data);
loadSourceStatus();
},
Expand All @@ -72,6 +82,10 @@ export const useLogSource = ({
return await callFetchLogSourceStatusAPI(sourceId, fetch);
},
onResolve: ({ data }) => {
if (!getIsMounted()) {
return;
}

setSourceStatus(data);
},
},
Expand Down
Loading

0 comments on commit 3fcedaa

Please sign in to comment.