Skip to content

Commit

Permalink
renamed reloadAlerts to onSave wit hdeprecation (#91997) (#92375)
Browse files Browse the repository at this point in the history
The `reloadAlerts` properties in `AlertAdd` and `AlertEdit` are confusing property names.
In this PR we deprecate those and replace them with `onSave`.
  • Loading branch information
gmmorris committed Feb 23, 2021
1 parent 24fea4d commit 1d63263
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 12 deletions.
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

0 comments on commit 1d63263

Please sign in to comment.