-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
feat(dashboards): add create link button to table edit #101204
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
Merged
DominikB2014
merged 5 commits into
master
from
dominikbuszowiecki/browse-68-add-ui-to-link-one-dashboard-to-another-in-the-frontend
Oct 9, 2025
+232
−7
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
184 changes: 184 additions & 0 deletions
184
static/app/components/modals/widgetBuilder/linkToDashboardModal.tsx
This file contains hidden or 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,184 @@ | ||
import {Fragment, useCallback, useEffect, useState, type ReactNode} from 'react'; | ||
import {css} from '@emotion/react'; | ||
import styled from '@emotion/styled'; | ||
|
||
import {fetchDashboard, fetchDashboards} from 'sentry/actionCreators/dashboards'; | ||
import type {ModalRenderProps} from 'sentry/actionCreators/modal'; | ||
import {Button} from 'sentry/components/core/button'; | ||
import {ButtonBar} from 'sentry/components/core/button/buttonBar'; | ||
import {Select} from 'sentry/components/core/select'; | ||
import {t, tct} from 'sentry/locale'; | ||
import {space} from 'sentry/styles/space'; | ||
import type {SelectValue} from 'sentry/types/core'; | ||
import useApi from 'sentry/utils/useApi'; | ||
import useOrganization from 'sentry/utils/useOrganization'; | ||
import {useParams} from 'sentry/utils/useParams'; | ||
import {DashboardCreateLimitWrapper} from 'sentry/views/dashboards/createLimitWrapper'; | ||
import type {DashboardDetails, DashboardListItem} from 'sentry/views/dashboards/types'; | ||
import {MAX_WIDGETS} from 'sentry/views/dashboards/types'; | ||
import {NEW_DASHBOARD_ID} from 'sentry/views/dashboards/widgetBuilder/utils'; | ||
|
||
export type LinkToDashboardModalProps = { | ||
source?: string; // TODO: perhpas make this an enum | ||
}; | ||
|
||
type Props = ModalRenderProps & LinkToDashboardModalProps; | ||
|
||
const SELECT_DASHBOARD_MESSAGE = t('Select a dashboard'); | ||
|
||
export function LinkToDashboardModal({Header, Body, Footer, closeModal}: Props) { | ||
const api = useApi(); | ||
const organization = useOrganization(); | ||
const [dashboards, setDashboards] = useState<DashboardListItem[] | null>(null); | ||
const [_, setSelectedDashboard] = useState<DashboardDetails | null>(null); | ||
const [selectedDashboardId, setSelectedDashboardId] = useState<string | null>(null); | ||
|
||
const {dashboardId: currentDashboardId} = useParams<{dashboardId: string}>(); | ||
|
||
useEffect(() => { | ||
// Track mounted state so we dont call setState on unmounted components | ||
let unmounted = false; | ||
|
||
fetchDashboards(api, organization.slug).then(response => { | ||
// If component has unmounted, dont set state | ||
if (unmounted) { | ||
return; | ||
} | ||
|
||
setDashboards(response); | ||
}); | ||
|
||
return () => { | ||
unmounted = true; | ||
}; | ||
}, [api, organization.slug]); | ||
|
||
useEffect(() => { | ||
// Track mounted state so we dont call setState on unmounted components | ||
let unmounted = false; | ||
|
||
if (selectedDashboardId === NEW_DASHBOARD_ID || selectedDashboardId === null) { | ||
setSelectedDashboard(null); | ||
} else { | ||
fetchDashboard(api, organization.slug, selectedDashboardId).then(response => { | ||
// If component has unmounted, dont set state | ||
if (unmounted) { | ||
return; | ||
} | ||
|
||
setSelectedDashboard(response); | ||
}); | ||
} | ||
|
||
return () => { | ||
unmounted = true; | ||
}; | ||
}, [api, organization.slug, selectedDashboardId]); | ||
|
||
const canSubmit = selectedDashboardId !== null; | ||
|
||
const getOptions = useCallback( | ||
( | ||
hasReachedDashboardLimit: boolean, | ||
isLoading: boolean, | ||
limitMessage: ReactNode | null | ||
) => { | ||
if (dashboards === null) { | ||
return null; | ||
} | ||
|
||
return [ | ||
{ | ||
label: t('+ Create New Dashboard'), | ||
value: 'new', | ||
disabled: hasReachedDashboardLimit || isLoading, | ||
tooltip: hasReachedDashboardLimit ? limitMessage : undefined, | ||
tooltipOptions: {position: 'right', isHoverable: true}, | ||
}, | ||
...dashboards | ||
.filter(dashboard => | ||
// if adding from a dashboard, currentDashboardId will be set and we'll remove it from the list of options | ||
currentDashboardId ? dashboard.id !== currentDashboardId : true | ||
) | ||
.map(({title, id, widgetDisplay}) => ({ | ||
label: title, | ||
value: id, | ||
disabled: widgetDisplay.length >= MAX_WIDGETS, | ||
tooltip: | ||
widgetDisplay.length >= MAX_WIDGETS && | ||
tct('Max widgets ([maxWidgets]) per dashboard reached.', { | ||
maxWidgets: MAX_WIDGETS, | ||
}), | ||
tooltipOptions: {position: 'right'}, | ||
})), | ||
].filter(Boolean) as Array<SelectValue<string>>; | ||
}, | ||
[currentDashboardId, dashboards] | ||
); | ||
|
||
function linkToDashboard() { | ||
// TODO: Update the local state of the widget to include the links | ||
// When the user clicks `save widget` we should update the dashboard widget link on the backend | ||
closeModal(); | ||
} | ||
|
||
return ( | ||
<Fragment> | ||
<Header closeButton>{t('Link to Dashboard')}</Header> | ||
<Body> | ||
<Wrapper> | ||
<DashboardCreateLimitWrapper> | ||
{({hasReachedDashboardLimit, isLoading, limitMessage}) => ( | ||
<Select | ||
disabled={dashboards === null} | ||
name="dashboard" | ||
placeholder={t('Select Dashboard')} | ||
value={selectedDashboardId} | ||
options={getOptions(hasReachedDashboardLimit, isLoading, limitMessage)} | ||
onChange={(option: SelectValue<string>) => { | ||
if (option.disabled) { | ||
return; | ||
} | ||
setSelectedDashboardId(option.value); | ||
}} | ||
/> | ||
)} | ||
</DashboardCreateLimitWrapper> | ||
</Wrapper> | ||
</Body> | ||
<Footer> | ||
<StyledButtonBar gap="lg"> | ||
<Button | ||
disabled={!canSubmit} | ||
title={canSubmit ? undefined : SELECT_DASHBOARD_MESSAGE} | ||
onClick={() => linkToDashboard()} | ||
aria-label={t('Link to dashboard')} | ||
> | ||
{t('Link to dashboard')} | ||
</Button> | ||
</StyledButtonBar> | ||
</Footer> | ||
</Fragment> | ||
); | ||
} | ||
|
||
const Wrapper = styled('div')` | ||
margin-bottom: ${space(2)}; | ||
`; | ||
|
||
const StyledButtonBar = styled(ButtonBar)` | ||
@media (max-width: ${props => props.theme.breakpoints.sm}) { | ||
grid-template-rows: repeat(2, 1fr); | ||
gap: ${space(1.5)}; | ||
width: 100%; | ||
|
||
> button { | ||
width: 100%; | ||
} | ||
} | ||
`; | ||
|
||
export const modalCss = css` | ||
max-width: 700px; | ||
margin: 70px auto; | ||
`; |
This file contains hidden or 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 hidden or 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,6 @@ | ||
import useOrganization from 'sentry/utils/useOrganization'; | ||
|
||
export function useHasDrillDownFlows() { | ||
const organization = useOrganization(); | ||
return organization.features.includes('dashboards-drilldown-flow'); | ||
} |
This file contains hidden or 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 hidden or 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
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.
We probably don't want the user to be able to link to a creation flow, do we?
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.
I think we might want to do that tbh, depends on what we decide UX wise, but I could definitely see a scenario where you create a summary dashboard off a widget.