Add `fault_or_suspend_on_exception` and `exception_notification_addresses` to Process Model interface and create/update form.

This commit is contained in:
mike cullerton 2023-01-09 13:00:51 -05:00
parent 7edc5b6c1f
commit 03b961b53f
2 changed files with 117 additions and 0 deletions

View File

@ -8,6 +8,8 @@ import {
TextInput, TextInput,
Grid, Grid,
Column, Column,
Select,
SelectItem,
// @ts-ignore // @ts-ignore
} from '@carbon/react'; } from '@carbon/react';
// @ts-ignore // @ts-ignore
@ -76,6 +78,8 @@ export default function ProcessModelForm({
display_name: processModel.display_name, display_name: processModel.display_name,
description: processModel.description, description: processModel.description,
metadata_extraction_paths: processModel.metadata_extraction_paths, metadata_extraction_paths: processModel.metadata_extraction_paths,
fault_or_suspend_on_exception: processModel.fault_or_suspend_on_exception,
exception_notification_addresses: processModel.exception_notification_addresses,
}; };
if (mode === 'new') { if (mode === 'new') {
Object.assign(postBody, { Object.assign(postBody, {
@ -173,6 +177,69 @@ export default function ProcessModelForm({
updateProcessModel({ metadata_extraction_paths: cep }); updateProcessModel({ metadata_extraction_paths: cep });
}; };
const notificationAddressForm = (
index: number,
notificationAddress: string
) => {
return (
<Grid>
<Column md={3} lg={7} sm={1}>
<TextInput
id={`process-model-notification-address-key-${index}`}
labelText="Address"
value={notificationAddress}
onChange={(event: any) => {
const notificationAddresses: string[] =
processModel.exception_notification_addresses || [];
notificationAddresses[index] = event.target.value;
updateProcessModel({
exception_notification_addresses: notificationAddresses,
});
}}
/>
</Column>
<Column md={1} lg={1} sm={1}>
<Button
kind="ghost"
renderIcon={TrashCan}
iconDescription="Remove Address"
hasIconOnly
size="lg"
className="with-extra-top-margin"
onClick={() => {
const notificationAddresses: string[] =
processModel.exception_notification_addresses || [];
notificationAddresses.splice(index, 1);
updateProcessModel({
exception_notification_addresses: notificationAddresses,
});
}}
/>
</Column>
</Grid>
);
};
const notificationAddressFormArea = () => {
if (processModel.exception_notification_addresses) {
return processModel.exception_notification_addresses.map(
(notificationAddress: string, index: number) => {
return notificationAddressForm(index, notificationAddress);
}
);
}
return null;
};
const addBlankNotificationAddress = () => {
const notificationAddresses: string[] =
processModel.exception_notification_addresses || [];
notificationAddresses.push('');
updateProcessModel({
exception_notification_addresses: notificationAddresses,
});
};
const onDisplayNameChanged = (newDisplayName: any) => { const onDisplayNameChanged = (newDisplayName: any) => {
setDisplayNameInvalid(false); setDisplayNameInvalid(false);
const updateDict = { display_name: newDisplayName }; const updateDict = { display_name: newDisplayName };
@ -182,6 +249,11 @@ export default function ProcessModelForm({
updateProcessModel(updateDict); updateProcessModel(updateDict);
}; };
const onNotificationTypeChanged = (newNotificationType: string) => {
const updateDict = { fault_or_suspend_on_exception: newNotificationType };
updateProcessModel(updateDict);
};
const formElements = () => { const formElements = () => {
const textInputs = [ const textInputs = [
<TextInput <TextInput
@ -230,6 +302,49 @@ export default function ProcessModelForm({
/> />
); );
textInputs.push(
<Select
id="notification-type"
defaultValue="fault"
labelText="Notification Type"
onChange={(event: any) => {
onNotificationTypeChanged(event.target.value);
}}
>
<SelectItem value="fault" text="Fault" />
<SelectItem value="suspend" text="Suspend" />
</Select>
);
textInputs.push(<h2>Notification Addresses</h2>);
textInputs.push(
<Grid>
<Column md={8} lg={16} sm={4}>
<p className="data-table-description">
You can provide one or more addresses to notify if this model fails.
</p>
</Column>
</Grid>
);
textInputs.push(<>{notificationAddressFormArea()}</>);
textInputs.push(
<Grid>
<Column md={4} lg={8} sm={2}>
<Button
data-qa="add-notification-address-button"
renderIcon={AddAlt}
className="button-white-background"
kind=""
size="sm"
onClick={() => {
addBlankNotificationAddress();
}}
>
Add Notification Address
</Button>
</Column>
</Grid>
);
textInputs.push(<h2>Metadata Extractions</h2>); textInputs.push(<h2>Metadata Extractions</h2>);
textInputs.push( textInputs.push(
<Grid> <Grid>

View File

@ -146,6 +146,8 @@ export interface ProcessModel {
files: ProcessFile[]; files: ProcessFile[];
parent_groups?: ProcessGroupLite[]; parent_groups?: ProcessGroupLite[];
metadata_extraction_paths?: MetadataExtractionPath[]; metadata_extraction_paths?: MetadataExtractionPath[];
fault_or_suspend_on_exception?: string;
exception_notification_addresses?: string[];
} }
export interface ProcessGroup { export interface ProcessGroup {