Skip to content

Commit

Permalink
[Share] Add loading state to link_content (elastic#196809)
Browse files Browse the repository at this point in the history
## Summary

This PR adds a loading state to `Copy Link` button in share modal.

Fixes: elastic#194641
  • Loading branch information
kowalczyk-krzysztof authored Oct 18, 2024
1 parent 592225d commit 32dec20
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 32dec20

Please sign in to comment.