Skip to content

Commit

Permalink
Revert signal for loadRule as there is no tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fkanout committed May 12, 2022
1 parent a9e9704 commit e8fa815
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 28 deletions.
38 changes: 14 additions & 24 deletions x-pack/plugins/observability/public/hooks/use_fetch_rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,39 +22,29 @@ export function useFetchRule({ ruleId, http }: FetchRuleProps) {

const fetchRuleSummary = useCallback(async () => {
try {
isCancelledRef.current = false;
abortCtrlRef.current.abort();
abortCtrlRef.current = new AbortController();
const [rule, ruleTypes] = await Promise.all([
loadRule({
http,
ruleId,
signal: abortCtrlRef.current.signal,
}),
loadRuleTypes({ http }),
]);

if (!isCancelledRef.current) {
const ruleType = ruleTypes.find((type) => type.id === rule.ruleTypeId);
setRuleSummary((oldState: FetchRule) => ({
...oldState,
isRuleLoading: false,
rule,
ruleType,
}));
}
const ruleType = ruleTypes.find((type) => type.id === rule.ruleTypeId);
setRuleSummary((oldState: FetchRule) => ({
...oldState,
isRuleLoading: false,
rule,
ruleType,
}));
} catch (error) {
if (!isCancelledRef.current) {
if (error.name !== 'AbortError') {
setRuleSummary((oldState: FetchRule) => ({
...oldState,
isRuleLoading: false,
errorRule: RULE_LOAD_ERROR(
error instanceof Error ? error.message : typeof error === 'string' ? error : ''
),
}));
}
}
setRuleSummary((oldState: FetchRule) => ({
...oldState,
isRuleLoading: false,
errorRule: RULE_LOAD_ERROR(
error instanceof Error ? error.message : typeof error === 'string' ? error : ''
),
}));
}
}, [ruleId, http]);
useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,14 @@ import { transformRule } from './common_transformations';

export async function loadRule({
http,
signal,

ruleId,
}: {
http: HttpSetup;
signal: AbortSignal;
ruleId: string;
}): Promise<Rule> {
const res = await http.get<AsApiContract<Rule>>(
`${INTERNAL_BASE_ALERTING_API_PATH}/rule/${encodeURIComponent(ruleId)}`,
{ signal }
`${INTERNAL_BASE_ALERTING_API_PATH}/rule/${encodeURIComponent(ruleId)}`
);
return transformRule(res);
}

0 comments on commit e8fa815

Please sign in to comment.