RestoreDashboards: Add link to dashboards browse view (#94000)

* feat: add button

* refactor: clean up

* feat: add tracking

* refactor: change button copy

* refactor: add payload to tracking

* refactor: add subURL

* refactor: user permissions

* refactor: group conditions

Co-authored-by: Alex Khomenko <Clarity-89@users.noreply.github.com>

---------

Co-authored-by: Alex Khomenko <Clarity-89@users.noreply.github.com>
This commit is contained in:
Laura Benz 2024-10-03 15:13:29 +02:00 committed by GitHub
parent 4224d05934
commit f92ef0e126
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 28 additions and 3 deletions

View File

@ -387,7 +387,7 @@ func (s *ServiceImpl) buildDashboardNavLinks(c *contextmodel.ReqContext) []*navt
}) })
} }
if s.features.IsEnabled(c.Req.Context(), featuremgmt.FlagDashboardRestoreUI) && c.SignedInUser.GetOrgRole() == org.RoleAdmin { if s.features.IsEnabled(c.Req.Context(), featuremgmt.FlagDashboardRestoreUI) && (c.SignedInUser.GetOrgRole() == org.RoleAdmin || c.IsGrafanaAdmin) {
dashboardChildNavs = append(dashboardChildNavs, &navtree.NavLink{ dashboardChildNavs = append(dashboardChildNavs, &navtree.NavLink{
Text: "Recently deleted", Text: "Recently deleted",
SubTitle: "Any items listed here for more than 30 days will be automatically deleted.", SubTitle: "Any items listed here for more than 30 days will be automatically deleted.",

View File

@ -4,11 +4,14 @@ import { useLocation, useParams } from 'react-router-dom-v5-compat';
import AutoSizer from 'react-virtualized-auto-sizer'; import AutoSizer from 'react-virtualized-auto-sizer';
import { GrafanaTheme2 } from '@grafana/data'; import { GrafanaTheme2 } from '@grafana/data';
import { reportInteraction } from '@grafana/runtime'; import { config, reportInteraction } from '@grafana/runtime';
import { FilterInput, useStyles2 } from '@grafana/ui'; import { LinkButton, FilterInput, useStyles2 } from '@grafana/ui';
import { Page } from 'app/core/components/Page/Page'; import { Page } from 'app/core/components/Page/Page';
import { getConfig } from 'app/core/config';
import { Trans } from 'app/core/internationalization';
import { useDispatch } from 'app/types'; import { useDispatch } from 'app/types';
import { contextSrv } from '../../core/services/context_srv';
import { buildNavModel, getDashboardsTabID } from '../folders/state/navModel'; import { buildNavModel, getDashboardsTabID } from '../folders/state/navModel';
import { useSearchStateManager } from '../search/state/SearchStateManager'; import { useSearchStateManager } from '../search/state/SearchStateManager';
import { getSearchPlaceholder } from '../search/tempI18nPhrases'; import { getSearchPlaceholder } from '../search/tempI18nPhrases';
@ -81,6 +84,7 @@ const BrowseDashboardsPage = memo(() => {
const { data: rootFolder } = useGetFolderQuery('general'); const { data: rootFolder } = useGetFolderQuery('general');
let folder = folderDTO ? folderDTO : rootFolder; let folder = folderDTO ? folderDTO : rootFolder;
const { canEditFolders, canEditDashboards, canCreateDashboards, canCreateFolders } = getFolderPermissions(folder); const { canEditFolders, canEditDashboards, canCreateDashboards, canCreateFolders } = getFolderPermissions(folder);
const hasAdminRights = contextSrv.hasRole('Admin') || contextSrv.isGrafanaAdmin;
const showEditTitle = canEditFolders && folderUID; const showEditTitle = canEditFolders && folderUID;
const canSelect = canEditFolders || canEditDashboards; const canSelect = canEditFolders || canEditDashboards;
@ -104,6 +108,12 @@ const BrowseDashboardsPage = memo(() => {
} }
}; };
const handleButtonClickToRecentlyDeleted = () => {
reportInteraction('grafana_browse_dashboards_page_button_to_recently_deleted', {
origin: window.location.pathname === getConfig().appSubUrl + '/dashboards' ? 'Dashboards' : 'Folder view',
});
};
return ( return (
<Page <Page
navId="dashboards/browse" navId="dashboards/browse"
@ -111,6 +121,15 @@ const BrowseDashboardsPage = memo(() => {
onEditTitle={showEditTitle ? onEditTitle : undefined} onEditTitle={showEditTitle ? onEditTitle : undefined}
actions={ actions={
<> <>
{config.featureToggles.dashboardRestore && config.featureToggles.dashboardRestoreUI && hasAdminRights && (
<LinkButton
variant="secondary"
href={getConfig().appSubUrl + '/dashboard/recently-deleted'}
onClick={handleButtonClickToRecentlyDeleted}
>
<Trans i18nKey="browse-dashboards.actions.button-to-recently-deleted">Recently deleted</Trans>
</LinkButton>
)}
{folderDTO && <FolderActionsButton folder={folderDTO} />} {folderDTO && <FolderActionsButton folder={folderDTO} />}
{(canCreateDashboards || canCreateFolders) && ( {(canCreateDashboards || canCreateFolders) && (
<CreateNewButton <CreateNewButton

View File

@ -329,6 +329,9 @@
"moving": "Moving...", "moving": "Moving...",
"new-folder-name-required-phrase": "Folder name is required." "new-folder-name-required-phrase": "Folder name is required."
}, },
"actions": {
"button-to-recently-deleted": "Recently deleted"
},
"counts": { "counts": {
"alertRule_one": "{{count}} alert rule", "alertRule_one": "{{count}} alert rule",
"alertRule_other": "{{count}} alert rules", "alertRule_other": "{{count}} alert rules",

View File

@ -329,6 +329,9 @@
"moving": "Mővįʼnģ...", "moving": "Mővįʼnģ...",
"new-folder-name-required-phrase": "Főľđęř ʼnämę įş řęqūįřęđ." "new-folder-name-required-phrase": "Főľđęř ʼnämę įş řęqūįřęđ."
}, },
"actions": {
"button-to-recently-deleted": "Ŗęčęʼnŧľy đęľęŧęđ"
},
"counts": { "counts": {
"alertRule_one": "{{count}} äľęřŧ řūľę", "alertRule_one": "{{count}} äľęřŧ řūľę",
"alertRule_other": "{{count}} äľęřŧ řūľęş", "alertRule_other": "{{count}} äľęřŧ řūľęş",