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

[Security Solution] Fixes exception modal not loading content #72770

Merged
merged 1 commit into from
Jul 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,12 @@ export const AddExceptionModal = memo(function AddExceptionModal({
const { loading: isSignalIndexLoading, signalIndexName } = useSignalIndex();
const [
{ isLoading: isSignalIndexPatternLoading, indexPatterns: signalIndexPatterns },
] = useFetchIndexPatterns(signalIndexName !== null ? [signalIndexName] : []);
] = useFetchIndexPatterns(signalIndexName !== null ? [signalIndexName] : [], 'signals');

const [{ isLoading: isIndexPatternLoading, indexPatterns }] = useFetchIndexPatterns(ruleIndices);
const [{ isLoading: isIndexPatternLoading, indexPatterns }] = useFetchIndexPatterns(
ruleIndices,
'rules'
);

const onError = useCallback(
(error: Error) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,12 @@ export const EditExceptionModal = memo(function EditExceptionModal({
const { loading: isSignalIndexLoading, signalIndexName } = useSignalIndex();
const [
{ isLoading: isSignalIndexPatternLoading, indexPatterns: signalIndexPatterns },
] = useFetchIndexPatterns(signalIndexName !== null ? [signalIndexName] : []);
] = useFetchIndexPatterns(signalIndexName !== null ? [signalIndexName] : [], 'signals');

const [{ isLoading: isIndexPatternLoading, indexPatterns }] = useFetchIndexPatterns(ruleIndices);
const [{ isLoading: isIndexPatternLoading, indexPatterns }] = useFetchIndexPatterns(
ruleIndices,
'rules'
);

const onError = useCallback(
(error) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,14 @@ const DEFAULT_BROWSER_FIELDS = {};
const DEFAULT_INDEX_PATTERNS = { fields: [], title: '' };
const DEFAULT_DOC_VALUE_FIELDS: DocValueFields[] = [];

export const useFetchIndexPatterns = (defaultIndices: string[] = []): Return => {
// Fun fact: When using this hook multiple times within a component (e.g. add_exception_modal & edit_exception_modal),
// the apolloClient will perform queryDeduplication and prevent the first query from executing. A deep compare is not
// performed on `indices`, so another field must be passed to circumvent this.
// For details, see https://github.com/apollographql/react-apollo/issues/2202
export const useFetchIndexPatterns = (
defaultIndices: string[] = [],
queryDeduplication?: string
): Return => {
const apolloClient = useApolloClient();
const [indices, setIndices] = useState<string[]>(defaultIndices);

Expand Down Expand Up @@ -74,6 +81,7 @@ export const useFetchIndexPatterns = (defaultIndices: string[] = []): Return =>
variables: {
sourceId: 'default',
defaultIndex: indices,
...(queryDeduplication != null ? { queryDeduplication } : {}),
},
context: {
fetchOptions: {
Expand Down