Skip to content

Commit

Permalink
[Cases] Table Solution Filter Not Rendering Any Checked Option When A…
Browse files Browse the repository at this point in the history
…ll Selected (elastic#172460)

Co-authored-by: Christos Nasikas <[email protected]>
  • Loading branch information
jcger and cnasikas authored Dec 13, 2023
1 parent d3535bd commit b6d291d
Show file tree
Hide file tree
Showing 11 changed files with 207 additions and 168 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,6 @@ describe('AllCasesListGeneric', () => {
filterOptions: {
...DEFAULT_FILTER_OPTIONS,
searchFields: ['title', 'description'],
owner: ['securitySolution'],
category: ['twix'],
},
queryParams: DEFAULT_QUERY_PARAMS,
Expand Down Expand Up @@ -645,82 +644,6 @@ describe('AllCasesListGeneric', () => {
});

describe('Solutions', () => {
it('should set the owner to all available solutions when deselecting all solutions', async () => {
const { getByTestId } = render(
<TestProviders owner={[]}>
<AllCasesList />
</TestProviders>
);

expect(useGetCasesMock).toHaveBeenCalledWith({
filterOptions: {
search: '',
searchFields: ['title', 'description'],
severity: [],
reporters: [],
status: [],
tags: [],
assignees: [],
owner: ['securitySolution', 'observability'],
category: [],
customFields: {},
},
queryParams: DEFAULT_QUERY_PARAMS,
});

userEvent.click(getByTestId('options-filter-popover-button-owner'));

await waitForEuiPopoverOpen();

userEvent.click(
getByTestId(`options-filter-popover-item-${SECURITY_SOLUTION_OWNER}`),
undefined,
{
skipPointerEventsCheck: true,
}
);

expect(useGetCasesMock).toBeCalledWith({
filterOptions: {
search: '',
searchFields: ['title', 'description'],
severity: [],
reporters: [],
status: [],
tags: [],
assignees: [],
owner: ['securitySolution'],
category: [],
customFields: {},
},
queryParams: DEFAULT_QUERY_PARAMS,
});

userEvent.click(
getByTestId(`options-filter-popover-item-${SECURITY_SOLUTION_OWNER}`),
undefined,
{
skipPointerEventsCheck: true,
}
);

expect(useGetCasesMock).toHaveBeenLastCalledWith({
filterOptions: {
search: '',
searchFields: ['title', 'description'],
severity: [],
reporters: [],
status: [],
tags: [],
assignees: [],
owner: ['securitySolution', 'observability'],
category: [],
customFields: {},
},
queryParams: DEFAULT_QUERY_PARAMS,
});
});

it('should hide the solutions filter if the owner is provided', async () => {
const { queryByTestId } = render(
<TestProviders owner={[SECURITY_SOLUTION_OWNER]}>
Expand All @@ -730,30 +653,6 @@ describe('AllCasesListGeneric', () => {

expect(queryByTestId('options-filter-popover-button-owner')).toBeFalsy();
});

it('should call useGetCases with the correct owner on initial render', async () => {
render(
<TestProviders owner={[SECURITY_SOLUTION_OWNER]}>
<AllCasesList />
</TestProviders>
);

expect(useGetCasesMock).toHaveBeenCalledWith({
filterOptions: {
search: '',
searchFields: ['title', 'description'],
severity: [],
reporters: [],
status: [],
tags: [],
assignees: [],
owner: ['securitySolution'],
category: [],
customFields: {},
},
queryParams: DEFAULT_QUERY_PARAMS,
});
});
});

describe('Actions', () => {
Expand Down Expand Up @@ -1102,7 +1001,6 @@ describe('AllCasesListGeneric', () => {
expect(useGetCasesMock).toHaveBeenLastCalledWith({
filterOptions: {
...DEFAULT_FILTER_OPTIONS,
owner: [SECURITY_SOLUTION_OWNER],
assignees: [],
},
queryParams: DEFAULT_QUERY_PARAMS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ export const AllCasesList = React.memo<AllCasesListProps>(
const isLoading = useIsLoadingCases();

const hasOwner = !!owner.length;

const firstAvailableStatus = head(difference(caseStatuses, hiddenStatuses));
const initialFilterOptions = {
...(!isEmpty(hiddenStatuses) && firstAvailableStatus && { status: [firstAvailableStatus] }),
owner: hasOwner ? owner : availableSolutions,
};

const { queryParams, setQueryParams, filterOptions, setFilterOptions } = useAllCasesState(
Expand Down Expand Up @@ -210,7 +210,6 @@ export const AllCasesList = React.memo<AllCasesListProps>(
availableSolutions={hasOwner ? [] : availableSolutions}
hiddenStatuses={hiddenStatuses}
onCreateCasePressed={onCreateCasePressed}
initialFilterOptions={initialFilterOptions}
isSelectorView={isSelectorView}
isLoading={isLoadingCurrentUserProfile}
currentUserProfile={currentUserProfile}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ describe('SolutionFilter ', () => {

expect(onChange).toHaveBeenCalledWith({
filterId: 'owner',
selectedOptionKeys: [solutions[0]],
selectedOptionKeys: [],
});
});
});
Expand Down Expand Up @@ -168,7 +168,7 @@ describe('SolutionFilter ', () => {

expect(onChange).toHaveBeenCalledWith({
filterId: 'owner',
selectedOptionKeys: [solutions[0], solutions[1]],
selectedOptionKeys: [],
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,37 +43,6 @@ export const SolutionFilterComponent = ({
const options = mapToMultiSelectOption(hasOwner ? owner : availableSolutions);
const solutions = availableSolutions.map((solution) => mapToReadableSolutionName(solution));

/**
* If the user selects and deselects all solutions then the owner is set to an empty array.
* This results in fetching all cases the user has access to including
* the ones with read access. We want to show only the cases the user has full access to.
* For that reason we fallback to availableSolutions if the owner is empty.
*
* If the consumer of cases has passed an owner we fallback to the provided owner
*/
const _onChange = ({
filterId,
selectedOptionKeys: newOptions,
}: {
filterId: string;
selectedOptionKeys: string[];
}) => {
if (hasOwner) {
onChange({
filterId,
selectedOptionKeys: newOptions.length === 0 ? owner : newOptions,
});
} else {
onChange({
filterId,
selectedOptionKeys: newOptions.length === 0 ? availableSolutions : newOptions,
});
}
};

const selectedOptionsInFilter =
selectedOptionKeys.length === availableSolutions.length ? [] : selectedOptionKeys;

const renderOption = (option: EuiSelectableOption) => {
const solution = solutions.find((solutionData) => solutionData.id === option.label) as Solution;
return (
Expand All @@ -90,10 +59,10 @@ export const SolutionFilterComponent = ({
<MultiSelectFilter
buttonLabel={i18n.SOLUTION}
id={'owner'}
onChange={_onChange}
onChange={onChange}
options={options}
renderOption={renderOption}
selectedOptionKeys={selectedOptionsInFilter}
selectedOptionKeys={selectedOptionKeys}
/>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import React from 'react';

import type { FilterOptions } from '../../../../common/ui';
import type { CaseStatuses } from '../../../../common/types/domain';
import { MAX_TAGS_FILTER_LENGTH, MAX_CATEGORY_FILTER_LENGTH } from '../../../../common/constants';
import { MultiSelectFilter, mapToMultiSelectOption } from '../multi_select_filter';
Expand All @@ -28,7 +27,6 @@ interface UseFilterConfigProps {
countOpenCases: number | null;
currentUserProfile: CurrentUserProfile;
hiddenStatuses?: CaseStatuses[];
initialFilterOptions: Partial<FilterOptions>;
isLoading: boolean;
isSelectorView?: boolean;
onFilterOptionsChange: FilterChangeHandler;
Expand All @@ -44,7 +42,6 @@ export const getSystemFilterConfig = ({
countOpenCases,
currentUserProfile,
hiddenStatuses,
initialFilterOptions,
isLoading,
isSelectorView,
onFilterOptionsChange,
Expand All @@ -69,7 +66,7 @@ export const getSystemFilterConfig = ({
isAvailable: true,
getEmptyOptions: () => {
return {
severity: initialFilterOptions.severity || [],
severity: [],
};
},
render: ({ filterOptions }: FilterConfigRenderParams) => (
Expand All @@ -86,7 +83,7 @@ export const getSystemFilterConfig = ({
isAvailable: true,
getEmptyOptions: () => {
return {
status: initialFilterOptions.status || [],
status: [],
};
},
render: ({ filterOptions }: FilterConfigRenderParams) => (
Expand All @@ -107,7 +104,7 @@ export const getSystemFilterConfig = ({
isAvailable: caseAssignmentAuthorized && !isSelectorView,
getEmptyOptions: () => {
return {
assignees: initialFilterOptions.assignees || [],
assignees: [],
};
},
render: ({ filterOptions }: FilterConfigRenderParams) => {
Expand All @@ -128,7 +125,7 @@ export const getSystemFilterConfig = ({
isAvailable: true,
getEmptyOptions: () => {
return {
tags: initialFilterOptions.tags || [],
tags: [],
};
},
render: ({ filterOptions }: FilterConfigRenderParams) => (
Expand All @@ -150,7 +147,7 @@ export const getSystemFilterConfig = ({
isAvailable: true,
getEmptyOptions: () => {
return {
category: initialFilterOptions.category || [],
category: [],
};
},
render: ({ filterOptions }: FilterConfigRenderParams) => (
Expand All @@ -172,7 +169,7 @@ export const getSystemFilterConfig = ({
isAvailable: availableSolutions.length > 1,
getEmptyOptions: () => {
return {
owner: initialFilterOptions.owner || [],
owner: [],
};
},
render: ({ filterOptions }: FilterConfigRenderParams) => (
Expand All @@ -195,7 +192,6 @@ export const useSystemFilterConfig = ({
countOpenCases,
currentUserProfile,
hiddenStatuses,
initialFilterOptions,
isLoading,
isSelectorView,
onFilterOptionsChange,
Expand All @@ -210,7 +206,6 @@ export const useSystemFilterConfig = ({
countOpenCases,
currentUserProfile,
hiddenStatuses,
initialFilterOptions,
isLoading,
isSelectorView,
onFilterOptionsChange,
Expand Down
Loading

0 comments on commit b6d291d

Please sign in to comment.