-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:elastic/kibana into fix.apm.links
- Loading branch information
Showing
36 changed files
with
938 additions
and
594 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 0 additions & 38 deletions
38
x-pack/plugins/canvas/public/components/function_form/function_form.js
This file was deleted.
Oops, something went wrong.
60 changes: 60 additions & 0 deletions
60
x-pack/plugins/canvas/public/components/function_form/function_form.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { FunctionFormComponent } from './function_form_component'; | ||
import { FunctionUnknown } from './function_unknown'; | ||
import { FunctionFormContextPending } from './function_form_context_pending'; | ||
import { FunctionFormContextError } from './function_form_context_error'; | ||
import { ExpressionContext } from '../../../types'; | ||
import { RenderArgData, ExpressionType } from '../../expression_types/types'; | ||
|
||
type FunctionFormProps = RenderArgData; | ||
|
||
// helper to check the state of the passed in expression type | ||
function is( | ||
state: ExpressionContext['state'], | ||
expressionType: ExpressionType, | ||
context?: ExpressionContext | ||
) { | ||
const matchState = !context || context.state === state; | ||
return expressionType && expressionType.requiresContext && matchState; | ||
} | ||
|
||
export const FunctionForm: React.FunctionComponent<FunctionFormProps> = (props) => { | ||
const { expressionType, context } = props; | ||
|
||
if (!expressionType) { | ||
return <FunctionUnknown argType={props.argType} />; | ||
} | ||
|
||
if (is('pending', expressionType, context)) { | ||
return ( | ||
<FunctionFormContextPending | ||
context={props.context} | ||
expressionType={props.expressionType} | ||
updateContext={props.updateContext} | ||
/> | ||
); | ||
} | ||
|
||
if (is('error', expressionType, context)) { | ||
return ( | ||
<FunctionFormContextError | ||
context={ | ||
context ?? { | ||
state: 'error', | ||
error: 'Error occured', | ||
value: expressionType, | ||
} | ||
} | ||
/> | ||
); | ||
} | ||
|
||
return <FunctionFormComponent {...props} />; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 0 additions & 46 deletions
46
x-pack/plugins/canvas/public/components/function_form/function_form_context_pending.js
This file was deleted.
Oops, something went wrong.
47 changes: 47 additions & 0 deletions
47
x-pack/plugins/canvas/public/components/function_form/function_form_context_pending.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React, { useCallback, useEffect } from 'react'; | ||
import usePrevious from 'react-use/lib/usePrevious'; | ||
import { Loading } from '../loading'; | ||
import { CanvasElement, ExpressionContext } from '../../../types'; | ||
import { ExpressionType } from '../../expression_types/types'; | ||
|
||
interface FunctionFormContextPendingProps { | ||
context?: ExpressionContext; | ||
contextExpression?: string; | ||
expressionType: ExpressionType; | ||
updateContext: (element?: CanvasElement) => void; | ||
} | ||
|
||
export const FunctionFormContextPending: React.FunctionComponent<FunctionFormContextPendingProps> = ( | ||
props | ||
) => { | ||
const { contextExpression, expressionType, context, updateContext } = props; | ||
const prevContextExpression = usePrevious(contextExpression); | ||
const fetchContext = useCallback( | ||
(force = false) => { | ||
// dispatch context update if none is provided | ||
if (force || (context == null && expressionType.requiresContext)) { | ||
updateContext(); | ||
} | ||
}, | ||
[context, expressionType.requiresContext, updateContext] | ||
); | ||
|
||
useEffect(() => { | ||
const forceUpdate = | ||
expressionType.requiresContext && prevContextExpression !== contextExpression; | ||
fetchContext(forceUpdate); | ||
}, [contextExpression, expressionType, fetchContext, prevContextExpression]); | ||
|
||
return ( | ||
<div className="canvasFunctionForm canvasFunctionForm--loading"> | ||
<Loading /> | ||
</div> | ||
); | ||
}; |
Oops, something went wrong.