forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Actionable Observability][BUG] Fix connectors doesn't appear in the …
…Rule Details page after creating first connector (elastic#133737) * Move rule actions to the hook which is right call * Update naming * Fix when a connector is deleted from connector page in Stack Management * Fix tests * Update tests and mock loadAllActions API * Remove unused import * Call the connectors API only when the rule has actions
- Loading branch information
Showing
5 changed files
with
109 additions
and
83 deletions.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
x-pack/plugins/observability/public/hooks/use_fetch_rule_action_connectors.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { useEffect, useState, useCallback } from 'react'; | ||
import { ActionConnector, loadAllActions } from '@kbn/triggers-actions-ui-plugin/public'; | ||
import { intersectionBy } from 'lodash'; | ||
import { FetchRuleActionConnectorsProps } from '../pages/rule_details/types'; | ||
import { ACTIONS_LOAD_ERROR } from '../pages/rule_details/translations'; | ||
|
||
interface FetchActionConnectors { | ||
isLoadingActionConnectors: boolean; | ||
actionConnectors: Array<ActionConnector<Record<string, unknown>>>; | ||
errorActionConnectors?: string; | ||
} | ||
|
||
export function useFetchRuleActionConnectors({ | ||
http, | ||
ruleActions, | ||
}: FetchRuleActionConnectorsProps) { | ||
const [actionConnectors, setActionConnector] = useState<FetchActionConnectors>({ | ||
isLoadingActionConnectors: true, | ||
actionConnectors: [] as Array<ActionConnector<Record<string, unknown>>>, | ||
errorActionConnectors: undefined, | ||
}); | ||
|
||
const fetchRuleActionConnectors = useCallback(async () => { | ||
try { | ||
if (!ruleActions || ruleActions.length <= 0) { | ||
setActionConnector((oldState: FetchActionConnectors) => ({ | ||
...oldState, | ||
isLoadingActionConnectors: false, | ||
actionConnectors: [], | ||
})); | ||
return; | ||
} | ||
const allActions = await loadAllActions({ | ||
http, | ||
}); | ||
const actions = intersectionBy(allActions, ruleActions, 'actionTypeId'); | ||
setActionConnector((oldState: FetchActionConnectors) => ({ | ||
...oldState, | ||
isLoadingActionConnectors: false, | ||
actionConnectors: actions, | ||
})); | ||
} catch (error) { | ||
setActionConnector((oldState: FetchActionConnectors) => ({ | ||
...oldState, | ||
isLoadingActionConnectors: false, | ||
errorActionConnectors: ACTIONS_LOAD_ERROR( | ||
error instanceof Error ? error.message : typeof error === 'string' ? error : '' | ||
), | ||
})); | ||
} | ||
}, [http, ruleActions]); | ||
useEffect(() => { | ||
fetchRuleActionConnectors(); | ||
}, [fetchRuleActionConnectors]); | ||
|
||
return { | ||
...actionConnectors, | ||
reloadRuleActionConnectors: fetchRuleActionConnectors, | ||
}; | ||
} |
51 changes: 0 additions & 51 deletions
51
x-pack/plugins/observability/public/hooks/use_fetch_rule_actions.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters