Skip to content

Commit

Permalink
cache-first
Browse files Browse the repository at this point in the history
  • Loading branch information
patrykkopycinski committed Jul 27, 2020
1 parent 023fbc4 commit de4940d
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ const StatefulEventsViewerComponent: React.FC<Props> = ({
}) => {
const [
{ docValueFields, browserFields, indexPatterns, isLoading: isLoadingIndexPattern },
] = useFetchIndexPatterns(defaultIndices ?? useUiSetting<string[]>(DEFAULT_INDEX_KEY));
] = useFetchIndexPatterns(
defaultIndices ?? useUiSetting<string[]>(DEFAULT_INDEX_KEY),
'events_viewer'
);

useEffect(() => {
if (createTimeline != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ interface UseWithSourceState {
export const useWithSource = (
sourceId = 'default',
indexToAdd?: string[] | null,
onlyCheckIndexToAdd?: boolean
onlyCheckIndexToAdd?: boolean,
queryDeduplication? = 'default'
) => {
const [configIndex] = useUiSetting$<string[]>(DEFAULT_INDEX_KEY);
const defaultIndex = useMemo<string[]>(() => {
Expand Down Expand Up @@ -160,6 +161,7 @@ export const useWithSource = (
variables: {
sourceId,
defaultIndex,
queryDeduplication,
},
context: {
fetchOptions: {
Expand Down Expand Up @@ -206,7 +208,7 @@ export const useWithSource = (
isSubscribed = false;
return abortCtrl.abort();
};
}, [apolloClient, sourceId, defaultIndex]);
}, [apolloClient, sourceId, defaultIndex, queryDeduplication]);

return state;
};
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ export const AlertsTableComponent: React.FC<AlertsTableComponentProps> = ({
addExceptionModalInitialState
);
const [{ browserFields, indexPatterns }] = useFetchIndexPatterns(
signalsIndex !== '' ? [signalsIndex] : []
signalsIndex !== '' ? [signalsIndex] : [],
'alerts_table'
);
const kibana = useKibana();
const [, dispatchToaster] = useStateToaster();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ const StepAboutRuleComponent: FC<StepAboutRuleProps> = ({
const initialState = defaultValues ?? stepAboutDefaultValue;
const [myStepData, setMyStepData] = useState<AboutStepRule>(initialState);
const [{ isLoading: indexPatternLoading, indexPatterns }] = useFetchIndexPatterns(
defineRuleData?.index ?? []
defineRuleData?.index ?? [],
'about_rule_form'
);
const canUseExceptions =
defineRuleData?.ruleType &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ const StepDefineRuleComponent: FC<StepDefineRuleProps> = ({
const [myStepData, setMyStepData] = useState<DefineStepRule>(initialState);
const [
{ browserFields, indexPatterns: indexPatternQueryBar, isLoading: indexPatternLoadingQueryBar },
] = useFetchIndexPatterns(myStepData.index);
] = useFetchIndexPatterns(myStepData.index, 'define_rule_form');

const { form } = useForm({
defaultValue: initialState,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export const useFetchIndexPatterns = (
apolloClient
.query<SourceQuery.Query, SourceQuery.Variables>({
query: sourceQuery,
fetchPolicy: 'network-only',
fetchPolicy: 'cache-first',
variables: {
sourceId: 'default',
defaultIndex: indices,
Expand Down

0 comments on commit de4940d

Please sign in to comment.