fix: dashboard delete is fixed and toast message is added (#4050)

* fix: dashboard delete is fixed and toast message is added

* fix: dashboard delete is fixed and toast message is added

* chore: message is updated
This commit is contained in:
Palash Gupta 2023-11-24 11:51:26 +05:30 committed by GitHub
parent 399d49b3c0
commit fc4cdea539
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 7 deletions

View File

@ -20,5 +20,6 @@
"variable_updated_successfully": "Variable updated successfully", "variable_updated_successfully": "Variable updated successfully",
"error_while_updating_variable": "Error while updating variable", "error_while_updating_variable": "Error while updating variable",
"dashboard_has_been_updated": "Dashboard has been updated", "dashboard_has_been_updated": "Dashboard has been updated",
"do_you_want_to_refresh_the_dashboard": "Do you want to refresh the dashboard?" "do_you_want_to_refresh_the_dashboard": "Do you want to refresh the dashboard?",
"delete_dashboard_success": "{{name}} dashboard deleted successfully"
} }

View File

@ -23,5 +23,6 @@
"dashboard_has_been_updated": "Dashboard has been updated", "dashboard_has_been_updated": "Dashboard has been updated",
"do_you_want_to_refresh_the_dashboard": "Do you want to refresh the dashboard?", "do_you_want_to_refresh_the_dashboard": "Do you want to refresh the dashboard?",
"locked_dashboard_delete_tooltip_admin_author": "Dashboard is locked. Please unlock the dashboard to enable delete.", "locked_dashboard_delete_tooltip_admin_author": "Dashboard is locked. Please unlock the dashboard to enable delete.",
"locked_dashboard_delete_tooltip_editor": "Dashboard is locked. Please contact admin to delete the dashboard." "locked_dashboard_delete_tooltip_editor": "Dashboard is locked. Please contact admin to delete the dashboard.",
"delete_dashboard_success": "{{name}} dashboard deleted successfully"
} }

View File

@ -2,6 +2,7 @@ import { DeleteOutlined, ExclamationCircleOutlined } from '@ant-design/icons';
import { Modal, Tooltip, Typography } from 'antd'; import { Modal, Tooltip, Typography } from 'antd';
import { REACT_QUERY_KEY } from 'constants/reactQueryKeys'; import { REACT_QUERY_KEY } from 'constants/reactQueryKeys';
import { useDeleteDashboard } from 'hooks/dashboard/useDeleteDashboard'; import { useDeleteDashboard } from 'hooks/dashboard/useDeleteDashboard';
import { useNotifications } from 'hooks/useNotifications';
import { useCallback } from 'react'; import { useCallback } from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { useQueryClient } from 'react-query'; import { useQueryClient } from 'react-query';
@ -32,6 +33,8 @@ function DeleteButton({
const queryClient = useQueryClient(); const queryClient = useQueryClient();
const { notifications } = useNotifications();
const { t } = useTranslation(['dashboard']); const { t } = useTranslation(['dashboard']);
const deleteDashboardMutation = useDeleteDashboard(id); const deleteDashboardMutation = useDeleteDashboard(id);
@ -49,6 +52,11 @@ function DeleteButton({
onOk() { onOk() {
deleteDashboardMutation.mutateAsync(undefined, { deleteDashboardMutation.mutateAsync(undefined, {
onSuccess: () => { onSuccess: () => {
notifications.success({
message: t('dashboard:delete_dashboard_success', {
name,
}),
});
queryClient.invalidateQueries([REACT_QUERY_KEY.GET_ALL_DASHBOARDS]); queryClient.invalidateQueries([REACT_QUERY_KEY.GET_ALL_DASHBOARDS]);
}, },
}); });
@ -57,7 +65,7 @@ function DeleteButton({
okButtonProps: { danger: true }, okButtonProps: { danger: true },
centered: true, centered: true,
}); });
}, [modal, name, deleteDashboardMutation, queryClient]); }, [modal, name, deleteDashboardMutation, notifications, t, queryClient]);
const getDeleteTooltipContent = (): string => { const getDeleteTooltipContent = (): string => {
if (isLocked) { if (isLocked) {

View File

@ -66,9 +66,7 @@ function ListOfAllDashboard(): JSX.Element {
}; };
useEffect(() => { useEffect(() => {
if (dashboardListResponse.length) {
sortDashboardsByCreatedAt(dashboardListResponse); sortDashboardsByCreatedAt(dashboardListResponse);
}
}, [dashboardListResponse]); }, [dashboardListResponse]);
const [newDashboardState, setNewDashboardState] = useState({ const [newDashboardState, setNewDashboardState] = useState({