RestoreDashboards: Fix counting bug (#89201)

Fix restore modal showing incorrect counts

Co-authored-by: joshhunt <josh@trtr.co>
This commit is contained in:
Laura Benz 2024-06-14 14:30:05 +02:00 committed by GitHub
parent 4e3294cd8d
commit d44ddba996
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 10 deletions

View File

@ -3,22 +3,23 @@ import React from 'react';
import { ConfirmModal, Text } from '@grafana/ui';
import { Trans, t } from '../../../core/internationalization';
import { DashboardTreeSelection } from '../../browse-dashboards/types';
interface Props {
isOpen: boolean;
onConfirm: () => Promise<void>;
onDismiss: () => void;
selectedItems: DashboardTreeSelection;
selectedDashboards: string[];
isLoading: boolean;
}
export const RestoreModal = ({ onConfirm, onDismiss, selectedItems, isLoading, ...props }: Props) => {
const numberOfDashboards = selectedItems ? Object.keys(selectedItems.dashboard).length : 0;
export const RestoreModal = ({ onConfirm, onDismiss, selectedDashboards, isLoading, ...props }: Props) => {
const numberOfDashboards = selectedDashboards.length;
const onRestore = async () => {
await onConfirm();
onDismiss();
};
return (
<ConfirmModal
body={

View File

@ -1,5 +1,5 @@
import { css } from '@emotion/css';
import React from 'react';
import React, { useMemo } from 'react';
import { GrafanaTheme2 } from '@grafana/data/';
import { Button, useStyles2 } from '@grafana/ui';
@ -17,11 +17,17 @@ export function RecentlyDeletedActions() {
const styles = useStyles2(getStyles);
const dispatch = useDispatch();
const selectedItems = useActionSelectionState();
const selectedItemsState = useActionSelectionState();
const [, stateManager] = useRecentlyDeletedStateManager();
const [restoreDashboard, { isLoading: isRestoreLoading }] = useRestoreDashboardMutation();
const selectedDashboards = useMemo(() => {
return Object.entries(selectedItemsState.dashboard)
.filter(([_, selected]) => selected)
.map(([uid]) => uid);
}, [selectedItemsState.dashboard]);
const onActionComplete = () => {
dispatch(setAllSelection({ isSelected: false, folderUID: undefined }));
@ -29,9 +35,8 @@ export function RecentlyDeletedActions() {
};
const onRestore = async () => {
const promises = Object.entries(selectedItems.dashboard)
.filter(([_, selected]) => selected)
.map(([uid]) => restoreDashboard({ dashboardUID: uid }));
const promises = selectedDashboards.map((uid) => restoreDashboard({ dashboardUID: uid }));
await Promise.all(promises);
onActionComplete();
};
@ -41,7 +46,7 @@ export function RecentlyDeletedActions() {
new ShowModalReactEvent({
component: RestoreModal,
props: {
selectedItems,
selectedDashboards,
onConfirm: onRestore,
isLoading: isRestoreLoading,
},