Skip to content

Commit

Permalink
[8.x] [Share] Add loading state to link_content (#196809) (#196833)
Browse files Browse the repository at this point in the history
# Backport

This will backport the following commits from `main` to `8.x`:
- [[Share] Add loading state to link_content
(#196809)](#196809)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Krzysztof
Kowalczyk","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-10-18T10:09:54Z","message":"[Share]
Add loading state to link_content (#196809)\n\n## Summary\r\n\r\nThis PR
adds a loading state to `Copy Link` button in share modal.\r\n\r\nFixes:
#194641","sha":"32dec20719f12277234d99953370a4060d4ebaac","branchLabelMapping":{"^v9.0.0$":"main","^v8.17.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","Feature:SharingURLs","release_note:skip","v9.0.0","Team:SharedUX","backport:prev-minor"],"title":"[Share]
Add loading state to
link_content","number":196809,"url":"https://github.com/elastic/kibana/pull/196809","mergeCommit":{"message":"[Share]
Add loading state to link_content (#196809)\n\n## Summary\r\n\r\nThis PR
adds a loading state to `Copy Link` button in share modal.\r\n\r\nFixes:
#194641","sha":"32dec20719f12277234d99953370a4060d4ebaac"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/196809","number":196809,"mergeCommit":{"message":"[Share]
Add loading state to link_content (#196809)\n\n## Summary\r\n\r\nThis PR
adds a loading state to `Copy Link` button in share modal.\r\n\r\nFixes:
#194641","sha":"32dec20719f12277234d99953370a4060d4ebaac"}}]}]
BACKPORT-->

Co-authored-by: Krzysztof Kowalczyk <[email protected]>
  • Loading branch information
kibanamachine and kowalczyk-krzysztof authored Oct 18, 2024
1 parent 1f3a485 commit 10a9161
Showing 1 changed file with 4 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export const LinkContent = ({
const [urlParams] = useState<UrlParams | undefined>(undefined);
const [isTextCopied, setTextCopied] = useState(false);
const [shortUrlCache, setShortUrlCache] = useState<string | undefined>(undefined);
const [isLoading, setIsLoading] = useState(false);

const getUrlWithUpdatedParams = useCallback(
(tempUrl: string): string => {
Expand Down Expand Up @@ -99,6 +100,7 @@ export const LinkContent = ({
}, [shareableUrlLocatorParams, urlService.shortUrls, getSnapshotUrl, setShortUrlCache]);

const copyUrlHelper = useCallback(async () => {
setIsLoading(true);
let urlToCopy = url;

if (!urlToCopy || delegatedShareUrlHandler) {
Expand All @@ -112,6 +114,7 @@ export const LinkContent = ({
copyToClipboard(urlToCopy);
setUrl(urlToCopy);
setTextCopied(true);
setIsLoading(false);
return urlToCopy;
}, [url, delegatedShareUrlHandler, allowShortUrl, createShortUrl, getSnapshotUrl]);

Expand Down Expand Up @@ -164,6 +167,7 @@ export const LinkContent = ({
onBlur={() => (objectType === 'lens' && isDirty ? null : setTextCopied(false))}
onClick={copyUrlHelper}
color={objectType === 'lens' && isDirty ? 'warning' : 'primary'}
isLoading={isLoading}
>
<FormattedMessage id="share.link.copyLinkButton" defaultMessage="Copy link" />
</EuiButton>
Expand Down

0 comments on commit 10a9161

Please sign in to comment.