Skip to content

Commit

Permalink
renamed reloadAlerts to onSave wit hdeprecation
Browse files Browse the repository at this point in the history
  • Loading branch information
gmmorris committed Feb 19, 2021
1 parent bf7fdfc commit c94e84a
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 @@ -143,7 +143,7 @@ describe('alert_add', () => {
consumer={ALERTS_FEATURE_ID}
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 @@ -38,7 +38,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 @@ -51,8 +53,10 @@ const AlertAdd = ({
alertTypeId,
initialValues,
reloadAlerts,
onSave,
metadata,
}: AlertAddProps) => {
const onSaveHandler = onSave ?? reloadAlerts;
const initialAlert: InitialAlert = useMemo(
() => ({
params: {},
Expand Down Expand Up @@ -128,8 +132,8 @@ const AlertAdd = ({
setIsSaving(false);
if (savedAlert) {
onClose();
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 @@ -39,18 +39,22 @@ export interface AlertEditProps<MetaData = Record<string, any>> {
alertTypeRegistry: AlertTypeRegistryContract;
actionTypeRegistry: ActionTypeRegistryContract;
onClose(): 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 @@ -198,8 +202,8 @@ export const AlertEdit = ({
setIsSaving(false);
if (savedAlert) {
onClose();
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 c94e84a

Please sign in to comment.