Skip to content

Commit

Permalink
Pass owner to get cases
Browse files Browse the repository at this point in the history
  • Loading branch information
cnasikas committed May 12, 2021
1 parent 8e33930 commit cb62698
Show file tree
Hide file tree
Showing 19 changed files with 66 additions and 10 deletions.
1 change: 1 addition & 0 deletions x-pack/plugins/cases/common/ui/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export interface FilterOptions {
status: CaseStatusWithAllStatus;
tags: string[];
reporters: User[];
owner: string[];
onlyCollectionType?: boolean;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ interface AllCasesGenericProps {
onRowClick?: (theCase?: Case | SubCase) => void;
updateCase?: (newCase: Case) => void;
userCanCrud: boolean;
owner: string[];
}

export const AllCasesGeneric = React.memo<AllCasesGenericProps>(
Expand All @@ -77,6 +78,7 @@ export const AllCasesGeneric = React.memo<AllCasesGenericProps>(
onRowClick,
updateCase,
userCanCrud,
owner,
}) => {
const { actionLicense } = useGetActionLicense();
const {
Expand All @@ -90,7 +92,7 @@ export const AllCasesGeneric = React.memo<AllCasesGenericProps>(
setFilters,
setQueryParams,
setSelectedCases,
} = useGetCases();
} = useGetCases({ initialFilterOptions: { owner } });

// Post Comment to Case
const { postComment, isLoading: isCommentUpdating } = usePostComment();
Expand Down Expand Up @@ -286,6 +288,7 @@ export const AllCasesGeneric = React.memo<AllCasesGenericProps>(
reporters: filterOptions.reporters,
tags: filterOptions.tags,
status: filterOptions.status,
owner: filterOptions.owner,
}}
setFilterRefetch={setFilterRefetch}
disabledStatuses={disabledStatuses}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ describe('AllCasesGeneric', () => {
onClick: jest.fn(),
},
userCanCrud: true,
owner: ['securitySolution'],
};

const dispatchResetIsDeleted = jest.fn();
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/cases/public/components/all_cases/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface AllCasesProps {
configureCasesNavigation: CasesNavigation; // if not passed, header with nav is not displayed (Formerly dependant on isSelector)
createCaseNavigation: CasesNavigation;
userCanCrud: boolean;
owner: string[];
}

export const AllCases: React.FC<AllCasesProps> = (props) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const defaultProps = {
createCaseNavigation,
onRowClick,
userCanCrud: true,
owner: ['securitySolution'],
};
const updateCase = jest.fn();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface AllCasesSelectorModalProps {
onRowClick: (theCase?: Case | SubCase) => void;
updateCase?: (newCase: Case) => void;
userCanCrud: boolean;
owner: string[];
}

const Modal = styled(EuiModal)`
Expand All @@ -36,6 +37,7 @@ export const AllCasesSelectorModal: React.FC<AllCasesSelectorModalProps> = ({
onRowClick,
updateCase,
userCanCrud,
owner,
}) => {
const [isModalOpen, setIsModalOpen] = useState<boolean>(true);
const closeModal = useCallback(() => setIsModalOpen(false), []);
Expand All @@ -60,6 +62,7 @@ export const AllCasesSelectorModal: React.FC<AllCasesSelectorModalProps> = ({
onRowClick={onClick}
userCanCrud={userCanCrud}
updateCase={updateCase}
owner={owner}
/>
</EuiModalBody>
</Modal>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const defaultInitial = {
reporters: [],
status: StatusAll,
tags: [],
owner: [],
};

const CasesTableFiltersComponent = ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,17 @@ const CaseParamsFields: React.FunctionComponent<ActionParamsProps<CaseActionPara
actionParams.subAction,
]);

/**
* TODO: When the case connector is enabled we need to figure out
* how we can pass the owner to this component
*/
return (
<Container>
<ExistingCase onCaseChanged={onCaseChanged} selectedCase={selectedCase} />
<ExistingCase
onCaseChanged={onCaseChanged}
selectedCase={selectedCase}
owner="securitySolution"
/>
<EuiSpacer size="m" />
<EuiCallOut size="s" title={i18n.CASE_CONNECTOR_CALL_OUT_TITLE} iconType="iInCircle">
<p>{i18n.CASE_CONNECTOR_CALL_OUT_MSG}</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,25 @@ import { CasesDropdown, ADD_CASE_BUTTON_ID } from './cases_dropdown';
interface ExistingCaseProps {
selectedCase: string | null;
onCaseChanged: (id: string) => void;
/**
* We allow only one owner as this component queries
* for multiple cases and creates a single case.
*/
owner: string;
}

const ExistingCaseComponent: React.FC<ExistingCaseProps> = ({ onCaseChanged, selectedCase }) => {
const { data: cases, loading: isLoadingCases, refetchCases } = useGetCases(DEFAULT_QUERY_PARAMS, {
...DEFAULT_FILTER_OPTIONS,
onlyCollectionType: true,
const ExistingCaseComponent: React.FC<ExistingCaseProps> = ({
onCaseChanged,
selectedCase,
owner,
}) => {
const { data: cases, loading: isLoadingCases, refetchCases } = useGetCases({
initialQueryParams: DEFAULT_QUERY_PARAMS,
initialFilterOptions: {
...DEFAULT_FILTER_OPTIONS,
onlyCollectionType: true,
owner: [owner],
},
});

const onCaseCreated = useCallback(
Expand All @@ -41,6 +54,7 @@ const ExistingCaseComponent: React.FC<ExistingCaseProps> = ({ onCaseChanged, sel
// We are making the assumption that this component is only used in rules creation
// that's why we want to hide ServiceNow SIR
hideConnectorServiceNowSir: true,
owner,
});

const onChange = useCallback(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const defaultProps = {
onClick: jest.fn(),
},
maxCasesToShow: 10,
owner: ['securitySolution'],
};
const setFilters = jest.fn();
const mockData = {
Expand Down
3 changes: 3 additions & 0 deletions x-pack/plugins/cases/public/components/recent_cases/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ export interface RecentCasesProps {
caseDetailsNavigation: CasesNavigation<CaseDetailsHrefSchema, 'configurable'>;
createCaseNavigation: CasesNavigation;
maxCasesToShow: number;
owner: string[];
}

const RecentCases = ({
allCasesNavigation,
caseDetailsNavigation,
createCaseNavigation,
maxCasesToShow,
owner,
}: RecentCasesProps) => {
const currentUser = useCurrentUser();
const [recentCasesFilterBy, setRecentCasesFilterBy] = useState<RecentCasesFilterMode>(
Expand Down Expand Up @@ -74,6 +76,7 @@ const RecentCases = ({
createCaseNavigation={createCaseNavigation}
filterOptions={recentCasesFilterOptions}
maxCasesToShow={maxCasesToShow}
owner={owner}
/>
<EuiHorizontalRule margin="s" />
<EuiText size="xs">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export interface RecentCasesProps {
caseDetailsNavigation: CasesNavigation<CaseDetailsHrefSchema, 'configurable'>;
createCaseNavigation: CasesNavigation;
maxCasesToShow: number;
owner: string[];
}
const usePrevious = (value: Partial<FilterOptions>) => {
const ref = useRef();
Expand All @@ -44,9 +45,13 @@ export const RecentCasesComp = ({
createCaseNavigation,
filterOptions,
maxCasesToShow,
owner,
}: RecentCasesProps) => {
const previousFilterOptions = usePrevious(filterOptions);
const { data, loading, setFilters } = useGetCases({ perPage: maxCasesToShow });
const { data, loading, setFilters } = useGetCases({
initialQueryParams: { perPage: maxCasesToShow },
initialFilterOptions: { owner },
});

useEffect(() => {
if (previousFilterOptions !== undefined && !isEqual(previousFilterOptions, filterOptions)) {
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/cases/public/containers/__mocks__/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export const getCases = async ({
reporters: [],
status: CaseStatuses.open,
tags: [],
owner: [],
},
queryParams = {
page: 1,
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/cases/public/containers/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ export const getCases = async ({
reporters: [],
status: StatusAll,
tags: [],
owner: [],
},
queryParams = {
page: 1,
Expand All @@ -186,6 +187,7 @@ export const getCases = async ({
status: filterOptions.status,
...(filterOptions.search.length > 0 ? { search: filterOptions.search } : {}),
...(filterOptions.onlyCollectionType ? { type: CaseType.collection } : {}),
...(filterOptions.owner.length > 0 ? { owner: filterOptions.owner } : {}),
...queryParams,
};
const response = await KibanaServices.get().http.fetch<CasesFindResponse>(`${CASES_URL}/_find`, {
Expand Down
13 changes: 10 additions & 3 deletions x-pack/plugins/cases/public/containers/use_get_cases.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export const DEFAULT_FILTER_OPTIONS: FilterOptions = {
status: StatusAll,
tags: [],
onlyCollectionType: false,
owner: [],
};

export const DEFAULT_QUERY_PARAMS: QueryParams = {
Expand Down Expand Up @@ -139,12 +140,18 @@ export interface UseGetCases extends UseGetCasesState {

const empty = {};
export const useGetCases = (
initialQueryParams: Partial<QueryParams> = empty,
initialFilterOptions: Partial<FilterOptions> = empty
params: Partial<{
initialQueryParams?: Partial<QueryParams>;
initialFilterOptions?: Partial<FilterOptions>;
}> = {}
): UseGetCases => {
const { initialQueryParams = empty, initialFilterOptions = empty } = params;
const [state, dispatch] = useReducer(dataFetchReducer, {
data: initialData,
filterOptions: { ...DEFAULT_FILTER_OPTIONS, ...initialFilterOptions },
filterOptions: {
...DEFAULT_FILTER_OPTIONS,
...initialFilterOptions,
},
isError: false,
loading: [],
queryParams: { ...DEFAULT_QUERY_PARAMS, ...initialQueryParams },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export const AllCases = React.memo<AllCasesProps>(({ userCanCrud }) => {
onClick: goToCreateCase,
},
userCanCrud,
owner: [APP_ID],
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ const AddToCaseActionComponent: React.FC<AddToCaseActionProps> = ({
onRowClick: onCaseClicked,
updateCase: onCaseSuccess,
userCanCrud: userPermissions?.crud ?? false,
owner: [APP_ID],
})}
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const RecentCasesComponent = () => {
},
},
maxCasesToShow: MAX_CASES_TO_SHOW,
owner: [APP_ID],
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ const AddToCaseButtonComponent: React.FC<Props> = ({ timelineId }) => {
},
onRowClick,
userCanCrud: userPermissions?.crud ?? false,
owner: [APP_ID],
})}
</>
);
Expand Down

0 comments on commit cb62698

Please sign in to comment.