mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
Backports the following commits to 6.x: - Remove usage of ts-optchain in the browser (#27148)
This commit is contained in:
parent
ae37523a54
commit
031759a497
2 changed files with 39 additions and 15 deletions
|
@ -9,7 +9,6 @@ import { Container as ConstateContainer, OnMount } from 'constate';
|
|||
import React from 'react';
|
||||
import { ApolloConsumer } from 'react-apollo';
|
||||
import { createSelector } from 'reselect';
|
||||
import { oc } from 'ts-optchain';
|
||||
|
||||
import { StaticIndexPattern } from 'ui/index_patterns';
|
||||
import { memoizeLast } from 'ui/utils/memoize';
|
||||
|
@ -46,9 +45,20 @@ const createContainerProps = memoizeLast((sourceId: string, apolloClient: Apollo
|
|||
});
|
||||
|
||||
const getDerivedIndexPattern = createSelector(
|
||||
(state: State) => oc(state).source.status.indexFields([]),
|
||||
(state: State) => oc(state).source.configuration.logAlias(),
|
||||
(state: State) => oc(state).source.configuration.metricAlias(),
|
||||
(state: State) =>
|
||||
(state && state.source && state.source.status && state.source.status.indexFields) || [],
|
||||
(state: State) =>
|
||||
(state &&
|
||||
state.source &&
|
||||
state.source.configuration &&
|
||||
state.source.configuration.logAlias) ||
|
||||
undefined,
|
||||
(state: State) =>
|
||||
(state &&
|
||||
state.source &&
|
||||
state.source.configuration &&
|
||||
state.source.configuration.metricAlias) ||
|
||||
undefined,
|
||||
(indexFields, logAlias, metricAlias) => ({
|
||||
fields: indexFields,
|
||||
title: `${logAlias},${metricAlias}`,
|
||||
|
@ -57,9 +67,15 @@ const createContainerProps = memoizeLast((sourceId: string, apolloClient: Apollo
|
|||
|
||||
const selectors = inferSelectorMap<State>()({
|
||||
...createStatusSelectors(({ operationStatusHistory }: State) => operationStatusHistory),
|
||||
getConfiguredFields: () => state => oc(state).source.configuration.fields(),
|
||||
getLogIndicesExist: () => state => oc(state).source.status.logIndicesExist(),
|
||||
getMetricIndicesExist: () => state => oc(state).source.status.metricIndicesExist(),
|
||||
getConfiguredFields: () => state =>
|
||||
(state && state.source && state.source.configuration && state.source.configuration.fields) ||
|
||||
undefined,
|
||||
getLogIndicesExist: () => state =>
|
||||
(state && state.source && state.source.status && state.source.status.logIndicesExist) ||
|
||||
undefined,
|
||||
getMetricIndicesExist: () => state =>
|
||||
(state && state.source && state.source.status && state.source.status.metricIndicesExist) ||
|
||||
undefined,
|
||||
getDerivedIndexPattern: () => getDerivedIndexPattern,
|
||||
});
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
*/
|
||||
|
||||
import last from 'lodash/fp/last';
|
||||
import { oc } from 'ts-optchain';
|
||||
|
||||
export interface InProgressStatus<O extends Operation<string, any>> {
|
||||
operation: O;
|
||||
|
@ -43,13 +42,22 @@ export interface Operation<Name extends string, Parameters> {
|
|||
export const createStatusSelectors = <S extends {}>(
|
||||
selectStatusHistory: (state: S) => Array<OperationStatus<any>>
|
||||
) => ({
|
||||
getIsInProgress: () => (state: S) =>
|
||||
oc(last(selectStatusHistory(state))).status() === 'in-progress',
|
||||
getHasSucceeded: () => (state: S) =>
|
||||
oc(last(selectStatusHistory(state))).status() === 'succeeded',
|
||||
getHasFailed: () => (state: S) => oc(last(selectStatusHistory(state))).status() === 'failed',
|
||||
getLastFailureMessage: () => (state: S) =>
|
||||
oc(last(selectStatusHistory(state).filter(isFailedStatus))).message(),
|
||||
getIsInProgress: () => (state: S) => {
|
||||
const lastStatus = last(selectStatusHistory(state));
|
||||
return lastStatus ? lastStatus.status === 'in-progress' : false;
|
||||
},
|
||||
getHasSucceeded: () => (state: S) => {
|
||||
const lastStatus = last(selectStatusHistory(state));
|
||||
return lastStatus ? lastStatus.status === 'succeeded' : false;
|
||||
},
|
||||
getHasFailed: () => (state: S) => {
|
||||
const lastStatus = last(selectStatusHistory(state));
|
||||
return lastStatus ? lastStatus.status === 'failed' : false;
|
||||
},
|
||||
getLastFailureMessage: () => (state: S) => {
|
||||
const lastStatus = last(selectStatusHistory(state).filter(isFailedStatus));
|
||||
return lastStatus ? lastStatus.message : undefined;
|
||||
},
|
||||
});
|
||||
|
||||
export type StatusHistoryUpdater<Operations extends Operation<string, any>> = (
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue