-
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 'main' into mw-scoped-query-api-changes
- Loading branch information
Showing
14 changed files
with
133 additions
and
190 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 was deleted.
Oops, something went wrong.
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,38 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { useContext, useEffect, useState } from 'react'; | ||
|
||
import { LinksAttributes } from '../../common/content_management'; | ||
import { LinksContext, LinksEmbeddable } from '../embeddable/links_embeddable'; | ||
|
||
export const useLinks = (): LinksEmbeddable => { | ||
const linksEmbeddable = useContext<LinksEmbeddable | null>(LinksContext); | ||
if (linksEmbeddable == null) { | ||
throw new Error('useLinks must be used inside LinksContext.'); | ||
} | ||
return linksEmbeddable!; | ||
}; | ||
|
||
export const useLinksAttributes = (): LinksAttributes | undefined => { | ||
const linksEmbeddable = useLinks(); | ||
const [attributes, setAttributes] = useState<LinksAttributes | undefined>( | ||
linksEmbeddable.attributes | ||
); | ||
|
||
useEffect(() => { | ||
const attributesSubscription = linksEmbeddable.attributes$.subscribe((newAttributes) => { | ||
setAttributes(newAttributes); | ||
}); | ||
return () => { | ||
attributesSubscription.unsubscribe(); | ||
}; | ||
}, [linksEmbeddable.attributes$]); | ||
|
||
return attributes; | ||
}; |
Oops, something went wrong.