Skip to content
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

MPDX-8237 - Shows tasks count, updates Tasks once deleted. #1088

Merged
merged 12 commits into from
Sep 26, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@

const [contactDetailsOpen, setContactDetailsOpen] = useState(false);
const [contactDetailsId, setContactDetailsId] = useState<string>();
const [idsToRemove, setIdsToRemove] = useState<string[]>([]);

const { contactId, searchTerm } = query;

Expand Down Expand Up @@ -242,6 +243,7 @@
activeFilters,
searchTerm as string,
starredFilter,
idsToRemove,
);
//#endregion

Expand Down Expand Up @@ -344,6 +346,7 @@
toggleStarredFilter={setStarredFilter}
headerCheckboxState={selectionType}
massDeselectAll={deselectAll}
showShowingCount
caleballdrin marked this conversation as resolved.
Show resolved Hide resolved
selectedIds={ids}
buttonGroup={
<Hidden xsDown>
Expand Down Expand Up @@ -415,6 +418,7 @@
onTaskCheckToggle={toggleSelectionById}
isChecked={isRowChecked(task.id)}
useTopMargin={index === 0}
removeSelectedIds={(id) => setIdsToRemove([id])}

Check warning on line 421 in pages/accountLists/[accountListId]/tasks/[[...contactId]].page.tsx

View check run for this annotation

Codecov / codecov/patch

pages/accountLists/[accountListId]/tasks/[[...contactId]].page.tsx#L421

Added line #L421 was not covered by tests
/>
</Box>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ interface DeleteTaskIconButtonProps {
accountListId: string;
taskId: string;
onDeleteConfirm?: () => void;
removeSelectedIds?: (id: string) => void;
}

export const DeleteTaskIconButton: React.FC<DeleteTaskIconButtonProps> = ({
accountListId,
taskId,
onDeleteConfirm,
removeSelectedIds,
}) => {
const { t } = useTranslation();

Expand All @@ -36,6 +38,7 @@ export const DeleteTaskIconButton: React.FC<DeleteTaskIconButtonProps> = ({
onClickDecline={setRemoveDialogOpen}
accountListId={accountListId}
taskId={taskId}
removeSelectedIds={removeSelectedIds}
/>
</>
);
Expand Down
34 changes: 30 additions & 4 deletions src/components/Shared/Header/ListHeader.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
ContactFilterSetInput,
TaskFilterSetInput,
} from 'src/graphql/types.generated';
import { useAccountListId } from 'src/hooks/useAccountListId';
import i18n from 'src/lib/i18n';
import theme from '../../../theme';
import { TasksMassActionsDropdown } from '../MassActions/TasksMassActionsDropdown';
Expand Down Expand Up @@ -112,9 +111,9 @@ const router = {
push,
};

beforeEach(() => {
(useAccountListId as jest.Mock).mockReturnValue(router);
});
// beforeEach(() => {
// (useAccountListId as jest.Mock).mockReturnValue(router);
// });
caleballdrin marked this conversation as resolved.
Show resolved Hide resolved

const ButtonGroup: React.FC = () => {
return (
Expand Down Expand Up @@ -226,6 +225,33 @@ describe('ListHeader', () => {

expect(getByPlaceholderText('Search Tasks')).toBeVisible();
});
it('Should update count upon deletion', async () => {
const { queryByText, getByText } = render(
<Components
selectedIds={['a', 'b', 'c']}
page={PageEnum.Task}
totalItems={50}
showShowingCount={true}
/>,
);
expect(queryByText('Showing 50')).toBeInTheDocument();
wjames111 marked this conversation as resolved.
Show resolved Hide resolved
expect(queryByText('3 Selected')).toBeInTheDocument();
const actionsButton = getByText('Actions');
userEvent.click(actionsButton);
expect(getByText('Delete Tasks')).toBeInTheDocument();
userEvent.click(getByText('Delete Tasks'));
await waitFor(() => {
expect(
queryByText('Are you sure you wish to delete the 3 selected tasks?'),
).toBeInTheDocument();
});

userEvent.click(getByText('Yes'));

await waitFor(() => {
expect(queryByText('Showing 50')).toBeInTheDocument();
});
});
});

it('checkbox is unchecked', async () => {
Expand Down
3 changes: 3 additions & 0 deletions src/components/Task/TaskRow/TaskRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ interface TaskRowProps {
onContactSelected: (taskId: string) => void;
onTaskCheckToggle: (taskId: string) => void;
useTopMargin?: boolean;
removeSelectedIds?: (id: string) => void;
}

export const TaskRow: React.FC<TaskRowProps> = ({
Expand All @@ -75,6 +76,7 @@ export const TaskRow: React.FC<TaskRowProps> = ({
onContactSelected,
onTaskCheckToggle,
useTopMargin,
removeSelectedIds,
}) => {
const { t } = useTranslation();

Expand Down Expand Up @@ -269,6 +271,7 @@ export const TaskRow: React.FC<TaskRowProps> = ({
<DeleteTaskIconButton
accountListId={accountListId}
taskId={taskId}
removeSelectedIds={removeSelectedIds}
/>
</Box>
<Box onClick={(e) => e.stopPropagation()}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ interface DeleteConfirmationProps {
accountListId?: string;
taskId?: string;
onClose?: () => void;
removeSelectedIds?: (id: string) => void;
}

export const DeleteConfirmation: React.FC<DeleteConfirmationProps> = ({
Expand All @@ -40,6 +41,7 @@ export const DeleteConfirmation: React.FC<DeleteConfirmationProps> = ({
accountListId,
taskId,
onClose,
removeSelectedIds,
}) => {
const { t } = useTranslation();
const { enqueueSnackbar } = useSnackbar();
Expand All @@ -56,12 +58,18 @@ export const DeleteConfirmation: React.FC<DeleteConfirmationProps> = ({
cache.evict({ id: `Task:${taskId}` });
cache.gc();
},
refetchQueries: ['ContactTasksTab', 'GetWeeklyActivity', 'GetThisWeek'],
refetchQueries: [
'ContactTasksTab',
'GetWeeklyActivity',
'GetThisWeek',
'Tasks',
],
});
enqueueSnackbar(t('Task deleted successfully'), { variant: 'success' });
onClickDecline(false);
onClose && onClose();
onClickConfirm && onClickConfirm();
removeSelectedIds && removeSelectedIds(taskId);
}
};

Expand Down
7 changes: 7 additions & 0 deletions src/hooks/useMassSelection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const useMassSelection = (
activeFilters?: ContactFilterSetInput | ReportContactFilterSetInput,
wildcardSearch?: string,
starredFilter?: ContactFilterSetInput,
idsToRemove?: string[],
): {
ids: string[];
selectionType: ListHeaderCheckBoxState;
Expand All @@ -26,6 +27,12 @@ export const useMassSelection = (
);
const [ids, setIds] = useState<string[]>([]);

useEffect(() => {
wjames111 marked this conversation as resolved.
Show resolved Hide resolved
if (idsToRemove) {
setIds(ids.filter((id) => !idsToRemove.includes(id)));
}
}, [idsToRemove]);

const toggleSelectionById = (id: string) => {
switch (selectionType) {
case ListHeaderCheckBoxState.Partial:
Expand Down
Loading