[Cases] Do not show status dropdown on modal cases selector (#111101)

This commit is contained in:
Christos Nasikas 2021-09-03 16:10:29 +03:00 committed by GitHub
parent 71571c5b60
commit 6f357e0433
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 63 additions and 35 deletions

View file

@ -203,7 +203,8 @@ export const AllCasesGeneric = React.memo<AllCasesGenericProps>(
handleIsLoading,
isLoadingCases: loading,
refreshCases,
showActions,
// isSelectorView is boolean | undefined. We need to convert it to a boolean.
isSelectorView: !!isSelectorView,
userCanCrud,
connectors,
});

View file

@ -72,7 +72,7 @@ export interface GetCasesColumn {
handleIsLoading: (a: boolean) => void;
isLoadingCases: string[];
refreshCases?: (a?: boolean) => void;
showActions: boolean;
isSelectorView: boolean;
userCanCrud: boolean;
connectors?: ActionConnector[];
}
@ -84,7 +84,7 @@ export const useCasesColumns = ({
handleIsLoading,
isLoadingCases,
refreshCases,
showActions,
isSelectorView,
userCanCrud,
connectors = [],
}: GetCasesColumn): CasesColumns[] => {
@ -281,38 +281,42 @@ export const useCasesColumns = ({
return getEmptyTagValue();
},
},
{
name: i18n.STATUS,
render: (theCase: Case) => {
if (theCase?.subCases == null || theCase.subCases.length === 0) {
if (theCase.status == null || theCase.type === CaseType.collection) {
return getEmptyTagValue();
}
return (
<StatusContextMenu
currentStatus={theCase.status}
disabled={!userCanCrud || isLoadingCases.length > 0}
onStatusChanged={(status) =>
handleDispatchUpdate({
updateKey: 'status',
updateValue: status,
caseId: theCase.id,
version: theCase.version,
})
...(!isSelectorView
? [
{
name: i18n.STATUS,
render: (theCase: Case) => {
if (theCase?.subCases == null || theCase.subCases.length === 0) {
if (theCase.status == null || theCase.type === CaseType.collection) {
return getEmptyTagValue();
}
return (
<StatusContextMenu
currentStatus={theCase.status}
disabled={!userCanCrud || isLoadingCases.length > 0}
onStatusChanged={(status) =>
handleDispatchUpdate({
updateKey: 'status',
updateValue: status,
caseId: theCase.id,
version: theCase.version,
})
}
/>
);
}
/>
);
}
const badges = getSubCasesStatusCountsBadges(theCase.subCases);
return badges.map(({ color, count }, index) => (
<EuiBadge key={index} color={color}>
{count}
</EuiBadge>
));
},
},
...(showActions
const badges = getSubCasesStatusCountsBadges(theCase.subCases);
return badges.map(({ color, count }, index) => (
<EuiBadge key={index} color={color}>
{count}
</EuiBadge>
));
},
},
]
: []),
...(userCanCrud && !isSelectorView
? [
{
name: (

View file

@ -144,7 +144,7 @@ describe('AllCasesGeneric', () => {
filterStatus: CaseStatuses.open,
handleIsLoading: jest.fn(),
isLoadingCases: [],
showActions: true,
isSelectorView: false,
userCanCrud: true,
};
@ -377,7 +377,7 @@ describe('AllCasesGeneric', () => {
isLoadingCases: [],
filterStatus: CaseStatuses.open,
handleIsLoading: jest.fn(),
showActions: false,
isSelectorView: true,
userCanCrud: true,
})
);
@ -926,4 +926,27 @@ describe('AllCasesGeneric', () => {
).toBeFalsy();
});
});
it('should not render status when isSelectorView=true', async () => {
const wrapper = mount(
<TestProviders>
<AllCases {...defaultAllCasesProps} isSelectorView={true} />
</TestProviders>
);
const { result } = renderHook<GetCasesColumn, CasesColumns[]>(() =>
useCasesColumns({
...defaultColumnArgs,
isSelectorView: true,
})
);
expect(result.current.find((i) => i.name === 'Status')).toBeFalsy();
await waitFor(() => {
expect(wrapper.find('[data-test-subj="cases-table"]').exists()).toBeTruthy();
});
expect(wrapper.find('[data-test-subj="case-view-status-dropdown"]').exists()).toBeFalsy();
});
});