Skip to content

Commit

Permalink
PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
cnasikas committed Oct 5, 2022
1 parent 76c8eb9 commit b4da899
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,7 @@ describe('AllCasesListGeneric', () => {
});
});

it('should disable row actions when bulk selecting cases', async () => {
it('should disable row actions when bulk selecting all cases', async () => {
const res = appMockRenderer.render(<AllCasesList />);

act(() => {
Expand All @@ -925,6 +925,21 @@ describe('AllCasesListGeneric', () => {
}
});
});

it('should disable row actions when selecting a case', async () => {
const res = appMockRenderer.render(<AllCasesList />);
const caseToSelect = defaultGetCases.data.cases[0];

act(() => {
userEvent.click(res.getByTestId(`checkboxSelectRow-${caseToSelect.id}`));
});

await waitFor(() => {
for (const theCase of defaultGetCases.data.cases) {
expect(res.getByTestId(`case-action-popover-button-${theCase.id}`)).toBeDisabled();
}
});
});
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe('AllCasesSelectorModal', () => {
expect(res.queryByTestId('all-cases-modal')).toBeFalsy();
});

it('should hide bulk actions and row actions', async () => {
it('should not show bulk actions and row actions on the modal', async () => {
const res = appMockRenderer.render(<AllCasesSelectorModal {...defaultProps} />);
await waitFor(() => {
expect(res.getByTestId('cases-table')).toBeInTheDocument();
Expand Down
16 changes: 6 additions & 10 deletions x-pack/plugins/cases/public/components/all_cases/use_actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import React, { useCallback, useState } from 'react';
import React, { useCallback, useMemo, useState } from 'react';
import {
EuiButtonIcon,
EuiContextMenu,
Expand Down Expand Up @@ -49,9 +49,9 @@ const ActionColumnComponent: React.FC<{ theCase: Case; disableActions: boolean }
const canDelete = deleteAction.canDelete;
const canUpdate = statusAction.canUpdateStatus;

const getPanels = useCallback((): EuiContextMenuPanelDescriptor[] => {
const panels = useMemo((): EuiContextMenuPanelDescriptor[] => {
const mainPanelItems: EuiContextMenuPanelItemDescriptor[] = [];
const panels: EuiContextMenuPanelDescriptor[] = [
const panelsToBuild: EuiContextMenuPanelDescriptor[] = [
{ id: 0, items: mainPanelItems, title: i18n.ACTIONS },
];

Expand Down Expand Up @@ -89,14 +89,14 @@ const ActionColumnComponent: React.FC<{ theCase: Case; disableActions: boolean }
}

if (canUpdate) {
panels.push({
panelsToBuild.push({
id: 1,
title: i18n.STATUS,
items: statusAction.getActions([theCase]),
});
}

return panels;
return panelsToBuild;
}, [canDelete, canUpdate, deleteAction, statusAction, theCase]);

return (
Expand All @@ -121,11 +121,7 @@ const ActionColumnComponent: React.FC<{ theCase: Case; disableActions: boolean }
panelPaddingSize="none"
anchorPosition="downLeft"
>
<EuiContextMenu
initialPanelId={0}
panels={getPanels()}
key={`case-action-menu-${theCase.id}`}
/>
<EuiContextMenu initialPanelId={0} panels={panels} key={`case-action-menu-${theCase.id}`} />
</EuiPopover>
{deleteAction.isModalVisible ? (
<ConfirmDeleteCaseModal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { EuiContextMenuPanelDescriptor, EuiContextMenuPanelItemDescriptor } from '@elastic/eui';
import React, { useCallback } from 'react';
import React, { useMemo } from 'react';

import { Case } from '../../containers/types';
import { useDeleteAction } from '../actions/delete/use_delete_action';
Expand Down Expand Up @@ -47,9 +47,9 @@ export const useBulkActions = ({
const canDelete = deleteAction.canDelete;
const canUpdate = statusAction.canUpdateStatus;

const getPanels = useCallback((): EuiContextMenuPanelDescriptor[] => {
const panels = useMemo((): EuiContextMenuPanelDescriptor[] => {
const mainPanelItems: EuiContextMenuPanelItemDescriptor[] = [];
const panels: EuiContextMenuPanelDescriptor[] = [
const panelsToBuild: EuiContextMenuPanelDescriptor[] = [
{ id: 0, items: mainPanelItems, title: i18n.ACTIONS },
];

Expand Down Expand Up @@ -81,14 +81,14 @@ export const useBulkActions = ({
}

if (canUpdate) {
panels.push({
panelsToBuild.push({
id: 1,
title: i18n.STATUS,
items: statusAction.getActions(selectedCases),
});
}

return panels;
return panelsToBuild;
}, [canDelete, canUpdate, deleteAction, isDisabled, selectedCases, statusAction]);

return {
Expand All @@ -103,6 +103,6 @@ export const useBulkActions = ({
) : null}
</>
),
panels: getPanels(),
panels,
};
};

0 comments on commit b4da899

Please sign in to comment.