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

[Alerting] deprecates reloadAlerts and replaces with onSave in Alert creation and editing #91997

Merged
merged 4 commits into from
Feb 23, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion x-pack/plugins/ml/public/alerting/ml_alerting_flyout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const MlAnomalyAlertFlyout: FC<MlAnomalyAlertFlyoutProps> = ({
onCloseFlyout();
},
// Callback for successful save
reloadAlerts: async () => {
onSave: async () => {
if (onSave) {
onSave();
}
Expand Down
6 changes: 3 additions & 3 deletions x-pack/plugins/triggers_actions_ui/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,7 @@ interface AlertAddProps {
alertTypeId?: string;
canChangeTrigger?: boolean;
initialValues?: Partial<Alert>;
reloadAlerts?: () => Promise<void>;
onSave?: () => Promise<void>;
metadata?: MetaData;
}
```
Expand All @@ -845,7 +845,7 @@ interface AlertAddProps {
|setAddFlyoutVisibility|Function for changing visibility state of the Create Alert flyout.|
|alertTypeId|Optional property to preselect alert type.|
|canChangeTrigger|Optional property, that hides change alert type possibility.|
|reloadAlerts|Optional function, which will be executed if alert was saved sucsessfuly.|
|onSave|Optional function, which will be executed if alert was saved sucsessfuly.|
|initialValues|Default values for Alert properties.|
|metadata|Optional generic property, which allows to define component specific metadata. This metadata can be used for passing down preloaded data for Alert type expression component.|

Expand Down Expand Up @@ -1470,7 +1470,7 @@ interface ActionAccordionFormProps {

|Property|Description|
|---|---|
|reloadAlerts|Optional function, which will be executed if alert was saved sucsessfuly.|
|onSave|Optional function, which will be executed if alert was saved sucsessfuly.|
|http|HttpSetup needed for executing API calls.|
|alertTypeRegistry|Registry for alert types.|
|actionTypeRegistry|Registry for action types.|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export const AlertDetails: React.FunctionComponent<AlertDetailsProps> = ({
}}
actionTypeRegistry={actionTypeRegistry}
alertTypeRegistry={alertTypeRegistry}
reloadAlerts={setAlert}
onSave={setAlert}
/>
)}
</Fragment>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ describe('alert_add', () => {
consumer={ALERTS_FEATURE_ID}
onClose={onClose}
initialValues={initialValues}
reloadAlerts={() => {
onSave={() => {
return new Promise<void>(() => {});
}}
actionTypeRegistry={actionTypeRegistry}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ export interface AlertAddProps<MetaData = Record<string, any>> {
alertTypeId?: string;
canChangeTrigger?: boolean;
initialValues?: Partial<Alert>;
/** @deprecated use `onSave` as a callback after an alert is saved*/
reloadAlerts?: () => Promise<void>;
onSave?: () => Promise<void>;
metadata?: MetaData;
}

Expand All @@ -52,8 +54,10 @@ const AlertAdd = ({
alertTypeId,
initialValues,
reloadAlerts,
onSave,
metadata,
}: AlertAddProps) => {
const onSaveHandler = onSave ?? reloadAlerts;
const initialAlert: InitialAlert = useMemo(
() => ({
params: {},
Expand Down Expand Up @@ -129,8 +133,8 @@ const AlertAdd = ({
setIsSaving(false);
if (savedAlert) {
onClose(AlertFlyoutCloseReason.SAVED);
if (reloadAlerts) {
reloadAlerts();
if (onSaveHandler) {
onSaveHandler();
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ describe('alert_edit', () => {
<AlertEdit
onClose={() => {}}
initialAlert={alert}
reloadAlerts={() => {
onSave={() => {
return new Promise<void>(() => {});
}}
actionTypeRegistry={actionTypeRegistry}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,22 @@ export interface AlertEditProps<MetaData = Record<string, any>> {
alertTypeRegistry: AlertTypeRegistryContract;
actionTypeRegistry: ActionTypeRegistryContract;
onClose: (reason: AlertFlyoutCloseReason) => void;
/** @deprecated use `onSave` as a callback after an alert is saved*/
reloadAlerts?: () => Promise<void>;
onSave?: () => Promise<void>;
metadata?: MetaData;
}

export const AlertEdit = ({
initialAlert,
onClose,
reloadAlerts,
onSave,
alertTypeRegistry,
actionTypeRegistry,
metadata,
}: AlertEditProps) => {
const onSaveHandler = onSave ?? reloadAlerts;
const [{ alert }, dispatch] = useReducer(alertReducer as ConcreteAlertReducer, {
alert: cloneDeep(initialAlert),
});
Expand Down Expand Up @@ -203,8 +207,8 @@ export const AlertEdit = ({
setIsSaving(false);
if (savedAlert) {
onClose(AlertFlyoutCloseReason.SAVED);
if (reloadAlerts) {
reloadAlerts();
if (onSaveHandler) {
onSaveHandler();
}
}
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ export const AlertsList: React.FunctionComponent = () => {
}}
actionTypeRegistry={actionTypeRegistry}
alertTypeRegistry={alertTypeRegistry}
reloadAlerts={loadAlertsData}
onSave={loadAlertsData}
/>
)}
</section>
Expand Down