New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ShareModal: Share link redesign under newDashboardSharingComponent
FF
#87011
Merged
juanicabanas
merged 15 commits into
main
from
juanicabanas/share-internally-sharing-redesign
May 3, 2024
Merged
Changes from 12 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
fcfd7ab
share link in progress
juanicabanas 0fef45e
link in progress
juanicabanas 0150d17
code improved
juanicabanas 4b6b54b
clipboard removed
juanicabanas 9ed224d
function reused
juanicabanas dd4a0cf
async removed
juanicabanas aba0bf1
Merge branch 'main' into juanicabanas/share-internally-sharing-redesign
juanicabanas 646829b
tests added
juanicabanas c8c27cd
require actual added
juanicabanas eb34350
Merge branch 'main' into juanicabanas/share-internally-sharing-redesign
juanicabanas 4c1290f
link text modified. test fixed
juanicabanas f2166d5
testid added
juanicabanas 36a5152
improvements
juanicabanas 2e04670
Merge branch 'main' into juanicabanas/share-internally-sharing-redesign
juanicabanas 045ab79
changed
juanicabanas File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -23,6 +23,7 @@ import { getDashboardSrv } from 'app/features/dashboard/services/DashboardSrv'; | |
import { playlistSrv } from 'app/features/playlist/PlaylistSrv'; | ||
|
||
import { PanelEditor } from '../panel-edit/PanelEditor'; | ||
import ShareButton from '../sharing/ShareButton/ShareButton'; | ||
import { ShareModal } from '../sharing/ShareModal'; | ||
import { DashboardInteractions } from '../utils/interactions'; | ||
import { DynamicDashNavButtonModel, dynamicDashNavActions } from '../utils/registerDynamicDashNavAction'; | ||
|
@@ -302,12 +303,14 @@ export function ToolbarActions({ dashboard }: Props) { | |
|
||
toolbarActions.push({ | ||
group: 'main-buttons', | ||
condition: uid && !isEditing && !meta.isSnapshot && !isPlaying, | ||
condition: | ||
!config.featureToggles.newDashboardSharingComponent && uid && !isEditing && !meta.isSnapshot && !isPlaying, | ||
render: () => ( | ||
<Button | ||
key="share-dashboard-button" | ||
tooltip={t('dashboard.toolbar.share', 'Share dashboard')} | ||
size="sm" | ||
data-testid={selectors.pages.Dashboard.DashNav.shareButton} | ||
className={styles.buttonWithExtraMargin} | ||
fill="outline" | ||
onClick={() => { | ||
|
@@ -331,14 +334,21 @@ export function ToolbarActions({ dashboard }: Props) { | |
tooltip="Enter edit mode" | ||
key="edit" | ||
className={styles.buttonWithExtraMargin} | ||
variant="primary" | ||
variant={config.featureToggles.newDashboardSharingComponent ? 'secondary' : 'primary'} | ||
juanicabanas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
size="sm" | ||
> | ||
Edit | ||
</Button> | ||
), | ||
}); | ||
|
||
toolbarActions.push({ | ||
group: 'new-share-dashboard-button', | ||
condition: | ||
config.featureToggles.newDashboardSharingComponent && uid && !isEditing && !meta.isSnapshot && !isPlaying, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe this |
||
render: () => <ShareButton key="new-share-dashboard-button" dashboard={dashboard} />, | ||
}); | ||
|
||
toolbarActions.push({ | ||
group: 'settings', | ||
condition: isEditing && dashboard.canEditDashboard() && isShowingDashboard, | ||
|
73 changes: 73 additions & 0 deletions
73
public/app/features/dashboard-scene/sharing/ShareButton/ShareButton.test.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,73 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import React from 'react'; | ||
|
||
import { selectors as e2eSelectors } from '@grafana/e2e-selectors'; | ||
import { SceneGridLayout, SceneTimeRange, VizPanel } from '@grafana/scenes'; | ||
|
||
import { DashboardGridItem } from '../../scene/DashboardGridItem'; | ||
import { DashboardScene } from '../../scene/DashboardScene'; | ||
|
||
import ShareButton from './ShareButton'; | ||
|
||
const createAndCopyDashboardShortLinkMock = jest.fn(); | ||
jest.mock('app/core/utils/shortLinks', () => ({ | ||
...jest.requireActual('app/core/utils/shortLinks'), | ||
createAndCopyDashboardShortLink: () => createAndCopyDashboardShortLinkMock(), | ||
})); | ||
|
||
const selector = e2eSelectors.pages.Dashboard.DashNav.newShareButton; | ||
describe('ShareButton', () => { | ||
it('should render share link button and menu', async () => { | ||
setup(); | ||
|
||
expect(await screen.findByTestId(selector.shareLink)).toBeInTheDocument(); | ||
expect(await screen.findByTestId(selector.arrowMenu)).toBeInTheDocument(); | ||
}); | ||
|
||
it('should call createAndCopyDashboardShortLink when share link clicked', async () => { | ||
setup(); | ||
|
||
const shareLink = await screen.findByTestId(selector.shareLink); | ||
|
||
await userEvent.click(shareLink); | ||
expect(createAndCopyDashboardShortLinkMock).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should render menu when arrow button clicked', async () => { | ||
setup(); | ||
|
||
const arrowMenu = await screen.findByTestId(selector.arrowMenu); | ||
await userEvent.click(arrowMenu); | ||
|
||
expect(await screen.findByTestId(selector.menu.container)).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
function setup() { | ||
const panel = new VizPanel({ | ||
title: 'Panel A', | ||
pluginId: 'table', | ||
key: 'panel-12', | ||
}); | ||
|
||
const dashboard = new DashboardScene({ | ||
title: 'hello', | ||
uid: 'dash-1', | ||
$timeRange: new SceneTimeRange({}), | ||
body: new SceneGridLayout({ | ||
children: [ | ||
new DashboardGridItem({ | ||
key: 'griditem-1', | ||
x: 0, | ||
y: 0, | ||
width: 10, | ||
height: 12, | ||
body: panel, | ||
}), | ||
], | ||
}), | ||
}); | ||
|
||
render(<ShareButton dashboard={dashboard} />); | ||
} |
42 changes: 42 additions & 0 deletions
42
public/app/features/dashboard-scene/sharing/ShareButton/ShareButton.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,42 @@ | ||
import React, { useCallback, useState } from 'react'; | ||
import { useAsyncFn } from 'react-use'; | ||
|
||
import { selectors as e2eSelectors } from '@grafana/e2e-selectors'; | ||
import { Button, ButtonGroup, Dropdown } from '@grafana/ui'; | ||
import { createAndCopyDashboardShortLink } from 'app/core/utils/shortLinks'; | ||
|
||
import { DashboardScene } from '../../scene/DashboardScene'; | ||
import { DashboardInteractions } from '../../utils/interactions'; | ||
|
||
import ShareMenu from './ShareMenu'; | ||
|
||
const newShareButtonSelector = e2eSelectors.pages.Dashboard.DashNav.newShareButton; | ||
|
||
export default function ShareButton({ dashboard }: { dashboard: DashboardScene }) { | ||
const [isOpen, setIsOpen] = useState(false); | ||
|
||
const [_, buildUrl] = useAsyncFn(async () => { | ||
return await createAndCopyDashboardShortLink(dashboard, { useAbsoluteTimeRange: true, theme: 'current' }); | ||
}, [dashboard]); | ||
|
||
const onMenuClick = useCallback((isOpen: boolean) => { | ||
if (isOpen) { | ||
DashboardInteractions.toolbarShareClick(); | ||
} | ||
|
||
setIsOpen(isOpen); | ||
}, []); | ||
|
||
const MenuActions = () => <ShareMenu dashboard={dashboard} />; | ||
|
||
return ( | ||
<ButtonGroup data-testid={newShareButtonSelector.container}> | ||
<Button data-testid={newShareButtonSelector.shareLink} size="sm" tooltip="Copy shortened URL" onClick={buildUrl}> | ||
Share | ||
</Button> | ||
<Dropdown overlay={MenuActions} placement="bottom-end" onVisibleChange={onMenuClick}> | ||
<Button data-testid={newShareButtonSelector.arrowMenu} size="sm" icon={isOpen ? 'angle-up' : 'angle-down'} /> | ||
</Dropdown> | ||
</ButtonGroup> | ||
); | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of curiosity:
screen.queryByTestId(selectors.pages.Dashboard.DashNav.shareButton)
instead ofscreen.findByText('Share')
as above to retrieve the old share button?findByTestId
instead ofqueryByTestId
as above to retrieve the new share button?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.