Skip to content

Commit cf26f23

Browse files
committed
Fixes empty exception modal issue
1 parent b0ef3e9 commit cf26f23

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

x-pack/plugins/security_solution/public/common/components/exceptions/add_exception_modal/index.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,12 @@ export const AddExceptionModal = memo(function AddExceptionModal({
114114
const { loading: isSignalIndexLoading, signalIndexName } = useSignalIndex();
115115
const [
116116
{ isLoading: isSignalIndexPatternLoading, indexPatterns: signalIndexPatterns },
117-
] = useFetchIndexPatterns(signalIndexName !== null ? [signalIndexName] : []);
117+
] = useFetchIndexPatterns(signalIndexName !== null ? [signalIndexName] : [], 'signals');
118118

119-
const [{ isLoading: isIndexPatternLoading, indexPatterns }] = useFetchIndexPatterns(ruleIndices);
119+
const [{ isLoading: isIndexPatternLoading, indexPatterns }] = useFetchIndexPatterns(
120+
ruleIndices,
121+
'rules'
122+
);
120123

121124
const onError = useCallback(
122125
(error: Error) => {

x-pack/plugins/security_solution/public/common/components/exceptions/edit_exception_modal/index.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,12 @@ export const EditExceptionModal = memo(function EditExceptionModal({
9797
const { loading: isSignalIndexLoading, signalIndexName } = useSignalIndex();
9898
const [
9999
{ isLoading: isSignalIndexPatternLoading, indexPatterns: signalIndexPatterns },
100-
] = useFetchIndexPatterns(signalIndexName !== null ? [signalIndexName] : []);
100+
] = useFetchIndexPatterns(signalIndexName !== null ? [signalIndexName] : [], 'signals');
101101

102-
const [{ isLoading: isIndexPatternLoading, indexPatterns }] = useFetchIndexPatterns(ruleIndices);
102+
const [{ isLoading: isIndexPatternLoading, indexPatterns }] = useFetchIndexPatterns(
103+
ruleIndices,
104+
'rules'
105+
);
103106

104107
const onError = useCallback(
105108
(error) => {

x-pack/plugins/security_solution/public/detections/containers/detection_engine/rules/fetch_index_patterns.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,14 @@ const DEFAULT_BROWSER_FIELDS = {};
3838
const DEFAULT_INDEX_PATTERNS = { fields: [], title: '' };
3939
const DEFAULT_DOC_VALUE_FIELDS: DocValueFields[] = [];
4040

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

@@ -74,6 +81,7 @@ export const useFetchIndexPatterns = (defaultIndices: string[] = []): Return =>
7481
variables: {
7582
sourceId: 'default',
7683
defaultIndex: indices,
84+
...(queryDeduplication != null ? { queryDeduplication } : {}),
7785
},
7886
context: {
7987
fetchOptions: {

0 commit comments

Comments
 (0)