-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updates existing embeddable with updates on edit Select incoming embeddable element on load Fixed ts errors Added use incoming embeddable hook Fixed eslint errors Added comment Fixed typo
- Loading branch information
Showing
18 changed files
with
184 additions
and
41 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
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
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
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
63 changes: 63 additions & 0 deletions
63
x-pack/plugins/canvas/public/components/hooks/workpad/use_incoming_embeddable.ts
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,63 @@ | ||
/* | ||
* 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 { useEffect } from 'react'; | ||
import { useDispatch } from 'react-redux'; | ||
import { CANVAS_APP } from '../../../../common/lib'; | ||
import { encode } from '../../../../common/lib/embeddable_dataurl'; | ||
import { useEmbeddablesService, useLabsService } from '../../../services'; | ||
// @ts-expect-error unconverted file | ||
import { addElement } from '../../../state/actions/elements'; | ||
// @ts-expect-error unconverted file | ||
import { selectToplevelNodes } from '../../../state/actions/transient'; | ||
|
||
import { | ||
updateEmbeddableExpression, | ||
fetchEmbeddableRenderable, | ||
} from '../../../state/actions/embeddable'; | ||
import { clearValue } from '../../../state/actions/resolved_args'; | ||
|
||
export const useIncomingEmbeddable = (pageId: string) => { | ||
const embeddablesService = useEmbeddablesService(); | ||
const labsService = useLabsService(); | ||
const dispatch = useDispatch(); | ||
const isByValueEnabled = labsService.isProjectEnabled('labs:canvas:byValueEmbeddable'); | ||
const stateTransferService = embeddablesService.getStateTransfer(); | ||
|
||
// fetch incoming embeddable from state transfer service. | ||
const incomingEmbeddable = stateTransferService.getIncomingEmbeddablePackage(CANVAS_APP, true); | ||
|
||
useEffect(() => { | ||
if (isByValueEnabled && incomingEmbeddable) { | ||
const { embeddableId, input, type } = incomingEmbeddable; | ||
|
||
const config = encode(input); | ||
const expression = `embeddable config="${config}" | ||
type="${type}" | ||
| render`; | ||
|
||
if (embeddableId) { | ||
// clear out resolved arg for old embeddable | ||
const argumentPath = [embeddableId, 'expressionRenderable']; | ||
dispatch(clearValue({ path: argumentPath })); | ||
|
||
// update existing embeddable expression | ||
dispatch( | ||
updateEmbeddableExpression({ elementId: embeddableId, embeddableExpression: expression }) | ||
); | ||
|
||
// update resolved args | ||
dispatch(fetchEmbeddableRenderable(embeddableId)); | ||
|
||
// select new embeddable element | ||
dispatch(selectToplevelNodes([embeddableId])); | ||
} else { | ||
dispatch(addElement(pageId, { expression })); | ||
} | ||
} | ||
}, [dispatch, pageId, incomingEmbeddable, isByValueEnabled]); | ||
}; |
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
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
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
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
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,16 @@ | ||
/* | ||
* 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 { TimeRange } from 'src/plugins/data/public'; | ||
import { Filter } from '@kbn/es-query'; | ||
import { EmbeddableInput as Input } from '../../../../src/plugins/embeddable/common/'; | ||
|
||
export type EmbeddableInput = Input & { | ||
timeRange?: TimeRange; | ||
filters?: Filter[]; | ||
savedObjectId?: string; | ||
}; |
Oops, something went wrong.