Skip to content

Commit

Permalink
feat: split delete enrollment actions
Browse files Browse the repository at this point in the history
  • Loading branch information
eirikhaugstulen committed Aug 28, 2024
1 parent 9de9a83 commit 82b1d22
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 55 deletions.
26 changes: 16 additions & 10 deletions i18n/en.pot
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ msgstr ""
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
"POT-Creation-Date: 2024-08-26T17:35:42.543Z\n"
"PO-Revision-Date: 2024-08-26T17:35:42.543Z\n"
"POT-Creation-Date: 2024-08-28T06:51:14.983Z\n"
"PO-Revision-Date: 2024-08-28T06:51:14.983Z\n"

msgid "Choose one or more dates..."
msgstr "Choose one or more dates..."
Expand Down Expand Up @@ -1685,24 +1685,30 @@ msgstr "No active enrollments to complete"
msgid "An error occurred while completing the enrollments"
msgstr "An error occurred while completing the enrollments"

msgid "You do not have the required authority to delete enrollments"
msgstr "You do not have the required authority to delete enrollments"

msgid "Delete enrollments"
msgstr "Delete enrollments"

msgid "Are you sure you want to delete all enrollments in the selected program?"
msgstr "Are you sure you want to delete all enrollments in the selected program?"

msgid "Total enrollments to be deleted"
msgstr "Total enrollments to be deleted"
msgid "Total"
msgstr "Total"

msgid "No active enrollments to delete"
msgstr "No active enrollments to delete"

msgid "Delete active enrollments"
msgstr "Delete active enrollments"

msgid "No enrollments to delete"
msgstr "No enrollments to delete"

msgid "Delete all enrollments"
msgstr "Delete all enrollments"

msgid "An error occurred when deleting enrollments"
msgstr "An error occurred when deleting enrollments"

msgid "You do not have the required authority to delete tracked entities"
msgstr "You do not have the required authority to delete tracked entities"

msgid "Delete {{ trackedEntityName }} with all enrollments"
msgstr "Delete {{ trackedEntityName }} with all enrollments"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
Button,
} from '@dhis2/ui';
import { useAuthority } from '../../../../../../utils/userInfo/useAuthority';
import { ConditionalTooltip } from '../../../../../Tooltips/ConditionalTooltip';
import { EnrollmentDeleteModal } from './EnrollmentDeleteModal';

type Props = {
Expand All @@ -24,20 +23,18 @@ export const DeleteEnrollmentsAction = ({
const [isDeleteDialogOpen, setIsDeleteDialogOpen] = useState(false);
const { hasAuthority } = useAuthority({ authority: CASCADE_DELETE_TEI_AUTHORITY });

if (!hasAuthority) {
return null;
}

return (
<>
<ConditionalTooltip
enabled={!hasAuthority}
content={i18n.t('You do not have the required authority to delete enrollments')}
<Button
small
onClick={() => setIsDeleteDialogOpen(true)}
>
<Button
small
onClick={() => setIsDeleteDialogOpen(true)}
disabled={!hasAuthority}
>
{i18n.t('Delete enrollments')}
</Button>
</ConditionalTooltip>
{i18n.t('Delete enrollments')}
</Button>

{isDeleteDialogOpen && (
<EnrollmentDeleteModal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
import i18n from '@dhis2/d2-i18n';
import { BulkActionCountTable } from '../../../../../WorkingListsBase/BulkActionBar';
import { useDeleteEnrollments } from '../hooks/useDeleteEnrollments';
import { ConditionalTooltip } from '../../../../../../Tooltips/ConditionalTooltip';

type Props = {
selectedRows: { [id: string]: boolean },
Expand Down Expand Up @@ -41,7 +42,6 @@ export const EnrollmentDeleteModal = ({

return (
<Modal
small
onClose={() => setIsDeleteDialogOpen(false)}
>
<ModalTitle>
Expand All @@ -52,9 +52,9 @@ export const EnrollmentDeleteModal = ({
{i18n.t('Are you sure you want to delete all enrollments in the selected program?')}

<BulkActionCountTable
total={enrollmentCounts?.total}
isLoading={isLoadingEnrollments}
totalLabel={i18n.t('Total enrollments to be deleted')}
total={enrollmentCounts?.total}
totalLabel={i18n.t('Total')}
>
<DataTableRow>
<DataTableCell>
Expand Down Expand Up @@ -84,13 +84,34 @@ export const EnrollmentDeleteModal = ({
>
{i18n.t('Cancel')}
</Button>
<Button
destructive
loading={isDeletingEnrollments}
onClick={deleteEnrollments}

<ConditionalTooltip
enabled={!enrollmentCounts?.active}
content={i18n.t('No active enrollments to delete')}
>
{i18n.t('Delete')}
</Button>
<Button
destructive
loading={isDeletingEnrollments}
onClick={() => deleteEnrollments({ activeOnly: true })}
disabled={!enrollmentCounts?.active}
>
{i18n.t('Delete active enrollments')}
</Button>
</ConditionalTooltip>

<ConditionalTooltip
enabled={!enrollmentCounts?.total}
content={i18n.t('No enrollments to delete')}
>
<Button
destructive
loading={isDeletingEnrollments}
onClick={() => deleteEnrollments({ activeOnly: false })}
disabled={!enrollmentCounts?.total}
>
{i18n.t('Delete all enrollments')}
</Button>
</ConditionalTooltip>
</ButtonStrip>
</ModalActions>
</Modal>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,14 @@ export const useDeleteEnrollments = ({
);

const { mutate: deleteEnrollments, isLoading: isDeletingEnrollments } = useMutation<any>(
() => dataEngine.mutate({
({ activeOnly }: any) => dataEngine.mutate({
resource: 'tracker?async=false&importStrategy=DELETE',
type: 'create',
data: {
// $FlowFixMe - business logic dictates that enrollments is not undefined at this point
enrollments: enrollments.map(({ enrollment }) => ({ enrollment })),
enrollments: enrollments
// $FlowFixMe - business logic dictates that enrollments is not undefined at this point
.filter(({ status }) => !activeOnly || status === 'ACTIVE')
.map(({ enrollment }) => ({ enrollment })),
},
}),
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import React, { useState } from 'react';
import i18n from '@dhis2/d2-i18n';
import { Button, ButtonStrip, Modal, ModalActions, ModalContent, ModalTitle } from '@dhis2/ui';
import { useAuthority } from '../../../../../../utils/userInfo/useAuthority';
import { ConditionalTooltip } from '../../../../../Tooltips/ConditionalTooltip';
import { useCascadeDeleteTei } from './hooks/useCascadeDeleteTei';

type Props = {
Expand All @@ -27,22 +26,20 @@ export const DeleteTeiAction = ({
onUpdateList,
});

if (!hasAuthority) {
return null;
}

return (
<>
<ConditionalTooltip
enabled={!hasAuthority}
content={i18n.t('You do not have the required authority to delete tracked entities')}
<Button
small
onClick={() => setIsDeleteDialogOpen(true)}
>
<Button
small
onClick={() => setIsDeleteDialogOpen(true)}
disabled={!hasAuthority}
>
{i18n.t('Delete {{ trackedEntityName }} with all enrollments', {
trackedEntityName: 'Person'.toLowerCase(),
})}
</Button>
</ConditionalTooltip>
{i18n.t('Delete {{ trackedEntityName }} with all enrollments', {
trackedEntityName: 'Person'.toLowerCase(),
})}
</Button>

{isDeleteDialogOpen && (
<Modal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @flow
import React from 'react';
import { BulkActionBar } from '../../WorkingListsBase/BulkActionBar';
import { CompleteAction, DeleteTeiAction } from './Actions';
import { CompleteAction } from './Actions';
import type { Props } from './TrackedEntityBulkActions.types';
import { DeleteEnrollmentsAction } from './Actions/DeleteEnrollmentsAction';

Expand Down Expand Up @@ -34,11 +34,11 @@ export const TrackedEntityBulkActionsComponent = ({
onUpdateList={onUpdateList}
/>

<DeleteTeiAction
selectedRows={selectedRows}
selectedRowsCount={selectedRowsCount}
onUpdateList={onUpdateList}
/>
{/* <DeleteTeiAction */}
{/* selectedRows={selectedRows} */}
{/* selectedRowsCount={selectedRowsCount} */}
{/* onUpdateList={onUpdateList} */}
{/* /> */}
</BulkActionBar>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import i18n from '@dhis2/d2-i18n';
import { withStyles } from '@material-ui/core/';

type Props = {
total: ?number,
total?: ?number,
isLoading: boolean,
totalLabel?: string,
children: React$Node,
Expand Down

0 comments on commit 82b1d22

Please sign in to comment.